Jump to content

Custom Server Commands


xxxgamer

Recommended Posts

Hi guys,

 

Just downloaded and got everything set up and wondering could someone please give me some pointers to how to create new custom server side commands that I can type into the chat. I am currently looking at the Commandkill.java class along with all the other CommandServer classes but still a bit confussed.

 

How would I get a hook into displaying how many drops are currently in the world?

 

Appreciate any help!

Link to comment
Share on other sites

I recommend taking a look at this: http://www.minecraftforum.net/topic/1419836-131-forge-4x-events-howto/ to get some grounding on using events and event hooks.

 

As for creating commands your new command class should inherit from "CommandBase" and should be registered in the Server Command Manager after initialisation.

 

Something like this:

MinecraftServer server = ModLoader.getMinecraftServerInstance();
ICommandManager commandManager = server.getCommandManager();
ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);
serverCommandManager.registerCommand(new YourCommand());

If I helped you, thank me. If I didn't, let me know.

Link to comment
Share on other sites

Thank you very much both of you!

 

One last question and I am aware this is probably covered in a few areas somewhere, Once I have my extra command for the server I can just compile it and then drop "only" that package onto the server? So I dont need to upload a full new server.jar correct? (I dont want an answer explaining how to, I can look that up, just if that is the way its done, So similar to bukkit where you just drop your extra files onto the server?)

 

Thanks again guys!

Link to comment
Share on other sites

Yes! you basically can. Do some digging on the wiki and find wuppy's tutorials and then the one about releasing a mod. All that is needed is a recompile,reobfuscate and then zip your package for release to be dropped into the mods folder. As I said the tutorial will tell you what you need.

If I helped you, thank me. If I didn't, let me know.

Link to comment
Share on other sites

Thanks Jammas, Making progress, Have registered the events and I can see them doing exactly what I want on the server, but now my client crashes due to this line:

 

ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);

 

How do I specify that I ONLY want these files loaded on the server? The client does not needs these files as it is only command server side.

 

Thanks again mate.

 

Link to comment
Share on other sites

No worries.

 

Are you using the @NetworkMod annotation?

@NetworkMod(clientSideRequired = false, serverSideRequired = false)

It should come just after the @Mod.

 

Is that what you were asking? I'm not too sure.

 

But if you could also post what error you're getting upon the crash that would be sweet.

 

 

If I helped you, thank me. If I didn't, let me know.

Link to comment
Share on other sites

Yep have that in there, I could actually launch the client and use the ingame server commands and all off a sudden it started crashing.

 

Full Error is:

 

 

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader]

mcp [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized

FML [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized

Forge [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized

worldDropsCheck [World Drops Checker] (bin) Unloaded->Constructed->Pre-initialized->Errored

worldDropsRemove [World Drops Checkesr] (bin) Unloaded->Constructed->Pre-initialized->Errored

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] The following problems were captured during this phase

2012-12-11 21:50:11 [sEVERE] [ForgeModLoader] Caught exception from worldDropsCheck

java.lang.NullPointerException

at maxedgaming.worldDropsCheck.worldDropsCheck.init(worldDropsCheck.java:42)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:440)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)

at com.google.common.eventbus.EventBus.post(EventBus.java:268)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:651)

at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:197)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:469)

at net.minecraft.client.Minecraft.run(Minecraft.java:756)

at java.lang.Thread.run(Unknown Source)

 

 

And the lines specific to that are:

 

 

@Init

public void init(FMLInitializationEvent event) {

MinecraftServer server = ModLoader.getMinecraftServerInstance();

ICommandManager commandManager = server.getCommandManager();

ServerCommandManager serverCommandManager = ((ServerCommandManager)commandManager);

serverCommandManager.registerCommand(new worldDropsCheck());

}

 

 

Where ICommandManager commandManager = server.getCommandManager();  is line 42.

 

Edit: Just to make it clearer, I only want to have these files on the server, I'm sure the client doesn't need any of these as I am just working with server instance and processing commands which shouldn't be files required on a client level correct?

Link to comment
Share on other sites

Yes, if your NetworkMod annotation shows that the client does not need the mod files to join a server you are fine.

 

Now, preInit, init, and positInit all happen before the server is actually started. So, when you set up all you commands and register them with the managers no instance of the server exists. The null pointer exception means that commandManager is trying to access a null object that does not exist. This is because the server instance had not been started when you set up all your commands.

 

To fix this, you need to put all your command initialisation inside another method with the annotation @ServerStarting or @ServerStarted.

 

Let me know if you understand what I mean?

If I helped you, thank me. If I didn't, let me know.

Link to comment
Share on other sites

Oh I realize I might have been a bit unclear, 'FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dimension).loadedEntityList.size();' will return all entities, including mobs, If you only want item drops, you can iterate and count the EntityItems:

int count = 0;
List list = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(dimension).loadedEntityList;
for(Entity entity: (List<Entity>)list){
if(entity != null && entity instanceof EntityItem){
count++;
}
}

count would then have the item drop count. I just typed that off the top of my head, so it may have mistakes.

Link to comment
Share on other sites

Hey guys,

 

I have everything working when I launch the client/server through eclipse but when I want to move the mod over to my live server it crashes, Have posted a new topic for new problem:

 

http://www.minecraftforge.net/forum/index.php/topic,4024.0.html

 

Would appreciate it if ye could help me out to get me up and running on a live server :) Thanks guys.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm using Modrinth as a launcher for a forge modpack on 1.20.1, and can't diagnose the issue on the crash log myself. Have tried repairing the Minecraft instillation as well as removing a few mods that have been problematic for me in the past to no avail. Crash log is below, if any further information is necessary let me know. Thank you! https://paste.ee/p/k6xnS
    • Hey folks. I am working on a custom "Mecha" entity (extended from LivingEntity) that the player builds up from blocks that should get modular stats depending on the used blocks. e.g. depending on what will be used for the legs, the entity will have a different jump strength. However, something unexpected is happening when trying to override a few of LivingEntity's functions and using my new own "Mecha" specific fields: instead of their actual instance-specific value, the default value is used (0f for a float, null for an object...) This is especially strange as when executing with the same entity from a point in the code specific to the mecha entity, the correct value is used. Here are some code snippets to better illustrate what I mean: /* The main Mecha class, cut down for brevity */ public class Mecha extends LivingEntity { protected float jumpMultiplier; //somewhere later during the code when spawning the entity, jumpMultiplier is set to something like 1.5f //changing the access to public didn't help @Override //Overridden from LivingEntity, this function is only used in the jumpFromGround() function, used in the aiStep() function, used in the LivingEntity tick() function protected float getJumpPower() { //something is wrong with this function //for some reason I can't correctly access the fields and methods from the instanciated entity when I am in one of those overridden protected functions. this is very annoying LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 0f return this.jumpMultiplier * super.getJumpPower(); } //The code above does not operate properly. Written as is, the entity will not jump, and adding debug logs shows that when executing the code, the value of this.jumpMultiplier is 0f //in contrast, it will be the correct value when done here: @Override public void tick() { super.tick(); //inherited LivingEntity logic //Custom logic LogUtils.getLogger().info(String.valueOf(this.jumpMultiplier))) //will print 1.5f } } My actual code is slightly different, as the jumpMuliplier is stored in another object (so I am calling "this.legModule.getJumpPower()" instead of the float), but even using a simple float exactly like in the code above didn't help. When running my usual code, the object I try to use is found to be null instead, leading to a crash from a nullPointerException. Here is the stacktrace of said crash: The full code can be viewed here. I have found a workaround in the case of jump strength, but have already found the same problem for another parameter I want to do, and I do not understand why the code is behaving as such, and I would very much like to be able to override those methods as intended - they seemed to work just fine like that for vanilla mobs... Any clues as to what may be happening here?
    • Please delete post. Had not noticed the newest edition for 1.20.6 which resolves the issue.
    • https://paste.ee/p/GTgAV Here's my debug log, I'm on 1.18.2 with forge 40.2.4 and I just want to get it to work!! I cant find any mod names in the error part and I would like some help from the pros!! I have 203 mods at the moment.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.