I want a command to be accessible by all players on a server as well as in single player. But I only manage to use the command if I'm an OP or allow a local server to use cheats. Could you help me out here?
The code in my command class:
package com.ottoguy.pointsmodmain.command;
import net.minecraft.block.Block;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.client.IClientCommand;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.server.permission.PermissionAPI;
public class CommandChooseTeam extends CommandBase{
@Override
public String getName() {
// TODO Auto-generated method stub
return "points";
}
@Override
public String getUsage(ICommandSender sender) {
// TODO Auto-generated method stub
return "Used for choosing team in points mod";
}
@Override
public int getRequiredPermissionLevel()
{
return 0;
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
World world = sender.getEntityWorld();
if (world.isRemote) {
System.out.println("Processing on the client side");
}else {
System.out.println("Processing on the server side");
EntityPlayerMP player = getCommandSenderAsPlayer(sender);
if(args[0].equals("red")) {
int count = 1;
while (count < 64) {
String itemName = "minecraft:red_flower";
ItemStack itemstack = new ItemStack(getItemByText(sender, "minecraft:red_flower"));
player.inventory.addItemStackToInventory(itemstack);
count++;
}
}else if(args[0].equals("blue")) {
int count = 0;
while (count < 12) {
String itemName = "minecraft:lapis_ore";
ItemStack itemstack = new ItemStack(getItemByText(sender, "minecraft:lapis_ore"));
player.inventory.addItemStackToInventory(itemstack);
count++;
}
}
}
}
}