-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Ban command + functionality added Player save and load function Signed-off-by: Grafe <[email protected]>
- Loading branch information
Showing
9 changed files
with
532 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.dre.managerxl; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
public class MPlayer { | ||
private static Set<MPlayer> mPlayers = new HashSet<MPlayer>(); | ||
|
||
private String name; | ||
public String getName() {return name;} | ||
|
||
public Player getPlayer(){ | ||
if(this.isOnline){ | ||
return P.p.getServer().getPlayer(this.name); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private boolean isOnline; | ||
public boolean isOnline() {return isOnline;} | ||
public void setOnline(boolean online) {isOnline = online;} | ||
|
||
private boolean isBanned; | ||
public boolean isBanned() {return isBanned;} | ||
public void setBanned(boolean banned){ | ||
isBanned = banned; | ||
|
||
if(isBanned){ | ||
if(isOnline()){ | ||
getPlayer().kickPlayer(P.p.replaceColors(P.p.getLanguageReader().get("Player_Kick_Ban", this.getBannedReason()))); | ||
} | ||
} | ||
} | ||
|
||
private int bannedTime; | ||
public void setBannedTime(int bannedTime) {this.bannedTime = bannedTime;} | ||
public int getBannedTime() {return bannedTime;} | ||
|
||
private String bannedReason; | ||
public void setBannedReason(String bannedReason) {this.bannedReason = bannedReason;} | ||
public String getBannedReason() {return bannedReason;} | ||
|
||
public MPlayer(String name){ | ||
mPlayers.add(this); | ||
|
||
this.name = name; | ||
} | ||
|
||
//Statics | ||
public static Set<MPlayer> get(){ | ||
return mPlayers; | ||
} | ||
|
||
public static MPlayer get(String name){ | ||
for(MPlayer mPlayer : mPlayers){ | ||
if(mPlayer.getName().equalsIgnoreCase(name)){ | ||
return mPlayer; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static MPlayer getOrCreate(String name){ | ||
for(MPlayer mPlayer : mPlayers){ | ||
if(mPlayer.getName().equalsIgnoreCase(name)){ | ||
return mPlayer; | ||
} | ||
} | ||
|
||
return new MPlayer(name); | ||
} | ||
|
||
//Save and Load Functions | ||
public static boolean SaveAsYml(File file){ | ||
FileConfiguration ymlFile = new YamlConfiguration(); | ||
|
||
for(MPlayer player : MPlayer.get()){ | ||
ymlFile.set(player.getName()+".isBanned", player.isBanned()); | ||
ymlFile.set(player.getName()+".bannedTime", player.getBannedTime()); | ||
ymlFile.set(player.getName()+".bannedReason", player.getBannedReason()); | ||
} | ||
|
||
try { | ||
ymlFile.save(file); | ||
} catch (IOException e) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static boolean LoadAsYml(File file){ | ||
FileConfiguration ymlFile = YamlConfiguration.loadConfiguration(file); | ||
|
||
Set<String> keys = ymlFile.getKeys(false); | ||
|
||
for(String name : keys){ | ||
MPlayer mPlayer = new MPlayer(name); | ||
mPlayer.setBanned(ymlFile.getBoolean(name+".isBanned")); | ||
mPlayer.setBannedTime(ymlFile.getInt(name+".bannedTime")); | ||
mPlayer.setBannedReason(ymlFile.getString(name+".bannedReason")); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.dre.managerxl.commands; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import com.dre.managerxl.P; | ||
import com.dre.managerxl.commands.player.Ban; | ||
import com.dre.managerxl.commands.player.Unban; | ||
|
||
public abstract class MCommand { | ||
private static MCommandExecutor commandListener = new MCommandExecutor(); | ||
private static Set<MCommand> commands = new HashSet<MCommand>(); | ||
|
||
public static MCommand cmdHelp; | ||
|
||
protected String command; | ||
protected MCommand parrent; | ||
protected String help; | ||
protected String permission; | ||
|
||
protected boolean isConsoleCommand; | ||
protected boolean isPlayerCommand; | ||
|
||
public abstract void onExecute(String[] args, CommandSender sender); | ||
|
||
public String getCommand(){ | ||
return command; | ||
} | ||
|
||
public MCommand getParrent(){ | ||
return parrent; | ||
} | ||
|
||
public String getHelp(){ | ||
return help; | ||
} | ||
|
||
public boolean isConsoleCommand(){ | ||
return isConsoleCommand; | ||
} | ||
|
||
public boolean isPlayerCommand(){ | ||
return isPlayerCommand; | ||
} | ||
|
||
public boolean playerHasPermissions(Player player){ | ||
if(P.p.getPermissionHandler().playerHas(player, permission) || player.isOp()){ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public void init(){ | ||
commands.add(this); | ||
P.p.getCommand(this.getCommand()).setExecutor(commandListener); | ||
} | ||
|
||
public void displayHelp(CommandSender sender){ | ||
P.p.msg(sender, getHelp()); | ||
} | ||
|
||
//Static | ||
public static void initCommands(){ | ||
|
||
// PlayerCommands | ||
new Ban(); | ||
new Unban(); | ||
} | ||
|
||
public static Set<MCommand> get(){ | ||
return commands; | ||
} | ||
|
||
public static MCommand get(String command){ | ||
for(MCommand mCommand : commands){ | ||
if(mCommand.getCommand().equals(command)){ | ||
return mCommand; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.