diff --git a/plugin.yml b/plugin.yml index d7e7dd2..e8d885b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -19,4 +19,7 @@ commands: kickall: description: Kick all players mute: - description: Un/Mute a player \ No newline at end of file + description: Un/Mute a player + gamemode: + aliases: [gm] + description: Set the GameMode of a player \ No newline at end of file diff --git a/src/com/dre/managerxl/LanguageReader.java b/src/com/dre/managerxl/LanguageReader.java index 297cabe..f77f27a 100644 --- a/src/com/dre/managerxl/LanguageReader.java +++ b/src/com/dre/managerxl/LanguageReader.java @@ -51,11 +51,14 @@ private void setDefaults(){ defaults.put("Help_Kick", "/kick [reason] - Kicke einen Spieler"); defaults.put("Help_KickAll", "/kickall [reason] - Kickt alle Spieler"); defaults.put("Help_Mute", "/mute - Muted einen Spieler"); + defaults.put("Help_GameMode", "/gamemode [player] [mode] - Setzt/Wechselt den GameMode eines Spielers"); /* Player */ defaults.put("Player_Kick_Ban", "&4Du wurdest gebannt. Grund: &6&v1"); defaults.put("Player_Kick_TimeBan", "&4Du wurdest gebannt für &6&v2&4. Grund: &6&v1"); defaults.put("Player_Muted", "&4Du bist gemuted!"); + defaults.put("Player_GameModeChanged", "&6Dein GameMode hat sich in &4&v1&6 geändert!"); + defaults.put("Player_TargetGameModeChanged", "&4&v2's&6 GameMode hat sich in &4&v1&6 geändert!"); /* CMDs */ defaults.put("Cmd_Ban_Success", "&6Spieler &4&v1&6 wurde erfolgreich gebannt!"); @@ -83,6 +86,7 @@ private void setDefaults(){ defaults.put("Error_CmdNotExist2","&4Bitte gib &6/mxl help&4 für Hilfe ein!"); defaults.put("Error_CmdHome_NoHome","&4Du hast noch kein Home gesetzt. Benutze bitte zuerst &6/sethome&4!"); defaults.put("Error_CmdHome_NoHome2","&6&v1&4 hat noch kein Home gesetzt!"); + defaults.put("Error_CmdGameMode_NotExist","&4GameMode &6&v1&4 existiert nicht!"); /* Format */ defaults.put("Format_Days","Tage"); diff --git a/src/com/dre/managerxl/MPlayer.java b/src/com/dre/managerxl/MPlayer.java index 459e471..b376792 100644 --- a/src/com/dre/managerxl/MPlayer.java +++ b/src/com/dre/managerxl/MPlayer.java @@ -74,6 +74,24 @@ public void setBanned(boolean banned){ public boolean isMuted() {return isMuted;} public void setMuted(boolean isMuted) {this.isMuted = isMuted;} + private int gameMode = 0; + public int getGameMode() {return gameMode;} + public boolean setGameMode(int gameMode) { + org.bukkit.GameMode gm = org.bukkit.GameMode.getByValue(gameMode); + if(gm != null){ + this.gameMode = gameMode; + + if(this.getPlayer() != null){ + this.getPlayer().setGameMode(gm); + P.p.msg(this.getPlayer(), P.p.getLanguageReader().get("Player_GameModeChanged", gm.name())); + } + + return true; + } + + return false; + } + public MPlayer(String name){ mPlayers.add(this); @@ -122,6 +140,9 @@ public static boolean SaveAsYml(File file){ /* Mute */ ymlFile.set(player.getName()+".isMuted", player.isMuted()); + /* GameMode */ + ymlFile.set(player.getName()+".GameMode", player.getGameMode()); + /* Home */ if(player.getHome() != null){ ymlFile.set(player.getName()+".home.x", player.getHome().getX()); @@ -158,6 +179,9 @@ public static boolean LoadAsYml(File file){ /* Mute */ mPlayer.setMuted(ymlFile.getBoolean(name+".isMuted")); + /* GameMode */ + mPlayer.setGameMode(ymlFile.getInt(name+".GameMode")); + /* Location */ if(ymlFile.contains(name+".home")){ World world = Bukkit.getWorld(ymlFile.getString(name+".home.world")); @@ -176,4 +200,5 @@ public static boolean LoadAsYml(File file){ return true; } + } diff --git a/src/com/dre/managerxl/commands/MCommand.java b/src/com/dre/managerxl/commands/MCommand.java index 605cb9f..7518b71 100644 --- a/src/com/dre/managerxl/commands/MCommand.java +++ b/src/com/dre/managerxl/commands/MCommand.java @@ -8,6 +8,7 @@ import com.dre.managerxl.P; import com.dre.managerxl.commands.player.Ban; +import com.dre.managerxl.commands.player.GameMode; import com.dre.managerxl.commands.player.Home; import com.dre.managerxl.commands.player.Kick; import com.dre.managerxl.commands.player.KickAll; @@ -81,6 +82,7 @@ public static void initCommands(){ new Kick(); new KickAll(); new Mute(); + new GameMode(); } public static Set get(){ diff --git a/src/com/dre/managerxl/commands/player/GameMode.java b/src/com/dre/managerxl/commands/player/GameMode.java new file mode 100644 index 0000000..1c04e65 --- /dev/null +++ b/src/com/dre/managerxl/commands/player/GameMode.java @@ -0,0 +1,64 @@ +package com.dre.managerxl.commands.player; + +import org.bukkit.command.CommandSender; + +import com.dre.managerxl.MPlayer; +import com.dre.managerxl.P; +import com.dre.managerxl.commands.MCommand; +import com.dre.managerxl.util.MUtility; + +public class GameMode extends MCommand{ + + public GameMode(){ + this.command = "gamemode"; + this.parrent = null; + this.help = P.p.getLanguageReader().get("Help_GameMode"); + this.permission = "mxl.cmd.player.gamemode"; + + this.isConsoleCommand = false; + this.isPlayerCommand = true; + + this.init(); + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + MPlayer player = MPlayer.getOrCreate(sender.getName()); + + if(player.getPlayer() != null){ + if(args.length < 1){ + if(player.getGameMode() == 1){ + player.setGameMode(0); + } else { + player.setGameMode(1); + } + } else { + MPlayer targetPlayer = MPlayer.get(args[0]); + if(targetPlayer != null){ + if(args.length < 2){ + if(targetPlayer.getGameMode() == 1){ + targetPlayer.setGameMode(0); + } else { + targetPlayer.setGameMode(1); + } + + if(targetPlayer != player){ + P.p.msg(sender, P.p.getLanguageReader().get("Player_TargetGameModeChanged", org.bukkit.GameMode.getByValue(targetPlayer.getGameMode()).name(), targetPlayer.getName())); + } + } else { + if(targetPlayer.setGameMode(MUtility.parseInt(args[1]))){ + if(targetPlayer != player){ + P.p.msg(sender, P.p.getLanguageReader().get("Player_TargetGameModeChanged", org.bukkit.GameMode.getByValue(targetPlayer.getGameMode()).name(), targetPlayer.getName())); + } + } else { + P.p.msg(sender, P.p.getLanguageReader().get("Error_CmdGameMode_NotExist", args[1])); + } + } + } else { + P.p.msg(sender, P.p.getLanguageReader().get("Error_PlayerNotExist", args[0])); + } + } + } + } + +} diff --git a/src/com/dre/managerxl/listeners/PlayerListener.java b/src/com/dre/managerxl/listeners/PlayerListener.java index 3ef364d..db2b9af 100644 --- a/src/com/dre/managerxl/listeners/PlayerListener.java +++ b/src/com/dre/managerxl/listeners/PlayerListener.java @@ -31,13 +31,10 @@ public void onPlayerLogin(PlayerLoginEvent event){ @EventHandler() public void onPlayerJoin(PlayerJoinEvent event){ - MPlayer player = MPlayer.get(event.getPlayer().getName()); - - if(player == null){ - player = new MPlayer(event.getPlayer().getName()); - } + MPlayer player = MPlayer.getOrCreate(event.getPlayer().getName()); player.setOnline(true); + player.setGameMode(player.getGameMode()); }