From f56b940a73562f3927722f93341d402f0e6cfd9d Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 18 Mar 2017 23:33:30 +0000 Subject: [PATCH 01/21] Super rough and ready persistence --- .../texttutorial/TextTutorialManager.java | 7 +- .../src/mineplex/gemhunters/GemHunters.java | 9 +- .../gemhunters/economy/EconomyModule.java | 5 + .../persistence/PersistenceData.java | 27 ++++ .../persistence/PersistenceModule.java | 74 +++++++++ .../persistence/PersistenceRepository.java | 153 ++++++++++++++++++ .../gemhunters/spawn/SpawnModule.java | 14 +- .../gemhunters/world/WorldDataModule.java | 8 +- .../gemhunters/world/WorldListeners.java | 2 +- 9 files changed, 287 insertions(+), 12 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/texttutorial/TextTutorialManager.java b/Plugins/Mineplex.Core/src/mineplex/core/texttutorial/TextTutorialManager.java index cd444453e..5a76c4021 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/texttutorial/TextTutorialManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/texttutorial/TextTutorialManager.java @@ -5,6 +5,7 @@ import java.util.Iterator; import org.bukkit.Bukkit; import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -75,6 +76,8 @@ public class TextTutorialManager extends MiniPlugin { other.hidePlayer(event.getPlayer()); } + + ((CraftPlayer) event.getPlayer()).getHandle().spectating = true; return; } @@ -116,7 +119,9 @@ public class TextTutorialManager extends MiniPlugin { other.showPlayer(player); } - + + ((CraftPlayer) player).getHandle().spectating = false; + //Gems if (tut.getGemReward() > 0) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 76c0c5c84..8e53e7fd0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -1,5 +1,9 @@ package mineplex.gemhunters; +import mineplex.core.task.TaskManager; +import mineplex.core.texttutorial.TextTutorialManager; +import mineplex.gemhunters.persistence.PersistenceModule; +import mineplex.gemhunters.tutorial.GemHuntersTutorial; import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; @@ -260,8 +264,8 @@ public class GemHunters extends JavaPlugin gadgetManager.setGadgetEnabled(false); // Tutorials - //TextTutorialManager tutorialManager = new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager)); - //tutorialManager.addTutorial(new GemHuntersTutorial()); + TextTutorialManager tutorialManager = new TextTutorialManager(this, donationManager, new TaskManager(this, clientManager)); + tutorialManager.addTutorial(new GemHuntersTutorial()); // Now we finally get to enable the Gem Hunters modules // Though if any other module needs one of these it will be generated in @@ -277,6 +281,7 @@ public class GemHunters extends JavaPlugin require(ItemMapModule.class); require(ModerationModule.class); require(MountModule.class); + require(PersistenceModule.class); require(PlayerStatusModule.class); require(QuestModule.class); require(QuitNPCModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index db11cf43f..d1b803c6a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -116,6 +116,11 @@ public class EconomyModule extends MiniClientPlugin Set(player, gems); } + public void setStore(UUID player, int gems) + { + Set(player, gems); + } + public int getGems(Player player) { return Get(player); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java new file mode 100644 index 000000000..d939056fd --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java @@ -0,0 +1,27 @@ +package mineplex.gemhunters.persistence; + +import org.bukkit.Location; + +public class PersistenceData +{ + + private int _gems; + private Location _location; + + public PersistenceData(int gems, Location location) + { + _gems = gems; + _location = location; + } + + public int getGems() + { + return _gems; + } + + public Location getLocation() + { + return _location; + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java new file mode 100644 index 000000000..b1a343fb0 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -0,0 +1,74 @@ +package mineplex.gemhunters.persistence; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.economy.EconomyModule; +import mineplex.serverdata.database.DBPool; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@ReflectivelyCreateMiniPlugin +public class PersistenceModule extends MiniPlugin +{ + + private final CoreClientManager _client; + private final EconomyModule _economy; + + private final PersistenceRepository _repository; + + private final Map _toTeleport; + + public PersistenceModule() + { + super("Persistence"); + + _client = require(CoreClientManager.class); + _economy = require(EconomyModule.class); + + _repository = new PersistenceRepository(DBPool.getAccount()); + + _toTeleport = new HashMap<>(); + + _client.addStoredProcedureLoginProcessor(_repository.buildPersistenceDataLoginProcessor((uuid, data) -> + { + _economy.setStore(uuid, data.getGems()); + _toTeleport.put(uuid, data.getLocation()); + })); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void playerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + + if (_toTeleport.containsKey(player.getUniqueId())) + { + player.teleport(_toTeleport.get(player.getUniqueId())); + } + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + Player player = event.getPlayer(); + _repository.savePersistence(event.getPlayer(), new PersistenceData(_economy.Get(player), player.getLocation())); + } + + @EventHandler + public void playerDeath(PlayerDeathEvent event) + { + Player player = event.getEntity(); + _repository.deletePersistence(player); + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java new file mode 100644 index 000000000..e6e6fa3b0 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -0,0 +1,153 @@ +package mineplex.gemhunters.persistence; + +import mineplex.core.Managers; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.ILoginProcessor; +import mineplex.core.common.util.UtilServer; +import mineplex.gemhunters.world.WorldDataModule; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.function.BiConsumer; + +public class PersistenceRepository +{ + + private static final String INSERT_PERSISTENCE = "INSERT INTO gemHunters VALUES (?,?,?);"; + private static final String UPDATE_PERSISTENCE = "UPDATE gemHunters SET gems=?,location=? WHERE accountId=?;"; + private static final String DELETE_PERSISTENCE = "DELETE FROM gemHunters WHERE accountId=?;"; + + private final CoreClientManager _client; + private final WorldDataModule _worldData; + + private final DataSource _dataSource; + + private final List _exists; + + public PersistenceRepository(DataSource source) + { + _dataSource = source; + _client = Managers.require(CoreClientManager.class); + _worldData = Managers.require(WorldDataModule.class); + + _exists = new ArrayList<>(); + } + + public ILoginProcessor buildPersistenceDataLoginProcessor(BiConsumer consumer) + { + return new ILoginProcessor() + { + @Override + public String getName() + { + return "Gem Hunters Persistence"; + } + + @Override + public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException + { + if (resultSet.next()) + { + _exists.add(accountId); + consumer.accept(uuid, fromResultSet(resultSet)); + } + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT * FROM gemHunters WHERE accountId=" + accountId + ";"; + } + }; + } + + public void savePersistence(Player player, PersistenceData data) + { + int accountId = _client.Get(player).getAccountId(); + + UtilServer.runAsync(() -> + { + try (Connection connection = _dataSource.getConnection()) + { + boolean update = _exists.contains(accountId); + + PreparedStatement statement = connection.prepareStatement(update ? UPDATE_PERSISTENCE : INSERT_PERSISTENCE); + + if (update) + { + statement.setInt(1, data.getGems()); + statement.setString(2, locationToString(data.getLocation())); + statement.setInt(3, accountId); + } + else + { + statement.setInt(1, accountId); + statement.setInt(2, data.getGems()); + statement.setString(3, locationToString(data.getLocation())); + } + + _exists.remove(Integer.valueOf(accountId)); + statement.executeUpdate(); + } + catch (SQLException e) + { + throw new CompletionException(e); + } + }); + } + + public void deletePersistence(Player player) + { + int accountId = _client.Get(player).getAccountId(); + + if (!_exists.contains(accountId)) + { + return; + } + + UtilServer.runAsync(() -> + { + try (Connection connection = _dataSource.getConnection()) + { + PreparedStatement statement = connection.prepareStatement(DELETE_PERSISTENCE); + + statement.setInt(1, accountId); + + statement.executeUpdate(); + } + catch (SQLException e) + { + throw new CompletionException(e); + } + }); + } + private PersistenceData fromResultSet(ResultSet set) throws SQLException + { + int gems = set.getInt(2); + Location location = stringToLocation(set.getString(3)); + + return new PersistenceData(gems, location); + } + + private Location stringToLocation(String loc) + { + String[] coords = loc.split(","); + + return new Location(_worldData.World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5, Float.valueOf(coords[3]), Float.valueOf(coords[4])); + } + + private String locationToString(Location loc) + { + return loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + "," + loc.getYaw() + "," + loc.getPitch(); + } +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 9ffa6b0c2..93bbcece0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -88,13 +88,13 @@ public class SpawnModule extends MiniPlugin } player.teleport(_spawn); - player.setFoodLevel(20); - player.setExhaustion(0); - player.setLevel(0); - player.setExp(0); - player.getInventory().clear(); - player.getInventory().setArmorContents(null); - player.updateInventory(); +// player.setFoodLevel(20); +// player.setExhaustion(0); +// player.setLevel(0); +// player.setExp(0); +// player.getInventory().clear(); +// player.getInventory().setArmorContents(null); +// player.updateInventory(); if (_npcsSpawned) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java index 6bce809d5..b7315dc08 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -112,7 +112,9 @@ public class WorldDataModule extends MiniPlugin { Location loc = stringToLocation(tokens[i]); if (loc == null) + { continue; + } loc.setYaw(currentDirection); @@ -132,7 +134,9 @@ public class WorldDataModule extends MiniPlugin { Location loc = stringToLocation(tokens[i]); if (loc == null) + { continue; + } currentData.add(loc); } @@ -150,7 +154,9 @@ public class WorldDataModule extends MiniPlugin { Location loc = stringToLocation(tokens[i]); if (loc == null) + { continue; + } currentData.add(loc); } @@ -280,7 +286,7 @@ public class WorldDataModule extends MiniPlugin return CUSTOM_LOCAITONS.get(id); } - + public Map> getAllSpawnLocations() { return SPAWN_LOCATIONS; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index b81b81279..3688a3f17 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -49,7 +49,7 @@ public class WorldListeners implements Listener plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @EventHandler + //@EventHandler public void deletePlayerData(PlayerQuitEvent event) { _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { From ca1b185ba2a76c4da7e480a0cd904d8ff2dde5bc Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 23 Mar 2017 19:18:16 +0000 Subject: [PATCH 02/21] Improve the persistence system --- .../death/event/QuitNPCDespawnEvent.java | 17 +- .../gemhunters/death/quitnpc/QuitNPC.java | 41 ++-- .../death/quitnpc/QuitNPCModule.java | 2 +- .../persistence/PersistenceData.java | 14 +- .../persistence/PersistenceModule.java | 51 ++--- .../persistence/PersistenceRepository.java | 188 +++++++----------- .../gemhunters/spawn/SpawnModule.java | 2 +- 7 files changed, 151 insertions(+), 164 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/QuitNPCDespawnEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/QuitNPCDespawnEvent.java index e7e36626e..8e4de19b7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/QuitNPCDespawnEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/event/QuitNPCDespawnEvent.java @@ -10,20 +10,27 @@ public class QuitNPCDespawnEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); - + private final QuitNPC _npc; + private final boolean _pluginRemove; private boolean _cancel; - - public QuitNPCDespawnEvent(QuitNPC npc) + + public QuitNPCDespawnEvent(QuitNPC npc, boolean pluginRemove) { _npc = npc; + _pluginRemove = pluginRemove; } public QuitNPC getNpc() { return _npc; } - + + public boolean isPluginRemove() + { + return _pluginRemove; + } + public HandlerList getHandlers() { return HANDLERS; @@ -45,5 +52,5 @@ public class QuitNPCDespawnEvent extends Event implements Cancellable { _cancel = cancel; } - + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java index db22be9be..c0b5f38c1 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java @@ -52,7 +52,7 @@ public class QuitNPC implements Listener // Unlocked Slots private final int _slotsUnlocked; - + // Gems private final int _gems; @@ -94,7 +94,7 @@ public class QuitNPC implements Listener // Unlocked Slots _slotsUnlocked = Managers.get(InventoryModule.class).getSlotsUnlocked(player); - + // Gems _gems = Managers.get(EconomyModule.class).Get(player); @@ -118,11 +118,11 @@ public class QuitNPC implements Listener player.getInventory().setItem(i++, itemStack); } - player.getInventory().setArmorContents(_inventory.getArmorContents()); - + player.getInventory().setArmorContents(_inventory.getArmorContents()); + // Unlocked Slots Managers.get(InventoryModule.class).setSlotsUnlocked(player, _slotsUnlocked); - + // Gems // Subtract GEM_START_COST (100 by default) because EconomyModule adds // this value on join regardless if they have an NPC. @@ -132,12 +132,12 @@ public class QuitNPC implements Listener Managers.require(QuestModule.class).setPlayerData(player, _questPlayerData); } - public void despawn() + public void despawn(boolean pluginRemove) { - QuitNPCDespawnEvent event = new QuitNPCDespawnEvent(this); + QuitNPCDespawnEvent event = new QuitNPCDespawnEvent(this, pluginRemove); UtilServer.CallEvent(event); - + if (event.isCancelled()) { return; @@ -153,24 +153,24 @@ public class QuitNPC implements Listener public void dropItems() { Location location = _entity.getLocation().add(0, 1, 0); - + for (ItemStack itemStack : _inventory.getContents()) { if (itemStack == null || itemStack.getType() == Material.AIR) { continue; } - + location.getWorld().dropItemNaturally(location, itemStack); } - + for (ItemStack itemStack : _inventory.getArmorContents()) { if (itemStack == null || itemStack.getType() == Material.AIR) { continue; } - + location.getWorld().dropItemNaturally(location, itemStack); } } @@ -185,7 +185,7 @@ public class QuitNPC implements Listener if (UtilTime.elapsed(_start, _quitMills)) { - despawn(); + despawn(true); } else { @@ -200,21 +200,21 @@ public class QuitNPC implements Listener { return; } - + Player killer = event.getEntity().getKiller(); - + if (killer != null) { _npc.setKilledBy(_uuid, killer.getName()); Managers.get(EconomyModule.class).addToStore(killer, "Killing " + F.name(_name + "'s") + " NPC", (int) (_gems * EconomyModule.GEM_KILL_FACTOR)); } - + event.getDrops().clear(); _entity.setHealth(_entity.getMaxHealth()); dropItems(); - despawn(); + despawn(false); } - + @EventHandler public void entityCombust(EntityCombustEvent event) { @@ -226,6 +226,11 @@ public class QuitNPC implements Listener event.setCancelled(true); } + public String getName() + { + return _name; + } + public UUID getUniqueId() { return _uuid; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java index bd3490372..6ee5de84f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java @@ -101,7 +101,7 @@ public class QuitNPCModule extends MiniPlugin @EventHandler public void npcDespawn(QuitNPCDespawnEvent event) { - log("Despawning npc for " + _npcs.remove(event.getNpc().getUniqueId()).getUniqueId()); + log("Despawning npc for " + _npcs.remove(event.getNpc().getUniqueId()).getName()); } @EventHandler diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java index d939056fd..f0788c04c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java @@ -1,17 +1,20 @@ package mineplex.gemhunters.persistence; +import mineplex.gemhunters.quest.QuestPlayerData; import org.bukkit.Location; public class PersistenceData { - private int _gems; - private Location _location; + private final int _gems; + private final Location _location; + private final QuestPlayerData _questData; - public PersistenceData(int gems, Location location) + public PersistenceData(int gems, Location location, QuestPlayerData questData) { _gems = gems; _location = location; + _questData = questData; } public int getGems() @@ -24,4 +27,9 @@ public class PersistenceData return _location; } + public QuestPlayerData getQuestData() + { + return _questData; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index b1a343fb0..1b0702979 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -2,73 +2,78 @@ package mineplex.gemhunters.persistence; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.death.event.QuitNPCDespawnEvent; import mineplex.gemhunters.economy.EconomyModule; -import mineplex.serverdata.database.DBPool; -import org.bukkit.Location; +import mineplex.gemhunters.quest.QuestModule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - @ReflectivelyCreateMiniPlugin public class PersistenceModule extends MiniPlugin { private final CoreClientManager _client; private final EconomyModule _economy; + private final QuestModule _quest; private final PersistenceRepository _repository; - private final Map _toTeleport; - public PersistenceModule() { super("Persistence"); _client = require(CoreClientManager.class); + _quest = require(QuestModule.class); _economy = require(EconomyModule.class); - _repository = new PersistenceRepository(DBPool.getAccount()); - - _toTeleport = new HashMap<>(); - - _client.addStoredProcedureLoginProcessor(_repository.buildPersistenceDataLoginProcessor((uuid, data) -> - { - _economy.setStore(uuid, data.getGems()); - _toTeleport.put(uuid, data.getLocation()); - })); + _repository = new PersistenceRepository(); } @EventHandler(priority = EventPriority.HIGHEST) public void playerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + CoreClient client = _client.Get(player); - if (_toTeleport.containsKey(player.getUniqueId())) + runAsync(() -> _repository.getPersistenceData(response -> { - player.teleport(_toTeleport.get(player.getUniqueId())); - } + _economy.setStore(player, response.getGems()); + player.teleport(response.getLocation()); + _quest.setPlayerData(player, response.getQuestData()); + }, client)); } @EventHandler public void playerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - _repository.savePersistence(event.getPlayer(), new PersistenceData(_economy.Get(player), player.getLocation())); + CoreClient client = _client.Get(player); + PersistenceData data = new PersistenceData(_economy.Get(player), player.getLocation(), _quest.Get(player)); + + runAsync(() -> _repository.savePersistence(client, data)); } @EventHandler public void playerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - _repository.deletePersistence(player); + CoreClient client = _client.Get(player); + + runAsync(() -> _repository.deletePersistence(client)); + } + + @EventHandler + public void npcDespawn(QuitNPCDespawnEvent event) + { + if (!event.isPluginRemove()) + { + runAsync(() -> _client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence)); + } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index e6e6fa3b0..3b2c2c6f8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -1,153 +1,115 @@ package mineplex.gemhunters.persistence; -import mineplex.core.Managers; -import mineplex.core.account.CoreClientManager; -import mineplex.core.account.ILoginProcessor; -import mineplex.core.common.util.UtilServer; -import mineplex.gemhunters.world.WorldDataModule; +import com.google.gson.Gson; +import mineplex.core.account.CoreClient; +import mineplex.gemhunters.quest.QuestPlayerData; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; +import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.entity.Player; -import javax.sql.DataSource; import java.sql.Connection; -import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.function.BiConsumer; +import java.util.function.Consumer; -public class PersistenceRepository +public class PersistenceRepository extends RepositoryBase { - private static final String INSERT_PERSISTENCE = "INSERT INTO gemHunters VALUES (?,?,?);"; - private static final String UPDATE_PERSISTENCE = "UPDATE gemHunters SET gems=?,location=? WHERE accountId=?;"; - private static final String DELETE_PERSISTENCE = "DELETE FROM gemHunters WHERE accountId=?;"; + private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=?;"; + private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?);"; + private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=? WHERE accountId=?;"; + private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;"; + private static final Gson GSON; - private final CoreClientManager _client; - private final WorldDataModule _worldData; - - private final DataSource _dataSource; + static + { + GSON = new Gson(); + } private final List _exists; - public PersistenceRepository(DataSource source) + public PersistenceRepository() { - _dataSource = source; - _client = Managers.require(CoreClientManager.class); - _worldData = Managers.require(WorldDataModule.class); + super(DBPool.getAccount()); _exists = new ArrayList<>(); } - public ILoginProcessor buildPersistenceDataLoginProcessor(BiConsumer consumer) + public void getPersistenceData(Consumer response, CoreClient client) { - return new ILoginProcessor() + int accountId = client.getAccountId(); + + executeQuery(GET_DATA, resultSet -> { - @Override - public String getName() + if (resultSet.next()) { - return "Gem Hunters Persistence"; - } + int gems = resultSet.getInt("gems"); + int x = resultSet.getInt("x"); + int y = resultSet.getInt("y"); + int z = resultSet.getInt("z"); + int yaw = resultSet.getInt("yaw"); + int pitch = resultSet.getInt("pitch"); + String quests = resultSet.getString("quests"); + QuestPlayerData questData = GSON.fromJson(quests, QuestPlayerData.class); - @Override - public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException - { - if (resultSet.next()) - { - _exists.add(accountId); - consumer.accept(uuid, fromResultSet(resultSet)); - } + _exists.add(accountId); + PersistenceData data = new PersistenceData(gems, new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch), questData); + response.accept(data); } - - @Override - public String getQuery(int accountId, String uuid, String name) - { - return "SELECT * FROM gemHunters WHERE accountId=" + accountId + ";"; - } - }; + }, new ColumnInt("accountId", accountId)); } - public void savePersistence(Player player, PersistenceData data) + public void savePersistence(CoreClient client, PersistenceData data) { - int accountId = _client.Get(player).getAccountId(); + int accountId = client.getAccountId(); - UtilServer.runAsync(() -> + int gems = data.getGems(); + int x = data.getLocation().getBlockX(); + int y = data.getLocation().getBlockY(); + int z = data.getLocation().getBlockZ(); + int yaw = (int) data.getLocation().getYaw(); + int pitch = (int) data.getLocation().getPitch(); + + if (_exists.contains(accountId)) { - try (Connection connection = _dataSource.getConnection()) - { - boolean update = _exists.contains(accountId); - - PreparedStatement statement = connection.prepareStatement(update ? UPDATE_PERSISTENCE : INSERT_PERSISTENCE); - - if (update) - { - statement.setInt(1, data.getGems()); - statement.setString(2, locationToString(data.getLocation())); - statement.setInt(3, accountId); - } - else - { - statement.setInt(1, accountId); - statement.setInt(2, data.getGems()); - statement.setString(3, locationToString(data.getLocation())); - } - - _exists.remove(Integer.valueOf(accountId)); - statement.executeUpdate(); - } - catch (SQLException e) - { - throw new CompletionException(e); - } - }); - } - - public void deletePersistence(Player player) - { - int accountId = _client.Get(player).getAccountId(); - - if (!_exists.contains(accountId)) + executeUpdate(UPDATE_DATA, + new ColumnInt("gems", gems), + new ColumnInt("x", x), + new ColumnInt("y", y), + new ColumnInt("z", z), + new ColumnInt("yaw", yaw), + new ColumnInt("pitch", pitch), + new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), + new ColumnInt("accountId", accountId) + ); + } + else { - return; + executeInsert(INSERT_DATA, null, + new ColumnInt("accountId", accountId), + new ColumnInt("gems", gems), + new ColumnInt("x", x), + new ColumnInt("y", y), + new ColumnInt("z", z), + new ColumnInt("yaw", yaw), + new ColumnInt("pitch", pitch), + new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())) + ); } - UtilServer.runAsync(() -> - { - try (Connection connection = _dataSource.getConnection()) - { - PreparedStatement statement = connection.prepareStatement(DELETE_PERSISTENCE); - - statement.setInt(1, accountId); - - statement.executeUpdate(); - } - catch (SQLException e) - { - throw new CompletionException(e); - } - }); - } - private PersistenceData fromResultSet(ResultSet set) throws SQLException - { - int gems = set.getInt(2); - Location location = stringToLocation(set.getString(3)); - - return new PersistenceData(gems, location); + _exists.remove(Integer.valueOf(accountId)); } - private Location stringToLocation(String loc) + public void deletePersistence(CoreClient client) { - String[] coords = loc.split(","); + int accountId = client.getAccountId(); - return new Location(_worldData.World, Integer.valueOf(coords[0]) + 0.5, Integer.valueOf(coords[1]), Integer.valueOf(coords[2]) + 0.5, Float.valueOf(coords[3]), Float.valueOf(coords[4])); - } - - private String locationToString(Location loc) - { - return loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ() + "," + loc.getYaw() + "," + loc.getPitch(); + executeUpdate(DELETE_DATA, new ColumnInt("accountId", accountId)); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 93bbcece0..4898f6f0f 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -82,7 +82,7 @@ public class SpawnModule extends MiniPlugin { QuitNPC npc = _npc.getNPC(player); - npc.despawn(); + npc.despawn(true); npc.restore(player); return; } From 7a5e8241aa6faba153c796157b48d93c4c82aeea Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 29 Mar 2017 16:27:26 +0100 Subject: [PATCH 03/21] Implement more elements of persistence --- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/death/quitnpc/QuitNPC.java | 43 ---------- .../death/quitnpc/QuitNPCModule.java | 3 +- .../mineplex/gemhunters/join/JoinModule.java | 79 +++++++++++++++++++ .../persistence/PersistenceData.java | 38 ++++++++- .../persistence/PersistenceModule.java | 38 +++++---- .../persistence/PersistenceRepository.java | 54 +++++++++++-- .../gemhunters/quest/QuestModule.java | 10 +-- .../gemhunters/spawn/SpawnModule.java | 1 - .../gemhunters/world/WorldListeners.java | 2 +- 10 files changed, 195 insertions(+), 75 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 0edc77dd1..8d4ea4135 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -2,6 +2,7 @@ package mineplex.gemhunters; import mineplex.core.task.TaskManager; import mineplex.core.texttutorial.TextTutorialManager; +import mineplex.gemhunters.join.JoinModule; import mineplex.gemhunters.persistence.PersistenceModule; import mineplex.gemhunters.tutorial.GemHuntersTutorial; import net.minecraft.server.v1_8_R3.MinecraftServer; @@ -281,6 +282,7 @@ public class GemHunters extends JavaPlugin require(InventoryModule.class); require(LootModule.class); require(ItemMapModule.class); + require(JoinModule.class); require(ModerationModule.class); require(MountModule.class); require(PersistenceModule.class); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java index c0b5f38c1..5a860af08 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPC.java @@ -50,15 +50,8 @@ public class QuitNPC implements Listener private final UUID _uuid; private final PlayerInventory _inventory; - // Unlocked Slots - private final int _slotsUnlocked; - - // Gems private final int _gems; - // Quests - private final QuestPlayerData _questPlayerData; - public QuitNPC(QuitNPCModule npc, Player player, long quitMills) { // Managers @@ -91,47 +84,11 @@ public class QuitNPC implements Listener _name = player.getName(); _uuid = player.getUniqueId(); _inventory = player.getInventory(); - - // Unlocked Slots - _slotsUnlocked = Managers.get(InventoryModule.class).getSlotsUnlocked(player); - - // Gems _gems = Managers.get(EconomyModule.class).Get(player); - // Quests - _questPlayerData = Managers.get(QuestModule.class).Get(player); - UtilServer.RegisterEvents(this); } - public void restore(Player player) - { - // Player - player.getInventory().clear(); - player.teleport(_entity.getLocation()); - player.setHealth(_entity.getHealth()); - - // Inventory - int i = 0; - for (ItemStack itemStack : _inventory.getContents()) - { - player.getInventory().setItem(i++, itemStack); - } - - player.getInventory().setArmorContents(_inventory.getArmorContents()); - - // Unlocked Slots - Managers.get(InventoryModule.class).setSlotsUnlocked(player, _slotsUnlocked); - - // Gems - // Subtract GEM_START_COST (100 by default) because EconomyModule adds - // this value on join regardless if they have an NPC. - Managers.get(EconomyModule.class).setStore(player, _gems - EconomyModule.GEM_START_COST); - - // Quests - Managers.require(QuestModule.class).setPlayerData(player, _questPlayerData); - } - public void despawn(boolean pluginRemove) { QuitNPCDespawnEvent event = new QuitNPCDespawnEvent(this, pluginRemove); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java index 6ee5de84f..9ab4eb6d0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java @@ -7,6 +7,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; +import mineplex.core.common.util.UtilPlayer; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -90,7 +91,7 @@ public class QuitNPCModule extends MiniPlugin { Player player = event.getPlayer(); - if (_tutorial.isInTutorial(player)) + if (UtilPlayer.isSpectator(player)) { return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java new file mode 100644 index 000000000..b9c13d109 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java @@ -0,0 +1,79 @@ +package mineplex.gemhunters.join; + +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; +import mineplex.gemhunters.death.quitnpc.QuitNPC; +import mineplex.gemhunters.death.quitnpc.QuitNPCModule; +import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.persistence.PersistenceData; +import mineplex.gemhunters.persistence.PersistenceModule; +import mineplex.gemhunters.persistence.PersistenceRepository; +import mineplex.gemhunters.quest.QuestModule; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.function.Consumer; + +@ReflectivelyCreateMiniPlugin +public class JoinModule extends MiniPlugin +{ + + private final CoreClientManager _client; + private final EconomyModule _economy; + private final QuestModule _quest; + private final PersistenceModule _persistence; + private final QuitNPCModule _npc; + + private JoinModule() + { + super("Join"); + + _client = require(CoreClientManager.class); + _economy = require(EconomyModule.class); + _quest = require(QuestModule.class); + _persistence = require(PersistenceModule.class); + _npc = require(QuitNPCModule.class); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + Player player = event.getPlayer(); + CoreClient client = _client.Get(player); + PersistenceRepository repository = _persistence.getRepository(); + Consumer response = data -> + { + _economy.setStore(player, data.getGems()); + _quest.setPlayerData(player, data.getQuestData()); + player.teleport(data.getLocation()); + player.setHealth(data.getHealth()); + player.setMaxHealth(data.getMaxHealth()); + player.setFoodLevel(data.getHunger()); + player.getInventory().clear(); + player.getInventory().addItem(data.getItems()); + player.getInventory().setArmorContents(data.getArmour()); + }; + + player.getInventory().clear(); + + runAsync(() -> + { + repository.getPersistenceData(response, client); + + if (_npc.hasNPC(player)) + { + QuitNPC npc = _npc.getNPC(player); + npc.despawn(true); + } + + if (repository.exists(client)) + { + + } + }); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java index f0788c04c..dd0362ea8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java @@ -2,6 +2,7 @@ package mineplex.gemhunters.persistence; import mineplex.gemhunters.quest.QuestPlayerData; import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; public class PersistenceData { @@ -9,12 +10,22 @@ public class PersistenceData private final int _gems; private final Location _location; private final QuestPlayerData _questData; + private final int _health; + private final int _maxHealth; + private final int _hunger; + private final ItemStack[] _items; + private final ItemStack[] _armour; - public PersistenceData(int gems, Location location, QuestPlayerData questData) + public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, ItemStack[] items, ItemStack[] armour) { _gems = gems; _location = location; _questData = questData; + _health = health; + _maxHealth = maxHealth; + _hunger = hunger; + _items = items; + _armour = armour; } public int getGems() @@ -32,4 +43,29 @@ public class PersistenceData return _questData; } + public int getHealth() + { + return _health; + } + + public int getMaxHealth() + { + return _maxHealth; + } + + public int getHunger() + { + return _hunger; + } + + public ItemStack[] getItems() + { + return _items; + } + + public ItemStack[] getArmour() + { + return _armour; + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index 1b0702979..5e767abc5 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -5,14 +5,21 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.gemhunters.death.event.QuitNPCDespawnEvent; +import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.quest.QuestModule; +import mineplex.gemhunters.quest.QuestPlayerData; +import net.minecraft.server.v1_8_R3.EntityItemFrame; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; @ReflectivelyCreateMiniPlugin public class PersistenceModule extends MiniPlugin @@ -35,26 +42,22 @@ public class PersistenceModule extends MiniPlugin _repository = new PersistenceRepository(); } - @EventHandler(priority = EventPriority.HIGHEST) - public void playerJoin(PlayerJoinEvent event) - { - Player player = event.getPlayer(); - CoreClient client = _client.Get(player); - - runAsync(() -> _repository.getPersistenceData(response -> - { - _economy.setStore(player, response.getGems()); - player.teleport(response.getLocation()); - _quest.setPlayerData(player, response.getQuestData()); - }, client)); - } - @EventHandler public void playerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); CoreClient client = _client.Get(player); - PersistenceData data = new PersistenceData(_economy.Get(player), player.getLocation(), _quest.Get(player)); + + int gems = _economy.Get(player); + Location location = player.getLocation(); + QuestPlayerData quest = _quest.Get(player); + int health = (int) player.getHealth(); + int maxHealth = (int) player.getMaxHealth(); + int hunger = player.getFoodLevel(); + ItemStack[] items = player.getInventory().getContents(); + ItemStack[] armour = player.getInventory().getArmorContents(); + + PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, items, armour); runAsync(() -> _repository.savePersistence(client, data)); } @@ -76,4 +79,9 @@ public class PersistenceModule extends MiniPlugin runAsync(() -> _client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence)); } } + + public final PersistenceRepository getRepository() + { + return _repository; + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 3b2c2c6f8..5d5242d1e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -10,6 +10,8 @@ import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import java.sql.Connection; import java.sql.ResultSet; @@ -22,8 +24,8 @@ public class PersistenceRepository extends RepositoryBase { private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=?;"; - private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?);"; - private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=? WHERE accountId=?;"; + private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);"; + private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,items=?,armour=? WHERE accountId=?;"; private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;"; private static final Gson GSON; @@ -50,6 +52,9 @@ public class PersistenceRepository extends RepositoryBase if (resultSet.next()) { int gems = resultSet.getInt("gems"); + int health = resultSet.getInt("health"); + int maxHealth = resultSet.getInt("maxHealth"); + int hunger = resultSet.getInt("hunger"); int x = resultSet.getInt("x"); int y = resultSet.getInt("y"); int z = resultSet.getInt("z"); @@ -57,9 +62,15 @@ public class PersistenceRepository extends RepositoryBase int pitch = resultSet.getInt("pitch"); String quests = resultSet.getString("quests"); QuestPlayerData questData = GSON.fromJson(quests, QuestPlayerData.class); + String items = resultSet.getString("items"); + ItemStack[] itemsData = GSON.fromJson(items, ItemStack[].class); + String armour = resultSet.getString("armour"); + ItemStack[] armourData = GSON.fromJson(armour, ItemStack[].class); _exists.add(accountId); - PersistenceData data = new PersistenceData(gems, new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch), questData); + Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); + + PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, itemsData, armourData); response.accept(data); } }, new ColumnInt("accountId", accountId)); @@ -67,39 +78,67 @@ public class PersistenceRepository extends RepositoryBase public void savePersistence(CoreClient client, PersistenceData data) { + Bukkit.broadcastMessage("Saving data for " + client.getAccountId()); int accountId = client.getAccountId(); int gems = data.getGems(); + int health = data.getHealth(); + int maxHealth = data.getMaxHealth(); + int hunger = data.getHunger(); int x = data.getLocation().getBlockX(); int y = data.getLocation().getBlockY(); int z = data.getLocation().getBlockZ(); int yaw = (int) data.getLocation().getYaw(); int pitch = (int) data.getLocation().getPitch(); + ItemStack[] items = data.getItems(); - if (_exists.contains(accountId)) + for (int i = 0; i < items.length; i++) { + ItemStack itemStack = items[i]; + + if (itemStack != null && (itemStack.getType() == Material.EMERALD || itemStack.getType() == Material.MAP)) + { + Bukkit.broadcastMessage(itemStack.getType().name()); + items[i] = null; + } + } + + if (exists(client)) + { + Bukkit.broadcastMessage("Update"); executeUpdate(UPDATE_DATA, new ColumnInt("gems", gems), + new ColumnInt("health", health), + new ColumnInt("maxHealth", maxHealth), + new ColumnInt("hunger", hunger), new ColumnInt("x", x), new ColumnInt("y", y), new ColumnInt("z", z), new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), + new ColumnVarChar("items", 1000, GSON.toJson(data.getItems())), + new ColumnVarChar("armour", 100, GSON.toJson(data.getArmour())), new ColumnInt("accountId", accountId) ); } else { + Bukkit.broadcastMessage("Insert"); executeInsert(INSERT_DATA, null, new ColumnInt("accountId", accountId), new ColumnInt("gems", gems), + new ColumnInt("health", health), + new ColumnInt("maxHealth", maxHealth), + new ColumnInt("hunger", hunger), new ColumnInt("x", x), new ColumnInt("y", y), new ColumnInt("z", z), new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), - new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())) + new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), + new ColumnVarChar("items", 1000, GSON.toJson(data.getItems())), + new ColumnVarChar("armour", 100, GSON.toJson(data.getArmour())) ); } @@ -112,4 +151,9 @@ public class PersistenceRepository extends RepositoryBase executeUpdate(DELETE_DATA, new ColumnInt("accountId", accountId)); } + + public boolean exists(CoreClient client) + { + return _exists.contains(client.getAccountId()); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java index 342b1851c..da43ba06c 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/quest/QuestModule.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; +import mineplex.core.common.util.*; import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; @@ -25,14 +26,7 @@ import org.bukkit.metadata.FixedMetadataValue; import mineplex.core.MiniClientPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilInv; -import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem.ItemAttribute; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.menu.Menu; import mineplex.core.recharge.Recharge; @@ -491,7 +485,7 @@ public class QuestModule extends MiniClientPlugin @EventHandler public void debug(PlayerCommandPreprocessEvent event) { - if (event.getMessage().startsWith("/test")) + if (event.getMessage().startsWith("/questdatatest")) { event.setCancelled(true); Player player = event.getPlayer(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 4898f6f0f..7d1025675 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -83,7 +83,6 @@ public class SpawnModule extends MiniPlugin QuitNPC npc = _npc.getNPC(player); npc.despawn(true); - npc.restore(player); return; } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index 3688a3f17..b81b81279 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -49,7 +49,7 @@ public class WorldListeners implements Listener plugin.getServer().getPluginManager().registerEvents(this, plugin); } - //@EventHandler + @EventHandler public void deletePlayerData(PlayerQuitEvent event) { _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { From 4947b01f93526da09c9082c1a4d649beab93c75d Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 31 Mar 2017 20:24:45 +0100 Subject: [PATCH 04/21] Convert itemstacks to craftbukkit versions --- .../persistence/PersistenceRepository.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 5d5242d1e..0afc52806 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -5,17 +5,14 @@ import mineplex.core.account.CoreClient; import mineplex.gemhunters.quest.QuestPlayerData; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; -import mineplex.serverdata.database.ResultSetCallable; import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -78,7 +75,6 @@ public class PersistenceRepository extends RepositoryBase public void savePersistence(CoreClient client, PersistenceData data) { - Bukkit.broadcastMessage("Saving data for " + client.getAccountId()); int accountId = client.getAccountId(); int gems = data.getGems(); @@ -91,21 +87,40 @@ public class PersistenceRepository extends RepositoryBase int yaw = (int) data.getLocation().getYaw(); int pitch = (int) data.getLocation().getPitch(); ItemStack[] items = data.getItems(); + ItemStack[] armour = data.getItems(); + CraftItemStack[] nmsItems = new CraftItemStack[items.length]; + CraftItemStack[] nmsArmour = new CraftItemStack[armour.length]; for (int i = 0; i < items.length; i++) { ItemStack itemStack = items[i]; - if (itemStack != null && (itemStack.getType() == Material.EMERALD || itemStack.getType() == Material.MAP)) + if (itemStack == null) { - Bukkit.broadcastMessage(itemStack.getType().name()); - items[i] = null; + continue; } + + if (itemStack.getType() == Material.EMERALD || itemStack.getType() == Material.MAP) + { + nmsItems[i] = null; + continue; + } + + nmsItems[i] = CraftItemStack.asCraftCopy(itemStack); + } + + for (int i = 0; i < armour.length; i++) + { + if (armour[i] == null) + { + continue; + } + + nmsArmour[i] = CraftItemStack.asCraftCopy(armour[i]); } if (exists(client)) { - Bukkit.broadcastMessage("Update"); executeUpdate(UPDATE_DATA, new ColumnInt("gems", gems), new ColumnInt("health", health), @@ -117,14 +132,13 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), - new ColumnVarChar("items", 1000, GSON.toJson(data.getItems())), - new ColumnVarChar("armour", 100, GSON.toJson(data.getArmour())), + new ColumnVarChar("items", 1000, GSON.toJson(nmsItems)), + new ColumnVarChar("armour", 100, GSON.toJson(nmsArmour)), new ColumnInt("accountId", accountId) ); } else { - Bukkit.broadcastMessage("Insert"); executeInsert(INSERT_DATA, null, new ColumnInt("accountId", accountId), new ColumnInt("gems", gems), @@ -137,8 +151,8 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), - new ColumnVarChar("items", 1000, GSON.toJson(data.getItems())), - new ColumnVarChar("armour", 100, GSON.toJson(data.getArmour())) + new ColumnVarChar("items", 1000, GSON.toJson(nmsItems)), + new ColumnVarChar("armour", 100, GSON.toJson(nmsArmour)) ); } From 9ad8e181757721975d9b2182c888d9183fe1745f Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Apr 2017 20:16:03 +0100 Subject: [PATCH 05/21] More persistence senanagins --- .../persistence/PersistenceModule.java | 4 +- .../persistence/PersistenceRepository.java | 65 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index 5e767abc5..6457ff087 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -42,7 +42,7 @@ public class PersistenceModule extends MiniPlugin _repository = new PersistenceRepository(); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void playerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); @@ -62,7 +62,7 @@ public class PersistenceModule extends MiniPlugin runAsync(() -> _repository.savePersistence(client, data)); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void playerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 0afc52806..4e6cedd0a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.function.Consumer; public class PersistenceRepository extends RepositoryBase @@ -59,15 +60,29 @@ public class PersistenceRepository extends RepositoryBase int pitch = resultSet.getInt("pitch"); String quests = resultSet.getString("quests"); QuestPlayerData questData = GSON.fromJson(quests, QuestPlayerData.class); + String items = resultSet.getString("items"); - ItemStack[] itemsData = GSON.fromJson(items, ItemStack[].class); + List> itemsMap = GSON.fromJson(items, List.class); + List itemsList = new ArrayList<>(itemsMap.size()); + + for (Map map : itemsMap) + { + itemsList.add(CraftItemStack.deserialize(map)); + } + String armour = resultSet.getString("armour"); - ItemStack[] armourData = GSON.fromJson(armour, ItemStack[].class); + List> armourMap = GSON.fromJson(armour, List.class); + List armourList = new ArrayList<>(armourMap.size()); + + for (Map map : armourMap) + { + armourList.add(CraftItemStack.deserialize(map)); + } _exists.add(accountId); Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); - PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, itemsData, armourData); + PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0])); response.accept(data); } }, new ColumnInt("accountId", accountId)); @@ -87,36 +102,28 @@ public class PersistenceRepository extends RepositoryBase int yaw = (int) data.getLocation().getYaw(); int pitch = (int) data.getLocation().getPitch(); ItemStack[] items = data.getItems(); - ItemStack[] armour = data.getItems(); - CraftItemStack[] nmsItems = new CraftItemStack[items.length]; - CraftItemStack[] nmsArmour = new CraftItemStack[armour.length]; + ItemStack[] armour = data.getArmour(); + List> itemsMap = new ArrayList<>(items.length); + List> armourMap = new ArrayList<>(armour.length); - for (int i = 0; i < items.length; i++) + for (ItemStack itemStack : items) { - ItemStack itemStack = items[i]; + if (itemStack == null || itemStack.getType() == Material.MAP || itemStack.getType() == Material.STAINED_GLASS_PANE) + { + continue; + } + itemsMap.add(itemStack.serialize()); + } + + for (ItemStack itemStack : armour) + { if (itemStack == null) { continue; } - if (itemStack.getType() == Material.EMERALD || itemStack.getType() == Material.MAP) - { - nmsItems[i] = null; - continue; - } - - nmsItems[i] = CraftItemStack.asCraftCopy(itemStack); - } - - for (int i = 0; i < armour.length; i++) - { - if (armour[i] == null) - { - continue; - } - - nmsArmour[i] = CraftItemStack.asCraftCopy(armour[i]); + armourMap.add(itemStack.serialize()); } if (exists(client)) @@ -132,8 +139,8 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), - new ColumnVarChar("items", 1000, GSON.toJson(nmsItems)), - new ColumnVarChar("armour", 100, GSON.toJson(nmsArmour)), + new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)), + new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)), new ColumnInt("accountId", accountId) ); } @@ -151,8 +158,8 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), - new ColumnVarChar("items", 1000, GSON.toJson(nmsItems)), - new ColumnVarChar("armour", 100, GSON.toJson(nmsArmour)) + new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)), + new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)) ); } From b85214c7f00fb4e3b51d70562b826afe1fb24ac8 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 4 Apr 2017 21:12:39 +0100 Subject: [PATCH 06/21] Fix the "wooden pillar" bug with supply drops --- .../gemhunters/supplydrop/SupplyDrop.java | 23 +--- .../supplydrop/SupplyDropModule.java | 113 ++++++++++-------- 2 files changed, 67 insertions(+), 69 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java index 8f2ca4203..6977976c2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDrop.java @@ -5,19 +5,18 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; +import mineplex.core.common.util.*; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.FallingBlock; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BlockVector; import mineplex.core.common.block.schematic.Schematic; import mineplex.core.common.block.schematic.SchematicData; import mineplex.core.common.block.schematic.UtilSchematic; -import mineplex.core.common.util.UtilFirework; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilShapes; /** * Represents an instance of a Supply Drop.
@@ -101,11 +100,7 @@ public class SupplyDrop if (_blade != null) { - if (UtilMath.offset2d(_blade, _destination) < 1) - { - spawnLootChest(); - } - else if (UtilMath.offset2d(_blade, _despawn) < 1) + if (UtilMath.offset2d(_blade, _despawn) < 1) { for (Block block : _bladeBlocks) { @@ -197,16 +192,6 @@ public class SupplyDrop block.setType(Material.AIR); } } - - public void spawnLootChest() - { - FallingBlock fallingBlock = _blade.getWorld().spawnFallingBlock(_blade.clone().subtract(0, 10, 0), Material.WOOD, (byte) 0); - - fallingBlock.setHurtEntities(false); - fallingBlock.setDropItem(false); - - UtilFirework.playFirework(fallingBlock.getLocation().add(0.5, 1, 0.5), UtilFirework.getRandomFireworkEffect(false, 2, 1)); - } public final String getName() { @@ -222,4 +207,6 @@ public class SupplyDrop { return _destination; } + + public final Location getBladeLocation() { return _blade; } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java index ff2b59a26..54816bcbf 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -1,37 +1,32 @@ package mineplex.gemhunters.supplydrop; +import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; +import mineplex.core.blockrestore.BlockRestore; +import mineplex.core.common.Pair; +import mineplex.core.common.util.*; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.loot.LootModule; +import mineplex.gemhunters.supplydrop.command.SupplyDropCommand; +import mineplex.gemhunters.world.WorldDataModule; +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.FallingBlock; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.scheduler.BukkitRunnable; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.FallingBlock; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.ItemSpawnEvent; - -import mineplex.core.MiniPlugin; -import mineplex.core.ReflectivelyCreateMiniPlugin; -import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.Pair; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; -import mineplex.core.common.util.UtilWorld; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.gemhunters.loot.LootModule; -import mineplex.gemhunters.supplydrop.command.SupplyDropCommand; -import mineplex.gemhunters.world.WorldDataModule; - @ReflectivelyCreateMiniPlugin public class SupplyDropModule extends MiniPlugin { @@ -85,6 +80,10 @@ public class SupplyDropModule extends MiniPlugin { stopSequence(); } + else if (UtilMath.offset2d(_current.getBladeLocation(), _current.getChestLocation()) < 1) + { + spawnLootChest(); + } } else if (UtilTime.elapsed(_lastSupplyDrop, SEQUENCE_TIMER)) { @@ -103,31 +102,6 @@ public class SupplyDropModule extends MiniPlugin } } - @EventHandler - public void fallingBlockChange(EntityChangeBlockEvent event) - { - if (event.getEntity() instanceof FallingBlock && event.getTo() == Material.WOOD && isActive() && UtilMath.offsetSquared(_current.getChestLocation(), event.getBlock().getLocation()) < 16) - { - Block block = event.getBlock(); - - block.setType(Material.CHEST); - - // Add location that the chest will appear at into the spawned - // chests list so that LootModule can populate it with loot. - _loot.addSpawnedChest(block.getLocation(), CHEST_COLOUR); - - // Remove beacon - for (Block beacon : _beaconBlocks) - { - _blockRestore.restore(beacon); - } - - _beaconBlocks.clear(); - - event.setCancelled(true); - } - } - public void startSequence(String locationKey) { Location spawn = _worldData.getCustomLocation(LOCATION_DATA + " " + locationKey + " Start").get(0); @@ -168,6 +142,43 @@ public class SupplyDropModule extends MiniPlugin _current = null; } + public void spawnLootChest() + { + Location chest = _current.getBladeLocation().clone().subtract(0, 10, 0); + + runSyncTimer(new BukkitRunnable() + { + + Block chestBlock = chest.getBlock(); + + @Override + public void run() + { + chestBlock.setType(Material.AIR); + chestBlock = chestBlock.getRelative(BlockFace.DOWN); + chestBlock.setType(Material.CHEST); + + if (chestBlock.getRelative(BlockFace.DOWN).getType() != Material.AIR) + { + // Add location that the chest will appear at into the spawned + // chests list so that LootModule can populate it with loot. + _loot.addSpawnedChest(chestBlock.getLocation(), CHEST_COLOUR); + + // Remove beacon + for (Block beacon : _beaconBlocks) + { + _blockRestore.restore(beacon); + } + + _beaconBlocks.clear(); + cancel(); + } + + UtilFirework.playFirework(chestBlock.getLocation().add(0.5, 1, 0.5), FireworkEffect.Type.BALL, Color.YELLOW, true, false); + } + }, 0, 5); + } + public boolean isActive() { return _current != null; From 4552fc2e9bbe7e83ade1245c85f478423f597252 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 5 Apr 2017 21:14:12 +0100 Subject: [PATCH 07/21] Fix loot module NPE --- .../mineplex/gemhunters/loot/LootModule.java | 56 +++++++++---------- .../gemhunters/world/WorldListeners.java | 35 ++++++------ 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index bf41c3a9e..cb0932006 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -534,41 +534,41 @@ public class LootModule extends MiniPlugin String[] metadataSplit = lootItem.getMetadata().split(" "); String key = metadataSplit[0]; String[] values = new String[metadataSplit.length - 1]; - - for (int i = 1; i < metadataSplit.length; i++) - { - values[i - 1] = metadataSplit[i]; - } - + + System.arraycopy(metadataSplit, 1, values, 0, metadataSplit.length - 1); + switch (key) { - case "RANK_UPGRADE": - reward = new LootRankReward(itemStack); - break; - case "SHARD": - reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1])); - break; - case "CHEST": - reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2])); - break; - case "GADGET": - String gadget = ""; - - for (int i = 1; i < values.length; i++) - { - gadget += values[i] + " "; - } - - reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim()); - break; - default: - return; + case "RANK_UPGRADE": + reward = new LootRankReward(itemStack); + break; + case "SHARD": + reward = new LootShardReward(Integer.parseInt(values[0]) * 1000, itemStack, Integer.parseInt(values[1])); + break; + case "CHEST": + reward = new LootChestReward(Integer.parseInt(values[0]) * 1000, itemStack, values[1], Integer.parseInt(values[2])); + break; + case "GADGET": + String gadget = ""; + + for (int i = 1; i < values.length; i++) + { + gadget += values[i] + " "; + } + + reward = new LootGadgetReward(Integer.parseInt(values[0]) * 1000, itemStack, gadget.trim()); + break; + default: + return; } _itemRewards.add(reward); } - reward.collectItem(player); + if (reward != null) + { + reward.collectItem(player); + } } public void addItemReward(LootItemReward reward) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index b81b81279..f5eb8b845 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -24,11 +24,7 @@ import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.player.PlayerArmorStandManipulateEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -52,7 +48,8 @@ public class WorldListeners implements Listener @EventHandler public void deletePlayerData(PlayerQuitEvent event) { - _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { + _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> + { World world = event.getPlayer().getWorld(); UUID uuid = event.getPlayer().getUniqueId(); String path = world.getWorldFolder().getPath(); @@ -60,7 +57,7 @@ public class WorldListeners implements Listener new File(path + File.separator + "stats" + File.separator + uuid + ".json").delete(); }, 10); } - + @EventHandler public void customDamage(CustomDamageEvent event) { @@ -117,7 +114,7 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + @EventHandler public void itemFrames(PlayerInteractEntityEvent event) { @@ -134,16 +131,16 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + Block block = event.getClickedBlock(); - + if (block == null) { return; } - + Material material = block.getType(); - + if (material == Material.BEACON || material == Material.DISPENSER || material == Material.HOPPER || material == Material.BREWING_STAND || material == Material.DROPPER) { event.setCancelled(true); @@ -162,7 +159,7 @@ public class WorldListeners implements Listener { return; } - + event.setCancelled(true); } @@ -173,7 +170,7 @@ public class WorldListeners implements Listener { return; } - + event.setCancelled(true); } @@ -188,7 +185,7 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + @EventHandler public void leavesDecay(LeavesDecayEvent event) { @@ -203,7 +200,7 @@ public class WorldListeners implements Listener // Some witchcraft from the arcade, seems to make hunger not ridiculous. player.setSaturation(3.8F); } - + @EventHandler(priority = EventPriority.LOWEST) public void weather(WeatherChangeEvent event) { @@ -213,6 +210,12 @@ public class WorldListeners implements Listener } } + @EventHandler + public void bucketEmpty(PlayerBucketEmptyEvent event) + { + event.setCancelled(true); + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE; From 914de58dbc284cf66f6e979c5d00b1d4167101ca Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 9 Apr 2017 16:01:44 +0100 Subject: [PATCH 08/21] World Event bug fixes --- .../gemhunters/safezone/SafezoneModule.java | 2 +- .../gemhunters/world/WorldListeners.java | 25 +++++++++++++---- .../blizzard/BlizzardWorldEvent.java | 28 ++++--------------- .../worldevent/giant/GiantWorldEvent.java | 2 +- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 0673dadb9..795dcaaa3 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -138,7 +138,7 @@ public class SafezoneModule extends MiniPlugin Player player = (Player) event.getEntity(); - if (isInSafeZone(player)) + if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT) { event.setCancelled(true); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java index f5eb8b845..f40a2605b 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -14,16 +14,12 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockFadeEvent; -import org.bukkit.event.block.BlockIgniteEvent; +import org.bukkit.event.block.*; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.ChunkUnloadEvent; @@ -216,6 +212,23 @@ public class WorldListeners implements Listener event.setCancelled(true); } + @EventHandler + public void fishingExpRemove(PlayerFishEvent event) + { + event.setExpToDrop(0); + } + + @EventHandler + public void smelt(BlockExpEvent event) + { + Material material = event.getBlock().getType(); + + if (material == Material.FURNACE || material == Material.BURNING_FURNACE) + { + event.setExpToDrop(0); + } + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/blizzard/BlizzardWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/blizzard/BlizzardWorldEvent.java index 776e17506..031abd340 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/blizzard/BlizzardWorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/blizzard/BlizzardWorldEvent.java @@ -37,7 +37,6 @@ public class BlizzardWorldEvent extends WorldEvent private static final double START_CHANCE = 0.01; private static final long MAX_TIME = TimeUnit.MINUTES.toMillis(10); private static final long GRACE_TIME = TimeUnit.SECONDS.toMillis(60); - private static final long WARM_TIME = TimeUnit.SECONDS.toMillis(5); private static final int DAMAGE = 2; private static final String TIP = "EQUIP LEATHER ARMOUR OR GET NEAR A FIRE"; @@ -108,8 +107,13 @@ public class BlizzardWorldEvent extends WorldEvent { if (shouldDamage(player)) { + _playerStatus.setStatus(player, PlayerStatusType.COLD); _damage.NewDamageEvent(player, null, null, DamageCause.CUSTOM, DAMAGE, false, true, true, "Hurricane", "Frostbite"); } + else + { + _playerStatus.setStatus(player, PlayerStatusType.WARM); + } } } } @@ -141,30 +145,8 @@ public class BlizzardWorldEvent extends WorldEvent } } - _playerStatus.setStatus(player, PlayerStatusType.WARM, WARM_TIME); return false; } - - @EventHandler - public void updatePlayerStatus(UpdateEvent event) - { - if (event.getType() != UpdateType.SLOW || !isLive()) - { - return; - } - - for (Player player : Bukkit.getOnlinePlayers()) - { - PlayerStatus status = _playerStatus.Get(player); - - if (status.getStatusType() == PlayerStatusType.COLD) - { - continue; - } - - _playerStatus.setStatus(player, PlayerStatusType.COLD, true); - } - } @Override public void onStart() diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java index 1461add88..213b9a1aa 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/worldevent/giant/GiantWorldEvent.java @@ -73,7 +73,7 @@ public class GiantWorldEvent extends WorldEvent public void onEnd() { ItemStack itemStack = SkinData.OMEGA_CHEST.getSkull(C.cAqua + "Omega Chest", new ArrayList<>()); - LootChestReward reward = new LootChestReward(CASH_OUT_DELAY, SkinData.OMEGA_CHEST.getSkull(C.cAqua + "Omega Chest", null), "Omega", 1); + LootChestReward reward = new LootChestReward(CASH_OUT_DELAY, itemStack, "Omega", 1); _worldData.World.dropItemNaturally(getEventLocations()[0], itemStack); From f9c98ccf8cc0d661f9cc5b3ad3890b3c6d1539b2 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Apr 2017 20:05:43 +0100 Subject: [PATCH 09/21] Fix persistence? --- .../gemhunters/death/DeathModule.java | 8 ---- .../gemhunters/economy/CashOutModule.java | 42 ++++++++----------- .../gemhunters/economy/EconomyModule.java | 7 +--- .../gemhunters/loot/InventoryModule.java | 33 ++++++++------- .../persistence/PersistenceRepository.java | 42 ++++++++++++++++++- 5 files changed, 77 insertions(+), 55 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java index bb1de59d5..4f9baa634 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/DeathModule.java @@ -70,14 +70,6 @@ public class DeathModule extends MiniPlugin _toRemove = new HashMap<>(); } - @EventHandler(priority = EventPriority.MONITOR) - public void join(PlayerJoinEvent event) - { - PlayerCustomRespawnEvent event2 = new PlayerCustomRespawnEvent(event.getPlayer()); - - UtilServer.CallEvent(event2); - } - @EventHandler public void death(PlayerDeathEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 6f83a5af5..e3658be72 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -1,32 +1,10 @@ package mineplex.gemhunters.economy; -import java.text.DecimalFormat; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Material; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.ItemSpawnEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; - import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.currency.GlobalCurrency; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.*; import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.donation.DonationManager; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.portal.GenericServer; @@ -38,13 +16,29 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.gemhunters.economy.command.CashOutItemCommand; import mineplex.gemhunters.economy.event.PlayerCashOutCompleteEvent; import mineplex.gemhunters.spawn.event.PlayerTeleportIntoMapEvent; +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import java.text.DecimalFormat; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; @ReflectivelyCreateMiniPlugin public class CashOutModule extends MiniPlugin { private static final DecimalFormat ARMOUR_STAND_FORMAT = new DecimalFormat("0.0"); - public static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", C.cGray + "Click to begin the process to cash out.", C.cGray + "Cashing out gives you your gems, shards, ", C.cGray + "chests and any particles you have.", C.cGray + "However you will lose all your current loot!").build(); + public static final ItemStack CASH_OUT_ITEM = new ItemBuilder(Material.EMERALD).setTitle(C.cGreen + "Cash Out").addLore("", "Click to begin the process to cash out.", "Cashing out gives you your gems, shards,", "chests and any particles you have.", "However you will lose all your current loot!").build(); private static final int CASH_OUT_SECONDS = 10; private static final int CASH_OUT_COOLDOWN = 10000; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index d1b803c6a..06cdf5474 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -68,7 +68,7 @@ public class EconomyModule extends MiniClientPlugin int oldGems = getGems(player); - if (killer instanceof Player) + if (killer != null) { Player killerPlayer = (Player) killer; int newGems = (int) (oldGems * GEM_KILL_FACTOR); @@ -116,11 +116,6 @@ public class EconomyModule extends MiniClientPlugin Set(player, gems); } - public void setStore(UUID player, int gems) - { - Set(player, gems); - } - public int getGems(Player player) { return Get(player); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index a3d34e623..70f0ec9f8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -48,15 +49,13 @@ public class InventoryModule extends MiniPlugin @EventHandler public void respawn(PlayerCustomRespawnEvent event) { - Player player = event.getPlayer(); - Inventory inv = player.getInventory(); + resetSlots(event.getPlayer()); + } - _slotsUnlocked.put(player.getUniqueId(), 0); - - for (int i = START_INDEX; i < inv.getSize(); i++) - { - inv.setItem(i, LOCKED); - } + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + resetSlots(event.getPlayer()); } @EventHandler @@ -126,14 +125,16 @@ public class InventoryModule extends MiniPlugin player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); _slotsUnlocked.put(key, _slotsUnlocked.get(key) + slots); } - - public void setSlotsUnlocked(Player player, int amount) + + private void resetSlots(Player player) { - _slotsUnlocked.put(player.getUniqueId(), amount); - } - - public int getSlotsUnlocked(Player player) - { - return _slotsUnlocked.get(player.getUniqueId()); + Inventory inv = player.getInventory(); + + _slotsUnlocked.put(player.getUniqueId(), 0); + + for (int i = START_INDEX; i < inv.getSize(); i++) + { + inv.setItem(i, LOCKED); + } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 4e6cedd0a..dc2ee5fd0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -12,7 +12,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -67,7 +69,14 @@ public class PersistenceRepository extends RepositoryBase for (Map map : itemsMap) { - itemsList.add(CraftItemStack.deserialize(map)); + ItemStack itemStack = CraftItemStack.deserialize(map); + + if (map.containsKey("meta")) + { + itemStack.setItemMeta(deserialiseMeta(map.get("meta"))); + } + + itemsList.add(itemStack); } String armour = resultSet.getString("armour"); @@ -76,6 +85,13 @@ public class PersistenceRepository extends RepositoryBase for (Map map : armourMap) { + ItemStack itemStack = CraftItemStack.deserialize(map); + + if (map.containsKey("meta")) + { + itemStack.setItemMeta(deserialiseMeta(map.get("meta"))); + } + armourList.add(CraftItemStack.deserialize(map)); } @@ -177,4 +193,28 @@ public class PersistenceRepository extends RepositoryBase { return _exists.contains(client.getAccountId()); } + + private ItemMeta deserialiseMeta(Object map) + { + if (!(map instanceof Map)) + { + return null; + } + + try + { + Class clazz = Class.forName("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaItem"); + Constructor constructor = clazz.getDeclaredConstructor(Map.class); + + constructor.setAccessible(true); + + return (ItemMeta) constructor.newInstance(map); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } } From 82db46c1e632b2cbf03ce2c7aca70f3424447ace Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 21 Apr 2017 22:52:34 +0100 Subject: [PATCH 10/21] Displayname fix --- .../gemhunters/persistence/PersistenceRepository.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index dc2ee5fd0..13de53322 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -7,6 +7,7 @@ import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnVarChar; +import net.minecraft.server.v1_8_R3.ItemMapEmpty; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -208,7 +209,10 @@ public class PersistenceRepository extends RepositoryBase constructor.setAccessible(true); - return (ItemMeta) constructor.newInstance(map); + ItemMeta meta = (ItemMeta) constructor.newInstance(map); + meta.setDisplayName((String) ((Map) map).get("displayName")); + + return meta; } catch (Exception e) { From 90d173551d357cb6a06d52064dc123fe1fbf8b4f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 26 Apr 2017 21:56:01 +0100 Subject: [PATCH 11/21] Fix not lobby gem duping --- .../src/mineplex/gemhunters/economy/EconomyModule.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 06cdf5474..364db0796 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -42,12 +42,6 @@ public class EconomyModule extends MiniClientPlugin addCommand(new GiveGemsCommand(this)); } - @EventHandler - public void respawn(PlayerCustomRespawnEvent event) - { - addToStore(event.getPlayer(), null, GEM_START_COST); - } - @EventHandler public void teleportIn(PlayerTeleportIntoMapEvent event) { @@ -58,6 +52,8 @@ public class EconomyModule extends MiniClientPlugin { _donation.purchaseUnknownSalesPackage(player, "Gem Hunters Access", GlobalCurrency.GEM, GEM_START_COST, false, null); } + + addToStore(event.getPlayer(), null, GEM_START_COST); } @EventHandler From 6d8c65ed0825d4d0136e7e229502c14d5596649d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 May 2017 23:17:06 +0100 Subject: [PATCH 12/21] Lots of great fixes --- .../gemhunters/economy/CashOutModule.java | 29 +++++++++-- .../gemhunters/economy/EconomyModule.java | 4 +- .../mineplex/gemhunters/join/JoinModule.java | 48 +++++++++++-------- .../gemhunters/loot/InventoryModule.java | 25 ++++++---- .../mineplex/gemhunters/loot/LootModule.java | 10 ++-- .../gemhunters/map/ItemMapModule.java | 16 +++++-- .../persistence/PersistenceData.java | 9 +++- .../persistence/PersistenceModule.java | 6 ++- .../persistence/PersistenceRepository.java | 10 ++-- .../gemhunters/safezone/SafezoneModule.java | 5 +- .../gemhunters/spawn/SpawnModule.java | 21 +------- 11 files changed, 115 insertions(+), 68 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index e3658be72..08ae25420 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -66,7 +66,7 @@ public class CashOutModule extends MiniPlugin @EventHandler public void teleportIn(PlayerTeleportIntoMapEvent event) { - if (event.isCancelled()) + if (event.isCancelled() || event.getPlayer().getInventory().contains(CASH_OUT_ITEM)) { return; } @@ -120,7 +120,7 @@ public class CashOutModule extends MiniPlugin while (iterator.hasNext()) { UUID key = iterator.next(); - Player player = UtilPlayer.searchExact(key); + final Player player = UtilPlayer.searchExact(key); CashOutSession session = _sessions.get(key); double current = session.getCurrent(); ArmorStand stand = session.getArmourStand(); @@ -140,14 +140,30 @@ public class CashOutModule extends MiniPlugin if (session.getCurrent() <= 0) { PlayerCashOutCompleteEvent completeEvent = new PlayerCashOutCompleteEvent(player); - + UtilServer.CallEvent(completeEvent); _donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems()); session.endSession(); iterator.remove(); - Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.FORCE_TRANSFER); + + if (UtilServer.isTestServer()) + { + kickPlayer(player); + } + else + { + Portal.getInstance().sendPlayerToGenericServer(player, GenericServer.BETA_HUB, Intent.FORCE_TRANSFER); + + runSyncLater(() -> + { + if (player.isOnline()) + { + kickPlayer(player); + } + }, 20); + } } } } @@ -260,4 +276,9 @@ public class CashOutModule extends MiniPlugin return null; } + private void kickPlayer(Player player) + { + player.kickPlayer(C.cGreen + "Imagine you are being sent to the lobby."); + } + } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java index 364db0796..5ebb5e001 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -46,14 +46,14 @@ public class EconomyModule extends MiniClientPlugin public void teleportIn(PlayerTeleportIntoMapEvent event) { Player player = event.getPlayer(); + addToStore(event.getPlayer(), null, GEM_START_COST); + Donor donor = _donation.Get(event.getPlayer()); if (donor.getBalance(GlobalCurrency.GEM) >= GEM_START_COST) { _donation.purchaseUnknownSalesPackage(player, "Gem Hunters Access", GlobalCurrency.GEM, GEM_START_COST, false, null); } - - addToStore(event.getPlayer(), null, GEM_START_COST); } @EventHandler diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java index b9c13d109..deb3644d7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/join/JoinModule.java @@ -4,13 +4,17 @@ import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; +import mineplex.core.inventory.InventoryManager; import mineplex.gemhunters.death.quitnpc.QuitNPC; import mineplex.gemhunters.death.quitnpc.QuitNPCModule; import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.loot.InventoryModule; +import mineplex.gemhunters.map.ItemMapModule; import mineplex.gemhunters.persistence.PersistenceData; import mineplex.gemhunters.persistence.PersistenceModule; import mineplex.gemhunters.persistence.PersistenceRepository; import mineplex.gemhunters.quest.QuestModule; +import mineplex.gemhunters.spawn.SpawnModule; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -26,6 +30,8 @@ public class JoinModule extends MiniPlugin private final QuestModule _quest; private final PersistenceModule _persistence; private final QuitNPCModule _npc; + private final InventoryModule _inventory; + private final SpawnModule _spawn; private JoinModule() { @@ -36,6 +42,8 @@ public class JoinModule extends MiniPlugin _quest = require(QuestModule.class); _persistence = require(PersistenceModule.class); _npc = require(QuitNPCModule.class); + _inventory = require(InventoryModule.class); + _spawn = require(SpawnModule.class); } @EventHandler @@ -45,33 +53,35 @@ public class JoinModule extends MiniPlugin CoreClient client = _client.Get(player); PersistenceRepository repository = _persistence.getRepository(); Consumer response = data -> - { - _economy.setStore(player, data.getGems()); - _quest.setPlayerData(player, data.getQuestData()); - player.teleport(data.getLocation()); - player.setHealth(data.getHealth()); - player.setMaxHealth(data.getMaxHealth()); - player.setFoodLevel(data.getHunger()); - player.getInventory().clear(); - player.getInventory().addItem(data.getItems()); - player.getInventory().setArmorContents(data.getArmour()); - }; + runSync(() -> { + _economy.setStore(player, data.getGems()); + _quest.setPlayerData(player, data.getQuestData()); + player.teleport(data.getLocation()); + player.setHealth(data.getHealth()); + player.setMaxHealth(data.getMaxHealth()); + player.setFoodLevel(data.getHunger()); + player.getInventory().addItem(data.getItems()); + player.getInventory().setArmorContents(data.getArmour()); + _inventory.unlockSlots(player, data.getSlots(), false); + }); player.getInventory().clear(); + if (_npc.hasNPC(player)) + { + QuitNPC npc = _npc.getNPC(player); + npc.despawn(true); + } + + _inventory.resetSlots(player); + runAsync(() -> { repository.getPersistenceData(response, client); - if (_npc.hasNPC(player)) + if (!repository.exists(client)) { - QuitNPC npc = _npc.getNPC(player); - npc.despawn(true); - } - - if (repository.exists(client)) - { - + _spawn.teleportToSpawn(player); } }); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java index 70f0ec9f8..92c349c1e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -52,12 +52,6 @@ public class InventoryModule extends MiniPlugin resetSlots(event.getPlayer()); } - @EventHandler - public void playerJoin(PlayerJoinEvent event) - { - resetSlots(event.getPlayer()); - } - @EventHandler public void quit(PlayerQuitEvent event) { @@ -110,6 +104,13 @@ public class InventoryModule extends MiniPlugin public void unlockSlots(Player player, int slots) { + unlockSlots(player, slots, true); + } + + public void unlockSlots(Player player, int slots, boolean inform) + { + _slotsUnlocked.putIfAbsent(player.getUniqueId(), 0); + Inventory inv = player.getInventory(); UUID key = player.getUniqueId(); @@ -122,11 +123,14 @@ public class InventoryModule extends MiniPlugin inv.setItem(i, null); } - player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); + if (inform) + { + player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); + } _slotsUnlocked.put(key, _slotsUnlocked.get(key) + slots); } - private void resetSlots(Player player) + public void resetSlots(Player player) { Inventory inv = player.getInventory(); @@ -137,4 +141,9 @@ public class InventoryModule extends MiniPlugin inv.setItem(i, LOCKED); } } + + public int getSlots(Player player) + { + return _slotsUnlocked.get(player.getUniqueId()); + } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java index cb0932006..a60f1e7f0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -613,20 +613,20 @@ public class LootModule extends MiniPlugin { return; } - + _shownPlayers.clear(); - + for (Player player : Bukkit.getOnlinePlayers()) { UUID key = player.getUniqueId(); - + for (LootItemReward itemReward : _itemRewards) { if (itemReward.getPlayer() == null) { continue; } - + if (itemReward.getPlayer().equals(player)) { _shownPlayers.add(key); @@ -641,7 +641,7 @@ public class LootModule extends MiniPlugin { event.getPlayer().getInventory().addItem(SPAWN_ITEMS); } - + @EventHandler public void cashOutComplete(PlayerCashOutCompleteEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java index 6b85e8ba4..c556b8273 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/map/ItemMapModule.java @@ -29,6 +29,7 @@ import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.inventory.ItemStack; @@ -662,12 +663,21 @@ public class ItemMapModule extends MiniPlugin showZoom(player, info); } + @EventHandler(priority = EventPriority.HIGHEST) + public void playerJoin(PlayerJoinEvent event) + { + handleGive(event.getPlayer()); + } + @EventHandler - public void teleportIn(PlayerCustomRespawnEvent event) + public void respawn(PlayerCustomRespawnEvent event) + { + handleGive(event.getPlayer()); + } + + public void handleGive(Player player) { MapInfo info = new MapInfo(_mapId); - - Player player = event.getPlayer(); Location loc = player.getLocation(); int zoom = getZoom(1); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java index dd0362ea8..dc8fe78ed 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceData.java @@ -13,10 +13,11 @@ public class PersistenceData private final int _health; private final int _maxHealth; private final int _hunger; + private final int _slots; private final ItemStack[] _items; private final ItemStack[] _armour; - public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, ItemStack[] items, ItemStack[] armour) + public PersistenceData(int gems, Location location, QuestPlayerData questData, int health, int maxHealth, int hunger, int slots, ItemStack[] items, ItemStack[] armour) { _gems = gems; _location = location; @@ -25,6 +26,7 @@ public class PersistenceData _maxHealth = maxHealth; _hunger = hunger; _items = items; + _slots = slots; _armour = armour; } @@ -58,6 +60,11 @@ public class PersistenceData return _hunger; } + public int getSlots() + { + return _slots; + } + public ItemStack[] getItems() { return _items; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index 6457ff087..0b6b39e36 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -7,6 +7,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.gemhunters.death.event.QuitNPCDespawnEvent; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; +import mineplex.gemhunters.loot.InventoryModule; import mineplex.gemhunters.quest.QuestModule; import mineplex.gemhunters.quest.QuestPlayerData; import net.minecraft.server.v1_8_R3.EntityItemFrame; @@ -28,6 +29,7 @@ public class PersistenceModule extends MiniPlugin private final CoreClientManager _client; private final EconomyModule _economy; private final QuestModule _quest; + private final InventoryModule _inventory; private final PersistenceRepository _repository; @@ -38,6 +40,7 @@ public class PersistenceModule extends MiniPlugin _client = require(CoreClientManager.class); _quest = require(QuestModule.class); _economy = require(EconomyModule.class); + _inventory = require(InventoryModule.class); _repository = new PersistenceRepository(); } @@ -54,10 +57,11 @@ public class PersistenceModule extends MiniPlugin int health = (int) player.getHealth(); int maxHealth = (int) player.getMaxHealth(); int hunger = player.getFoodLevel(); + int slots = _inventory.getSlots(player); ItemStack[] items = player.getInventory().getContents(); ItemStack[] armour = player.getInventory().getArmorContents(); - PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, items, armour); + PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, slots, items, armour); runAsync(() -> _repository.savePersistence(client, data)); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 13de53322..7b9b03979 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -25,8 +25,8 @@ public class PersistenceRepository extends RepositoryBase { private static final String GET_DATA = "SELECT * FROM gemHunters WHERE accountId=?;"; - private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);"; - private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,items=?,armour=? WHERE accountId=?;"; + private static final String INSERT_DATA = "INSERT INTO gemHunters VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=? WHERE accountId=?;"; private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;"; private static final Gson GSON; @@ -61,6 +61,7 @@ public class PersistenceRepository extends RepositoryBase int z = resultSet.getInt("z"); int yaw = resultSet.getInt("yaw"); int pitch = resultSet.getInt("pitch"); + int slots = resultSet.getInt("slots"); String quests = resultSet.getString("quests"); QuestPlayerData questData = GSON.fromJson(quests, QuestPlayerData.class); @@ -99,7 +100,7 @@ public class PersistenceRepository extends RepositoryBase _exists.add(accountId); Location location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); - PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0])); + PersistenceData data = new PersistenceData(gems, location, questData, health, maxHealth, hunger, slots, itemsList.toArray(new ItemStack[0]), armourList.toArray(new ItemStack[0])); response.accept(data); } }, new ColumnInt("accountId", accountId)); @@ -118,6 +119,7 @@ public class PersistenceRepository extends RepositoryBase int z = data.getLocation().getBlockZ(); int yaw = (int) data.getLocation().getYaw(); int pitch = (int) data.getLocation().getPitch(); + int slots = data.getSlots(); ItemStack[] items = data.getItems(); ItemStack[] armour = data.getArmour(); List> itemsMap = new ArrayList<>(items.length); @@ -156,6 +158,7 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), + new ColumnInt("slots", slots), new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)), new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)), new ColumnInt("accountId", accountId) @@ -175,6 +178,7 @@ public class PersistenceRepository extends RepositoryBase new ColumnInt("yaw", yaw), new ColumnInt("pitch", pitch), new ColumnVarChar("quests", 500, GSON.toJson(data.getQuestData())), + new ColumnInt("slots", slots), new ColumnVarChar("items", 10000, GSON.toJson(itemsMap)), new ColumnVarChar("armour", 1000, GSON.toJson(armourMap)) ); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index 795dcaaa3..e9010c662 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import mineplex.core.recharge.Recharge; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.HumanEntity; @@ -112,7 +113,7 @@ public class SafezoneModule extends MiniPlugin { _playerStatus.setStatus(player, PlayerStatusType.SAFE, true); } - else + else if (Recharge.Instance.usable(player, "Cash Out")) { _playerStatus.setStatus(player, PlayerStatusType.SAFE); } @@ -138,7 +139,7 @@ public class SafezoneModule extends MiniPlugin Player player = (Player) event.getEntity(); - if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT) + if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT && Recharge.Instance.usable(player, "Cash Out")) { event.setCancelled(true); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 7d1025675..3dc75cca8 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -67,7 +67,7 @@ public class SpawnModule extends MiniPlugin addCommand(new HubCommand(this)); } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOWEST) public void playerJoin(PlayerJoinEvent event) { if (_spawn == null || _center == null) @@ -76,25 +76,6 @@ public class SpawnModule extends MiniPlugin _center = new Location(_worldData.World, 0, 64, 0); } - Player player = event.getPlayer(); - - if (_npc.hasNPC(player)) - { - QuitNPC npc = _npc.getNPC(player); - - npc.despawn(true); - return; - } - - player.teleport(_spawn); -// player.setFoodLevel(20); -// player.setExhaustion(0); -// player.setLevel(0); -// player.setExp(0); -// player.getInventory().clear(); -// player.getInventory().setArmorContents(null); -// player.updateInventory(); - if (_npcsSpawned) { return; From 4a984f3c410bd4e0a64f8e282c03b80c2811e16f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 3 May 2017 22:05:10 +0100 Subject: [PATCH 13/21] More fixes! --- .../death/quitnpc/QuitNPCModule.java | 28 ++++------ .../gemhunters/economy/CashOutModule.java | 23 ++++++-- .../persistence/PersistenceModule.java | 54 +++++++++++++++++-- .../persistence/PersistenceRepository.java | 4 +- .../gemhunters/safezone/SafezoneModule.java | 10 +++- .../gemhunters/spawn/SpawnModule.java | 1 + .../tutorial/GemHuntersTutorial.java | 34 ++++++++++-- 7 files changed, 119 insertions(+), 35 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java index 9ab4eb6d0..1576c696e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/death/quitnpc/QuitNPCModule.java @@ -8,6 +8,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import mineplex.core.common.util.UtilPlayer; +import mineplex.gemhunters.economy.CashOutModule; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -29,22 +30,20 @@ public class QuitNPCModule extends MiniPlugin { private static final long LOG_OUT_TIME = TimeUnit.SECONDS.toMillis(60); - - private final TextTutorialManager _tutorial; - + + private final CashOutModule _cashOut; + private final Map _npcs; private final Map _killedBy; - private final Set _aboutToCashOut; - + private QuitNPCModule() { super("Quit NPC"); - - _tutorial = require(TextTutorialManager.class); - + + _cashOut = require(CashOutModule.class); + _npcs = new HashMap<>(); _killedBy = new HashMap<>(); - _aboutToCashOut = new HashSet<>(); } public void spawnNpc(Player player) @@ -57,10 +56,9 @@ public class QuitNPCModule extends MiniPlugin return; } - if (_aboutToCashOut.contains(player.getUniqueId())) + if (_cashOut.isAboutToCashOut(player)) { log(player.getName() + " was cashing out"); - _aboutToCashOut.remove(player.getUniqueId()); return; } @@ -78,14 +76,6 @@ public class QuitNPCModule extends MiniPlugin _npcs.put(player.getUniqueId(), new QuitNPC(this, player, LOG_OUT_TIME)); } - @EventHandler - public void cashOutComplete(PlayerCashOutCompleteEvent event) - { - UUID key = event.getPlayer().getUniqueId(); - - _aboutToCashOut.add(key); - } - @EventHandler(priority = EventPriority.LOWEST) public void playerQuit(PlayerQuitEvent event) { diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java index 08ae25420..88a603396 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -25,13 +25,11 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import java.text.DecimalFormat; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; +import java.util.*; @ReflectivelyCreateMiniPlugin public class CashOutModule extends MiniPlugin @@ -47,7 +45,8 @@ public class CashOutModule extends MiniPlugin private final DonationManager _donation; private final Map _sessions; - + private final Set _aboutToCashOut; + public CashOutModule() { super("Cash Out"); @@ -55,6 +54,7 @@ public class CashOutModule extends MiniPlugin _donation = require(DonationManager.class); _sessions = new HashMap<>(); + _aboutToCashOut = new HashSet<>(); } @Override @@ -143,6 +143,8 @@ public class CashOutModule extends MiniPlugin UtilServer.CallEvent(completeEvent); + _aboutToCashOut.add(player.getUniqueId()); + _donation.rewardCurrencyUntilSuccess(GlobalCurrency.GEM, player, "Earned", completeEvent.getGems()); session.endSession(); @@ -230,6 +232,12 @@ public class CashOutModule extends MiniPlugin } } + @EventHandler(priority = EventPriority.MONITOR) + public void playerQuit(PlayerQuitEvent event) + { + _aboutToCashOut.remove(event.getPlayer().getUniqueId()); + } + public void attemptCashOut(Player player) { UUID key = player.getUniqueId(); @@ -263,6 +271,11 @@ public class CashOutModule extends MiniPlugin return getCashOutSession(player) != null; } + public boolean isAboutToCashOut(Player player) + { + return _aboutToCashOut.contains(player.getUniqueId()); + } + public CashOutSession getCashOutSession(Player player) { for (UUID key : _sessions.keySet()) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java index 0b6b39e36..657cf4431 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceModule.java @@ -18,31 +18,52 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + @ReflectivelyCreateMiniPlugin public class PersistenceModule extends MiniPlugin { private final CoreClientManager _client; + private final CashOutModule _cashOut; private final EconomyModule _economy; private final QuestModule _quest; private final InventoryModule _inventory; private final PersistenceRepository _repository; + private final List _denyJoining; + public PersistenceModule() { super("Persistence"); _client = require(CoreClientManager.class); + _cashOut = require(CashOutModule.class); _quest = require(QuestModule.class); _economy = require(EconomyModule.class); _inventory = require(InventoryModule.class); _repository = new PersistenceRepository(); + + _denyJoining = Collections.synchronizedList(new ArrayList<>()); + } + + @EventHandler + public void preLogin(AsyncPlayerPreLoginEvent event) + { + if (_denyJoining.contains(event.getName())) + { + event.disallow(Result.KICK_OTHER, "Please wait a few seconds before connecting again."); + } } @EventHandler(priority = EventPriority.LOWEST) @@ -51,6 +72,17 @@ public class PersistenceModule extends MiniPlugin Player player = event.getPlayer(); CoreClient client = _client.Get(player); + if (_cashOut.isAboutToCashOut(player)) + { + runAsync(() -> + { + _denyJoining.add(player.getName()); + _repository.deletePersistence(client); + _denyJoining.remove(player.getName()); + }); + return; + } + int gems = _economy.Get(player); Location location = player.getLocation(); QuestPlayerData quest = _quest.Get(player); @@ -63,7 +95,12 @@ public class PersistenceModule extends MiniPlugin PersistenceData data = new PersistenceData(gems, location, quest, health, maxHealth, hunger, slots, items, armour); - runAsync(() -> _repository.savePersistence(client, data)); + runAsync(() -> + { + _denyJoining.add(player.getName()); + _repository.savePersistence(client, data); + _denyJoining.remove(player.getName()); + }); } @EventHandler(priority = EventPriority.LOWEST) @@ -72,7 +109,12 @@ public class PersistenceModule extends MiniPlugin Player player = event.getEntity(); CoreClient client = _client.Get(player); - runAsync(() -> _repository.deletePersistence(client)); + runAsync(() -> + { + _denyJoining.add(player.getName()); + _repository.deletePersistence(client); + _denyJoining.remove(player.getName()); + }); } @EventHandler @@ -80,7 +122,13 @@ public class PersistenceModule extends MiniPlugin { if (!event.isPluginRemove()) { - runAsync(() -> _client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence)); + runAsync(() -> + { + String name = event.getNpc().getName(); + _denyJoining.add(name); + _client.getOrLoadClient(event.getNpc().getName(), _repository::deletePersistence); + _denyJoining.remove(name); + }); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java index 7b9b03979..ab34b4bab 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/persistence/PersistenceRepository.java @@ -29,6 +29,7 @@ public class PersistenceRepository extends RepositoryBase private static final String UPDATE_DATA = "UPDATE gemHunters SET gems=?,health=?,maxHealth=?,hunger=?,x=?,y=?,z=?,yaw=?,pitch=?,quests=?,slots=?,items=?,armour=? WHERE accountId=?;"; private static final String DELETE_DATA = "DELETE FROM gemHunters WHERE accountId=?;"; private static final Gson GSON; + private static final ItemStack AIR = new ItemStack(Material.AIR); static { @@ -129,7 +130,7 @@ public class PersistenceRepository extends RepositoryBase { if (itemStack == null || itemStack.getType() == Material.MAP || itemStack.getType() == Material.STAINED_GLASS_PANE) { - continue; + itemStack = AIR; } itemsMap.add(itemStack.serialize()); @@ -192,6 +193,7 @@ public class PersistenceRepository extends RepositoryBase int accountId = client.getAccountId(); executeUpdate(DELETE_DATA, new ColumnInt("accountId", accountId)); + _exists.remove(Integer.valueOf(accountId)); } public boolean exists(CoreClient client) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java index e9010c662..b9e1ce380 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -13,6 +13,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; @@ -129,7 +130,7 @@ public class SafezoneModule extends MiniPlugin _currentSafezone.remove(player.getUniqueId()); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void entityDamage(EntityDamageEvent event) { if (!(event.getEntity() instanceof Player)) @@ -139,10 +140,15 @@ public class SafezoneModule extends MiniPlugin Player player = (Player) event.getEntity(); - if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT && Recharge.Instance.usable(player, "Cash Out")) + if (isInSafeZone(player) && _playerStatus.Get(player).getStatusType() != PlayerStatusType.COMBAT) { event.setCancelled(true); } + + if (!Recharge.Instance.usable(player, "Cash Out")) + { + event.setCancelled(false); + } } @EventHandler diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java index 3dc75cca8..edb9c4fe2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/spawn/SpawnModule.java @@ -74,6 +74,7 @@ public class SpawnModule extends MiniPlugin { _spawn = _worldData.getCustomLocation("PLAYER_SPAWN").get(0); _center = new Location(_worldData.World, 0, 64, 0); + _worldData.World.setSpawnLocation(_spawn.getBlockX(), _spawn.getBlockY(), _spawn.getBlockZ()); } if (_npcsSpawned) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/tutorial/GemHuntersTutorial.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/tutorial/GemHuntersTutorial.java index 856cb4a90..5918c03a9 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/tutorial/GemHuntersTutorial.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/tutorial/GemHuntersTutorial.java @@ -1,5 +1,8 @@ package mineplex.gemhunters.tutorial; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -11,8 +14,10 @@ import mineplex.core.texttutorial.tutorial.Tutorial; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.spawn.SpawnModule; import mineplex.gemhunters.world.WorldDataModule; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; -public class GemHuntersTutorial extends Tutorial +public class GemHuntersTutorial extends Tutorial implements Listener { private final SpawnModule _spawn; @@ -51,7 +56,7 @@ public class GemHuntersTutorial extends Tutorial })); addPhase(new Phase(getLocation(1), "PVP", new String[] { "Players start with " + C.cGreen + EconomyModule.GEM_START_COST + C.cWhite + " Gems and must survive in the city.", - "Killing another player will gift you " + C.cYellow + "50%" + C.cWhite + "of their total gems.", + "Killing another player will gift you " + C.cYellow + "50%" + C.cWhite + " of their total gems.", })); addPhase(new Phase(getLocation(2), "Safezones", new String[] { "In Safe Zones you cannot take damage and can purchase items like", @@ -59,8 +64,8 @@ public class GemHuntersTutorial extends Tutorial })); addPhase(new Phase(getLocation(3), "Items", new String[] { "Collect items from chests and powerup.", - "You can find anything from Weaponrs to Cosmetics.", - "If you find somethiing you want to keep you can", + "You can find anything from Weapons to Cosmetics.", + "If you find something you want to keep you can", C.cGreen + "Cash Out" + C.cWhite + " at any time by right clicking the " + C.cGreen + "Emerald" + C.cWhite + " in your inventory.", })); addPhase(new Phase(getLocation(4), "Cashing Out", new String[] { @@ -71,13 +76,15 @@ public class GemHuntersTutorial extends Tutorial addPhase(new Phase(getLocation(5), "Good luck", new String[] { "Stay safe! Anarchy rules in the world of " + C.cGreen + "Gem Hunters" + C.cWhite + "!" })); + + UtilServer.RegisterEvents(this); } @Override public void startTutorial(Player player) { super.startTutorial(player); - + player.setAllowFlight(true); player.setFlying(true); } @@ -100,4 +107,21 @@ public class GemHuntersTutorial extends Tutorial return new Location(_worldData.World, locations[0] + 0.5, locations[1] + 0.5, locations[2] + 0.5, locations[3], locations[4]); } + @EventHandler + public void updateFlight(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + if (isInTutorial(player) && !player.isFlying()) + { + player.setFlying(true); + } + } + } + } From 66136a035b2e02648c5bba8dfa1a48f19e350d7e Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 18:30:36 -0700 Subject: [PATCH 14/21] Change scoreboard tag for Event Moderator This ensures that they're sorted next to Sr Mods in the tab list --- Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java index d80564eda..8d5cd7db5 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Rank.java @@ -18,7 +18,7 @@ public enum Rank JNR_DEV("Jr.Dev", "jrdev", ChatColor.GOLD, "Junior Developers work behind the scenes to \ncreate new games and features, and fix bugs to \ngive the best experience.", -1, DyeColor.ORANGE), SUPPORT("Support", "spp", ChatColor.BLUE, "Support agents handle tickets and \nprovide customer service.", 47, DyeColor.BLUE), CMOD("C.Mod", "cmod", ChatColor.GOLD, "Clans Moderators are members of the Clans Management Senior Mod team. \nTheir duties include moderation and support within the Clans servers. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 32, DyeColor.ORANGE), - EVENT_MODERATOR("Sr.Mod", "eventmod", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 44, DyeColor.ORANGE), + EVENT_MODERATOR("Sr.Mod", "srmod_event", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 44, DyeColor.ORANGE), SNR_MODERATOR("Sr.Mod", "srmod", ChatColor.GOLD, "Senior Moderators are members of a special \nSenior Moderator team where they have to fulfill specific tasks. \nJust like Moderators, you can always ask them for help. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 44, DyeColor.ORANGE), MODERATOR("Mod", "mod", ChatColor.GOLD, "Moderators enforce rules and provide help to \nanyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 32, DyeColor.ORANGE), HELPER("Trainee", "train", ChatColor.GOLD, "Trainees are moderators-in-training. \nTheir duties include enforcing the rules and \nproviding help to anyone with questions or concerns. \n\nFor assistance, contact them using " + F.elem("/a ") + ".", 24, DyeColor.ORANGE), From 404733cd34551f8482ee1791c884070a1771052b Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 18:42:31 -0700 Subject: [PATCH 15/21] Disable Speed UHC --- .../hub/server/ui/ServerGameMenu.java | 2 +- .../hub/server/ui/UHCServerTypePage.java | 24 ++++--------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java index 0253eaa66..5bfebcbdd 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerGameMenu.java @@ -120,7 +120,7 @@ public class ServerGameMenu extends ShopPageBase C.Reset + "Extremely hard team-based survival ", C.Reset + "Gather materials and fight your way", C.Reset + "to become the last team standing!", - }, new String[] {"UHC", "UHC2", "UHCS", "UHCS2"}, "UHC", new SelectUHCButton(this)); + }, new String[] {"UHC", "UHC2"}, "UHC", new SelectUHCButton(this)); add(17, Material.BLAZE_ROD, C.cYellowB + "Wizards " + C.cGray + "Last Man Standing", new String[] { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java index 76cc3595b..4daad3dfd 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/UHCServerTypePage.java @@ -24,38 +24,22 @@ public class UHCServerTypePage extends ShopPageBase getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Solo", player, "UHC2"))); - getButtonMap().put(12, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC", player, "UHC"))); - getButtonMap().put(14, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Speed Solo", player, "UHCS2"))); - getButtonMap().put(16, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Speed", player, "UHCS"))); + getButtonMap().put(12, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC Solo", player, "UHC2"))); + getButtonMap().put(14, (player, __) -> getShop().openPageForPlayer(player, new ServerNpcPage(getPlugin(), getShop(), getClientManager(), getDonationManager(), "UHC", player, "UHC"))); } public void Update() From 3d37fab71f626112cf3b45e4ee44196dad7916c8 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 18:44:05 -0700 Subject: [PATCH 16/21] Disable movement checks in Dragons --- .../arcade/game/games/dragons/Dragons.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragons/Dragons.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragons/Dragons.java index 46b956a9d..4edb06d91 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragons/Dragons.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragons/Dragons.java @@ -11,9 +11,15 @@ import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent; +import com.mineplex.anticheat.checks.move.Glide; +import com.mineplex.anticheat.checks.move.HeadRoll; +import com.mineplex.anticheat.checks.move.Speed; + +import mineplex.core.Managers; +import mineplex.core.antihack.AntiHack; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; @@ -22,12 +28,15 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; + import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.PlayerStateChangeEvent; -import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.GameTeam.PlayerState; -import nautilus.game.arcade.game.games.dragons.kits.*; +import nautilus.game.arcade.game.SoloGame; +import nautilus.game.arcade.game.games.dragons.kits.KitCoward; +import nautilus.game.arcade.game.games.dragons.kits.KitMarksman; +import nautilus.game.arcade.game.games.dragons.kits.KitPyrotechnic; import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.Perk; @@ -80,6 +89,12 @@ public class Dragons extends SoloGame .setGiveCompassToSpecs(true) .setGiveCompassToAlive(false) .register(this); + + // Disable specific GWEN checks for this game + AntiHack antiHack = Managers.get(AntiHack.class); + antiHack.addIgnoredCheck(Speed.class); + antiHack.addIgnoredCheck(Glide.class); + antiHack.addIgnoredCheck(HeadRoll.class); } @Override From 4da069b244ec821f536caf6be0eee252426bb475 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 14 Apr 2017 07:32:36 +0200 Subject: [PATCH 17/21] Fix Booster Kit making you fly --- .../arcade/game/games/skyfall/kits/perks/PerkElytraBoost.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/kits/perks/PerkElytraBoost.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/kits/perks/PerkElytraBoost.java index 33b30aaa4..ac0b9f1cc 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/kits/perks/PerkElytraBoost.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/kits/perks/PerkElytraBoost.java @@ -40,7 +40,7 @@ public class PerkElytraBoost extends Perk { super(name, new String[] { - C.cYellow + "Double tap jump" + C.cWhite + " to use your " + C.cGreen +"Elytra Boost" + C.cYellow + "Double tap jump" + C.cWhite + " to use your " + C.cGreen + "Elytra Boost" }); _cooldown = cooldown; @@ -63,6 +63,7 @@ public class PerkElytraBoost extends Perk if (!UtilPlayer.isGliding(player) || !Recharge.Instance.usable(player, GetName())) { player.setAllowFlight(false); + player.setFlying(false); return; } player.setAllowFlight(true); From 779256e1cac1b816095838c9a4d575e1a2837593 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 18:45:39 -0700 Subject: [PATCH 18/21] Enable the Skyfall booster kit --- .../src/nautilus/game/arcade/game/games/skyfall/Skyfall.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java index 1043881ad..7fb612534 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Skyfall.java @@ -78,6 +78,7 @@ import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.games.skyfall.kits.KitAeronaught; +import nautilus.game.arcade.game.games.skyfall.kits.KitBooster; import nautilus.game.arcade.game.games.skyfall.kits.KitDeadeye; import nautilus.game.arcade.game.games.skyfall.kits.KitJouster; import nautilus.game.arcade.game.games.skyfall.kits.KitSpeeder; @@ -169,7 +170,7 @@ public abstract class Skyfall extends Game new Kit[] { new KitSpeeder(manager), - //new KitBooster(manager), // Broken? :( + new KitBooster(manager), new KitJouster(manager), new KitStunner(manager), //new KitSurefoot(manager), From 6fdf926d5149614f39be6146322373a36ca1e3e3 Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 21:47:08 -0700 Subject: [PATCH 19/21] Add temporary(!!) gem hunters server sender In the near future, with more time, we'll abstract out the MOTD parsing hackiness from ServerInfo and add the same mechanism to Gem Hunters, so it gets a ServerNpcPage for free. --- .../src/mineplex/hub/HubManager.java | 3 + .../TemporaryGemHuntersServerSender.java | 92 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 79cbfdd70..51d2ca779 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -130,6 +130,7 @@ import mineplex.hub.modules.MavericksManager; import mineplex.hub.modules.NewsManager; import mineplex.hub.modules.ParkourManager; import mineplex.hub.modules.SoccerManager; +import mineplex.hub.modules.TemporaryGemHuntersServerSender; import mineplex.hub.modules.ValentinesManager; import mineplex.hub.modules.WorldManager; import mineplex.hub.modules.salesannouncements.SalesAnnouncementManager; @@ -291,6 +292,8 @@ public class HubManager extends MiniClientPlugin implements IChatMess new EasterEggHunt(plugin, _clientManager); + new TemporaryGemHuntersServerSender(_portal); + ScoreboardManager scoreboardManager = new ScoreboardManager(plugin) { @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java new file mode 100644 index 000000000..93c3989bb --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java @@ -0,0 +1,92 @@ +package mineplex.hub.modules; + +import java.util.Comparator; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.UtilTime; +import mineplex.core.npc.event.NpcInteractEntityEvent; +import mineplex.core.portal.Intent; +import mineplex.core.portal.Portal; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.hub.server.ServerInfo; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.MinecraftServer; +import mineplex.serverdata.servers.ServerManager; + +// A hacky mess. Did not have time before release to solve this properly. soon. +// Essentially a copy/paste from the clans hub server load/send mechanism +public class TemporaryGemHuntersServerSender extends MiniPlugin +{ + private static final int SERVER_RELOAD_INTERVAL = 5000; + private final Portal _portal; + private final Map _servers = new ConcurrentHashMap<>(); + private long _lastLoaded = 0; + private boolean _loading; + + public TemporaryGemHuntersServerSender(Portal portal) + { + super("Gem Hunters Server Sender"); + _portal = portal; + } + + @EventHandler + public void reloadServers(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC || _loading || !UtilTime.elapsed(_lastLoaded, SERVER_RELOAD_INTERVAL)) + { + return; + } + _loading = true; + runAsync(() -> + { + reload(); + runSync(() -> + { + _lastLoaded = System.currentTimeMillis(); + _loading = false; + }); + }); + } + public void reload() + { + _servers.clear(); + for (MinecraftServer server : ServerManager.getServerRepository(Region.US).getServerStatusesByPrefix("GH-")) + { + ServerInfo info = new ServerInfo(); + info.Name = server.getName(); + info.MOTD = server.getMotd(); + info.CurrentPlayers = server.getPlayerCount(); + info.MaxPlayers = server.getMaxPlayerCount(); + _servers.put(server, info); + } + } + + @EventHandler + public void onUseNPC(NpcInteractEntityEvent event) + { + if (event.getNpc().getName().contains("Gem Hunters")) + { + java.util.Optional info = _servers.entrySet().stream() + // Ignore the type noise here; it's temporary + .sorted(Comparator.>comparingInt(entry -> entry.getKey().getPlayerCount()).>reversed()) + .filter(entry -> entry.getKey().getPlayerCount() < entry.getKey().getMaxPlayerCount() - 5) + .map(Map.Entry::getValue) + .findFirst(); + + if (info.isPresent()) + { + _portal.sendPlayerToServer(event.getPlayer(), info.get().Name, Intent.PLAYER_REQUEST); + } + else + { + event.getPlayer().sendMessage(ChatColor.RED + "All servers are full; please try again in a moment!"); + } + } + } +} From 840b50d56a438cd6a22136b6e0a9cd9789c8532c Mon Sep 17 00:00:00 2001 From: cnr Date: Wed, 3 May 2017 21:59:55 -0700 Subject: [PATCH 20/21] Disable beta whitelist for open beta --- .../src/mineplex/gemhunters/GemHunters.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index f89b5f947..28fe07631 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -15,7 +15,6 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; import mineplex.core.aprilfools.AprilFoolsManager; -import mineplex.core.beta.BetaWhitelist; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.boosters.BoosterManager; import mineplex.core.chat.Chat; @@ -54,7 +53,6 @@ import mineplex.core.party.PartyManager; import mineplex.core.pet.PetManager; import mineplex.core.portal.GenericServer; import mineplex.core.portal.Portal; -import mineplex.core.powerplayclub.PowerPlayClubRepository; import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; @@ -316,9 +314,6 @@ public class GemHunters extends JavaPlugin // Two-factor auth require(TwoFactorAuth.class); - - // beta whitelist - new BetaWhitelist(clientManager, new PowerPlayClubRepository(this, clientManager, donationManager)); } @Override From 53eb49923670c4a2d9d17019e865209457ac4df6 Mon Sep 17 00:00:00 2001 From: cnr Date: Thu, 4 May 2017 01:48:05 -0700 Subject: [PATCH 21/21] Use correct region when searching for Gem Hunters --- .../mineplex/hub/modules/TemporaryGemHuntersServerSender.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java index 93c3989bb..a1e3e9d36 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/TemporaryGemHuntersServerSender.java @@ -56,7 +56,9 @@ public class TemporaryGemHuntersServerSender extends MiniPlugin public void reload() { _servers.clear(); - for (MinecraftServer server : ServerManager.getServerRepository(Region.US).getServerStatusesByPrefix("GH-")) + + Region region = getPlugin().getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; + for (MinecraftServer server : ServerManager.getServerRepository(region).getServerStatusesByPrefix("GH-")) { ServerInfo info = new ServerInfo(); info.Name = server.getName();