UHC Duels hub game
This commit is contained in:
parent
b3c216b7a8
commit
30125038b5
@ -1,5 +1,10 @@
|
||||
package mineplex.hub;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.CustomTagFix;
|
||||
import mineplex.core.PacketsInteractionFix;
|
||||
import mineplex.core.TwitchIntegrationFix;
|
||||
@ -36,7 +41,6 @@ import mineplex.core.itemstack.ItemStackFactory;
|
||||
import mineplex.core.memory.MemoryFix;
|
||||
import mineplex.core.message.MessageManager;
|
||||
import mineplex.core.monitor.LagMeter;
|
||||
import mineplex.core.movement.Movement;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.party.PartyManager;
|
||||
@ -74,20 +78,10 @@ import mineplex.hub.brawl.fountain.FountainManager;
|
||||
import mineplex.hub.modules.AprilFoolsTreasureHunt;
|
||||
import mineplex.hub.queue.QueueManager;
|
||||
import mineplex.hub.server.ServerManager;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClassManager;
|
||||
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
|
||||
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
|
||||
import mineplex.minecraft.game.classcombat.item.ItemFactory;
|
||||
import mineplex.minecraft.game.classcombat.shop.ClassCombatShop;
|
||||
import mineplex.minecraft.game.classcombat.shop.ClassShopManager;
|
||||
import mineplex.minecraft.game.core.IRelation;
|
||||
import mineplex.minecraft.game.core.combat.CombatManager;
|
||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
import mineplex.minecraft.game.core.fire.Fire;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import static mineplex.core.Managers.require;
|
||||
|
||||
@ -210,28 +204,28 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
DamageManager damage = new DamageManager(this, combatManager, npcManager, disguiseManager, conditionManager);
|
||||
conditionManager.setDamageManager(damage);
|
||||
|
||||
Fire fire = new Fire(this, conditionManager, damage);
|
||||
// Fire fire = new Fire(this, conditionManager, damage);
|
||||
Teleport teleport = new Teleport(this, clientManager);
|
||||
Energy energy = new Energy(this);
|
||||
energy.setEnabled(false);
|
||||
|
||||
ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager);
|
||||
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy);
|
||||
ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory);
|
||||
// ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager);
|
||||
// SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, disguiseManager, blockRestore, fire, new Movement(this), teleport, energy);
|
||||
// ClassManager classManager = new ClassManager(this, clientManager, donationManager, hubManager.GetGadget(), skillManager, itemFactory);
|
||||
|
||||
ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager);
|
||||
// ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory, achievementManager, clientManager);
|
||||
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Brute", classManager.GetClass("Brute"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Mage", classManager.GetClass("Mage"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Ranger", classManager.GetClass("Ranger"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true);
|
||||
new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true);
|
||||
// new ClassCombatShop(shopManager, clientManager, donationManager, false, "Brute", classManager.GetClass("Brute"), true);
|
||||
// new ClassCombatShop(shopManager, clientManager, donationManager, false, "Mage", classManager.GetClass("Mage"), true);
|
||||
// new ClassCombatShop(shopManager, clientManager, donationManager, false, "Ranger", classManager.GetClass("Ranger"), true);
|
||||
// new ClassCombatShop(shopManager, clientManager, donationManager, false, "Knight", classManager.GetClass("Knight"), true);
|
||||
// new ClassCombatShop(shopManager, clientManager, donationManager, false, "Assassin", classManager.GetClass("Assassin"), true);
|
||||
|
||||
//Updates
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||
|
||||
require(TrackManager.class);
|
||||
require(Titles.class);
|
||||
require(Titles.class).forceDisable();
|
||||
require(TwoFactorAuth.class);
|
||||
require(TeamspeakManager.class);
|
||||
new WebsiteLinkManager(this, clientManager);
|
||||
|
@ -15,6 +15,7 @@ import mineplex.core.lifetimes.PhasedLifetime;
|
||||
import mineplex.core.newnpc.NPC;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
import mineplex.hub.hubgame.event.HubGameStateChangeEvent;
|
||||
import mineplex.hub.world.WorldDataModule;
|
||||
|
||||
public abstract class CycledGame extends PhasedLifetime<GameState> implements HubGame, Listener
|
||||
@ -64,8 +65,6 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
|
||||
start(_state);
|
||||
UtilServer.RegisterEvents(this);
|
||||
|
||||
onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,12 +99,17 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
@Override
|
||||
public List<Player> getAlivePlayers()
|
||||
{
|
||||
return getPlayers(true);
|
||||
return _alivePlayers;
|
||||
}
|
||||
|
||||
public List<Player> getAllPlayers()
|
||||
{
|
||||
return _allPlayers;
|
||||
}
|
||||
|
||||
protected <T extends HubGameComponent<?>> T registerComponent(T instance)
|
||||
{
|
||||
register(instance, Collections.singletonList(GameState.Live));
|
||||
register(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@ -113,13 +117,12 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
Game Events
|
||||
*/
|
||||
|
||||
public void onCreate()
|
||||
public void onPrepare()
|
||||
{
|
||||
}
|
||||
|
||||
public void onLive()
|
||||
{
|
||||
_lastStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public abstract boolean endCheck();
|
||||
@ -147,6 +150,7 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerDeath(Player player)
|
||||
{
|
||||
onPlayerDeath(player, false);
|
||||
@ -160,6 +164,8 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
}
|
||||
|
||||
_places.add(player);
|
||||
player.getInventory().clear();
|
||||
player.getInventory().setArmorContents(null);
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
player.teleport(_spawn);
|
||||
@ -186,6 +192,19 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
public void setState(GameState state)
|
||||
{
|
||||
_state = state;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case Prepare:
|
||||
onPrepare();
|
||||
break;
|
||||
case Live:
|
||||
_lastStart = System.currentTimeMillis();
|
||||
onLive();
|
||||
break;
|
||||
}
|
||||
|
||||
UtilServer.CallEvent(new HubGameStateChangeEvent(this, state));
|
||||
setPhase(state);
|
||||
}
|
||||
|
||||
@ -209,16 +228,6 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
return _queuedPlayers.subList(0, Math.min(_queuedPlayers.size(), _type.getMaxPlayers()));
|
||||
}
|
||||
|
||||
public boolean isAlive(Player player)
|
||||
{
|
||||
return getPlayers(true).contains(player);
|
||||
}
|
||||
|
||||
public List<Player> getPlayers(boolean alive)
|
||||
{
|
||||
return alive ? _alivePlayers : _allPlayers;
|
||||
}
|
||||
|
||||
public List<Player> getPlaces()
|
||||
{
|
||||
return _places;
|
||||
@ -237,7 +246,7 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
|
||||
public enum GameState
|
||||
{
|
||||
|
||||
Waiting, Live
|
||||
Waiting, Prepare, Live
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,15 @@ public interface HubGame
|
||||
|
||||
WorldDataModule getWorldData();
|
||||
|
||||
void onPlayerDeath(Player player);
|
||||
|
||||
List<Player> getAlivePlayers();
|
||||
|
||||
default boolean isAlive(Player player)
|
||||
{
|
||||
return getAlivePlayers().contains(player);
|
||||
}
|
||||
|
||||
default void announce(String message)
|
||||
{
|
||||
getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message)));
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
@ -19,6 +20,7 @@ import mineplex.core.newnpc.event.NPCInteractEvent;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.duel.Duels;
|
||||
import mineplex.hub.hubgame.tron.Tron;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
@ -27,6 +29,8 @@ public class HubGameManager extends MiniPlugin
|
||||
|
||||
private static final int MIN_PLAYERS_COUNTDOWN = 20;
|
||||
private static final int MAX_PLAYERS_COUNTDOWN = 5;
|
||||
private static final int PREPARE_COUNTDOWN = 5;
|
||||
private static final String HEADER_FOOTER = C.cDGreen + C.Strike + "================================";
|
||||
|
||||
private final NewNPCManager _npcManager;
|
||||
|
||||
@ -43,6 +47,7 @@ public class HubGameManager extends MiniPlugin
|
||||
runSyncLater(this::spawnNPCs, 50);
|
||||
|
||||
addGame(new Tron(this));
|
||||
addGame(new Duels(this));
|
||||
}
|
||||
|
||||
private void addGame(HubGame game)
|
||||
@ -95,9 +100,7 @@ public class HubGameManager extends MiniPlugin
|
||||
}
|
||||
else
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You have left the queue for " + F.name(getGameName(cycledGame)) + "."));
|
||||
queuedPlayers.remove(player);
|
||||
cycledGame.onPlayerLeaveQueue(player);
|
||||
leaveQueue(cycledGame, player);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -108,6 +111,14 @@ public class HubGameManager extends MiniPlugin
|
||||
}
|
||||
else
|
||||
{
|
||||
for (HubGame other : _games)
|
||||
{
|
||||
if (other instanceof CycledGame && ((CycledGame) other).getQueuedPlayers().remove(player))
|
||||
{
|
||||
leaveQueue(cycledGame, player);
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(F.main(_moduleName, "You have joined the queue for " + F.name(getGameName(cycledGame)) + "."));
|
||||
queuedPlayers.add(player);
|
||||
cycledGame.onPlayerQueue(player);
|
||||
@ -119,6 +130,13 @@ public class HubGameManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private void leaveQueue(CycledGame game, Player player)
|
||||
{
|
||||
player.sendMessage(F.main(_moduleName, "You have left the queue for " + F.name(getGameName(game)) + "."));
|
||||
game.getQueuedPlayers().remove(player);
|
||||
game.onPlayerLeaveQueue(player);
|
||||
}
|
||||
|
||||
private void informQueuePosition(CycledGame game, Player player)
|
||||
{
|
||||
int position = game.getQueuedPlayers().indexOf(player);
|
||||
@ -185,13 +203,12 @@ public class HubGameManager extends MiniPlugin
|
||||
{
|
||||
List<Player> players = cycledGame.getNextPlayers();
|
||||
|
||||
cycledGame.getPlayers(true).addAll(players);
|
||||
cycledGame.getPlayers(false).addAll(players);
|
||||
cycledGame.getAlivePlayers().addAll(players);
|
||||
cycledGame.getAllPlayers().addAll(players);
|
||||
cycledGame.getQueuedPlayers().removeAll(players);
|
||||
|
||||
cycledGame.setCountdown(-1);
|
||||
cycledGame.setState(GameState.Live);
|
||||
cycledGame.onLive();
|
||||
cycledGame.setCountdown(PREPARE_COUNTDOWN);
|
||||
cycledGame.setState(GameState.Prepare);
|
||||
|
||||
for (Player player : cycledGame.getQueuedPlayers())
|
||||
{
|
||||
@ -217,6 +234,75 @@ public class HubGameManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that prepare is run before the lobby update
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void updatePrepare(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (HubGame game : _games)
|
||||
{
|
||||
if (!(game instanceof CycledGame))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CycledGame cycledGame = (CycledGame) game;
|
||||
HubGameType gameType = game.getGameType();
|
||||
|
||||
if (cycledGame.getGameState() != GameState.Prepare)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int countdown = cycledGame.getCountdown();
|
||||
|
||||
if (countdown == PREPARE_COUNTDOWN)
|
||||
{
|
||||
String gameString = getGameHeader(cycledGame);
|
||||
|
||||
for (Player player : cycledGame.getAllPlayers())
|
||||
{
|
||||
player.sendMessage(HEADER_FOOTER);
|
||||
player.sendMessage(gameString);
|
||||
player.sendMessage("");
|
||||
|
||||
for (String description : gameType.getDescription())
|
||||
{
|
||||
player.sendMessage(" " + description);
|
||||
}
|
||||
|
||||
player.sendMessage("");
|
||||
player.sendMessage(HEADER_FOOTER);
|
||||
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 1.2F);
|
||||
}
|
||||
}
|
||||
else if (countdown == 0)
|
||||
{
|
||||
for (Player player : cycledGame.getAllPlayers())
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.2F);
|
||||
}
|
||||
|
||||
cycledGame.setState(GameState.Live);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player player : cycledGame.getAllPlayers())
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.CLICK, 1, 0.4F);
|
||||
UtilTextMiddle.display("", C.cRed + countdown, 0, 30, 0, player);
|
||||
}
|
||||
}
|
||||
|
||||
cycledGame.setCountdown(countdown - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateEnd(UpdateEvent event)
|
||||
{
|
||||
@ -238,15 +324,14 @@ public class HubGameManager extends MiniPlugin
|
||||
{
|
||||
cycledGame.onEnd();
|
||||
|
||||
for (Player player : cycledGame.getPlayers(true))
|
||||
for (Player player : cycledGame.getAlivePlayers())
|
||||
{
|
||||
cycledGame.onPlayerDeath(player, true);
|
||||
}
|
||||
|
||||
List<Player> places = cycledGame.getPlaces();
|
||||
Collections.reverse(places);
|
||||
String headerFooter = C.cDGreen + C.Strike + "================================";
|
||||
String gameString = C.cWhiteB + "Game" + C.cYellow + " - " + C.cWhiteB + getGameName(cycledGame);
|
||||
String gameString = getGameHeader(cycledGame);
|
||||
|
||||
for (Player player : places)
|
||||
{
|
||||
@ -255,7 +340,7 @@ public class HubGameManager extends MiniPlugin
|
||||
continue;
|
||||
}
|
||||
|
||||
player.sendMessage(headerFooter);
|
||||
player.sendMessage(HEADER_FOOTER);
|
||||
player.sendMessage(gameString);
|
||||
player.sendMessage("");
|
||||
if (!places.isEmpty())
|
||||
@ -271,7 +356,7 @@ public class HubGameManager extends MiniPlugin
|
||||
player.sendMessage(C.cYellowB + "3rd Place " + C.cWhite + places.get(2).getName());
|
||||
}
|
||||
player.sendMessage("");
|
||||
player.sendMessage(headerFooter);
|
||||
player.sendMessage(HEADER_FOOTER);
|
||||
}
|
||||
|
||||
cycledGame.onCleanup();
|
||||
@ -298,6 +383,11 @@ public class HubGameManager extends MiniPlugin
|
||||
return enough;
|
||||
}
|
||||
|
||||
private String getGameHeader(CycledGame game)
|
||||
{
|
||||
return C.cWhiteB + "Game" + C.cYellow + " - " + C.cWhiteB + getGameName(game);
|
||||
}
|
||||
|
||||
private String getGameName(CycledGame game)
|
||||
{
|
||||
return game.getGameType().getName();
|
||||
|
@ -8,6 +8,11 @@ public enum HubGameType
|
||||
"Testing 1",
|
||||
"Testing 2"
|
||||
}, 2, 4),
|
||||
DUELS("Duels", new String[]
|
||||
{
|
||||
"Testing 1",
|
||||
"Testing 2"
|
||||
}, 2, 2),
|
||||
;
|
||||
|
||||
private final String _name;
|
||||
|
@ -11,6 +11,5 @@ public class HubGameComponent<T extends HubGame> extends ListenerComponent
|
||||
public HubGameComponent(T game)
|
||||
{
|
||||
_game = game;
|
||||
activate();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package mineplex.hub.hubgame.common.damage;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import mineplex.core.common.util.UtilAction;
|
||||
import mineplex.hub.hubgame.HubGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
||||
|
||||
public class DamageComponent extends HubGameComponent<HubGame>
|
||||
{
|
||||
|
||||
public DamageComponent(HubGame game)
|
||||
{
|
||||
super(game);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void entityDamage(EntityDamageEvent event)
|
||||
{
|
||||
uncancelDamageEvent(event);
|
||||
}
|
||||
|
||||
private void uncancelDamageEvent(EntityDamageEvent event)
|
||||
{
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!_game.isAlive(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerDeath(CombatDeathEvent event)
|
||||
{
|
||||
Player player = (Player) event.GetEvent().getEntity();
|
||||
|
||||
if (!_game.isAlive(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.GetEvent().getDrops().clear();
|
||||
player.setHealth(player.getMaxHealth());
|
||||
UtilAction.zeroVelocity(player);
|
||||
_game.onPlayerDeath(player);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package mineplex.hub.hubgame.common.general;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
|
||||
public class GameTimeoutComponent extends HubGameComponent<CycledGame>
|
||||
{
|
||||
|
||||
private final long _timeout;
|
||||
|
||||
public GameTimeoutComponent(CycledGame game, long timeout)
|
||||
{
|
||||
super(game);
|
||||
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void updateTimeout(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SEC || !_game.isLive() || !UtilTime.elapsed(_game.getLastStart(), _timeout))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_game.announce("The game took too long and has timed out.");
|
||||
|
||||
for (Player player : _game.getAlivePlayers())
|
||||
{
|
||||
_game.onPlayerDeath(player, true);
|
||||
}
|
||||
|
||||
_game.getAlivePlayers().clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package mineplex.hub.hubgame.common.general;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import mineplex.hub.hubgame.HubGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
|
||||
public class InventoryEditComponent extends HubGameComponent<HubGame>
|
||||
{
|
||||
|
||||
public InventoryEditComponent(HubGame game)
|
||||
{
|
||||
super(game);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void inventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (_game.isAlive(player))
|
||||
{
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package mineplex.hub.hubgame.common.general;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
|
||||
public class PrepareFreezeComponent extends HubGameComponent<CycledGame>
|
||||
{
|
||||
|
||||
public PrepareFreezeComponent(CycledGame game)
|
||||
{
|
||||
super(game);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerMove(PlayerMoveEvent event)
|
||||
{
|
||||
if (_game.getGameState() != GameState.Prepare || !_game.isAlive(event.getPlayer()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
|
||||
if (from.getX() == to.getX() && from.getZ() == to.getZ())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setTo(from);
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package mineplex.hub.hubgame.common.map;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
import mineplex.hub.hubgame.event.HubGameStateChangeEvent;
|
||||
|
||||
public class BlockRecorderComponent extends HubGameComponent<CycledGame>
|
||||
{
|
||||
|
||||
private final Map<Location, Pair<Material, Byte>> _blocks;
|
||||
private final Set<Location> _placedBlocks;
|
||||
private final Location _cornerA;
|
||||
private final Location _cornerB;
|
||||
|
||||
public BlockRecorderComponent(CycledGame game, Location cornerA, Location cornerB)
|
||||
{
|
||||
super(game);
|
||||
|
||||
_placedBlocks = new HashSet<>();
|
||||
_blocks = new HashMap<>(500);
|
||||
|
||||
for (Block block : UtilBlock.getInBoundingBox(cornerA, cornerB, false))
|
||||
{
|
||||
_blocks.put(block.getLocation(), Pair.create(block.getType(), block.getData()));
|
||||
}
|
||||
|
||||
_cornerA = cornerA;
|
||||
_cornerB = cornerB;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void blockBreak(BlockBreakEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!_game.isLive() || !_game.isAlive(player) || !_placedBlocks.contains(location))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void blockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
||||
if (!_game.isLive() || !_game.isAlive(player) || !UtilAlg.inBoundingBox(location, _cornerA, _cornerB))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_placedBlocks.add(location);
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void end(HubGameStateChangeEvent event)
|
||||
{
|
||||
if (event.getState() != GameState.Waiting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UtilBlock.startQuickRecording();
|
||||
|
||||
_blocks.forEach((location, pair) -> UtilBlock.setQuick(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), pair.getLeft().getId(), pair.getRight()));
|
||||
|
||||
UtilBlock.stopQuickRecording();
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package mineplex.hub.hubgame.common.map;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.HubGame;
|
||||
import mineplex.hub.hubgame.common.HubGameComponent;
|
||||
import mineplex.hub.hubgame.event.HubGameStateChangeEvent;
|
||||
|
||||
public class TeleportIntoMapComponent extends HubGameComponent<HubGame>
|
||||
{
|
||||
|
||||
private final List<Location> _spawns;
|
||||
|
||||
public TeleportIntoMapComponent(HubGame game, List<Location> spawns)
|
||||
{
|
||||
super(game);
|
||||
|
||||
_spawns = spawns;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void prepare(HubGameStateChangeEvent event)
|
||||
{
|
||||
if (event.getState() != GameState.Prepare)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Location average = UtilAlg.getAverageLocation(_spawns);
|
||||
int i = 0;
|
||||
|
||||
for (Player player : _game.getAlivePlayers())
|
||||
{
|
||||
Location location = _spawns.get(i++);
|
||||
|
||||
if (location.getYaw() == 0)
|
||||
{
|
||||
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, average)));
|
||||
}
|
||||
|
||||
player.teleport(location);
|
||||
}
|
||||
}
|
||||
}
|
117
Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java
Normal file
117
Plugins/Mineplex.Hub/src/mineplex/hub/hubgame/duel/Duels.java
Normal file
@ -0,0 +1,117 @@
|
||||
package mineplex.hub.hubgame.duel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.HubGameManager;
|
||||
import mineplex.hub.hubgame.HubGameType;
|
||||
import mineplex.hub.hubgame.common.damage.DamageComponent;
|
||||
import mineplex.hub.hubgame.common.general.GameTimeoutComponent;
|
||||
import mineplex.hub.hubgame.common.general.InventoryEditComponent;
|
||||
import mineplex.hub.hubgame.common.general.PrepareFreezeComponent;
|
||||
import mineplex.hub.hubgame.common.map.BlockRecorderComponent;
|
||||
import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent;
|
||||
|
||||
public class Duels extends CycledGame
|
||||
{
|
||||
|
||||
private static final ItemStack[] ITEMS = {
|
||||
new ItemBuilder(Material.DIAMOND_SWORD)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.DAMAGE_ALL, 2)
|
||||
.build(),
|
||||
new ItemBuilder(Material.BOW)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.ARROW_DAMAGE, 2)
|
||||
.build(),
|
||||
new ItemBuilder(Material.FISHING_ROD)
|
||||
.setUnbreakable(true)
|
||||
.build(),
|
||||
new ItemStack(Material.GOLDEN_APPLE, 6),
|
||||
new ItemBuilder(Material.DIAMOND_AXE)
|
||||
.setUnbreakable(true)
|
||||
.build(),
|
||||
new ItemStack(Material.WOOD, 64),
|
||||
new ItemStack(Material.LAVA_BUCKET),
|
||||
new ItemStack(Material.WATER_BUCKET),
|
||||
new ItemStack(Material.ARROW, 16),
|
||||
};
|
||||
private static final ItemStack[] ARMOUR = {
|
||||
new ItemBuilder(Material.DIAMOND_BOOTS)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2)
|
||||
.build(),
|
||||
new ItemBuilder(Material.DIAMOND_LEGGINGS)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2)
|
||||
.build(),
|
||||
new ItemBuilder(Material.DIAMOND_CHESTPLATE)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2)
|
||||
.build(),
|
||||
new ItemBuilder(Material.DIAMOND_HELMET)
|
||||
.setUnbreakable(true)
|
||||
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2)
|
||||
.build(),
|
||||
};
|
||||
|
||||
public Duels(HubGameManager manager)
|
||||
{
|
||||
super(manager, HubGameType.DUELS);
|
||||
|
||||
registerComponent(new DamageComponent(this));
|
||||
registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("YELLOW")));
|
||||
registerComponent(new PrepareFreezeComponent(this));
|
||||
registerComponent(new InventoryEditComponent(this));
|
||||
registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(2)));
|
||||
|
||||
List<Location> corners = _worldData.getDataLocation("LIME");
|
||||
|
||||
registerComponent(new BlockRecorderComponent(this, corners.get(0), corners.get(1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepare()
|
||||
{
|
||||
for (Player player : getAlivePlayers())
|
||||
{
|
||||
//TODO remove clear when proper inventory handling is added
|
||||
player.getInventory().clear();
|
||||
player.getInventory().addItem(ITEMS);
|
||||
player.getInventory().setArmorContents(ARMOUR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endCheck()
|
||||
{
|
||||
return getAlivePlayers().size() <= 1;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void healthRegain(EntityRegainHealthEvent event)
|
||||
{
|
||||
if (event.getRegainReason() != RegainReason.SATIATED || !(event.getEntity() instanceof Player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (isAlive(player))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package mineplex.hub.hubgame.event;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.CycledGame.GameState;
|
||||
import mineplex.hub.hubgame.HubGame;
|
||||
|
||||
public class HubGameStateChangeEvent extends Event
|
||||
{
|
||||
|
||||
private static final HandlerList _handlers = new HandlerList();
|
||||
|
||||
private final CycledGame _game;
|
||||
private final GameState _state;
|
||||
|
||||
public HubGameStateChangeEvent(CycledGame game, GameState state)
|
||||
{
|
||||
_game = game;
|
||||
_state = state;
|
||||
}
|
||||
|
||||
public CycledGame getGame()
|
||||
{
|
||||
return _game;
|
||||
}
|
||||
|
||||
public GameState getState()
|
||||
{
|
||||
return _state;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return _handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
package mineplex.hub.hubgame.tron;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
@ -11,16 +10,18 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilAlg;
|
||||
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.UtilServer;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.hubgame.CycledGame;
|
||||
import mineplex.hub.hubgame.HubGameManager;
|
||||
import mineplex.hub.hubgame.HubGameType;
|
||||
import mineplex.hub.hubgame.common.general.GameTimeoutComponent;
|
||||
import mineplex.hub.hubgame.common.map.TeleportIntoMapComponent;
|
||||
import mineplex.hub.hubgame.common.powerup.PowerupComponent;
|
||||
import mineplex.hub.hubgame.tron.powerup.SpeedPowerup;
|
||||
|
||||
@ -46,29 +47,27 @@ public class Tron extends CycledGame
|
||||
PowerupComponent powerupComponent = registerComponent(new PowerupComponent(this, _worldData.getDataLocation("ORANGE")));
|
||||
_speedPowerup = new SpeedPowerup();
|
||||
powerupComponent.addPowerup(_speedPowerup);
|
||||
|
||||
registerComponent(new TeleportIntoMapComponent(this, _worldData.getDataLocation("RED")));
|
||||
registerComponent(new GameTimeoutComponent(this, TimeUnit.MINUTES.toMillis(3)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLive()
|
||||
public void onPrepare()
|
||||
{
|
||||
super.onLive();
|
||||
_trailSize = DEFAULT_SIZE;
|
||||
|
||||
List<Location> spawns = new ArrayList<>(_worldData.getDataLocation("RED"));
|
||||
UtilServer.runSyncLater(() ->
|
||||
{
|
||||
int colourId = 0;
|
||||
Location average = UtilAlg.getAverageLocation(spawns);
|
||||
|
||||
for (Player player : getPlayers(true))
|
||||
for (Player player : getAlivePlayers())
|
||||
{
|
||||
Location location = UtilAlg.Random(spawns);
|
||||
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(location, average)));
|
||||
player.teleport(location.add(0.5, 0, 0.5));
|
||||
spawns.remove(location);
|
||||
|
||||
TronBike bike = new TronBike(this, player, COLOURS[colourId++]);
|
||||
_bikes.put(player, bike);
|
||||
}
|
||||
|
||||
_trailSize = DEFAULT_SIZE;
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -88,7 +87,7 @@ public class Tron extends CycledGame
|
||||
|
||||
bike.updateDirection();
|
||||
|
||||
if (bike.updateLocation(_speedPowerup.isActive(player)) && UtilTime.elapsed(getLastStart(), 1000))
|
||||
if (isLive() && bike.updateLocation(_speedPowerup.isActive(player)) && UtilTime.elapsed(getLastStart(), 1000))
|
||||
{
|
||||
Location location = player.getLocation();
|
||||
|
||||
@ -119,7 +118,7 @@ public class Tron extends CycledGame
|
||||
@Override
|
||||
public boolean endCheck()
|
||||
{
|
||||
return getPlayers(true).size() <= 1;
|
||||
return getAlivePlayers().size() <= 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user