As stated in the Title I think that an FMLClientSetupEvent is Fired on a Forge-Minecraft dedicated Server. Forge Versions should be the same. All in all, this leads to the Error
java.lang.RuntimeException: Attempted to load class net/minecraft/client/renderer/entity/EntityRenderer for invalid dist DEDICATED_SERVER
I figured out that this is due to the CustomRender class which is a subclass of EntityRenderer.
When deleting the line "RenderingRegistry.registerEntityRend..." where I register the CustomRender the Server starts just fine.
Any ideas on that? I'm really not getting it myself because I can't debug the server app.
Documentation of FMLClientSetupEvent: https://mcforge.readthedocs.io/en/latest/conventions/loadstages/
My Code:
#Mod(Utils.MOD_ID)
public class Main {
public Main() {
ModItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
ModSounds.SOUNDS.register(FMLJavaModLoadingContext.get().getModEventBus());
ModEntityType.ENTITY_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::serverSetup);
}
private void commonSetup(FMLCommonSetupEvent evt) {
}
private void clientSetup(FMLClientSetupEvent evt) {
Phaser.arrow = ModEntityType.LASERSTRAHL_ENTITY.get();
RenderingRegistry.registerEntityRenderingHandler(Phaser.arrow, renderManager -> new CustomRender(renderManager));
}
private void serverSetup(FMLDedicatedServerSetupEvent evt) {
}
}
I figured it out. The event isn't fired but apparently the Server doesn't like the EntityRenderer class being imported. So i made a new class for client setup stuff and called that after the FMLClientSetupEvent.
Related
So I just started playing around with JDA API trying to create a little /info command which looked like shown below.
Issue: Unfortunately the bot does not react when I type /info.
While I was debugging, I found out, that the Info command never get's called and I will explain why later, after showing you the 3 classes that are involved in this problem.
public class InfoCommand extends Command {
public InfoCommand(String name) {
super(name);
}
#Override
public void handle(MessageReceivedEvent event, String... params) {
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("Test Title");
builder.setDescription("Test Description" );
builder.setFooter("Created by t0gepi");
builder.setColor(0xf45642);
event.getChannel().sendTyping().queue();
event.getChannel().sendMessageEmbeds(builder.build()).queue();
}
}
It has a method handle which will be called by a CommandManager, whenever /info is typed in the discord server.
So far so good.
Now the Main method is also quite simple. It just starts the bot and adds the CommandManager as a Listener to JDA:
public class Main {
public static JDA jda;
public static void main(String[] args) throws LoginException {
ResourceManager.init();
jda = JDABuilder.createDefault(ResourceManager.getProperty("discord.bottoken")).build();
jda.getPresence().setStatus(OnlineStatus.IDLE);
jda.getPresence().setActivity(Activity.playing("Sleeping"));
try {
jda.awaitReady();
} catch (InterruptedException e) {
e.printStackTrace();
}
CommandManager commandManager = new CommandManager();
commandManager.addCommand(new InfoCommand("info"));
jda.addEventListener(new CommandManager());
}
}
Lastly, let's get to the CommandManager:
public class CommandManager extends ListenerAdapter {
private Set<Command> commands;
public CommandManager(){
this.commands = new HashSet<>();
}
public void addCommand(Command command){
commands.add(command);
}
#Override
public void onMessageReceived(#NotNull MessageReceivedEvent event) {
String[] msg = event.getMessage().getContentRaw().split(" ");
String prefix = ResourceManager.getProperty("command.prefix");
String[] params = null;
if(!msg[0].startsWith(prefix)){
return;
}
if(msg.length > 1){
params = Arrays.copyOfRange(msg,1,msg.length);
}
Iterator<Command> iterator = commands.iterator();
Command command;
while(iterator.hasNext()){
command = iterator.next();
if(command.getAliases().stream().anyMatch(alias -> msg[0].equalsIgnoreCase(prefix + alias))){
command.handle(event, params);
return;
}
}
// Do nothing here if command wasn't found.
}
}
Now let's get to the actual issue, why does the InfoCommands handle method not get called? Keep in mind that
InfoCommand has bin initialized and added to the CommandManager
The CommandManagers onMessageReceived method is in fact being called when a message is typed
As I was debugging, I found out why but could not find an explanation to it.
The reason why the handle method of InfoCommand does not get called, is because as to the time when onMessageReceived gets called, the CommandManagers set of commands is empty.
Why is that? I added the InfoCommand in the beginning right?
When I added the InfoCommand in the beginning, the set of commands had a size of 1. All good. But when onMessageReceived got called, the set of Commands suddenly had a size of 0, which means that the Iterator doesn't have anything to iterate over.
Why is that? I furthermore found out the following:
As to the time where I initialized the CommandManager, the CommandManager had a different memory adress than when it's onMessageReceived method got called.
So somehow, JDA must have created another new instance of CommandManager and used that, instead of my instance, right?
I hope someone understands this and let me know if you have any questions :)
Thanks for reading that far and if you'd like, you can take a better look at all the files in this Project here. There really aren't much more.
You are creating a new instance of your command manager when you register it:
jda.addEventListener(new CommandManager());
Instead, you should just pass in the instance you previously created:
CommandManager commandManager = new CommandManager();
commandManager.addCommand(new InfoCommand("info"));
jda.addEventListener(commandManager);
I have a problem and am new at making Minecraft plugins and writing code in general.
I am trying to make a plugin that waits about 15 seconds before executing the second command however the code I have now has an error when I try to do (plugin, new Runnable(). I have done some research and it most people say that is because I don't have this in my Main class. The problem is that I don't want it in my Main. So I was wondering what I have to do to make this work.
Code below. Thanks in advance for any help you can provide.
~Stone
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player){
//checks to see if player sent command
Player player = (Player) sender;
if (args.length >= 1) {
//too many arguments message
player.sendMessage(Utils.chat("&4There were too many arguments, I could not complete that command"));
}
if (player.hasPermission("reloadc.use")) {
//reloads server, sends message, and stores variable value
Bukkit.broadcastMessage(Utils.chat("&6Server will be reloaded in 15 seconds by &5" + player.getDisplayName()));
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Bukkit.broadcastMessage(Utils.chat("&6This works"));
}
}, 20L);
Bukkit.broadcastMessage(Utils.chat("&6IT WORKED!!!!!"));
}
else if (!player.hasPermission("reloadc.use")) {
player.sendMessage(Utils.chat("&4You do not have permission to reload the server"));
player.sendMessage(Utils.chat("&5If you belive this is a mistake please contact an admin"));
}
}
return true;
}
}
The Code that is giving me problems is right here (the word plugin)
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
Bukkit.broadcastMessage(Utils.chat("&6This works"));
}
}, 20L);
Here are 3 images with the errors that it is giving me. The only change that i did not make was the getServer(). because it gave me more errors and did not change anything for the better at least from what I can tell.
1[]2
[]
Ok So I have completed the changes, everything says that it works but now when I run the command that I setup it does everything it should except wait for 15 seconds. It executes the text one after the other telling me that it will be reloaded in 15 seconds and then at the same time it tells me it worked. Nothing seems wrong to me now, it just says that it is running fine and my wait time is 300L which is server ticks. That should equal 15.
Images of completed code below.
In response to your update/edit:
Your error happens because you use plugin does not mean anything to your code. You need to declare it as a variable before you use in there, or assuming that you wrote all the code in one class for your plugin then you can easily replace plugin with this like so Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {.
If it is in another class then to declare the variable you need to pass it in from another class or call it from your Main plugin class. The following will show you haw to pass it to your listener class.
In your main plugin class you need to do this, note how we add this to the function that is calling your command class new CommandClass(this) note that your class will have a different name than CommandClass:
public class Main extends JavaPlugin{
#Override
public void onEnable(){
new CommandClass(this);
}
}
And then in the command class, we modify it to receive the variable public CommandClass(Main plugin):
public class CommandClass implements CommandExecutor{
private Main plugin;
public CommandClass(Main plugin){
this.plugin = plugin;
}
}
Now your onCommand method will work because you have a reference to plugin in your class:
#Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
#Override
public void run() {
Bukkit.broadcastMessage(Utils.chat("&6This works"));
}
}, 300L);
}
Original answer edited a little to include some of the response to your screenshots:
I can see four problems:
Your error happens because you have not referenced your actual plugin, but just typed plugin.
Please note that the delay is in server ticks, so 20L will only have
a delay of 1 second. If you want 15 seconds delay then use 300L.
You didn't use the #Override annotation, but it is very important for the runnable task.
You could use getServer().getScheduler() instead of Bukkit.getScheduler(), just in case there is something funky going on with your code and you have managed to start more than one instance of the server.
Here is an updated version of your code with 1 and 3 fixed:
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
#Override
public void run() {
Bukkit.broadcastMessage(Utils.chat("&6This works"));
}
}, 300L);
Here is an updated version of your code with suggestion 4 included:
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
#Override
public void run() {
Bukkit.broadcastMessage(Utils.chat("&6This works"));
}
}, 300L);
I created a config file for my plugin and I'm trying to get the PlayerJoinEvent to work so that when they join they will be displayed the message that is set in the config. When they join, no message is displayed though.
Code:
#EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
String welcomeMessage = ChatColor.translateAlternateColorCodes('&',
plugin.getConfig().getString("Message"));
p.sendMessage(welcomeMessage);
}
Config:
Message: '&4did it work?'
And this part isn't as neccessary but incase you are wondering I have added this portion of the code for the config
private void registerConfig() {
getConfig().options().copyDefaults(true);
saveConfig();
}
Did you register your EventHandler on the PluginManager?
You can achieve this by placing the following code in your plugins onEnable() method:
getServer().getPluginManager().registerEvent(new MyPlayerJoinListener(), this);
Hope it helps!
I am searching a listener in Eclipse, that will detect if a file is changed externally by third party software, like MKS.
I used IResourceChangeListener and it worked. But problem is, it also listens other changes of the file. For example, when I delete the markers, it also listens and execute the codes I wanted after listening.
Is there any Listener, which listens only if the file is changed (newly opened/refreshed) by third party software?
Updated:
My code:
public class Startup implements IStartup {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
if(event.getType() == IResourceChangeEvent.POST_CHANGE && IResourceDelta.MARKERS!=0){ //Filtering listener
System.out.println("Listener code should be implemented here");
}
System.out.println("listener is working"); //This line always get executed. That means the listener is working
}
};
#Override
public void earlyStartup() {
workspace.addResourceChangeListener(listener,IResourceChangeEvent.POST_CHANGE);
//... some time later one ...
// workspace.removeResourceChangeListener(listener);
}
}
My Activity is implementing OnInvitationReceivedListener along with all the other game services items. It requires that I have the onInvitationReceived function implemented (i.e. gives an error if I don't) so that's good. The problem is, I can send my account an invite and it will not call the onInvitationReceived function. The other listeners work and I can start a game and whatnot by opening the invitation list and accepting it, but this function simply never gets called. It should also consume the event but I still get an external notification as well.
Am I missing something? Is it not as simple as the below? All the other listeners work...
public class MyActivity extends BaseGameActivity
implements View.OnClickListener, RealTimeMessageReceivedListener,
RoomStatusUpdateListener, RoomUpdateListener, OnInvitationReceivedListener
{
public MyActivity(){...}
...
public void onInvitationReceived(Invitation arg0)
{
Log.v("meh", "Invitation Received");
}
}
Are you registering MyActivity for the callback?
Since you are using BaseGameActivity, try putting this in your post-connection callback:
getGamesClient().registerInvitationListener(this);
I'm somewhat surprised that this isn't done for you, but in looking at the BaseGameActivity class I don't see it.
I was having similar issues. (I still haven't cracked the code on the invite Bundle not being null everytime I start up the service... even when there are invitations waiting...)
From here Previous StackOverflow issue for Invitaion Listener I did get the issue mostly solved. (in that i do get notifications in my app code that a new invite has come in) However, there is nothing to tell you if an invite has been rescinded...
So, I also run a Timer and do this in my code:
#Override
public void loadInvitations(){
mHelper.getGamesClient().loadInvitations(new OnInvitationsLoadedListener() {
#Override
public void onInvitationsLoaded(int statusCode, InvitationBuffer buffer) {
dLog("invitations loaded " + buffer.getCount());
if(mHelper.getGamesClient().STATUS_OK == statusCode && buffer.getCount() > 0){
if(mGHInterface != null){
mGHInterface.haveInvitations(buffer.getCount());
}
} else if (mGHInterface != null){
mGHInterface.haveInvitations(0);
}
}
});
}
Up to you on how often you want to run this, but this way I have found that at least I do know if invitations exist or not, and update my app's actions accordingly.