Change Reverse Tag to be the longest held time, not round based.

This commit is contained in:
Sam 2018-09-05 21:02:06 +01:00 committed by Alexander Meech
parent af595585ea
commit 25013ea741
5 changed files with 298 additions and 373 deletions

View File

@ -19,11 +19,11 @@ import mineplex.game.nano.game.games.oits.SnowballTrouble;
import mineplex.game.nano.game.games.parkour.Parkour; import mineplex.game.nano.game.games.parkour.Parkour;
import mineplex.game.nano.game.games.quick.Quick; import mineplex.game.nano.game.games.quick.Quick;
import mineplex.game.nano.game.games.redgreenlight.RedGreenLight; import mineplex.game.nano.game.games.redgreenlight.RedGreenLight;
import mineplex.game.nano.game.games.reversetag.ReverseTag;
import mineplex.game.nano.game.games.slimecycles.SlimeCycles; import mineplex.game.nano.game.games.slimecycles.SlimeCycles;
import mineplex.game.nano.game.games.spleef.Spleef; import mineplex.game.nano.game.games.spleef.Spleef;
import mineplex.game.nano.game.games.sploor.Sploor; import mineplex.game.nano.game.games.sploor.Sploor;
import mineplex.game.nano.game.games.tag.HotPotato; import mineplex.game.nano.game.games.hotpotato.HotPotato;
import mineplex.game.nano.game.games.tag.ReverseTag;
import mineplex.game.nano.game.games.territory.Territory; import mineplex.game.nano.game.games.territory.Territory;
public enum GameType public enum GameType

View File

@ -1,34 +1,50 @@
package mineplex.game.nano.game.games.tag; package mineplex.game.nano.game.games.hotpotato;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.bukkit.Color;
import org.bukkit.EntityEffect; import org.bukkit.EntityEffect;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.nano.NanoManager; import mineplex.game.nano.NanoManager;
import mineplex.game.nano.game.GameType; import mineplex.game.nano.game.GameType;
import mineplex.game.nano.game.SoloGame; import mineplex.game.nano.game.SoloGame;
import mineplex.game.nano.game.event.PlayerGameRespawnEvent;
import mineplex.game.nano.game.event.PlayerStateChangeEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public abstract class TagGame extends SoloGame public class HotPotato extends SoloGame
{ {
private static final long ROUND_END_TIME = TimeUnit.SECONDS.toMillis(4); private static final long ROUND_END_TIME = TimeUnit.SECONDS.toMillis(4);
@ -42,9 +58,15 @@ public abstract class TagGame extends SoloGame
private List<Location> _teleportTo; private List<Location> _teleportTo;
private long _lastRoundStart, _lastRoundEnd, _roundTime; private long _lastRoundStart, _lastRoundEnd, _roundTime;
TagGame(NanoManager manager, GameType gameType, String[] description) public HotPotato(NanoManager manager)
{ {
super(manager, gameType, description); super(manager, GameType.HOT_POTATO, new String[]
{
"Run away from players with " + C.cRed + "TNT" + C.Reset + "!",
C.cYellow + "Punch players" + C.Reset + " to give them the " + C.cYellow + "Potato" + C.Reset + "!",
"Watch out! Potatoes are " + C.cRed + "Explosive" + C.Reset + ".",
C.cYellow + "Last player" + C.Reset + " standing wins!"
});
_holders = new ArrayList<>(); _holders = new ArrayList<>();
@ -67,7 +89,7 @@ public abstract class TagGame extends SoloGame
{ {
scoreboard.writeNewLine(); scoreboard.writeNewLine();
scoreboard.write(getScoreboardTitle()); scoreboard.write(C.cRedB + "Potatoes");
if (_holders.isEmpty()) if (_holders.isEmpty())
{ {
@ -95,24 +117,10 @@ public abstract class TagGame extends SoloGame
_teleportTo.forEach(location -> location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getSpectatorLocation())))); _teleportTo.forEach(location -> location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, getSpectatorLocation()))));
} }
protected abstract boolean canTag(boolean damageeHolder, boolean damagerHolder); @Override
public void disable()
protected abstract void tagPlayers(Player damagee, Player damager);
protected abstract void onTagged(Player player, boolean tagged, boolean initial);
protected abstract void onHolderTick(Player player);
protected abstract void onRoundEnd(List<Player> holders);
protected abstract String getScoreboardTitle();
protected abstract String getAnnounceRoundString(int holders);
@EventHandler
public void respawn(PlayerGameRespawnEvent event)
{ {
onTagged(event.getPlayer(), false, false); _holders.clear();
} }
@EventHandler @EventHandler
@ -132,7 +140,6 @@ public abstract class TagGame extends SoloGame
} }
List<Player> alive = getAlivePlayers(); List<Player> alive = getAlivePlayers();
_holders.addAll(alive); _holders.addAll(alive);
int players = (int) Math.floor(_holders.size() * POTATO_FACTOR); int players = (int) Math.floor(_holders.size() * POTATO_FACTOR);
@ -147,7 +154,7 @@ public abstract class TagGame extends SoloGame
_holders.remove(UtilMath.r(_holders.size())); _holders.remove(UtilMath.r(_holders.size()));
} }
announce(F.main(getManager().getName(), getAnnounceRoundString(_holders.size()))); announce(F.main(getManager().getName(), "A round has started with " + F.count(players) + " potato" + (players == 1 ? "" : "es") + "!"));
_lastRoundStart = System.currentTimeMillis(); _lastRoundStart = System.currentTimeMillis();
_roundTime = TimeUnit.SECONDS.toMillis(UtilMath.rRange(ROUND_MIN_TIME, ROUND_MAX_TIME)); _roundTime = TimeUnit.SECONDS.toMillis(UtilMath.rRange(ROUND_MIN_TIME, ROUND_MAX_TIME));
@ -172,13 +179,39 @@ public abstract class TagGame extends SoloGame
if (diff > _roundTime) if (diff > _roundTime)
{ {
_lastRoundEnd = System.currentTimeMillis(); _lastRoundEnd = System.currentTimeMillis();
onRoundEnd(_holders);
_holders.clear(); int exploded = 0;
FireworkEffect effect = FireworkEffect.builder()
.with(UtilMath.randomElement(Type.values()))
.withColor(Color.RED)
.build();
for (Player player : getAlivePlayers()) for (Player player : getAlivePlayers())
{ {
onTagged(player, false, false); if (!_holders.contains(player))
{
continue;
} }
Location location = player.getLocation().add(0, 1, 0);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location, null, 0, 1, ViewDist.LONG);
location.getWorld().playSound(location, Sound.EXPLODE, 1, 0.5F);
if (exploded++ < 5)
{
for (int i = 0; i < 3; i++)
{
UtilFirework.launchFirework(location, effect, null, i);
}
}
getManager().getDamageManager().NewDamageEvent(player, null, null, DamageCause.ENTITY_EXPLOSION, 500, false, true, true, getGameType().getName(), "The Hot Potato");
getManager().runSyncLater(() -> UtilAction.velocity(player, new Vector(0, 2, 0)), 1);
}
UtilTextBottom.display(C.cRedB + "BOOM!", UtilServer.getPlayers());
_holders.clear();
} }
else else
{ {
@ -186,26 +219,15 @@ public abstract class TagGame extends SoloGame
UtilTextBottom.displayProgress("Detonation", (double) diff / _roundTime, (diff < 3000 ? C.cRed : "") + UtilTime.MakeStr(Math.max(0, diff)), UtilServer.getPlayers()); UtilTextBottom.displayProgress("Detonation", (double) diff / _roundTime, (diff < 3000 ? C.cRed : "") + UtilTime.MakeStr(Math.max(0, diff)), UtilServer.getPlayers());
_holders.forEach(this::onHolderTick); _holders.forEach(player ->
} {
} List<Player> players = player.getWorld().getPlayers();
} players.remove(player);
protected void setTagged(Player player, boolean tagged, boolean initial) UtilParticle.PlayParticle(ParticleType.FLAME, player.getLocation().add(0, 2, 0), null, 0.01F, 1, ViewDist.LONG, players.toArray(new Player[0]));
{ });
if (tagged)
{
if (!initial)
{
_holders.add(player);
} }
} }
else
{
_holders.remove(player);
}
onTagged(player, tagged, initial);
} }
@EventHandler @EventHandler
@ -218,7 +240,7 @@ public abstract class TagGame extends SoloGame
Player damagee = event.GetDamageePlayer(), damager = event.GetDamagerPlayer(false); Player damagee = event.GetDamageePlayer(), damager = event.GetDamagerPlayer(false);
if (damagee == null || damager == null || UtilPlayer.isSpectator(damagee) || UtilPlayer.isSpectator(damager) || !canTag(_holders.contains(damagee), _holders.contains(damager))) if (damagee == null || damager == null || UtilPlayer.isSpectator(damagee) || UtilPlayer.isSpectator(damager) || _holders.contains(damagee) || !_holders.contains(damager))
{ {
return; return;
} }
@ -231,22 +253,50 @@ public abstract class TagGame extends SoloGame
} }
damagee.playEffect(EntityEffect.HURT); damagee.playEffect(EntityEffect.HURT);
tagPlayers(damagee, damager); setTagged(damagee, true, false);
setTagged(damager, false, false);
} }
@EventHandler private void setTagged(Player player, boolean tagged, boolean initial)
public void playerQut(PlayerStateChangeEvent event)
{ {
if (!event.isAlive()) if (tagged)
{ {
_holders.remove(event.getPlayer()); if (!initial)
} {
_holders.add(player);
} }
@Override PlayerInventory inventory = player.getInventory();
public void disable() ItemStack inHand = new ItemBuilder(Material.POTATO_ITEM)
.setTitle(C.cRedB + "Punch Someone!")
.build();
for (int i = 0; i < 9; i++)
{ {
_holders.clear(); inventory.setItem(i, inHand);
}
inventory.setHelmet(new ItemStack(Material.TNT));
inventory.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE)
.setColor(Color.RED)
.build());
inventory.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS)
.setColor(Color.RED)
.build());
inventory.setBoots(new ItemBuilder(Material.LEATHER_BOOTS)
.setColor(Color.RED)
.build());
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false));
UtilTextMiddle.display(null, C.cRed + "You have the Potato! Hit someone to get rid of it!", 0, initial ? 50 : 20, 10, player);
}
else
{
_holders.remove(player);
UtilPlayer.clearInventory(player);
player.removePotionEffect(PotionEffectType.SPEED);
}
} }
@EventHandler @EventHandler

View File

@ -0,0 +1,187 @@
package mineplex.game.nano.game.games.reversetag;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.Color;
import org.bukkit.EntityEffect;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.nano.NanoManager;
import mineplex.game.nano.game.GameType;
import mineplex.game.nano.game.ScoredSoloGame;
import mineplex.game.nano.game.event.GameStateChangeEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class ReverseTag extends ScoredSoloGame
{
private static final double EMERALD_FACTOR = 0.5;
private final List<Player> _holders;
public ReverseTag(NanoManager manager)
{
super(manager, GameType.REVERSE_TAG, new String[]
{
"Try to keep hold of the " + C.cGreen + "Emeralds" + C.Reset + "!",
C.cYellow + "Punch players" + C.Reset + " to take their " + C.cGreen + "Emeralds" + C.Reset + "!",
"Every " + C.cYellow + "Second" + C.Reset + " with " + C.cGreen + "Emeralds" + C.Reset + " you earn points.",
C.cYellow + "Most points" + C.Reset + " wins!"
});
_holders = new ArrayList<>();
_damageComponent
.setPvp(false)
.setFall(false);
_prepareComponent.setPrepareFreeze(false);
_playerComponent.setHideParticles(true);
_endComponent.setTimeout(TimeUnit.MINUTES.toMillis(1));
}
@Override
protected void parseData()
{
}
@Override
public void disable()
{
_holders.clear();
}
@EventHandler
public void live(GameStateChangeEvent event)
{
if (event.getState() != GameState.Live)
{
return;
}
List<Player> alive = getAlivePlayers();
int players = (int) Math.ceil(alive.size() * EMERALD_FACTOR);
if (players == 0)
{
setState(GameState.End);
return;
}
while (alive.size() > players)
{
alive.remove(UtilMath.r(alive.size()));
}
_holders.addAll(alive);
_holders.forEach(player -> setTagged(player, true, true));
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !isLive())
{
return;
}
_holders.forEach(player -> incrementScore(player, 1));
}
@EventHandler
public void damage(CustomDamageEvent event)
{
if (!isLive())
{
return;
}
Player damagee = event.GetDamageePlayer(), damager = event.GetDamagerPlayer(false);
if (damagee == null || damager == null || UtilPlayer.isSpectator(damagee) || UtilPlayer.isSpectator(damager) || !_holders.contains(damagee) || _holders.contains(damager))
{
return;
}
String name = "Tag Player";
if (!Recharge.Instance.usable(damagee, name) || !Recharge.Instance.use(damager, name, 500, false, false))
{
return;
}
damagee.playEffect(EntityEffect.HURT);
setTagged(damagee, false, false);
setTagged(damager, true, false);
}
private void setTagged(Player player, boolean tagged, boolean initial)
{
if (tagged)
{
if (!initial)
{
_holders.add(player);
}
PlayerInventory inventory = player.getInventory();
ItemStack inHand = new ItemBuilder(Material.EMERALD)
.setTitle(C.cGreenB + "Keep These!")
.build();
for (int i = 0; i < 9; i++)
{
inventory.setItem(i, inHand);
}
inventory.setHelmet(new ItemStack(Material.EMERALD_BLOCK));
inventory.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE)
.setColor(Color.LIME)
.build());
inventory.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS)
.setColor(Color.LIME)
.build());
inventory.setBoots(new ItemBuilder(Material.LEATHER_BOOTS)
.setColor(Color.LIME)
.build());
player.removePotionEffect(PotionEffectType.SPEED);
UtilTextMiddle.display(null, C.cGreen + "You have the Emeralds! Run!", 0, initial ? 50 : 20, 10, player);
}
else
{
_holders.remove(player);
UtilPlayer.clearInventory(player);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false));
}
}
@EventHandler
public void sneak(PlayerToggleSneakEvent event)
{
if (event.isSneaking() && isAlive(event.getPlayer()))
{
event.setCancelled(true);
}
}
}

View File

@ -1,156 +0,0 @@
package mineplex.game.nano.game.games.tag;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.nano.NanoManager;
import mineplex.game.nano.game.GameType;
public class HotPotato extends TagGame
{
public HotPotato(NanoManager manager)
{
super(manager, GameType.HOT_POTATO, new String[]
{
"Run away from players with " + C.cRed + "TNT" + C.Reset + "!",
C.cYellow + "Punch players" + C.Reset + " to give them the " + C.cYellow + "Potato" + C.Reset + "!",
"Watch out! Potatoes are " + C.cRed + "Explosive" + C.Reset + ".",
C.cYellow + "Last player" + C.Reset + " standing wins!"
});
}
@Override
protected boolean canTag(boolean damageeHolder, boolean damagerHolder)
{
return !damageeHolder && damagerHolder;
}
@Override
protected void tagPlayers(Player damagee, Player damager)
{
setTagged(damagee, true, false);
setTagged(damager, false, false);
}
@Override
protected void onTagged(Player player, boolean tagged, boolean initial)
{
if (tagged)
{
PlayerInventory inventory = player.getInventory();
ItemStack inHand = new ItemBuilder(Material.POTATO_ITEM)
.setTitle(C.cRedB + "Punch Someone!")
.build();
for (int i = 0; i < 9; i++)
{
inventory.setItem(i, inHand);
}
inventory.setHelmet(new ItemStack(Material.TNT));
inventory.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE)
.setColor(Color.RED)
.build());
inventory.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS)
.setColor(Color.RED)
.build());
inventory.setBoots(new ItemBuilder(Material.LEATHER_BOOTS)
.setColor(Color.RED)
.build());
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false));
UtilTextMiddle.display(null, C.cRed + "You have the Potato! Hit someone to get rid of it!", 0, initial ? 50 : 20, 10, player);
}
else
{
UtilPlayer.clearInventory(player);
player.removePotionEffect(PotionEffectType.SPEED);
}
}
@Override
protected void onHolderTick(Player player)
{
List<Player> players = new ArrayList<>(player.getWorld().getPlayers());
players.remove(player);
UtilParticle.PlayParticle(ParticleType.FLAME, player.getLocation().add(0, 2, 0), null, 0.01F, 1, ViewDist.LONG, players.toArray(new Player[0]));
}
@Override
protected void onRoundEnd(List<Player> holders)
{
int exploded = 0;
FireworkEffect effect = FireworkEffect.builder()
.with(UtilMath.randomElement(Type.values()))
.withColor(Color.RED)
.build();
for (Player player : getAlivePlayers())
{
if (!holders.contains(player))
{
continue;
}
Location location = player.getLocation().add(0, 1, 0);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, location, null, 0, 1, ViewDist.LONG);
location.getWorld().playSound(location, Sound.EXPLODE, 1, 0.5F);
if (exploded++ < 5)
{
for (int i = 0; i < 3; i++)
{
UtilFirework.launchFirework(location, effect, null, i);
}
}
getManager().getDamageManager().NewDamageEvent(player, null, null, DamageCause.ENTITY_EXPLOSION, 500, false, true, true, getGameType().getName(), "The Hot Potato");
getManager().runSyncLater(() -> UtilAction.velocity(player, new Vector(0, 2, 0)), 1);
}
UtilTextBottom.display(C.cRedB + "BOOM!", UtilServer.getPlayers());
}
@Override
protected String getScoreboardTitle()
{
return C.cRedB + "Potatoes";
}
@Override
protected String getAnnounceRoundString(int holders)
{
return "A round has started with " + F.count(holders) + " potato" + (holders == 1 ? "" : "es") + "!";
}
}

View File

@ -1,156 +0,0 @@
package mineplex.game.nano.game.games.tag;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilFirework;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.nano.NanoManager;
import mineplex.game.nano.game.GameType;
public class ReverseTag extends TagGame
{
public ReverseTag(NanoManager manager)
{
super(manager, GameType.REVERSE_TAG, new String[]
{
"Try to keep hold of the " + C.cGreen + "Emeralds" + C.Reset + "!",
C.cYellow + "Punch players" + C.Reset + " to take their " + C.cGreen + "Emeralds" + C.Reset + "!",
"If you don't have the " + C.cGreen + "Emeralds" + C.Reset + " when the time is up. You lose!",
C.cYellow + "Last player" + C.Reset + " standing wins!"
});
}
@Override
protected boolean canTag(boolean damageeHolder, boolean damagerHolder)
{
return damageeHolder && !damagerHolder;
}
@Override
protected void tagPlayers(Player damagee, Player damager)
{
setTagged(damager, true, false);
setTagged(damagee, false, false);
}
@Override
protected void onTagged(Player player, boolean tagged, boolean initial)
{
if (tagged)
{
PlayerInventory inventory = player.getInventory();
ItemStack inHand = new ItemBuilder(Material.EMERALD)
.setTitle(C.cGreenB + "Keep these. Run!")
.build();
for (int i = 0; i < 9; i++)
{
inventory.setItem(i, inHand);
}
inventory.setHelmet(new ItemStack(Material.EMERALD_BLOCK));
inventory.setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE)
.setColor(Color.LIME)
.build());
inventory.setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS)
.setColor(Color.LIME)
.build());
inventory.setBoots(new ItemBuilder(Material.LEATHER_BOOTS)
.setColor(Color.LIME)
.build());
player.removePotionEffect(PotionEffectType.SPEED);
UtilTextMiddle.display(null, C.cGreen + "You have Emeralds! Run!", 0, initial ? 50 : 20, 10, player);
}
else
{
UtilPlayer.clearInventory(player);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false));
}
}
@Override
protected void onHolderTick(Player player)
{
List<Player> players = new ArrayList<>(player.getWorld().getPlayers());
players.remove(player);
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, player.getLocation().add(0, 2, 0), null, 0.01F, 1, ViewDist.LONG, players.toArray(new Player[0]));
}
@Override
protected void onRoundEnd(List<Player> holders)
{
int exploded = 0;
FireworkEffect effect = FireworkEffect.builder()
.with(UtilMath.randomElement(Type.values()))
.withColor(Color.LIME)
.build();
for (Player player : getAlivePlayers())
{
if (holders.contains(player))
{
continue;
}
Location location = player.getLocation().add(0, 1, 0);
UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, location, 1, 1, 1, 0, 20, ViewDist.LONG);
location.getWorld().playSound(location, Sound.VILLAGER_DEATH, 1, 0.5F);
if (exploded++ < 5)
{
for (int i = 0; i < 3; i++)
{
UtilFirework.launchFirework(location, effect, null, i);
}
}
getManager().getDamageManager().NewDamageEvent(player, null, null, DamageCause.ENTITY_EXPLOSION, 500, false, true, true, getGameType().getName(), "Lack of Emeralds");
getManager().runSyncLater(() -> UtilAction.velocity(player, new Vector(0, 2, 0)), 1);
}
UtilTextBottom.display(C.cGreenB + "BOOM!", UtilServer.getPlayers());
}
@Override
protected String getScoreboardTitle()
{
return C.cGreenB + "Emerald Holders";
}
@Override
protected String getAnnounceRoundString(int holders)
{
return "A round has started with " + F.count(holders) + " player" + (holders == 1 ? "" : "s") + " with emeralds!";
}
}