Commits

zzzeek  committed e486ff2

- add gamemode command

  • Participants
  • Parent commits f060853

Comments (0)

Files changed (4)

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/ZeekTools.java

 import org.bukkit.util.config.Configuration;
 
 import com.zzzcomputing.bukkit.ZeekTools.commands.DestroyCommand;
+import com.zzzcomputing.bukkit.ZeekTools.commands.GameModeCommand;
 import com.zzzcomputing.bukkit.ZeekTools.commands.GiveCommand;
 import com.zzzcomputing.bukkit.ZeekTools.commands.GotoCommand;
 import com.zzzcomputing.bukkit.ZeekTools.commands.HelpCommand;
         if ("give".equals(cmd)) {
             new GiveCommand(this, player).execute(cmd, args);
         }
+        else if ("mode".equals(cmd)) {
+            new GameModeCommand(this, player).execute(cmd, args);
+        }
         else if ("destroy".equals(cmd)) {
             new DestroyCommand(this, player).execute(cmd, args);
         }

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/commands/GameModeCommand.java

+package com.zzzcomputing.bukkit.ZeekTools.commands;
+
+import org.bukkit.GameMode;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class GameModeCommand extends Command {
+    public GameModeCommand(JavaPlugin plugin, Player player) {
+        super(plugin, player);
+        // TODO Auto-generated constructor stub
+    }
+
+    @Override
+    public void execute(String command, String[] args) {
+        GameMode gm = player.getGameMode();
+        if (gm == GameMode.CREATIVE) {
+            gm = GameMode.SURVIVAL;
+        }
+        else {
+            gm = GameMode.CREATIVE;
+        }
+        player.setGameMode(gm);
+        this.sendPlayerMessage(String.format("Game mode toggled to '%s'", gm));        
+    }
+
+    
+}

File src/main/java/com/zzzcomputing/bukkit/ZeekTools/commands/HelpCommand.java

         sendPlayerMessage(ChatColor.WHITE, "/goto player <player> - goto player position");
         sendPlayerMessage(ChatColor.WHITE, "/goto spawn - goto spawn point/bed");
         sendPlayerMessage(ChatColor.WHITE, "/destroy - empty out the currently selected item stack");
+        sendPlayerMessage(ChatColor.WHITE, "/mode - Toggle current gamemode");
         sendPlayerMessage(ChatColor.WHITE, "/listwp - list waypoints");
         sendPlayerMessage(ChatColor.WHITE, "/setwp <waypoint> - set waypoint");
         sendPlayerMessage(ChatColor.WHITE, "/delwp <waypoint> - delete waypoint");

File src/main/resources/plugin.yml

     give:
         description: Give item.  Will give the max unless [num] given.
         usage: give <name_or_id> [num]
+    mode:
+        description: Toggle player's game mode
+        usage: gamemode
     destroy:
         description: clear out the current item stack
         usage: destroy