Skip to content

Commit

Permalink
Implemented Home and SetHome cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Joscha1234 <[email protected]>
  • Loading branch information
Joscha1234 committed Apr 14, 2013
1 parent b0cc97a commit 1b6f88e
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 33 deletions.
4 changes: 4 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ commands:
description: Unban a Player
timeban:
description: Ban a Player for a specific time
home:
description: Takes you to your Home
sethome:
description: Set your Home
4 changes: 4 additions & 0 deletions src/com/dre/managerxl/LanguageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ private void setDefaults(){
defaults.put("Cmd_Ban_DefaultReason", "Du hast gegen die Regeln verstossen!");
defaults.put("Cmd_TimeBan_Success", "&6Spieler &4&v1&6 wurde erfolgreich für &4&v2&6 gebannt!");
defaults.put("Cmd_UnBan_Success", "&6Spieler &4&v1&6 wurde erfolgreich entbannt!");
defaults.put("Cmd_SetHome_Success", "&6Home wurde gesetzt!");

/* Errors */
defaults.put("Error_NoPermissions","&4Du hast keine Erlaubnis dies zu tun!");
defaults.put("Error_PlayerNotExist","&4Spieler &6&v1&4 existiert nicht!");
defaults.put("Error_CmdBan_AlreadyBanned", "&4Spieler &6&v1&4 ist schon gebannt!");
defaults.put("Error_CmdBan_NotBanned", "&4Spieler &6&v1&4 ist nicht gebannt!");
defaults.put("Error_NoPlayerCommand", "&6/mxl &v1&4 kann man nicht als Spieler ausführen!");
defaults.put("Error_NoPermissions", "&4Du hast keine Erlaubnis dies zu tun!");
defaults.put("Error_CmdNotExist1","&4Befehl &6&v1&4 existiert nicht!");
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!");

/* Format */
defaults.put("Format_Days","Tage");
Expand Down
30 changes: 30 additions & 0 deletions src/com/dre/managerxl/MPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import java.util.HashSet;
import java.util.Set;



import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -61,6 +66,10 @@ public void setBanned(boolean banned){
public void setBannedReason(String bannedReason) {this.bannedReason = bannedReason;}
public String getBannedReason() {return bannedReason;}

private Location home;
public Location getHome() {return home;}
public void setHome(Location home) {this.home = home;}

public MPlayer(String name){
mPlayers.add(this);

Expand Down Expand Up @@ -100,6 +109,14 @@ public static boolean SaveAsYml(File file){
ymlFile.set(player.getName()+".isBanned", player.isBanned());
ymlFile.set(player.getName()+".bannedTime", player.getBannedTime());
ymlFile.set(player.getName()+".bannedReason", player.getBannedReason());

/* Location */
ymlFile.set(player.getName()+".home.x", player.getHome().getX());
ymlFile.set(player.getName()+".home.y", player.getHome().getY());
ymlFile.set(player.getName()+".home.z", player.getHome().getZ());
ymlFile.set(player.getName()+".home.yaw", (int) player.getHome().getYaw());
ymlFile.set(player.getName()+".home.pitch", (int) player.getHome().getPitch());
ymlFile.set(player.getName()+".home.world", player.getHome().getWorld().getName());
}

try {
Expand All @@ -121,6 +138,19 @@ public static boolean LoadAsYml(File file){
mPlayer.setBanned(ymlFile.getBoolean(name+".isBanned"));
mPlayer.setBannedTime(ymlFile.getInt(name+".bannedTime"));
mPlayer.setBannedReason(ymlFile.getString(name+".bannedReason"));

/* Location */
World world = Bukkit.getWorld(ymlFile.getString(name+".home.world"));
if(world != null){
Location loc = new Location(
world,
ymlFile.getDouble(name+".home.x"),
ymlFile.getDouble(name+".home.y"),
ymlFile.getDouble(name+".home.z"),
ymlFile.getInt(name+".home.pitch"),
ymlFile.getInt(name+".home.yaw"));
mPlayer.setHome(loc);
}
}

return true;
Expand Down
4 changes: 4 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,8 @@

import com.dre.managerxl.P;
import com.dre.managerxl.commands.player.Ban;
import com.dre.managerxl.commands.player.Home;
import com.dre.managerxl.commands.player.SetHome;
import com.dre.managerxl.commands.player.TimeBan;
import com.dre.managerxl.commands.player.Unban;

Expand Down Expand Up @@ -71,6 +73,8 @@ public static void initCommands(){
new Ban();
new Unban();
new TimeBan();
new Home();
new SetHome();
}

public static Set<MCommand> get(){
Expand Down
61 changes: 28 additions & 33 deletions src/com/dre/managerxl/commands/MCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,35 @@ public class MCommandExecutor implements CommandExecutor{

@Override
public boolean onCommand(CommandSender sender, Command command, String arg, String[] args) {
if(args.length > 0){
String cmd = args[0];

MCommand mCommand = MCommand.get(command.getName());

if(mCommand != null){
if(sender instanceof ConsoleCommandSender){
if(!mCommand.isConsoleCommand()){
P.p.msg(sender, P.p.getLanguageReader().get("Log_Error_NoConsoleCommand", mCommand.getCommand()));
return false;
}
}

if(sender instanceof Player){
Player player = (Player) sender;
if(!mCommand.isPlayerCommand){
P.p.msg(player, P.p.getLanguageReader().get("Error_NoPlayerCommand", mCommand.command));
return false;
} else {
if(!mCommand.playerHasPermissions(player)){
P.p.msg(player, P.p.getLanguageReader().get("Error_NoPermissions"));
return false;
}
}
}

mCommand.onExecute(args,sender);
} else {
P.p.msg(sender, P.p.getLanguageReader().get("Error_CmdNotExist1",cmd));
P.p.msg(sender, P.p.getLanguageReader().get("Error_CmdNotExist2"));
}
}else{
MCommand.cmdHelp.onExecute(args,sender);
}
MCommand mCommand = MCommand.get(command.getName());

if(mCommand != null){
if(sender instanceof ConsoleCommandSender){
if(!mCommand.isConsoleCommand()){
P.p.msg(sender, P.p.getLanguageReader().get("Log_Error_NoConsoleCommand", mCommand.getCommand()));
return false;
}
}

if(sender instanceof Player){
Player player = (Player) sender;
if(!mCommand.isPlayerCommand){
P.p.msg(player, P.p.getLanguageReader().get("Error_NoPlayerCommand", mCommand.command));
return false;
} else {
if(!mCommand.playerHasPermissions(player)){
P.p.msg(player, P.p.getLanguageReader().get("Error_NoPermissions"));
return false;
}
}
}

mCommand.onExecute(args,sender);
} else {
P.p.msg(sender, P.p.getLanguageReader().get("Error_CmdNotExist1",command.getName()));
P.p.msg(sender, P.p.getLanguageReader().get("Error_CmdNotExist2"));
}

return false;
}
Expand Down
51 changes: 51 additions & 0 deletions src/com/dre/managerxl/commands/player/Home.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.dre.managerxl.commands.player;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.dre.managerxl.MPlayer;
import com.dre.managerxl.P;
import com.dre.managerxl.commands.MCommand;

public class Home extends MCommand{

public Home(){
this.command = "home";
this.parrent = null;
this.help = P.p.getLanguageReader().get("Help_Home");
this.permission = "mxl.cmd.player.home";

this.isConsoleCommand = false;
this.isPlayerCommand = true;

this.init();
}

@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;

if(args.length < 1){
MPlayer mPlayer = MPlayer.getOrCreate(sender.getName());

if (mPlayer.getHome() != null){
player.teleport(mPlayer.getHome());
} else {
P.p.msg(player, P.p.getLanguageReader().get("Error_CmdHome_NoHome"));
}
} else {
MPlayer oPlayer = MPlayer.get(args[0]);
if (oPlayer != null){
if (oPlayer.getHome() != null){
player.teleport(oPlayer.getHome());
} else {
P.p.msg(player, P.p.getLanguageReader().get("Error_CmdHome_NoHome2", args[0]));
}
} else {
P.p.msg(player, P.p.getLanguageReader().get("Error_PlayerNotExist", args[0]));
}
}
}
}


33 changes: 33 additions & 0 deletions src/com/dre/managerxl/commands/player/SetHome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dre.managerxl.commands.player;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.dre.managerxl.MPlayer;
import com.dre.managerxl.P;
import com.dre.managerxl.commands.MCommand;

public class SetHome extends MCommand{

public SetHome(){
this.command = "sethome";
this.parrent = null;
this.help = P.p.getLanguageReader().get("Help_SetHome");
this.permission = "mxl.cmd.player.sethome";

this.isConsoleCommand = false;
this.isPlayerCommand = true;

this.init();
}

@Override
public void onExecute(String[] args, CommandSender sender) {
Player player = (Player) sender;
MPlayer mPlayer = MPlayer.getOrCreate(sender.getName());

mPlayer.setHome(player.getLocation());
P.p.msg(player, P.p.getLanguageReader().get("Cmd_SetHome_Success"));
}

}

0 comments on commit 1b6f88e

Please sign in to comment.