More hub changes

This commit is contained in:
Sam 2017-09-24 21:25:04 +01:00
parent 76ae23b56f
commit ff54aab560
16 changed files with 199 additions and 127 deletions

View File

@ -68,8 +68,8 @@ public class AchievementMainPage extends ShopPageBase<AchievementManager, Achiev
ArrayList<String> lore = new ArrayList<String>(); ArrayList<String> lore = new ArrayList<String>();
lore.add(" "); lore.add(" ");
category.addStats(getClientManager(), _statsManager, lore, category == AchievementCategory.GLOBAL ? 10 : 2, // category.addStats(getClientManager(), _statsManager, lore, category == AchievementCategory.GLOBAL ? 10 : 2,
getPlayer(), _targetName, _targetStats); // getPlayer(), _targetName, _targetStats);
lore.add(" "); lore.add(" ");
addAchievements(category, lore, 9); addAchievements(category, lore, 9);
lore.add(ChatColor.RESET + "Click for more details!"); lore.add(ChatColor.RESET + "Click for more details!");

View File

@ -236,7 +236,7 @@ public class AchievementPage extends ShopPageBase<AchievementManager, Achievemen
String itemName = C.Bold + _category.getFriendlyName() + " Stats"; String itemName = C.Bold + _category.getFriendlyName() + " Stats";
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
lore.add(" "); lore.add(" ");
_category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats); //_category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats);
ItemStack item = new ItemStack(material); ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();

View File

@ -41,7 +41,7 @@ public class ArcadeMainPage extends AchievementMainPage
ArrayList<String> lore = new ArrayList<String>(); ArrayList<String> lore = new ArrayList<String>();
lore.add(" "); lore.add(" ");
category.addStats(getClientManager(), _statsManager, lore, 2, getPlayer(), _targetName, _targetStats); //category.addStats(getClientManager(), _statsManager, lore, 2, getPlayer(), _targetName, _targetStats);
lore.add(" "); lore.add(" ");
addAchievements(category, lore, 9); addAchievements(category, lore, 9);
lore.add(" "); lore.add(" ");

View File

@ -41,7 +41,7 @@ public class UHCMainPage extends AchievementMainPage
ArrayList<String> lore = new ArrayList<String>(); ArrayList<String> lore = new ArrayList<String>();
lore.add(" "); lore.add(" ");
category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats); //category.addStats(getClientManager(), _statsManager, lore, getPlayer(), _targetName, _targetStats);
lore.add(" "); lore.add(" ");
addAchievements(category, lore, 9); addAchievements(category, lore, 9);
lore.add(" "); lore.add(" ");

View File

@ -81,7 +81,13 @@ public class NewNPCManager extends MiniPlugin
// Loading NPCs on the main thread makes sure that _npcs is populated before anything tries to spawn NPCs. // Loading NPCs on the main thread makes sure that _npcs is populated before anything tries to spawn NPCs.
loadNPCs(); loadNPCs();
// Any NPC with the metadata DUMMY will always be spawned regardless, useful for testing designs // Any NPC with the metadata DUMMY will always be spawned regardless, useful for testing designs
spawnNPCs("DUMMY", null); spawnNPCs("DUMMY", npc ->
{
if (npc instanceof PlayerNPC)
{
npc.getNameTag();
}
});
generatePermissions(); generatePermissions();
} }
@ -232,7 +238,6 @@ public class NewNPCManager extends MiniPlugin
/** /**
* Used by {@link NPCMoveCommand}. Has no other purpose. * Used by {@link NPCMoveCommand}. Has no other purpose.
*/ */
@Deprecated
public void setPlayerTeleport(Player player) public void setPlayerTeleport(Player player)
{ {
_teleportMap.put(player, player.getLocation()); _teleportMap.put(player, player.getLocation());

View File

@ -30,7 +30,7 @@ class NewNPCRepository extends RepositoryBase
/** /**
* A SQL statement that inserts an entry and returns the id field generated. * A SQL statement that inserts an entry and returns the id field generated.
*/ */
private static final String INSERT_NPC = "INSERT INTO newNPCs (entity_type, name, world, x, y, z, yaw, pitch, in_hand, in_hand_data, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; private static final String INSERT_NPC = "INSERT INTO newNPCs (entity_type, name, world, x, y, z, yaw, pitch, in_hand, in_hand_data, helmet, chestplate, leggings, boots, metadata, skinValue, skinSignature) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
/** /**
* A SQL statement that deletes an entry with a specific id field. * A SQL statement that deletes an entry with a specific id field.
*/ */

View File

@ -73,7 +73,7 @@ public class ProfileMainPage extends ShopPageBase<ProfileManager, ProfileShop>
private void addStatsButton() private void addStatsButton()
{ {
addButton(11, STATS_ITEM, new PageChangeButton()); //addButton(11, STATS_ITEM, new PageChangeButton());
} }
private class PageChangeButton implements IButton private class PageChangeButton implements IButton

View File

@ -90,7 +90,8 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.youtube.YoutubeManager; import mineplex.core.youtube.YoutubeManager;
import mineplex.hub.commands.GadgetToggle; import mineplex.hub.commands.GadgetToggle;
import mineplex.hub.doublejump.JumpManager; import mineplex.hub.doublejump.JumpManager;
import mineplex.hub.events.HubType; import mineplex.hub.plugin.HalloweenHubPlugin;
import mineplex.hub.plugin.HubPlugin;
import mineplex.hub.gamemode.GameModeManager; import mineplex.hub.gamemode.GameModeManager;
import mineplex.hub.hubgame.HubGameManager; import mineplex.hub.hubgame.HubGameManager;
import mineplex.hub.modules.ForcefieldManager; import mineplex.hub.modules.ForcefieldManager;
@ -137,6 +138,8 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
private final JumpManager _jumpManager; private final JumpManager _jumpManager;
private final HologramManager _hologramManager; private final HologramManager _hologramManager;
private final HubPlugin _hubPlugin;
private final WorldDataModule _worldData; private final WorldDataModule _worldData;
private final Location _spawn; private final Location _spawn;
@ -184,7 +187,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
new MavericksManager(_plugin, cosmeticManager, hologramManager, this); new MavericksManager(_plugin, cosmeticManager, hologramManager, this);
new SoccerManager(this, _gadgetManager); new SoccerManager(this, _gadgetManager);
new KothManager(this, _gadgetManager); //new KothManager(this, _gadgetManager);
new MenuManager(_plugin); new MenuManager(_plugin);
new NewInteractionsManager(); new NewInteractionsManager();
@ -229,7 +232,7 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
require(ProfileManager.class); require(ProfileManager.class);
require(HubPlayerManager.class); require(HubPlayerManager.class);
new HubType(); _hubPlugin = new HalloweenHubPlugin();
generatePermissions(); generatePermissions();
} }
@ -285,7 +288,6 @@ public class HubManager extends MiniClientPlugin<HubClient> implements IChatMess
runSyncLater(Bukkit::shutdown, 40); runSyncLater(Bukkit::shutdown, 40);
}, 60); }, 60);
} }
} }

View File

@ -1,33 +1,18 @@
package mineplex.hub.hubgame; package mineplex.hub.hubgame;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import mineplex.core.Managers;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
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.HubGamePlayerDeathEvent; import mineplex.hub.hubgame.event.HubGamePlayerDeathEvent;
import mineplex.hub.hubgame.event.HubGameStateChangeEvent; import mineplex.hub.hubgame.event.HubGameStateChangeEvent;
import mineplex.hub.world.WorldDataModule;
public abstract class CycledGame extends PhasedLifetime<GameState> implements HubGame, Listener public abstract class CycledGame extends HubGame
{ {
private final HubGameManager _manager;
private final Map<Class<? extends HubGameComponent<?>>, HubGameComponent<?>> _components;
// Game Properties // Game Properties
private final HubGameType _type;
private GameState _state; private GameState _state;
// Game Timer // Game Timer
@ -39,21 +24,13 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
private final List<Player> _allPlayers; private final List<Player> _allPlayers;
private final List<Player> _places; private final List<Player> _places;
// NPC
private NPC _npc;
// Lobby // Lobby
private Location _spawn;
private int _countdown; private int _countdown;
// World
protected WorldDataModule _worldData;
public CycledGame(HubGameManager manager, HubGameType type) public CycledGame(HubGameManager manager, HubGameType type)
{ {
_manager = manager; super(manager, type);
_components = new HashMap<>();
_type = type;
_state = GameState.Waiting; _state = GameState.Waiting;
_queuedPlayers = new ArrayList<>(); _queuedPlayers = new ArrayList<>();
@ -63,41 +40,7 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
_countdown = -1; _countdown = -1;
_worldData = Managers.require(WorldDataModule.class);
_spawn = _worldData.getCustomLocation(type.name() + " SPAWN").get(0);
start(_state); start(_state);
UtilServer.RegisterEvents(this);
}
@Override
public HubGameManager getManager()
{
return _manager;
}
@Override
public void setNpc(NPC npc)
{
_npc = npc;
if (npc.getEntity() != null)
{
_spawn.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(_spawn, npc.getEntity().getLocation())));
}
}
@Override
public NPC getNpc()
{
return _npc;
}
@Override
public WorldDataModule getWorldData()
{
return _worldData;
} }
@Override @Override
@ -111,26 +54,6 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
return _allPlayers; return _allPlayers;
} }
@Override
public Location getSpawn()
{
return _spawn;
}
@SuppressWarnings("unchecked")
protected <T extends HubGameComponent<?>> T registerComponent(T instance)
{
_components.put((Class<? extends HubGameComponent<?>>) instance.getClass(), instance);
register(instance);
return instance;
}
@SuppressWarnings("unchecked")
public <T extends HubGameComponent<?>> T getComponent(Class<T> clazz)
{
return (T) _components.get(clazz);
}
/* /*
Game Events Game Events
*/ */
@ -180,6 +103,7 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
UtilServer.CallEvent(event); UtilServer.CallEvent(event);
} }
@Override
public void onCleanupPlayer(Player player) public void onCleanupPlayer(Player player)
{ {
_queuedPlayers.remove(player); _queuedPlayers.remove(player);
@ -193,11 +117,6 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
return _state == GameState.Live; return _state == GameState.Live;
} }
public HubGameType getGameType()
{
return _type;
}
public void setState(GameState state) public void setState(GameState state)
{ {
_state = state; _state = state;
@ -234,7 +153,7 @@ public abstract class CycledGame extends PhasedLifetime<GameState> implements Hu
public List<Player> getNextPlayers() public List<Player> getNextPlayers()
{ {
return _queuedPlayers.subList(0, Math.min(_queuedPlayers.size(), _type.getMaxPlayers())); return _queuedPlayers.subList(0, Math.min(_queuedPlayers.size(), getGameType().getMaxPlayers()));
} }
public List<Player> getPlaces() public List<Player> getPlaces()

View File

@ -1,47 +1,103 @@
package mineplex.hub.hubgame; package mineplex.hub.hubgame;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import mineplex.core.Managers;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilServer;
import mineplex.core.lifetimes.PhasedLifetime;
import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NPC;
import mineplex.hub.hubgame.CycledGame.GameState;
import mineplex.hub.hubgame.common.HubGameComponent;
import mineplex.hub.hubgame.ui.HubGamePage; import mineplex.hub.hubgame.ui.HubGamePage;
import mineplex.hub.world.WorldDataModule; import mineplex.hub.world.WorldDataModule;
public interface HubGame public abstract class HubGame extends PhasedLifetime<GameState> implements Listener
{ {
HubGameManager getManager(); private final HubGameManager _manager;
private final HubGameType _type;
private final Map<Class<? extends HubGameComponent<?>>, HubGameComponent<?>> _components;
HubGameType getGameType(); protected final WorldDataModule _worldData;
void setNpc(NPC npc); private final Location _spawn;
NPC getNpc(); public HubGame(HubGameManager manager, HubGameType type)
{
_manager = manager;
_type = type;
_components = new HashMap<>();
WorldDataModule getWorldData(); _worldData = Managers.require(WorldDataModule.class);
_spawn = _worldData.getCustomLocation(type.name() + " SPAWN").get(0);
Location getSpawn(); start(GameState.Waiting);
UtilServer.RegisterEvents(this);
}
void onPlayerDeath(Player player); public abstract void onPlayerDeath(Player player);
List<Player> getAlivePlayers(); public abstract List<Player> getAlivePlayers();
default boolean isAlive(Player player) public abstract void onCleanupPlayer(Player player);
public HubGameManager getManager()
{
return _manager;
}
public HubGameType getGameType()
{
return _type;
}
@SuppressWarnings("unchecked")
protected <T extends HubGameComponent<?>> T registerComponent(T instance)
{
_components.put((Class<? extends HubGameComponent<?>>) instance.getClass(), instance);
register(instance);
return instance;
}
@SuppressWarnings("unchecked")
public <T extends HubGameComponent<?>> T getComponent(Class<T> clazz)
{
return (T) _components.get(clazz);
}
public void setNpc(NPC npc)
{
if (npc.getEntity() != null)
{
_spawn.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(_spawn, npc.getEntity().getLocation())));
}
}
public Location getSpawn()
{
return _spawn;
}
public boolean isAlive(Player player)
{ {
return getAlivePlayers().contains(player); return getAlivePlayers().contains(player);
} }
default void announce(String message) public void announce(String message)
{ {
getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message))); getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message)));
} }
default HubGamePage getInformationPage(Player player) public HubGamePage getInformationPage(Player player)
{ {
return new HubGamePage<>(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this); return new HubGamePage<>(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this);
} }
} }

View File

@ -101,13 +101,7 @@ public class HubGameManager extends MiniPlugin
@EventHandler @EventHandler
public void playerQuit(PlayerQuitEvent event) public void playerQuit(PlayerQuitEvent event)
{ {
_games.forEach(game -> _games.forEach(game -> game.onCleanupPlayer(event.getPlayer()));
{
if (game instanceof CycledGame)
{
((CycledGame) game).onCleanupPlayer(event.getPlayer());
}
});
} }
@EventHandler @EventHandler

View File

@ -20,6 +20,10 @@ public enum HubGameType
"You can place blocks!", "You can place blocks!",
"Kill your opponent to win!" "Kill your opponent to win!"
}, new ItemStack(Material.DIAMOND_SWORD), 2, 2), }, new ItemStack(Material.DIAMOND_SWORD), 2, 2),
FOOTBALL("Soccer", new String[]
{
}, new ItemStack(Material.SLIME_BALL), 1, 6),
; ;
private final String _name; private final String _name;

View File

@ -1,8 +1,37 @@
package mineplex.hub.hubgame; package mineplex.hub.hubgame;
public class SimpleGame import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
public class SimpleGame extends HubGame
{ {
private final List<Player> _players;
public SimpleGame(HubGameManager manager, HubGameType type)
{
super(manager, type);
_players = new ArrayList<>();
}
@Override
public void onPlayerDeath(Player player)
{
player.teleport(getSpawn());
}
@Override
public List<Player> getAlivePlayers()
{
return _players;
}
@Override
public void onCleanupPlayer(Player player)
{
_players.remove(player);
}
} }

View File

@ -13,6 +13,7 @@ import mineplex.hub.hubgame.HubGame;
import mineplex.hub.hubgame.common.HubGameComponent; import mineplex.hub.hubgame.common.HubGameComponent;
import mineplex.hub.hubgame.event.HubGameStateChangeEvent; import mineplex.hub.hubgame.event.HubGameStateChangeEvent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class DamageComponent extends HubGameComponent<HubGame> public class DamageComponent extends HubGameComponent<HubGame>
{ {
@ -68,6 +69,19 @@ public class DamageComponent extends HubGameComponent<HubGame>
event.setCancelled(false); event.setCancelled(false);
} }
@EventHandler
public void increaseKnockback(CustomDamageEvent event)
{
Player damagee = event.GetDamageePlayer();
if (damagee == null || !_game.isAlive(damagee))
{
return;
}
event.AddKnockback("Damage Component", 1.4);
}
@EventHandler @EventHandler
public void playerDeath(CombatDeathEvent event) public void playerDeath(CombatDeathEvent event)
{ {

View File

@ -0,0 +1,46 @@
package mineplex.hub.plugin;
import net.md_5.bungee.api.ChatColor;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextTop;
import mineplex.core.titles.tracks.custom.ScrollAnimation;
import mineplex.core.updater.UpdateType;
import mineplex.core.utils.UtilScheduler;
public class HalloweenHubPlugin extends HubPlugin
{
private final String[] NEWS_TEXT = new ScrollAnimation("HAPPY HALLOWEEN")
.withPrimaryColour(ChatColor.GOLD)
.withSecondaryColour(ChatColor.WHITE)
.withTertiaryColour(ChatColor.YELLOW)
.bold()
.build();
private int _newsIndex;
public HalloweenHubPlugin()
{
super("Halloween");
_newsManager.setEnabled(false);
UtilScheduler.runEvery(UpdateType.FASTEST, this::displayNews);
}
@Override
protected void setupWorld()
{
_manager.GetSpawn().getWorld().setTime(18000);
}
private void displayNews()
{
if (++_newsIndex == NEWS_TEXT.length)
{
_newsIndex = 0;
}
UtilTextTop.display(NEWS_TEXT[_newsIndex], UtilServer.getPlayers());
}
}

View File

@ -1,4 +1,4 @@
package mineplex.hub.events; package mineplex.hub.plugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.hub.HubManager; import mineplex.hub.HubManager;
@ -6,33 +6,36 @@ import mineplex.hub.hubgame.HubGame;
import mineplex.hub.hubgame.HubGameManager; import mineplex.hub.hubgame.HubGameManager;
import mineplex.hub.hubgame.duel.Duels; import mineplex.hub.hubgame.duel.Duels;
import mineplex.hub.hubgame.tron.Tron; import mineplex.hub.hubgame.tron.Tron;
import mineplex.hub.news.NewsManager;
/** /**
* Hub Types are effectively managers for specific events within the hub. Such as a Halloween or Christmas variants of the hub. * Hub Plugins are effectively managers for specific events within the hub. Such as a Halloween or Christmas variants of the hub.
* HubType means that lots of * HubPlugin means that lots of
* <pre> * <pre>
* if (HubType == HubType.SomeHubType) * if (HubPlugin == HubPlugin.SomeHubVariant)
* </pre> * </pre>
* *
* checks aren't needed within the entire hub, making it cleaner and easier to maintain. * checks aren't needed within the entire hub, making it cleaner and easier to maintain.
*/ */
public class HubType extends MiniPlugin public class HubPlugin extends MiniPlugin
{ {
protected final HubManager _manager; protected final HubManager _manager;
protected final HubGameManager _hubGameManager; protected final HubGameManager _hubGameManager;
protected final NewsManager _newsManager;
public HubType() public HubPlugin()
{ {
this("Normal"); this("Normal");
} }
public HubType(String moduleName) public HubPlugin(String moduleName)
{ {
super(moduleName); super(moduleName);
_manager = require(HubManager.class); _manager = require(HubManager.class);
_hubGameManager = require(HubGameManager.class); _hubGameManager = require(HubGameManager.class);
_newsManager = require(NewsManager.class);
setupWorld(); setupWorld();
addHubGames(); addHubGames();