diff --git a/src/main/java/de/fanta/challenges/Challenges.java b/src/main/java/de/fanta/challenges/Challenges.java index 3b1d8ea..369d9e0 100644 --- a/src/main/java/de/fanta/challenges/Challenges.java +++ b/src/main/java/de/fanta/challenges/Challenges.java @@ -16,9 +16,15 @@ import de.fanta.challenges.commands.coords.CoordsSaveCommand; import de.fanta.challenges.commands.coords.CoordsShareCommand; import de.fanta.challenges.commands.ResetCommand; -import de.fanta.challenges.commands.ReviveCommandTODO; -import de.fanta.challenges.commands.SettingsCommandTODO; -import de.fanta.challenges.commands.TimerCommandTODO; +import de.fanta.challenges.commands.revive.ReviveCommandTODO; +import de.fanta.challenges.commands.settings.SettingsCommandTODO; +import de.fanta.challenges.commands.timer.TimerForcemlgCommand; +import de.fanta.challenges.commands.timer.TimerPauseCommand; +import de.fanta.challenges.commands.timer.TimerResetCommand; +import de.fanta.challenges.commands.timer.TimerReverseCommand; +import de.fanta.challenges.commands.timer.TimerSetCommand; +import de.fanta.challenges.commands.timer.TimerStartCommand; +import de.fanta.challenges.commands.timer.TimerUtil; import de.fanta.challenges.commands.hp.HPAddCommand; import de.fanta.challenges.commands.hp.HPGetCommand; import de.fanta.challenges.commands.hp.HPMaxCommand; @@ -63,7 +69,7 @@ private FileConfiguration RndDropsConfig; - private TimerCommandTODO Timer; + private TimerUtil Timer; private BackpackCommand backpack; @@ -93,7 +99,7 @@ wolfyUtilities.setCHAT_PREFIX(PREFIX); wolfyUtilities.setCONSOLE_PREFIX(PREFIX); - this.Timer = new TimerCommandTODO(this); + this.Timer = new TimerUtil(this); this.rndDrops = new RandomDrops(); this.inventoryHandler = new InventoryHandler(this); @@ -103,7 +109,6 @@ getCommand("settings").setExecutor(new SettingsCommandTODO(this)); getCommand("revive").setExecutor(new ReviveCommandTODO(this)); - getCommand("timer").setExecutor(new TimerCommandTODO(this)); CommandRouter challengesRouter = new CommandRouter(getCommand("challenges")); challengesRouter.addCommandMapping(new ChallengesCommand(this)); @@ -129,6 +134,14 @@ hpRouter.addCommandMapping(new HPRemoveCommand(this), "remove"); hpRouter.addCommandMapping(new HPSetCommand(this), "set"); + CommandRouter timerRouter = new CommandRouter(getCommand("timer")); + timerRouter.addCommandMapping(new TimerForcemlgCommand(this), "forcemlg"); + timerRouter.addCommandMapping(new TimerPauseCommand(this), "pause"); + timerRouter.addCommandMapping(new TimerResetCommand(this), "reset"); + timerRouter.addCommandMapping(new TimerReverseCommand(this), "reverse"); + timerRouter.addCommandMapping(new TimerSetCommand(this), "set"); + timerRouter.addCommandMapping(new TimerStartCommand(this), "start"); + Bukkit.getPluginManager().registerEvents(new InventoryClickListener(), this); Bukkit.getPluginManager().registerEvents(new QuitJoinListener(), this); Bukkit.getPluginManager().registerEvents(new BlockDestroyListener(), this); diff --git a/src/main/java/de/fanta/challenges/commands/ResetCommand.java b/src/main/java/de/fanta/challenges/commands/ResetCommand.java index d235afb..1346c74 100644 --- a/src/main/java/de/fanta/challenges/commands/ResetCommand.java +++ b/src/main/java/de/fanta/challenges/commands/ResetCommand.java @@ -22,7 +22,10 @@ @Override public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) {// + for (Player p : Bukkit.getOnlinePlayers()) { + p.sendTitle(ChatColor.GREEN + "Server wird zurückgesetzt!", ChatColor.RED + "Bitte warte einen Moment" + ChatColor.GREEN + "." + ChatColor.AQUA + "." + ChatColor.YELLOW + ".", 10, 220, 10); + } plugin.getConfig().set("World_Name", Bukkit.getWorlds().get(0).getName()); plugin.getConfig().set("World_Reset", true); plugin.getConfig().set("timer.enabled", false); @@ -37,8 +40,7 @@ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { for (Player p : Bukkit.getOnlinePlayers()) { - p.sendTitle(ChatColor.GREEN + "Server wird zurückgesetzt!", ChatColor.RED + "Bitte warte einen Moment" + ChatColor.GREEN + "." + ChatColor.AQUA + "." + ChatColor.YELLOW + ".", 10, 220, 10); - p.kickPlayer(ChatColor.RED + "Welt wird zurückgesetzt!\n" + ChatColor.RED + "§cBitte warte einen Moment..."); + p.kickPlayer(ChatColor.RED + "Welt wird zurückgesetzt!\n" + ChatColor.RED + "Bitte warte einen Moment..."); } ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); Bukkit.dispatchCommand(console, "restart"); diff --git a/src/main/java/de/fanta/challenges/commands/ReviveCommandTODO.java b/src/main/java/de/fanta/challenges/commands/ReviveCommandTODO.java deleted file mode 100644 index eabb583..0000000 --- a/src/main/java/de/fanta/challenges/commands/ReviveCommandTODO.java +++ /dev/null @@ -1,74 +0,0 @@ -package de.fanta.challenges.commands; - -import de.fanta.challenges.Challenges; -import de.fanta.challenges.ChatUtil; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class ReviveCommandTODO implements CommandExecutor { - - private final Challenges plugin; - - public ReviveCommandTODO(Challenges plugin) { - this.plugin = plugin; - } - - @SuppressWarnings("deprecation") - @Override - public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { - if (args.length == 1) { - if (args[0].equalsIgnoreCase("all")) { - for (Player p : Bukkit.getOnlinePlayers()) { - p.setHealth(p.getMaxHealth()); - p.setGameMode(GameMode.SURVIVAL); - } - Bukkit.broadcastMessage("§bAlle Spieler wurden wiederbelebt! §aEs kann weiter gehen!"); - } else { - OfflinePlayer other = (Bukkit.getServer().getOfflinePlayer(args[0])); - if (other.isOnline()) { - Player p = (Player) other; - p.setHealth(p.getMaxHealth()); - p.setGameMode(GameMode.SURVIVAL); - Bukkit.broadcastMessage("§b" + p.getName() + " §awurde von §b" + sender.getName() + " §awiederbelebt!"); - } else - sender.sendMessage("§cDieser Spieler ist nicht online!"); - } - } else if (args.length >= 4) { - World w = Bukkit.getWorld(args[1]); - double x = Double.parseDouble(args[2]); - double y = Double.parseDouble(args[3]); - double z = Double.parseDouble(args[4]); - Location loc = new Location(w, x, y, z); - if (args[0].equalsIgnoreCase("all")) { - for (Player p : Bukkit.getOnlinePlayers()) { - p.teleport(loc); - p.setHealth(p.getMaxHealth()); - p.setGameMode(GameMode.SURVIVAL); - } - Bukkit.broadcastMessage("§bAlle Spieler wurden bei §c" + w.getName() + " " + x + " " + y + " " + z + " §bwiederbelebt! §aEs kann weiter gehen!"); - } else { - OfflinePlayer other = (Bukkit.getServer().getOfflinePlayer(args[0])); - if (other.isOnline()) { - Player p = (Player) other; - p.teleport(loc); - p.setHealth(p.getMaxHealth()); - p.setGameMode(GameMode.SURVIVAL); - Bukkit.broadcastMessage("§b" + p.getName() + " §awurde von §b" + sender.getName() + " §abei §c" + w.getName() + " " + x + " " + y + " " + z + " §awiederbelebt!"); - } else - sender.sendMessage("§cDieser Spieler ist nicht online!"); - } - } else - sender.sendMessage("§cBenutze: /revive [world] [x] [y] [z]"); - } else - ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! Nur " + plugin.getCurrentEditor().getName() + " kann spieler wiederbeleben!"); - return true; - } -} diff --git a/src/main/java/de/fanta/challenges/commands/SettingsCommandTODO.java b/src/main/java/de/fanta/challenges/commands/SettingsCommandTODO.java deleted file mode 100644 index f7f1db4..0000000 --- a/src/main/java/de/fanta/challenges/commands/SettingsCommandTODO.java +++ /dev/null @@ -1,152 +0,0 @@ -package de.fanta.challenges.commands; - -import de.fanta.challenges.Challenges; -import de.fanta.challenges.ChatUtil; -import me.wolfyscript.utilities.api.WolfyUtilities; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -public class SettingsCommandTODO implements CommandExecutor { - - - private final Challenges plugin; - - public SettingsCommandTODO(Challenges plugin) { - this.plugin = plugin; - } - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (sender instanceof Player) { - Player p = (Player) sender; - if (args.length == 0) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { - WolfyUtilities.getAPI(plugin).getInventoryAPI().openCluster(p, "none"); - return true; - } else { - ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); - } - } else if (args.length == 1) { - if (args[0].equalsIgnoreCase("get")) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { - ChatUtil.sendNormalMessage(p, "Einstellungen"); - ChatUtil.sendNormalMessage(p, "Crafting = " + plugin.getConfig().getBoolean("craftingtable")); - ChatUtil.sendNormalMessage(p, "Villager Handel = " + plugin.getConfig().getBoolean("allowtrading")); - ChatUtil.sendNormalMessage(p, "Sterben bei Fallschaden = " + plugin.getConfig().getBoolean("deathonfall")); - ChatUtil.sendNormalMessage(p, "Schaden bei Schleichen = " + plugin.getConfig().getBoolean("damageonsneak")); - ChatUtil.sendNormalMessage(p, "Schadens wert bei Schleichen = " + plugin.getConfig().getString("sneakdmg")); - ChatUtil.sendNormalMessage(p, "Geteielter Schaden = " + plugin.getConfig().getBoolean("sharedmg")); - ChatUtil.sendNormalMessage(p, "Ein Leben für alle = " + plugin.getConfig().getBoolean("onelife")); - ChatUtil.sendNormalMessage(p, "Schaden im Chat = " + plugin.getConfig().getBoolean("dmginchat")); - ChatUtil.sendNormalMessage(p, "Respawn = " + plugin.getConfig().getBoolean("respawn")); - ChatUtil.sendNormalMessage(p, "MLG " + plugin.getConfig().getBoolean("mlg.enabled")); - ChatUtil.sendNormalMessage(p, "MLG Kill All " + plugin.getConfig().getBoolean("mlg.killall")); - ChatUtil.sendNormalMessage(p, "Maximale zeit bis zum nächsten MLG = " + plugin.getConfig().getString("mlg.maxtime") + " Sekunden"); - ChatUtil.sendNormalMessage(p, "Sterben beim XP aufheben: " + plugin.getConfig().getBoolean("xpdeath")); - - } else { - ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); - } - } else { - ChatUtil.sendWarningMessage(p, "/settings Get/Crafting/Trading/DeathFall/DMGOnSneak/SneakDMG/RndDrops/ShareDMG/Respawn/OneLife/ChatDMG/MLG/MLGkillall/MLGTime/DeathXP/SprintDeath/JumpDeath [True/False]"); - } - } else if (args.length >= 2) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { - Boolean Bwert = Boolean.valueOf(Boolean.parseBoolean(args[1])); - switch (args[0].toLowerCase()) { - case "crafting": - plugin.getConfig().set("craftingtable", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Crafting = " + plugin.getConfig().getBoolean("craftingtable")); - break; - case "deathfall": - plugin.getConfig().set("deathonfall", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Sterben bei Fallschaden = " + plugin.getConfig().getBoolean("deathonfall")); - break; - case "trading": - plugin.getConfig().set("allowtrading", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Villager Handel = " + plugin.getConfig().getBoolean("allowtrading")); - break; - case "dmgonsneak": - plugin.getConfig().set("damageonsneak", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Schaden bei Schleichen = " + plugin.getConfig().getBoolean("damageonsneak")); - break; - case "sneakdmg": - Double Dwert = Double.valueOf(Double.parseDouble(args[1])); - plugin.getConfig().set("sneakdmg", Dwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Schadens wert bei Schleichen = " + plugin.getConfig().getString("sneakdmg")); - break; - case "rnddrops": - plugin.getConfig().set("rnddrops", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Random Drops = " + plugin.getConfig().getBoolean("rnddrops")); - break; - case "sharedmg": - plugin.getConfig().set("sharehp", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Geteielter Schaden = " + plugin.getConfig().getBoolean("sharedmg")); - case "respawn": - plugin.getConfig().set("respawn", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Respawn = " + plugin.getConfig().getBoolean("respawn")); - break; - case "onelife": - plugin.getConfig().set("onelife", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Ein Leben für alle = " + plugin.getConfig().getBoolean("onelife")); - break; - case "chatdmg": - plugin.getConfig().set("dmginchat", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Schaden im Chat = " + plugin.getConfig().getBoolean("dmginchat")); - break; - case "mlg": - plugin.getConfig().set("mlg.enabled", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "MLG " + plugin.getConfig().getBoolean("mlg.enabled")); - break; - case "mlgkillall": - plugin.getConfig().set("mlg.killall", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "MLG Kill All " + plugin.getConfig().getBoolean("mlg.killall")); - break; - case "mlgtime": - Double time = Double.valueOf(Double.parseDouble(args[1])); - plugin.getConfig().set("mlg.maxtime", time); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Maximale zeit bis zum nächsten MLG = " + plugin.getConfig().getString("mlg.maxtime") + " Sekunden"); - break; - case "deathxp": - plugin.getConfig().set("xpdeath", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Sterben beim XP aufheben: " + plugin.getConfig().getBoolean("xpdeath")); - break; - case "sprintdeath": - plugin.getConfig().set("deathonsprint", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Sterben durch sprinten: " + plugin.getConfig().getBoolean("deathonsprint")); - break; - case "jumpdeath": - plugin.getConfig().set("deathonjump", Bwert); - plugin.saveConfig(); - ChatUtil.sendNormalMessage(p, "Sterben durch springenn: " + plugin.getConfig().getBoolean("deathonjump")); - break; - } - } else { - ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); - } - } else { - ChatUtil.sendWarningMessage(p, "/settings Get/Crafting/Trading/DeathFall/DMGOnSneak/SneakDMG/RndDrops/ShareDMG/Respawn/OneLife/ChatDMG/MLG/MLGkillall/MLGTime/DeathXP/SprintDeath/JumpDeath [True/False]"); - } - } else { - ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); - } - return true; - } -} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/commands/TimerCommandTODO.java b/src/main/java/de/fanta/challenges/commands/TimerCommandTODO.java deleted file mode 100644 index ca8417a..0000000 --- a/src/main/java/de/fanta/challenges/commands/TimerCommandTODO.java +++ /dev/null @@ -1,252 +0,0 @@ -package de.fanta.challenges.commands; - -import de.fanta.challenges.Challenges; -import de.fanta.challenges.ChatUtil; -import java.util.Random; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Effect; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; - -public class TimerCommandTODO implements CommandExecutor { - - private final Challenges plugin; - - public TimerCommandTODO(Challenges plugin) { - this.plugin = plugin; - } - private int time; - private int sek; - private int min; - private int hrs; - private int tsincemlg = 0; - private String ssek; - private String smin; - private Random random = new Random(); - - private boolean mlg_active = false; - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) { - if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { - if (args.length == 1) { - if (args[0].equalsIgnoreCase("start")) { - if (!this.plugin.getConfig().getBoolean("timer.enabled")) { - this.plugin.getConfig().set("timer.enabled", Boolean.valueOf(true)); - Bukkit.broadcastMessage(Challenges.PREFIX + " §aDer Timer wird fortgesetzt!"); - } else { - ChatUtil.sendWarningMessage(sender, "Der Timer läuft bereits!"); - } - } else if (args[0].equalsIgnoreCase("pause")) { - if (this.plugin.getConfig().getBoolean("timer.enabled")) { - this.plugin.getConfig().set("timer.enabled", Boolean.valueOf(false)); - Bukkit.broadcastMessage(Challenges.PREFIX + " §6Der Timer wurde angehalten"); - } else { - ChatUtil.sendWarningMessage(sender, "Der Timer ist bereits pausiert!"); - } - } else if (args[0].equalsIgnoreCase("reset")) { - SetTimer(0); - Bukkit.broadcastMessage(Challenges.PREFIX + " §cDer Timer wurde zurückgesetzt!"); - } else if (args[0].equalsIgnoreCase("reverse")) { - this.plugin.getConfig().set("timer.reverse", Boolean.valueOf(!this.plugin.getConfig().getBoolean("timer.reverse"))); - this.plugin.saveConfig(); - if (this.plugin.getConfig().getBoolean("timer.reverse")) { - Bukkit.broadcastMessage(Challenges.PREFIX + " §5Der Timer läuft nun rückwärts!"); - } else { - Bukkit.broadcastMessage(Challenges.PREFIX + " §9Der Timer läuft nun vorwärts!"); - } - } else if (args[0].equalsIgnoreCase("forcemlg")) { - if (!this.mlg_active) { - this.mlg_active = true; - Bukkit.broadcastMessage(Challenges.PREFIX + " §bZeit für einen MLG! §6Viel Glück!"); - for (Player p : Bukkit.getOnlinePlayers()) { - if ((((p.getGameMode() == GameMode.SURVIVAL) ? 1 : 0) & (!p.isDead() ? 1 : 0)) != 0) { - TPMLG(p); - } - } - } else { - ChatUtil.sendWarningMessage(sender, "Ein MLG findet bereits statt!"); - } - } else { - ChatUtil.sendWarningMessage(sender, "Benutze: /timer start/pause/reset/reverse/set [Zeit in Sekunden]"); - } - } else if (args.length >= 2) { - if (args[0].equalsIgnoreCase("set")) { - SetTimer(Integer.parseInt(args[1])); - Bukkit.broadcastMessage(Challenges.PREFIX + " §bDer Timer wurde auf §a" + this.hrs + ":" + this.smin + ":" + this.ssek + " §bgesetzt!"); - } else { - - ChatUtil.sendWarningMessage(sender, "Benutze: /timer start/pause/reset/reverse/set [Zeit in Sekunden]"); - } - } else { - ChatUtil.sendNormalMessage(sender, "~~~~~ Timer command ~~~~~"); - ChatUtil.sendNormalMessage(sender, "/timer start - Setze den Timer fort"); - ChatUtil.sendNormalMessage(sender, "/timer pause - Pausiere den Timer"); - ChatUtil.sendNormalMessage(sender, "/timer reset - Setze den Timer zurück"); - ChatUtil.sendNormalMessage(sender, "/timer set [Zeit in Sekunden] - Setze den Timer auf eine bestimmte Zeit"); - ChatUtil.sendNormalMessage(sender, "/timer reverse - Ändere ob der Timer vor- oder rückwärts läuft"); - } - - } else { - ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); - } - return true; - } - - public void LoadTimer() { - this.time = this.plugin.getConfig().getInt("timer.time"); - UpdateStrings(); - StartTimer(); - } - - public void StartTimer() { - Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() { - @Override - public void run() { - int rndnmbr = TimerCommandTODO.this.random.nextInt(750); - boolean ttimer = TimerCommandTODO.this.plugin.getConfig().getBoolean("timer.enabled"); - int ttime = TimerCommandTODO.this.plugin.getConfig().getInt("timer.time"); - int thrs = TimerCommandTODO.this.plugin.getConfig().getInt("timer.hrs"); - String tsek = TimerCommandTODO.this.plugin.getConfig().getString("timer.sek"); - String tmin = TimerCommandTODO.this.plugin.getConfig().getString("timer.min"); - - if (ttimer) { - TimerCommandTODO.this.tsincemlg++; - if (TimerCommandTODO.this.plugin.getConfig().getBoolean("mlg.enabled") && !TimerCommandTODO.this.mlg_active && Bukkit.getOnlinePlayers().size() >= 1 && (rndnmbr == 638 || TimerCommandTODO.this.tsincemlg >= TimerCommandTODO.this.plugin.getConfig().getInt("mlg.maxtime"))) { - Bukkit.broadcastMessage(Challenges.PREFIX + " §bZeit für einen MLG! §6Viel Glück!"); - TimerCommandTODO.this.tsincemlg = 0; - for (Player p : Bukkit.getOnlinePlayers()) { - if ((((p.getGameMode() == GameMode.SURVIVAL) ? 1 : 0) & (!p.isDead() ? 1 : 0)) != 0) { - TimerCommandTODO.this.TPMLG(p); - } - } - } - - if (TimerCommandTODO.this.plugin.getConfig().getBoolean("timer.reverse")) { - if (ttime <= 0) { - TimerCommandTODO.this.plugin.getConfig().set("timer.enabled", Boolean.valueOf(false)); - for (Player p : Bukkit.getOnlinePlayers()) { - p.setGameMode(GameMode.SPECTATOR); - p.sendTitle("§4ZEIT ABGELAUFEN!", "§cChallenge fehgeschlagen", 10, 60, 10); - } - Bukkit.broadcastMessage(Challenges.PREFIX + " §4Die Zeit ist abgelaufen und die Challenge somit fehlgeschlagen!"); - - Bukkit.broadcastMessage(Challenges.PREFIX + " §aSeed: §b" + Bukkit.getWorlds().get(0).getSeed()); - } else { - ttime--; - TimerCommandTODO.this.time = ttime; - TimerCommandTODO.this.UpdateStrings(); - } - for (Player p : Bukkit.getOnlinePlayers()) { - p.sendActionBar(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + thrs + ":" + tmin + ":" + tsek); - } - } else { - - ttime++; - TimerCommandTODO.this.time = ttime; - TimerCommandTODO.this.UpdateStrings(); - for (Player p : Bukkit.getOnlinePlayers()) { - p.sendActionBar(ChatColor.GREEN + "" + ChatColor.BOLD + thrs + ":" + tmin + ":" + tsek); - } - } - } else { - - for (Player p : Bukkit.getOnlinePlayers()) { - p.sendActionBar(ChatColor.GOLD + "" + ChatColor.BOLD + "Der Timer ist pausiert."); - if (p.getGameMode() != GameMode.SPECTATOR) - p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 2); - } - } - } - }, 20L, 20L); - } - - public void SetTimer(int t) { - this.plugin.getConfig().set("timer.enabled", Boolean.valueOf(false)); - this.time = t; - UpdateStrings(); - SaveTimer(); - } - - public void UpdateStrings() { - this.min = this.time / 60; - this.hrs = this.min / 60; - this.min %= 60; - this.sek = this.time % 60; - if (this.sek >= 10) { - this.ssek = Integer.toString(this.sek); - } else { - this.ssek = '0' + Integer.toString(this.sek); - } - if (this.min >= 10) { - this.smin = Integer.toString(this.min); - } else { - this.smin = '0' + Integer.toString(this.min); - } - SaveTimer(); - } - - public void SaveTimer() { - this.plugin.getConfig().set("timer.time", Integer.valueOf(this.time)); - this.plugin.getConfig().set("timer.sek", this.ssek); - this.plugin.getConfig().set("timer.min", this.smin); - this.plugin.getConfig().set("timer.hrs", Integer.valueOf(this.hrs)); - this.plugin.saveConfig(); - } - - @SuppressWarnings("deprecation") - public void TPMLG(Player p) { - p.closeInventory(); - Inventory inv = Bukkit.createInventory(p, InventoryType.PLAYER, p.getName()); - inv.setContents(p.getInventory().getContents()); - p.getInventory().clear(); - p.getInventory().setItemInHand(new ItemStack(Material.WATER_BUCKET)); - int rndY = this.random.nextInt(20); - Location oldloc = p.getLocation(); - - Location newloc = new Location(Bukkit.getWorld("mlg_challenge"), p.getLocation().getBlockX(), (50 + rndY), p.getLocation().getBlockZ()); - p.teleport(newloc); - MLGResult(p, oldloc, inv); - } - - public void MLGResult(final Player p, final Location loc, final Inventory inv) { - Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() { - @Override - public void run() { - TimerCommandTODO.this.mlg_active = false; - if (!p.isDead() && p.getWorld() == Bukkit.getWorld("mlg_challenge")) { - if (TimerCommandTODO.this.plugin.getConfig().getBoolean("timer.enabled")) { - ChatUtil.sendNormalMessage(p, "§aDu hast den §bMLG §aerfolgreich absolviert! §6Weitere folgen..."); - p.setInvulnerable(true); - TimerCommandTODO.this.MLGBack(p, loc, inv); - } else { - TimerCommandTODO.this.MLGBack(p, loc, inv); - } - } else if (Bukkit.getWorlds().get(0).getGameRuleValue("keepInventory").equals("true")) { - p.getInventory().setContents(inv.getContents()); - } - } - }, 100L); - } - - public void MLGBack(final Player p, Location loc, Inventory inv) { - p.teleport(loc); - p.getInventory().setContents(inv.getContents()); - Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() { - @Override - public void run() { - p.setInvulnerable(false); - } - }, 60L); - } - -} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/commands/revive/ReviveCommandTODO.java b/src/main/java/de/fanta/challenges/commands/revive/ReviveCommandTODO.java new file mode 100644 index 0000000..e3c0fba --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/revive/ReviveCommandTODO.java @@ -0,0 +1,74 @@ +package de.fanta.challenges.commands.revive; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class ReviveCommandTODO implements CommandExecutor { + + private final Challenges plugin; + + public ReviveCommandTODO(Challenges plugin) { + this.plugin = plugin; + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) { + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + if (args.length == 1) { + if (args[0].equalsIgnoreCase("all")) { + for (Player p : Bukkit.getOnlinePlayers()) { + p.setHealth(p.getMaxHealth()); + p.setGameMode(GameMode.SURVIVAL); + } + Bukkit.broadcastMessage("§bAlle Spieler wurden wiederbelebt! §aEs kann weiter gehen!"); + } else { + OfflinePlayer other = (Bukkit.getServer().getOfflinePlayer(args[0])); + if (other.isOnline()) { + Player p = (Player) other; + p.setHealth(p.getMaxHealth()); + p.setGameMode(GameMode.SURVIVAL); + Bukkit.broadcastMessage("§b" + p.getName() + " §awurde von §b" + sender.getName() + " §awiederbelebt!"); + } else + sender.sendMessage("§cDieser Spieler ist nicht online!"); + } + } else if (args.length >= 4) { + World w = Bukkit.getWorld(args[1]); + double x = Double.parseDouble(args[2]); + double y = Double.parseDouble(args[3]); + double z = Double.parseDouble(args[4]); + Location loc = new Location(w, x, y, z); + if (args[0].equalsIgnoreCase("all")) { + for (Player p : Bukkit.getOnlinePlayers()) { + p.teleport(loc); + p.setHealth(p.getMaxHealth()); + p.setGameMode(GameMode.SURVIVAL); + } + Bukkit.broadcastMessage("§bAlle Spieler wurden bei §c" + w.getName() + " " + x + " " + y + " " + z + " §bwiederbelebt! §aEs kann weiter gehen!"); + } else { + OfflinePlayer other = (Bukkit.getServer().getOfflinePlayer(args[0])); + if (other.isOnline()) { + Player p = (Player) other; + p.teleport(loc); + p.setHealth(p.getMaxHealth()); + p.setGameMode(GameMode.SURVIVAL); + Bukkit.broadcastMessage("§b" + p.getName() + " §awurde von §b" + sender.getName() + " §abei §c" + w.getName() + " " + x + " " + y + " " + z + " §awiederbelebt!"); + } else + sender.sendMessage("§cDieser Spieler ist nicht online!"); + } + } else + sender.sendMessage("§cBenutze: /revive [world] [x] [y] [z]"); + } else + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! Nur " + plugin.getCurrentEditor().getName() + " kann spieler wiederbeleben!"); + return true; + } +} diff --git a/src/main/java/de/fanta/challenges/commands/settings/SettingsCommandTODO.java b/src/main/java/de/fanta/challenges/commands/settings/SettingsCommandTODO.java new file mode 100644 index 0000000..96b32b1 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/settings/SettingsCommandTODO.java @@ -0,0 +1,152 @@ +package de.fanta.challenges.commands.settings; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import me.wolfyscript.utilities.api.WolfyUtilities; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SettingsCommandTODO implements CommandExecutor { + + + private final Challenges plugin; + + public SettingsCommandTODO(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender instanceof Player) { + Player p = (Player) sender; + if (args.length == 0) { + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + WolfyUtilities.getAPI(plugin).getInventoryAPI().openCluster(p, "none"); + return true; + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + } else if (args.length == 1) { + if (args[0].equalsIgnoreCase("get")) { + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + ChatUtil.sendNormalMessage(p, "Einstellungen"); + ChatUtil.sendNormalMessage(p, "Crafting = " + plugin.getConfig().getBoolean("craftingtable")); + ChatUtil.sendNormalMessage(p, "Villager Handel = " + plugin.getConfig().getBoolean("allowtrading")); + ChatUtil.sendNormalMessage(p, "Sterben bei Fallschaden = " + plugin.getConfig().getBoolean("deathonfall")); + ChatUtil.sendNormalMessage(p, "Schaden bei Schleichen = " + plugin.getConfig().getBoolean("damageonsneak")); + ChatUtil.sendNormalMessage(p, "Schadens wert bei Schleichen = " + plugin.getConfig().getString("sneakdmg")); + ChatUtil.sendNormalMessage(p, "Geteielter Schaden = " + plugin.getConfig().getBoolean("sharedmg")); + ChatUtil.sendNormalMessage(p, "Ein Leben für alle = " + plugin.getConfig().getBoolean("onelife")); + ChatUtil.sendNormalMessage(p, "Schaden im Chat = " + plugin.getConfig().getBoolean("dmginchat")); + ChatUtil.sendNormalMessage(p, "Respawn = " + plugin.getConfig().getBoolean("respawn")); + ChatUtil.sendNormalMessage(p, "MLG " + plugin.getConfig().getBoolean("mlg.enabled")); + ChatUtil.sendNormalMessage(p, "MLG Kill All " + plugin.getConfig().getBoolean("mlg.killall")); + ChatUtil.sendNormalMessage(p, "Maximale zeit bis zum nächsten MLG = " + plugin.getConfig().getString("mlg.maxtime") + " Sekunden"); + ChatUtil.sendNormalMessage(p, "Sterben beim XP aufheben: " + plugin.getConfig().getBoolean("xpdeath")); + + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + } else { + ChatUtil.sendWarningMessage(p, "/settings Get/Crafting/Trading/DeathFall/DMGOnSneak/SneakDMG/RndDrops/ShareDMG/Respawn/OneLife/ChatDMG/MLG/MLGkillall/MLGTime/DeathXP/SprintDeath/JumpDeath [True/False]"); + } + } else if (args.length >= 2) { + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + Boolean Bwert = Boolean.valueOf(Boolean.parseBoolean(args[1])); + switch (args[0].toLowerCase()) { + case "crafting": + plugin.getConfig().set("craftingtable", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Crafting = " + plugin.getConfig().getBoolean("craftingtable")); + break; + case "deathfall": + plugin.getConfig().set("deathonfall", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Sterben bei Fallschaden = " + plugin.getConfig().getBoolean("deathonfall")); + break; + case "trading": + plugin.getConfig().set("allowtrading", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Villager Handel = " + plugin.getConfig().getBoolean("allowtrading")); + break; + case "dmgonsneak": + plugin.getConfig().set("damageonsneak", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Schaden bei Schleichen = " + plugin.getConfig().getBoolean("damageonsneak")); + break; + case "sneakdmg": + Double Dwert = Double.valueOf(Double.parseDouble(args[1])); + plugin.getConfig().set("sneakdmg", Dwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Schadens wert bei Schleichen = " + plugin.getConfig().getString("sneakdmg")); + break; + case "rnddrops": + plugin.getConfig().set("rnddrops", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Random Drops = " + plugin.getConfig().getBoolean("rnddrops")); + break; + case "sharedmg": + plugin.getConfig().set("sharehp", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Geteielter Schaden = " + plugin.getConfig().getBoolean("sharedmg")); + case "respawn": + plugin.getConfig().set("respawn", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Respawn = " + plugin.getConfig().getBoolean("respawn")); + break; + case "onelife": + plugin.getConfig().set("onelife", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Ein Leben für alle = " + plugin.getConfig().getBoolean("onelife")); + break; + case "chatdmg": + plugin.getConfig().set("dmginchat", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Schaden im Chat = " + plugin.getConfig().getBoolean("dmginchat")); + break; + case "mlg": + plugin.getConfig().set("mlg.enabled", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "MLG " + plugin.getConfig().getBoolean("mlg.enabled")); + break; + case "mlgkillall": + plugin.getConfig().set("mlg.killall", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "MLG Kill All " + plugin.getConfig().getBoolean("mlg.killall")); + break; + case "mlgtime": + Double time = Double.valueOf(Double.parseDouble(args[1])); + plugin.getConfig().set("mlg.maxtime", time); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Maximale zeit bis zum nächsten MLG = " + plugin.getConfig().getString("mlg.maxtime") + " Sekunden"); + break; + case "deathxp": + plugin.getConfig().set("xpdeath", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Sterben beim XP aufheben: " + plugin.getConfig().getBoolean("xpdeath")); + break; + case "sprintdeath": + plugin.getConfig().set("deathonsprint", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Sterben durch sprinten: " + plugin.getConfig().getBoolean("deathonsprint")); + break; + case "jumpdeath": + plugin.getConfig().set("deathonjump", Bwert); + plugin.saveConfig(); + ChatUtil.sendNormalMessage(p, "Sterben durch springenn: " + plugin.getConfig().getBoolean("deathonjump")); + break; + } + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + } else { + ChatUtil.sendWarningMessage(p, "/settings Get/Crafting/Trading/DeathFall/DMGOnSneak/SneakDMG/RndDrops/ShareDMG/Respawn/OneLife/ChatDMG/MLG/MLGkillall/MLGTime/DeathXP/SprintDeath/JumpDeath [True/False]"); + } + } else { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + } + return true; + } +} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerForcemlgCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerForcemlgCommand.java new file mode 100644 index 0000000..d0f7607 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerForcemlgCommand.java @@ -0,0 +1,49 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerForcemlgCommand extends SubCommand { + + private final Challenges plugin; + + public TimerForcemlgCommand(Challenges plugin) { + this.plugin = plugin; + } + + private static boolean mlg_active = false; + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + if (!mlg_active) { + mlg_active = true; + Bukkit.broadcastMessage(Challenges.PREFIX + " §bZeit für einen MLG! §6Viel Glück!"); + for (Player p : Bukkit.getOnlinePlayers()) { + if (p.getGameMode() == GameMode.SURVIVAL && !p.isDead()) { + TimerUtil.TPMLG(p); + } + return true; + } + } else { + ChatUtil.sendWarningMessage(sender, "Ein MLG findet bereits statt!"); + return true; + } + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerPauseCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerPauseCommand.java new file mode 100644 index 0000000..38a1dda --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerPauseCommand.java @@ -0,0 +1,40 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerPauseCommand extends SubCommand { + + private final Challenges plugin; + + public TimerPauseCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + if (this.plugin.getConfig().getBoolean("timer.enabled")) { + this.plugin.getConfig().set("timer.enabled", Boolean.FALSE); + Bukkit.broadcastMessage(Challenges.PREFIX + " §6Der Timer wurde angehalten"); + } else { + ChatUtil.sendWarningMessage(sender, "Der Timer ist bereits pausiert!"); + } + return true; + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerResetCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerResetCommand.java new file mode 100644 index 0000000..df79644 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerResetCommand.java @@ -0,0 +1,36 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerResetCommand extends SubCommand { + + private final Challenges plugin; + + public TimerResetCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + TimerUtil.SetTimer(0); + Bukkit.broadcastMessage(Challenges.PREFIX + " §cDer Timer wurde zurückgesetzt!"); + return true; + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return false; + } + +} diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerReverseCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerReverseCommand.java new file mode 100644 index 0000000..d982499 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerReverseCommand.java @@ -0,0 +1,41 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerReverseCommand extends SubCommand { + + private final Challenges plugin; + + public TimerReverseCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + this.plugin.getConfig().set("timer.reverse", !this.plugin.getConfig().getBoolean("timer.reverse")); + this.plugin.saveConfig(); + if (this.plugin.getConfig().getBoolean("timer.reverse")) { + Bukkit.broadcastMessage(Challenges.PREFIX + " §5Der Timer läuft nun rückwärts!"); + } else { + Bukkit.broadcastMessage(Challenges.PREFIX + " §9Der Timer läuft nun vorwärts!"); + } + return true; + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return false; + } + +} diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerSetCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerSetCommand.java new file mode 100644 index 0000000..e367592 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerSetCommand.java @@ -0,0 +1,42 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerSetCommand extends SubCommand { + + private final Challenges plugin; + + public TimerSetCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if (args.hasNext()) { + int time = args.getNext(-1); + if (time < 0) { + ChatUtil.sendErrorMessage(sender, "Zeit muss eine Zahl größer als 0 sein!"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + TimerUtil.SetTimer(time); + Bukkit.broadcastMessage(Challenges.PREFIX + " §bDer Timer wurde auf §a" + TimerUtil.hrs + ":" + TimerUtil.smin + ":" + TimerUtil.ssek + " §bgesetzt!"); + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return true; + } + return false; + } +} diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerStartCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerStartCommand.java new file mode 100644 index 0000000..2f5e044 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerStartCommand.java @@ -0,0 +1,40 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TimerStartCommand extends SubCommand { + + private final Challenges plugin; + + public TimerStartCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + if ((plugin.getCurrentEditor() != null && ((Player) sender).getUniqueId().equals(plugin.getCurrentEditor().getUniqueId())) || sender.hasPermission("Challenges.editor.override")) { + if (!this.plugin.getConfig().getBoolean("timer.enabled")) { + this.plugin.getConfig().set("timer.enabled", Boolean.TRUE); + Bukkit.broadcastMessage(Challenges.PREFIX + " §aDer Timer wird fortgesetzt!"); + } else { + ChatUtil.sendWarningMessage(sender, "Der Timer läuft bereits!"); + } + return true; + } else { + ChatUtil.sendErrorMessage(sender, "Du bist kein Editor! " + plugin.getCurrentEditor().getName() + " muss die Map bearbeiten!"); + } + return false; + } + +} diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerUtil.java b/src/main/java/de/fanta/challenges/commands/timer/TimerUtil.java new file mode 100644 index 0000000..6fe6274 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerUtil.java @@ -0,0 +1,187 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.ChatUtil; + +import java.util.Random; + +import de.iani.cubesideutils.StringUtil; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Effect; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class TimerUtil { + + private static Challenges plugin; + + public TimerUtil(Challenges plugin) { + TimerUtil.plugin = plugin; + } + + public static int time; + public static int sek; + public static int min; + public static int hrs; + public static int tsincemlg = 0; + public static String ssek; + public static String smin; + public static Random random = new Random(); + + private static boolean mlg_active = false; + + public void LoadTimer() { + time = plugin.getConfig().getInt("timer.time"); + UpdateStrings(); + StartTimer(); + } + + public void StartTimer() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { + @Override + public void run() { + int rndnmbr = random.nextInt(750); + boolean ttimer = plugin.getConfig().getBoolean("timer.enabled"); + int ttime = plugin.getConfig().getInt("timer.time"); + int thrs = plugin.getConfig().getInt("timer.hrs"); + String tsek = plugin.getConfig().getString("timer.sek"); + String tmin = plugin.getConfig().getString("timer.min"); + + if (ttimer) { + tsincemlg++; + if (plugin.getConfig().getBoolean("mlg.enabled") && !mlg_active && Bukkit.getOnlinePlayers().size() >= 1 && (rndnmbr == 638 || tsincemlg >= plugin.getConfig().getInt("mlg.maxtime"))) { + Bukkit.broadcastMessage(Challenges.PREFIX + " §bZeit für einen MLG! §6Viel Glück!"); + tsincemlg = 0; + for (Player p : Bukkit.getOnlinePlayers()) { + if ((((p.getGameMode() == GameMode.SURVIVAL) ? 1 : 0) & (!p.isDead() ? 1 : 0)) != 0) { + TPMLG(p); + } + } + } + + if (plugin.getConfig().getBoolean("timer.reverse")) { + if (ttime <= 0) { + plugin.getConfig().set("timer.enabled", Boolean.FALSE); + for (Player p : Bukkit.getOnlinePlayers()) { + p.setGameMode(GameMode.SPECTATOR); + p.sendTitle("§4ZEIT ABGELAUFEN!", "§cChallenge fehgeschlagen", 10, 60, 10); + } + Bukkit.broadcastMessage(Challenges.PREFIX + " §4Die Zeit ist abgelaufen und die Challenge somit fehlgeschlagen!"); + + Bukkit.broadcastMessage(Challenges.PREFIX + " §aSeed: §b" + Bukkit.getWorlds().get(0).getSeed()); + } else { + ttime--; + time = ttime; + UpdateStrings(); + } + sendTimerActionBar(ChatColor.DARK_GREEN); + } else { + + ttime++; + time = ttime; + UpdateStrings(); + sendTimerActionBar(ChatColor.GREEN); + } + } else { + + for (Player p : Bukkit.getOnlinePlayers()) { + p.sendActionBar(ChatColor.GOLD + "" + ChatColor.BOLD + "Der Timer ist pausiert."); + if (p.getGameMode() != GameMode.SPECTATOR) + p.getWorld().playEffect(p.getLocation(), Effect.ENDER_SIGNAL, 2); + } + } + } + }, 20L, 20L); + } + + private void sendTimerActionBar(ChatColor color) { + for (Player p : Bukkit.getOnlinePlayers()) { + p.sendActionBar(color + StringUtil.formatTimespan(time * 1000, ChatColor.GOLD + " Day/s", "", "", "", color + ":", ":", true, true)); + } + } + + public static void SetTimer(int t) { + time = t; + UpdateStrings(); + SaveTimer(); + } + + public static void UpdateStrings() { + min = time / 60; + hrs = min / 60; + min %= 60; + sek = time % 60; + if (sek >= 10) { + ssek = Integer.toString(sek); + } else { + ssek = '0' + Integer.toString(sek); + } + if (min >= 10) { + smin = Integer.toString(min); + } else { + smin = '0' + Integer.toString(min); + } + SaveTimer(); + } + + public static void SaveTimer() { + plugin.getConfig().set("timer.time", time); + plugin.getConfig().set("timer.sek", ssek); + plugin.getConfig().set("timer.min", smin); + plugin.getConfig().set("timer.hrs", hrs); + plugin.saveConfig(); + } + + @SuppressWarnings("deprecation") + public static void TPMLG(Player p) { + p.closeInventory(); + Inventory inv = Bukkit.createInventory(p, InventoryType.PLAYER, p.getName()); + inv.setContents(p.getInventory().getContents()); + p.getInventory().clear(); + p.getInventory().setItemInHand(new ItemStack(Material.WATER_BUCKET)); + int rndY = random.nextInt(20); + Location oldloc = p.getLocation(); + + Location newloc = new Location(Bukkit.getWorld("mlg_challenge"), p.getLocation().getBlockX(), (50 + rndY), p.getLocation().getBlockZ()); + p.teleport(newloc); + MLGResult(p, oldloc, inv); + } + + public static void MLGResult(final Player p, final Location loc, final Inventory inv) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + mlg_active = false; + if (!p.isDead() && p.getWorld() == Bukkit.getWorld("mlg_challenge")) { + if (plugin.getConfig().getBoolean("timer.enabled")) { + ChatUtil.sendNormalMessage(p, "§aDu hast den §bMLG §aerfolgreich absolviert! §6Weitere folgen..."); + p.setInvulnerable(true); + MLGBack(p, loc, inv); + } else { + MLGBack(p, loc, inv); + } + } else if (Bukkit.getWorlds().get(0).getGameRuleValue("keepInventory").equals("true")) { + p.getInventory().setContents(inv.getContents()); + } + } + }, 100L); + } + + public static void MLGBack(final Player p, Location loc, Inventory inv) { + p.teleport(loc); + p.getInventory().setContents(inv.getContents()); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + p.setInvulnerable(false); + } + }, 60L); + } + +} \ No newline at end of file diff --git a/src/main/java/de/fanta/challenges/events/DamageListener.java b/src/main/java/de/fanta/challenges/events/DamageListener.java index 941c33c..e6ea44b 100644 --- a/src/main/java/de/fanta/challenges/events/DamageListener.java +++ b/src/main/java/de/fanta/challenges/events/DamageListener.java @@ -163,14 +163,16 @@ @EventHandler public void onDamageclear(EntityDamageEvent e) { - Player p = (Player) e.getEntity(); if (e.getEntity() instanceof Player) { - if (chl.getConfig().getBoolean("clinvdmg")) { - if ((this.chl.getConfig().getBoolean("timer.enabled")) && p.getGameMode() == GameMode.SURVIVAL) { - for (Player pp : Bukkit.getOnlinePlayers()) { - pp.getInventory().clear(); - ChatUtil.sendNormalMessage(pp, e.getEntity().getName() + " hat Schaden bekommen! Alle Inventare wurden gelöscht!"); + Player p = (Player) e.getEntity(); + if (e.getEntity() instanceof Player) { + if (chl.getConfig().getBoolean("clinvdmg")) { + if ((this.chl.getConfig().getBoolean("timer.enabled")) && p.getGameMode() == GameMode.SURVIVAL) { + for (Player pp : Bukkit.getOnlinePlayers()) { + pp.getInventory().clear(); + ChatUtil.sendNormalMessage(pp, e.getEntity().getName() + " hat Schaden bekommen! Alle Inventare wurden gelöscht!"); + } } } }