12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package me.km.commands;
- import me.km.api.Utils;
- import me.km.api.GlobalText;
- import me.km.api.Module;
- import me.km.api.ModuleCommand;
- import me.km.exception.PlayerNotFoundException;
- import me.km.permissions.Permission;
- import me.km.permissions.Permissions;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.world.GameType;
- public class CommandGameMode extends ModuleCommand
- {
- public CommandGameMode(Module m)
- {
- super("gamemode", m);
- super.setDescription("Ändert den GameMode eines Spielers");
- super.setUsage("/gamemode <mode> [player]");
- super.setPermission(Permissions.GAMEMODE);
- }
- @Override
- public boolean execute(ICommandSender cs, String[] arg)
- {
- if(arg.length == 0)
- {
- return false;
- }
-
- EntityPlayer affectedPlayer;
- try
- {
- if(arg.length >= 2 && !Permission.has(cs, Permissions.GAMEMODE_OTHER))
- {
- this.getModule().send(cs, "Du darfst nur deinen eigenen GameMode setzen.");
- return true;
- }
- affectedPlayer = Utils.getPlayerByName(arg[1]);
- }
- catch(PlayerNotFoundException ex)
- {
- this.getModule().send(cs, GlobalText.cantFindPlayer(arg[1]));
- return true;
- }
- catch(IndexOutOfBoundsException ex)
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.missingParameter());
- return true;
- }
- affectedPlayer = (EntityPlayer) cs;
- }
- String mode;
- switch (arg[0].toLowerCase())
- {
- case "survival":
- case "s":
- case "0":
- affectedPlayer.setGameType(GameType.SURVIVAL);
- mode = "Survival";
- break;
- case "creative":
- case "c":
- case "1":
- affectedPlayer.setGameType(GameType.CREATIVE);
- mode = "Creative";
- break;
- case "adventure":
- case "a":
- case "2":
- affectedPlayer.setGameType(GameType.ADVENTURE);
- mode = "Adventure";
- break;
- case "specator":
- case "w":
- case "3":
- affectedPlayer.setGameType(GameType.SPECTATOR);
- mode = "Spectator";
- break;
- default:
- affectedPlayer.setGameType(GameType.CREATIVE);
- mode = "Creative";
- break;
- }
- this.getModule().send(affectedPlayer, "Du hast nun Gamemode " + mode + ".");
- if(!cs.equals(affectedPlayer))
- {
- this.getModule().send(cs, affectedPlayer.getName() + " hat nun Gamemode " + mode + ".");
- }
- return true;
- }
- }
|