Skip to content

Commit

Permalink
Implemented /gm commands
Browse files Browse the repository at this point in the history
Signed-off-by: Grafe <[email protected]>
  • Loading branch information
Grafe committed Apr 15, 2013
1 parent 810e260 commit 4e28b95
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 6 deletions.
5 changes: 4 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ commands:
kickall:
description: Kick all players
mute:
description: Un/Mute a player
description: Un/Mute a player
gamemode:
aliases: [gm]
description: Set the GameMode of a player
4 changes: 4 additions & 0 deletions src/com/dre/managerxl/LanguageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ private void setDefaults(){
defaults.put("Help_Kick", "/kick <player> [reason] - Kicke einen Spieler");
defaults.put("Help_KickAll", "/kickall [reason] - Kickt alle Spieler");
defaults.put("Help_Mute", "/mute <player> - 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!");
Expand Down Expand Up @@ -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");
Expand Down
25 changes: 25 additions & 0 deletions src/com/dre/managerxl/MPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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"));
Expand All @@ -176,4 +200,5 @@ public static boolean LoadAsYml(File file){

return true;
}

}
2 changes: 2 additions & 0 deletions src/com/dre/managerxl/commands/MCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,7 @@ public static void initCommands(){
new Kick();
new KickAll();
new Mute();
new GameMode();
}

public static Set<MCommand> get(){
Expand Down
64 changes: 64 additions & 0 deletions src/com/dre/managerxl/commands/player/GameMode.java
Original file line number Diff line number Diff line change
@@ -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]));
}
}
}
}

}
7 changes: 2 additions & 5 deletions src/com/dre/managerxl/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand Down

0 comments on commit 4e28b95

Please sign in to comment.