Add a countdown to the release of CC

This commit is contained in:
Sam 2017-11-28 17:22:24 +00:00 committed by Alexander Meech
parent 593952fa10
commit add1be1763
6 changed files with 135 additions and 32 deletions

View File

@ -136,6 +136,11 @@ public class NPC
return _id;
}
public String getName()
{
return _name;
}
public String getMetadata()
{
return _metadata;

View File

@ -140,7 +140,7 @@ public class NewNPCManager extends MiniPlugin
{
_creature.SetForce(true);
List<NPC> npcs = getUnloadedNPCs(metadata);
List<NPC> 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<NPC> 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<NPC> getUnloadedNPCs(String metadata)
public List<NPC> 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)
{

View File

@ -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<HubClient> implements IChatMess
//require(StaffBuild.class);
//require(HubPortalManager.class);
_hubPlugin = new HubPlugin();
_hubPlugin = new ChristmasHubPlugin();
generatePermissions();
}

View File

@ -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<NPC> 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();
}
}

View File

@ -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;
}
}
}

View File

@ -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("_");