From a64dc6a8d4ac8b39f0bd955a84d539c4227d1a71 Mon Sep 17 00:00:00 2001 From: William Burns Date: Thu, 31 Dec 2015 00:46:31 +0000 Subject: [PATCH] Made it activate in all lobbies via command. --- .../mineplex/hub/commands/NewYearCommand.java | 37 +++++++--- .../hub/modules/NewYearCountdown.java | 69 +++++++++++++------ .../hub/modules/newyear/NewYearHandler.java | 28 ++++++++ .../hub/modules/newyear/NewYearMessage.java | 29 ++++++++ 4 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearHandler.java create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearMessage.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java index 55e64903d..2e1ec8432 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/commands/NewYearCommand.java @@ -5,7 +5,10 @@ import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.hub.modules.NewYearCountdown; +import mineplex.hub.modules.newyear.NewYearMessage; /** * Created by William (WilliamTiger). @@ -23,28 +26,42 @@ public class NewYearCommand extends CommandBase { if (Plugin.isInProgress()) { - caller.sendMessage(ChatColor.RED + "A new year countdown event is already in progress!"); + caller.sendMessage(F.main("NYC", C.cRed + "A new year countdown event is already in progress!")); return; } - if (args.length != 1) + if (args.length != 3) { - caller.sendMessage(ChatColor.RED + "/newyear "); + caller.sendMessage(F.main("NYC", C.cRed + "/newyear ")); return; } - int mins = 0; + if (!(validateInteger(args[0]) && validateInteger(args[1]) && validateInteger(args[2]))) + { + caller.sendMessage(F.main("NYC", C.cRed + "You have entered invalid hours/minutes/seconds.")); + return; + } + + int hours = Integer.valueOf(args[0]); + int mins = Integer.valueOf(args[1]); + int secs = Integer.valueOf(args[2]); + int total = secs + (mins * 60) + (hours * 60 * 60); + + caller.sendMessage(F.main("NYC", "Sent command to all lobbies to start with " + F.elem(total + "") + " seconds.")); + new NewYearMessage(total).publish(); + } + + private boolean validateInteger(String str) + { + boolean passed = false; try { - mins = Integer.parseInt(args[0]); + int i = Integer.valueOf(str); + passed = true; } catch (Exception e) { - caller.sendMessage(ChatColor.RED + "That is not a valid amount of minutes!"); - return; } - - - Plugin.start(caller, mins); + return passed; } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewYearCountdown.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewYearCountdown.java index 027b1c89e..286a9a152 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewYearCountdown.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewYearCountdown.java @@ -6,10 +6,12 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.util.*; import java.util.List; +import java.util.concurrent.TimeUnit; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -30,6 +32,9 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.hub.commands.NewYearCommand; +import mineplex.hub.modules.newyear.NewYearHandler; +import mineplex.hub.modules.newyear.NewYearMessage; +import mineplex.serverdata.commands.ServerCommandManager; /** * Created by William (WilliamTiger). @@ -46,6 +51,10 @@ public class NewYearCountdown extends MiniPlugin { super("New Year Countdown", plugin); + ServerCommandManager.getInstance().registerCommandType("NewYearCommand", + NewYearMessage.class, new NewYearHandler(this)); + + _center = new Location(UtilWorld.getWorld("world"), 0.5, 85, 37.5); _inProgress = false; } @@ -60,24 +69,24 @@ public class NewYearCountdown extends MiniPlugin return _inProgress; } - public void start(Player player, int mins) + public void start(int seconds) { _inProgress = true; - _center = player.getLocation(); - _stage = mins * 60; - UtilServer.broadcast(C.cGreenB + player.getName() + " has started a " + C.cAquaB + "New Year's Countdown"); + _stage = seconds; UtilWorld.getWorld("world").setTime(18000); - _currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 36), formatTimer(_stage)); } @EventHandler public void cmd(PlayerCommandPreprocessEvent e) { + if (!e.getPlayer().getName().equalsIgnoreCase("WilliamTiger")) + return; + if (e.getMessage().equalsIgnoreCase("/lmao")) { e.setCancelled(true); - start(e.getPlayer(), 3); + start(30); } } @@ -92,6 +101,10 @@ public class NewYearCountdown extends MiniPlugin _stage--; + if (_stage > 0 && _stage <= 10) + for (Player p : UtilServer.getPlayers()) + p.playSound(p.getLocation(), Sound.NOTE_BASS, 1f, 1f); + if (_stage <= 0) return; @@ -109,7 +122,7 @@ public class NewYearCountdown extends MiniPlugin if (_stage == 0) { - _currentFrame = null; + _currentFrame = stringToBufferedImage(new Font("Tahoma", Font.PLAIN, 20), "Happy New Year"); UtilTextMiddle.display(C.cGoldB + "2016", C.cYellowB + "Happy New Year!", UtilServer.getPlayers()); } @@ -117,6 +130,7 @@ public class NewYearCountdown extends MiniPlugin { //End of event. _inProgress = false; + _currentFrame = null; UtilWorld.getWorld("world").setTime(0); return; } @@ -152,7 +166,7 @@ public class NewYearCountdown extends MiniPlugin continue; Vector v = new Vector((float) _currentFrame.getWidth() / 2 - x, (float) _currentFrame.getHeight() / 2 - y, 0).multiply(0.5); - UtilParticle.PlayParticle(UtilParticle.ParticleType.FLAME, _center.add(v), 0, 0, 0, 0, 1, UtilParticle.ViewDist.MAX); + UtilParticle.PlayParticle(UtilParticle.ParticleType.HAPPY_VILLAGER, _center.add(v), 0, 0, 0, 0, 1, UtilParticle.ViewDist.MAX); _center.subtract(v); } } @@ -182,19 +196,23 @@ public class NewYearCountdown extends MiniPlugin return img; } - private String formatTimer(int seconds) + private String formatTimer(long seconds) { - if (seconds <= 60) - return "" + seconds; + long minutes = seconds / 60; + long hours = minutes / 60; - int mins = seconds / 60; - int secs = seconds % 60; - String s = String.valueOf(secs); + if ((hours % 60) > 0) + return zeroNumber(hours % 60) + ":" + zeroNumber(minutes % 60) + ":" + zeroNumber(seconds % 60); - if (s.length() == 1) - s = "0" + s; + if ((minutes % 60) > 0) + return zeroNumber(minutes % 60) + ":" + zeroNumber(seconds % 60); - return mins + ":" + s; + return zeroNumber(seconds % 60); + } + + private String zeroNumber(long time) + { + return (time < 10 ? "0" : "") + time; } private Location offsetLoc(Location loc) @@ -224,13 +242,20 @@ public class NewYearCountdown extends MiniPlugin } FireworkEffect.Type t = FireworkEffect.Type.BALL; int rType = new Random().nextInt(4); - if (rType == 0) { + if (rType == 0) + { t = FireworkEffect.Type.BALL_LARGE; - } else if (rType == 1) { + } + else if (rType == 1) + { t = FireworkEffect.Type.BURST; - } else if (rType == 2) { + } + else if (rType == 2) + { t = FireworkEffect.Type.STAR; - } else if (rType == 3) { + } + else if (rType == 3) + { t = FireworkEffect.Type.CREEPER; } Firework f = l.getWorld().spawn(l, Firework.class); @@ -242,7 +267,7 @@ public class NewYearCountdown extends MiniPlugin public UtilParticle.ParticleType getRandomParticle() { - List types = Arrays.asList(UtilParticle.ParticleType.FLAME, UtilParticle.ParticleType.FIREWORKS_SPARK, UtilParticle.ParticleType.RED_DUST); + List types = Arrays.asList(UtilParticle.ParticleType.FLAME, UtilParticle.ParticleType.HAPPY_VILLAGER, UtilParticle.ParticleType.RED_DUST); return types.get(new Random().nextInt(types.size())); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearHandler.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearHandler.java new file mode 100644 index 000000000..7f2f3cf80 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearHandler.java @@ -0,0 +1,28 @@ +package mineplex.hub.modules.newyear; + +import mineplex.hub.modules.NewYearCountdown; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * Created by William (WilliamTiger). + * 31/12/15 + */ +public class NewYearHandler implements CommandCallback +{ + private NewYearCountdown _newYear; + + public NewYearHandler(NewYearCountdown newYear) + { + _newYear = newYear; + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof NewYearMessage) + { + _newYear.start(((NewYearMessage)command).getSeconds()); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearMessage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearMessage.java new file mode 100644 index 000000000..aaf21447f --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/newyear/NewYearMessage.java @@ -0,0 +1,29 @@ +package mineplex.hub.modules.newyear; + +import mineplex.serverdata.commands.ServerCommand; + +/** + * Created by William (WilliamTiger). + * 31/12/15 + */ +public class NewYearMessage extends ServerCommand +{ + + private int seconds; + + public NewYearMessage(int seconds) + { + this.seconds = seconds; + } + + public int getSeconds() + { + return seconds; + } + + @Override + public void run() + { + + } +}