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); + } + } + } + }