Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
}

}

 

@Mod(stuff, acceptableRemoteVersions = "*")

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Thank you so much! I kind of did know, there will be a very simple solution - I just did not know where to search for it :D

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.