Jump to content

[1.7.10] Run Mod on Server only


Mavi

Recommended Posts

Hi everyone.

 

I am new to Minecraft Forge. I am used to java and know how to create programs.

 

But I struggle with one little thing: I want to create a mod running on the server only. It is very basic: whenever someone uses a /-command, a random quote is printed to the chat (to all players). Unfortunately I do not know how to disable the check, if the mod is installed on the client side. Any help is appreciated. My mod looks like this:

 

My Controll class:

 

package my.commandcontroll;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLServerStartingEvent;

@Mod(modid="CommandControll", name="My Command Controll", version="0.1")
public class CommandControll{

@Instance(value="CommandControll")
public static CommandControllinstance;

@EventHandler
public void serverLoad(FMLServerStartingEvent event)
{
	event.registerServerCommand(new MyCommand());
}

}

 

 

My Command class:

 

package my.commandcontroll;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;

public class MyCommand implements ICommand 
{
private List aliases;
private List<String> quotes;
private Random random;

public MyCommand()
{
	this.aliases = new ArrayList();
	this.aliases.add("mycommandtext");

	random = new Random();

	quotes= new ArrayList<String>();
	quotes.add("some text");
	quotes.add("some other text");
}

@Override
public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) 
{
	int i = random.nextInt(strafen.size());
	EntityPlayer player = (EntityPlayer) p_71515_1_;
	MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(player.getDisplayName() + " -> " + qoutes.get(i)));

}

@Override
public int compareTo(Object o) {
	return 0;
}

@Override
public String getCommandName() {
	return "mycommandtext";
}

@Override
public String getCommandUsage(ICommandSender p_71518_1_) {
	return "mycommandtext";
}

@Override
public List getCommandAliases() {
	return this.aliases;
}

@Override
public boolean canCommandSenderUseCommand(ICommandSender p_71519_1_) {
	return true;
}

@Override
public List addTabCompletionOptions(ICommandSender p_71516_1_,
		String[] p_71516_2_) {
	return null;
}

@Override
public boolean isUsernameIndex(String[] p_82358_1_, int p_82358_2_) {
	return false;
}

}

 

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



×
×
  • Create New...

Important Information

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