From add1be17630b0aee8af0993419699cee401beccd Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Nov 2017 17:22:24 +0000 Subject: [PATCH] Add a countdown to the release of CC --- .../src/mineplex/core/newnpc/NPC.java | 5 + .../mineplex/core/newnpc/NewNPCManager.java | 17 ++- .../src/mineplex/hub/HubManager.java | 3 +- .../hub/plugin/ChristmasHubPlugin.java | 109 ++++++++++++++++++ .../hub/plugin/HalloweenHubPlugin.java | 26 ----- .../mineplex/hub/server/ServerManager.java | 7 +- 6 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/plugin/ChristmasHubPlugin.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java index 11d44065c..717115be6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NPC.java @@ -136,6 +136,11 @@ public class NPC return _id; } + public String getName() + { + return _name; + } + public String getMetadata() { return _metadata; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java index 0decb30d9..d15c3af7d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/newnpc/NewNPCManager.java @@ -140,7 +140,7 @@ public class NewNPCManager extends MiniPlugin { _creature.SetForce(true); - List npcs = getUnloadedNPCs(metadata); + List npcs = getNPCs(metadata, true); npcs.forEach(npc -> { @@ -470,15 +470,24 @@ public class NewNPCManager extends MiniPlugin event.GetEntities().removeIf(this::isNPC); } + /** + * @param metadata The metadata you wish to find all the NPCs of. + * @return A list of {@link NPC} that have the metadata which starts with that specified. + */ + public List getNPCs(String metadata) + { + return getNPCs(metadata, false); + } + /** * @param metadata The metadata you wish to find all the NPCs of. * @return A list of {@link NPC} that are unloaded (have no entity attached to them) and that have the metadata which * starts with that specified. */ - private List getUnloadedNPCs(String metadata) + public List getNPCs(String metadata, boolean unloaded) { return _npcs.stream() - .filter(npc -> npc.getMetadata().startsWith(metadata) && npc.getEntity() == null) + .filter(npc -> npc.getMetadata().startsWith(metadata) && (!unloaded || npc.getEntity() == null)) .collect(Collectors.toList()); } @@ -486,7 +495,7 @@ public class NewNPCManager extends MiniPlugin * @param entity The entity you want to get it's NPC of. * @return The {@link NPC} representation of that entity or null if the entity is not an NPC. */ - public NPC getNPC(Entity entity) + private NPC getNPC(Entity entity) { for (NPC npc : _npcs) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 761194774..e427dc9f4 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -89,6 +89,7 @@ import mineplex.hub.modules.salesannouncements.SalesAnnouncementManager; import mineplex.hub.news.NewsManager; import mineplex.hub.player.CreativeManager; import mineplex.hub.player.HubPlayerManager; +import mineplex.hub.plugin.ChristmasHubPlugin; import mineplex.hub.plugin.HubPlugin; import mineplex.hub.scoreboard.HubScoreboard; import mineplex.hub.world.HubWorldManager; @@ -233,7 +234,7 @@ public class HubManager extends MiniClientPlugin implements IChatMess //require(StaffBuild.class); //require(HubPortalManager.class); - _hubPlugin = new HubPlugin(); + _hubPlugin = new ChristmasHubPlugin(); generatePermissions(); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/ChristmasHubPlugin.java b/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/ChristmasHubPlugin.java new file mode 100644 index 000000000..174ddea75 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/ChristmasHubPlugin.java @@ -0,0 +1,109 @@ +package mineplex.hub.plugin; + +import java.util.Calendar; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; +import mineplex.core.newnpc.NPC; +import mineplex.core.newnpc.event.NPCInteractEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class ChristmasHubPlugin extends HubPlugin +{ + + private static final PotionEffect NIGHT_VISION = new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0); + private static final long RELEASE_DATE; + + static + { + Calendar calendar = Calendar.getInstance(); + calendar.set(2017, Calendar.DECEMBER, 8); + RELEASE_DATE = calendar.getTimeInMillis(); + } + + private NPC _christmasNPC; + + public ChristmasHubPlugin() + { + super("Christmas"); + } + + @Override + protected void setupWorld() + { + _manager.GetSpawn().getWorld().setTime(18000); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + event.getPlayer().addPotionEffect(NIGHT_VISION); + } + + @EventHandler + public void updateNPC(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + { + return; + } + + if (_christmasNPC == null) + { + List npcs = _npcManager.getNPCs("GAME_Christmas"); + + if (npcs.isEmpty()) + { + return; + } + + NPC npc = npcs.get(0); + + if (npc.getEntity() == null) + { + return; + } + + npc.getNameTag(); + _christmasNPC = npc; + } + + String formatted; + long time = getTimeUntilRelease(); + + if (time > 0) + { + formatted = C.cYellow + UtilTime.MakeStr(time); + } + else + { + formatted = C.cAquaB + "NEW GAME"; + } + + _christmasNPC.getNameTag().setText(formatted, C.cBlack, ChatColor.translateAlternateColorCodes('&', _christmasNPC.getName())); + } + + @EventHandler + public void npcInteract(NPCInteractEvent event) + { + if (event.getNpc().equals(_christmasNPC) && getTimeUntilRelease() > 0) + { + event.setCancelled(true); + event.getPlayer().sendMessage(F.main(_moduleName, "Coming soon.")); + } + } + + private long getTimeUntilRelease() + { + return RELEASE_DATE - System.currentTimeMillis(); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/HalloweenHubPlugin.java b/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/HalloweenHubPlugin.java index 777604f46..13e9a2f33 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/HalloweenHubPlugin.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/plugin/HalloweenHubPlugin.java @@ -2,12 +2,8 @@ package mineplex.hub.plugin; import net.md_5.bungee.api.ChatColor; -import org.bukkit.event.EventHandler; - import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextTop; -import mineplex.core.newnpc.NPC; -import mineplex.core.newnpc.event.NPCInteractEvent; import mineplex.core.titles.tracks.custom.ScrollAnimation; import mineplex.core.updater.UpdateType; import mineplex.core.utils.UtilScheduler; @@ -23,7 +19,6 @@ public class HalloweenHubPlugin extends HubPlugin .build(); private int _newsIndex; - private NPC _messengerNPC; public HalloweenHubPlugin() { @@ -31,17 +26,12 @@ public class HalloweenHubPlugin extends HubPlugin _newsManager.setEnabled(false); UtilScheduler.runEvery(UpdateType.FASTEST, this::displayNews); - UtilScheduler.runEvery(UpdateType.MIN_01, this::checkEventStart); } @Override protected void setupWorld() { _manager.GetSpawn().getWorld().setTime(18000); - _npcManager.spawnNPCs("HALLOWEEN_MESSENGER", npc -> - { - _messengerNPC = npc; - }); } private void displayNews() @@ -53,20 +43,4 @@ public class HalloweenHubPlugin extends HubPlugin UtilTextTop.display(NEWS_TEXT[_newsIndex], UtilServer.getPlayers()); } - - private void checkEventStart() - { - - } - - @EventHandler - public void npcInteract(NPCInteractEvent event) - { - if (!event.getNpc().equals(_messengerNPC)) - { - return; - } - - - } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index a148d09e0..2abb5fc38 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -136,9 +136,14 @@ public class ServerManager extends MiniPlugin PermissionGroup.BUILDER.setPermission(Perm.FEATURE_SERVER, true, true); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void npcInteract(NPCInteractEvent event) { + if (event.isCancelled()) + { + return; + } + String metadata = event.getNpc().getMetadata(); String[] split = metadata.split("_");