Jump to content

Permission for commands


Ottoguy
 Share

Recommended Posts

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

 

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

 Share



×
×
  • Create New...

Important Information

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