Anonymous avatar Anonymous committed e486ff2

- add gamemode command

Comments (0)

Files changed (4)

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

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

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");

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.