Added new class for peasants
This commit is contained in:
parent
25487ad0b1
commit
124d22ce31
@ -1,5 +1,8 @@
|
||||
package mineplex.core.gadget.gadgets.particle.king;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -16,6 +19,8 @@ import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.core.gadget.gadgets.particle.king.events.UpdateKingEvent;
|
||||
import mineplex.core.gadget.gadgets.particle.king.types.King;
|
||||
import mineplex.core.gadget.gadgets.particle.king.types.Peasant;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
|
||||
@ -39,6 +44,9 @@ public class CastleManager extends MiniPlugin
|
||||
|
||||
private boolean _isHub = false;
|
||||
|
||||
private Map<Player, King> _kings = new HashMap<>();
|
||||
private Map<Player, Peasant> _peasants = new HashMap<>();
|
||||
|
||||
public CastleManager(JavaPlugin plugin, HologramManager hologramManager, boolean isHub)
|
||||
{
|
||||
super("CastleManager", plugin);
|
||||
@ -191,4 +199,91 @@ public class CastleManager extends MiniPlugin
|
||||
_hologram.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void setPlayerAsKing(Player player)
|
||||
{
|
||||
if (isKing(player))
|
||||
return;
|
||||
|
||||
if (isPeasant(player))
|
||||
removePeasant(player, false);
|
||||
|
||||
_kings.put(player, new King(player));
|
||||
}
|
||||
|
||||
public boolean isKing(Player player)
|
||||
{
|
||||
return _kings.containsKey(player);
|
||||
}
|
||||
|
||||
public void removeKing(Player player, boolean setPeasant)
|
||||
{
|
||||
if (!isKing(player))
|
||||
return;
|
||||
|
||||
_kings.get(player).clearPeasants();
|
||||
_kings.remove(player);
|
||||
|
||||
if (setPeasant)
|
||||
setPlayerAsPeasant(player);
|
||||
}
|
||||
|
||||
public King getKing(Player player)
|
||||
{
|
||||
if (!isKing(player))
|
||||
return null;
|
||||
|
||||
return _kings.get(player);
|
||||
}
|
||||
|
||||
public void setPlayerAsPeasant(Player player)
|
||||
{
|
||||
if (isPeasant(player))
|
||||
return;
|
||||
|
||||
if (isKing(player))
|
||||
removeKing(player, false);
|
||||
|
||||
_peasants.put(player, new Peasant(player));
|
||||
}
|
||||
|
||||
public boolean isPeasant(Player player)
|
||||
{
|
||||
return _peasants.containsKey(player);
|
||||
}
|
||||
|
||||
public void removePeasant(Player player, boolean setKing)
|
||||
{
|
||||
if (!isPeasant(player))
|
||||
return;
|
||||
|
||||
_peasants.remove(player);
|
||||
|
||||
if (setKing)
|
||||
setPlayerAsKing(player);
|
||||
}
|
||||
|
||||
public Peasant getPeasant(Player player)
|
||||
{
|
||||
if (!isPeasant(player))
|
||||
return null;
|
||||
|
||||
return _peasants.get(player);
|
||||
}
|
||||
|
||||
public King getLobbyKing()
|
||||
{
|
||||
if (_kings.size() == 0)
|
||||
return null;
|
||||
|
||||
King lobbyKing = null;
|
||||
for (King king : _kings.values())
|
||||
{
|
||||
if (lobbyKing == null)
|
||||
lobbyKing = king;
|
||||
else if (lobbyKing.amountOfPeasants() < king.amountOfPeasants())
|
||||
lobbyKing = king;
|
||||
}
|
||||
return lobbyKing;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ package mineplex.core.gadget.gadgets.particle.king;
|
||||
import java.awt.Color;
|
||||
import java.time.Month;
|
||||
import java.time.YearMonth;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -14,11 +12,10 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import mineplex.core.arcadeevents.CoreGameStartEvent;
|
||||
import mineplex.core.common.shape.ShapeWings;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
@ -26,11 +23,10 @@ import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilParticle;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.gadget.gadgets.particle.king.events.UpdateKingEvent;
|
||||
import mineplex.core.gadget.types.GadgetType;
|
||||
import mineplex.core.gadget.types.OutfitGadget;
|
||||
import mineplex.core.gadget.gadgets.particle.king.types.King;
|
||||
import mineplex.core.gadget.gadgets.particle.king.types.Peasant;
|
||||
import mineplex.core.gadget.types.ParticleGadget;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
@ -38,7 +34,9 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
public class ParticleKing extends ParticleGadget
|
||||
{
|
||||
|
||||
private List<King> _kings = new ArrayList<>();
|
||||
private static final int CROWN_POINTS = 12;
|
||||
|
||||
private Map<Player, King> _kings = new HashMap<>();
|
||||
private Map<Player, Long> _taggedPlayers = new HashMap<>();
|
||||
|
||||
private ShapeWings _capeRed = new ShapeWings(UtilParticle.ParticleType.RED_DUST.particleName, new Vector(0.2,0.2,0.2), 1, 0, false, ShapeWings.NO_ROTATION, ShapeWings.KINGS_CAPE);
|
||||
@ -75,8 +73,19 @@ public class ParticleKing extends ParticleGadget
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getType() == UpdateType.FAST) _capeRed.displayColored(loc, Color.RED);
|
||||
if (event.getType() == UpdateType.FAST) _capeWhite.displayColored(loc, Color.WHITE);
|
||||
if (event.getType() == UpdateType.FAST)
|
||||
{
|
||||
_capeRed.displayColored(loc, Color.RED);
|
||||
_capeWhite.displayColored(loc, Color.WHITE);
|
||||
for (int i = 0; i < 360; i += 360/CROWN_POINTS)
|
||||
{
|
||||
double angle = (i * Math.PI / 180);
|
||||
double x = 0.5 * Math.cos(angle);
|
||||
double z = 0.5 * Math.sin(angle);
|
||||
Location crown = player.getEyeLocation().add(x, 0.15, z);
|
||||
UtilParticle.PlayParticleToAll(UtilParticle.ParticleType.FLAME, crown, null, 0, 1, UtilParticle.ViewDist.NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -84,12 +93,9 @@ public class ParticleKing extends ParticleGadget
|
||||
public void enableCustom(Player player, boolean message)
|
||||
{
|
||||
super.enableCustom(player, message);
|
||||
Manager.removeGadgetType(player, GadgetType.MORPH, this);
|
||||
Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET);
|
||||
player.getEquipment().setHelmet(new ItemStack(Material.GOLD_HELMET));
|
||||
_castleManager.setPlayerAsKing(player);
|
||||
if (_inLobby)
|
||||
{
|
||||
_kings.add(new King(player));
|
||||
updateKing();
|
||||
}
|
||||
}
|
||||
@ -98,24 +104,17 @@ public class ParticleKing extends ParticleGadget
|
||||
public void disableCustom(Player player, boolean message)
|
||||
{
|
||||
super.disableCustom(player, message);
|
||||
player.getInventory().setHelmet(null);
|
||||
_castleManager.setPlayerAsPeasant(player);
|
||||
if (_inLobby)
|
||||
{
|
||||
_kings.removeIf(king -> king.getKing().equals(player));
|
||||
updateKing();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGameStart(CoreGameStartEvent event)
|
||||
{
|
||||
for (King king : _kings)
|
||||
{
|
||||
Player player = king.getKing();
|
||||
player.getInventory().setHelmet(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When a player clicks another player, sets them as peasant
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void tagPlayer(EntityDamageByEntityEvent event)
|
||||
{
|
||||
@ -132,94 +131,94 @@ public class ParticleKing extends ParticleGadget
|
||||
Player clicked = (Player) event.getEntity();
|
||||
|
||||
// Checks if particle is active
|
||||
if (!isActive(clicker))
|
||||
if (_castleManager.isPeasant(clicker))
|
||||
return;
|
||||
|
||||
// Checks if the player isn't a king
|
||||
if (isActive(clicked))
|
||||
// Checks if the clicked player isn't a king
|
||||
if (_castleManager.isKing(clicked))
|
||||
return;
|
||||
|
||||
Peasant peasant = _castleManager.getPeasant(clicked);
|
||||
|
||||
// Checks if the clicked player isn't cooling down
|
||||
if (isPlayerCoolingDown(clicked))
|
||||
if (peasant.isInCooldown())
|
||||
{
|
||||
UtilPlayer.message(clicker, F.main("Kingdom", "You can't tag " + F.name(clicked.getName()) + " yet! That player is cooling down!"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (King king : _kings)
|
||||
King king = _castleManager.getKing(clicker);
|
||||
|
||||
if (king.hasPeasant(peasant))
|
||||
{
|
||||
// Checks if the player is owned by anyone else, if it is, then remove
|
||||
if (king.hasPeasant(clicked))
|
||||
{
|
||||
king.removePeasant(clicked);
|
||||
UtilPlayer.message(king.getKing(), F.main("Kingdom", "" + F.name(clicker.getName()) + " stole one of your peasants! You now have " + F.count(king.amountOfPeasants()) + " peasants!"));
|
||||
}
|
||||
// Finally, adds the player to the king that clicked the player
|
||||
else if (king.getKing().equals(clicker))
|
||||
{
|
||||
king.addPeasant(clicked);
|
||||
UtilPlayer.message(clicker, F.main("Kingdom", "You tagged " + F.name(clicked.getName()) + " as a peasant! You now have " + F.count(king.amountOfPeasants()) + " peasants!"));
|
||||
}
|
||||
UtilPlayer.message(clicker, F.main("Kingdom", "You can't tag " + F.name(clicked.getName()) + "! That player is already your peasant!"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Removes old king
|
||||
if (peasant.getKing() != null)
|
||||
{
|
||||
King oldKing = peasant.getKing();
|
||||
oldKing.removePeasant(peasant);
|
||||
UtilPlayer.message(oldKing.getKing(), F.main("Kingdom", "" + F.name(clicker.getName()) + " stole one of your peasants! You now have " + F.count(king.amountOfPeasants()) + " peasants!"));
|
||||
}
|
||||
|
||||
peasant.setCooldown();
|
||||
king.addPeasant(peasant);
|
||||
peasant.setKing(king);
|
||||
UtilPlayer.message(clicker, F.main("Kingdom", "You tagged " + F.name(clicked.getName()) + " as a peasant! You now have " + F.count(king.amountOfPeasants()) + " peasants!"));
|
||||
UtilPlayer.message(peasant.getPeasant(), F.main("Kingdom", "You were tagged by " + F.name(clicked.getName()) + " as a peasant!"));
|
||||
|
||||
updateKing();
|
||||
}
|
||||
|
||||
private boolean isPlayerCoolingDown(Player player)
|
||||
/**
|
||||
* Sets player as peasant
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (!_taggedPlayers.containsKey(player))
|
||||
return true;
|
||||
|
||||
if (UtilTime.elapsed(_taggedPlayers.get(player), 15000))
|
||||
{
|
||||
_taggedPlayers.remove(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
Player player = event.getPlayer();
|
||||
_castleManager.setPlayerAsPeasant(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes peasant from king, or removes king from peasant
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event)
|
||||
{
|
||||
if (!_inLobby)
|
||||
return;
|
||||
|
||||
for (King king : _kings)
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (_castleManager.isPeasant(player))
|
||||
{
|
||||
if (king.hasPeasant(event.getPlayer()))
|
||||
Peasant peasant = _castleManager.getPeasant(player);
|
||||
if (peasant.getKing() != null)
|
||||
{
|
||||
king.removePeasant(event.getPlayer());
|
||||
UtilPlayer.message(king.getKing(), F.main("Kingdom", "The peasant " + F.name(event.getPlayer().getName()) + " left your kingdom! You now have " + F.count(king.amountOfPeasants()) + " peasants!"));
|
||||
peasant.setKing(null);
|
||||
}
|
||||
_castleManager.removePeasant(player, false);
|
||||
}
|
||||
else if (_castleManager.isKing(player))
|
||||
{
|
||||
_castleManager.removeKing(player, false);
|
||||
}
|
||||
_kings.removeIf(king -> king.getKing().equals(event.getPlayer()));
|
||||
updateKing();
|
||||
}
|
||||
|
||||
private King getLobbyKing()
|
||||
{
|
||||
if (_kings.size() == 0)
|
||||
return null;
|
||||
else if (_kings.size() == 1)
|
||||
return _kings.get(0);
|
||||
|
||||
King lobbyKing = null;
|
||||
int peasants = 0;
|
||||
for (King king : _kings)
|
||||
{
|
||||
if (lobbyKing == null)
|
||||
lobbyKing = king;
|
||||
else if (king.amountOfPeasants() > peasants)
|
||||
lobbyKing = king;
|
||||
}
|
||||
return lobbyKing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current lobby king
|
||||
*/
|
||||
private void updateKing()
|
||||
{
|
||||
if (_inLobby)
|
||||
{
|
||||
King king = getLobbyKing();
|
||||
King king = _castleManager.getLobbyKing();
|
||||
King oldKing = _castleManager.getKing();
|
||||
if (king != null && oldKing != null)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@ package mineplex.core.gadget.gadgets.particle.king.events;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import mineplex.core.gadget.gadgets.particle.king.King;
|
||||
import mineplex.core.gadget.gadgets.particle.king.types.King;
|
||||
|
||||
public class UpdateKingEvent extends Event
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
package mineplex.core.gadget.gadgets.particle.king;
|
||||
package mineplex.core.gadget.gadgets.particle.king.types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -9,7 +9,7 @@ public class King
|
||||
{
|
||||
|
||||
private Player _king;
|
||||
private List<Player> _peasants = new ArrayList<>();
|
||||
private List<Peasant> _peasants = new ArrayList<>();
|
||||
|
||||
public King(Player king)
|
||||
{
|
||||
@ -26,19 +26,24 @@ public class King
|
||||
return _peasants.size();
|
||||
}
|
||||
|
||||
public void addPeasant(Player peasant)
|
||||
public void addPeasant(Peasant peasant)
|
||||
{
|
||||
_peasants.add(peasant);
|
||||
}
|
||||
|
||||
public void removePeasant(Player peasant)
|
||||
public void removePeasant(Peasant peasant)
|
||||
{
|
||||
_peasants.remove(peasant);
|
||||
}
|
||||
|
||||
public boolean hasPeasant(Player peasant)
|
||||
public boolean hasPeasant(Peasant peasant)
|
||||
{
|
||||
return _peasants.contains(peasant);
|
||||
}
|
||||
|
||||
public void clearPeasants()
|
||||
{
|
||||
_peasants.clear();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package mineplex.core.gadget.gadgets.particle.king.types;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
|
||||
public class Peasant
|
||||
{
|
||||
|
||||
private static final long PLAYER_COOLDOWN = 15000;
|
||||
|
||||
private Player _player;
|
||||
private long _cooldown = 0;
|
||||
private King _king;
|
||||
|
||||
public Peasant(Player player)
|
||||
{
|
||||
_player = player;
|
||||
}
|
||||
|
||||
public Player getPeasant()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
|
||||
public boolean isInCooldown()
|
||||
{
|
||||
return UtilTime.elapsed(_cooldown, PLAYER_COOLDOWN);
|
||||
}
|
||||
|
||||
public void setCooldown()
|
||||
{
|
||||
_cooldown = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public King getKing()
|
||||
{
|
||||
return _king;
|
||||
}
|
||||
|
||||
public void setKing(King king)
|
||||
{
|
||||
_king = king;
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +1,8 @@
|
||||
package nautilus.game.arcade.managers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.progression.data.PlayerKit;
|
||||
import mineplex.core.progression.gui.guis.KitDisplayMenu;
|
||||
import mineplex.core.progression.math.Calculations;
|
||||
import nautilus.game.arcade.ArcadeFormat;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.events.PlayerKitApplyEvent;
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.kit.ChampionsKit;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.kit.KitProgressionData;
|
||||
import nautilus.game.arcade.kit.ProgressingKit;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,8 +15,27 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.progression.data.PlayerKit;
|
||||
import mineplex.core.progression.gui.guis.KitDisplayMenu;
|
||||
import mineplex.core.progression.math.Calculations;
|
||||
|
||||
import nautilus.game.arcade.ArcadeFormat;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.events.PlayerKitApplyEvent;
|
||||
import nautilus.game.arcade.game.Game;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.kit.ChampionsKit;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.kit.KitProgressionData;
|
||||
import nautilus.game.arcade.kit.ProgressingKit;
|
||||
|
||||
/**
|
||||
* Manages all things related to the ProgressingKit System for Arcade
|
||||
|
Loading…
Reference in New Issue
Block a user