From 16773521b94000e8498f1adcfccdae0263c61193 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 11 Feb 2017 17:18:39 +0000 Subject: [PATCH] Lots of fixes --- .../core/google/GoogleSheetsManager.java | 2 +- .../src/mineplex/gemhunters/GemHunters.java | 2 + .../gemhunters/economy/CashOutModule.java | 2 +- .../gemhunters/economy/EconomyModule.java | 16 +- .../gemhunters/loot/ChestProperties.java | 21 +- .../gemhunters/loot/InventoryModule.java | 32 +-- .../mineplex/gemhunters/loot/LootModule.java | 203 ++++++++++-------- .../loot/command/SpawnChestCommand.java | 47 ++++ .../ChestPropertiesDeserialiser.java | 11 +- .../deserialisers/LootItemDeserialiser.java | 26 ++- .../loot/rewards/LootItemReward.java | 5 +- .../gemhunters/safezone/SafezoneModule.java | 31 ++- .../mineplex/gemhunters/shop/ShopModule.java | 6 +- .../mineplex/gemhunters/shop/TraderNPC.java | 1 - .../supplydrop/SupplyDropModule.java | 16 +- .../{commands => command}/EndCommand.java | 2 +- .../{commands => command}/StartCommand.java | 11 +- .../SupplyDropCommand.java | 2 +- .../mineplex/gemhunters/util/UtilDebug.java | 27 --- .../mineplex/gemhunters/world/TimeCycle.java | 1 - .../gemhunters/world/WorldDataModule.java | 60 +----- .../gemhunters/world/WorldListeners.java | 74 ++++++- 22 files changed, 365 insertions(+), 233 deletions(-) create mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/EndCommand.java (93%) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/StartCommand.java (91%) rename Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/{commands => command}/SupplyDropCommand.java (94%) delete mode 100644 Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java index 634ea5e65..12be686f9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/google/GoogleSheetsManager.java @@ -23,7 +23,7 @@ public class GoogleSheetsManager extends MiniPlugin private static final File DATA_STORE_DIR = new File(".." + File.separatorChar + ".." + File.separatorChar + "update" + File.separatorChar + "files"); - public GoogleSheetsManager() + private GoogleSheetsManager() { super("Google Sheets"); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index 6ac87f015..ee852603a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -52,6 +52,7 @@ import mineplex.core.visibility.VisibilityManager; import mineplex.gemhunters.bounties.BountyModule; import mineplex.gemhunters.chat.ChatModule; import mineplex.gemhunters.death.DeathModule; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.CashOutModule; import mineplex.gemhunters.economy.EconomyModule; import mineplex.gemhunters.loot.InventoryModule; @@ -210,6 +211,7 @@ public class GemHunters extends JavaPlugin new HologramManager(this, packetHandler); // Now we finally get to enable the Gem Hunters modules + require(DebugModule.class); require(BountyModule.class); require(CashOutModule.class); require(ChatModule.class); 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 9d606393b..b9295969e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/CashOutModule.java @@ -60,7 +60,7 @@ public class CashOutModule extends MiniPlugin @EventHandler public void playerInteract(PlayerInteractEvent event) - { + { if (!UtilEvent.isAction(event, ActionType.R)) { return; 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 075655a3d..893293ab0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/economy/EconomyModule.java @@ -44,17 +44,17 @@ public class EconomyModule extends MiniPlugin Player player = event.getEntity(); Entity killer = event.getEntity().getKiller(); - if (!(killer instanceof Player)) + int oldGems = getGems(player); + + if (killer instanceof Player) { + Player killerPlayer = (Player) killer; + int newGems = (int) (oldGems * GEM_KILL_FACTOR); + + addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); return; } - - Player killerPlayer = (Player) killer; - - int oldGems = _storedGems.get(player.getUniqueId()); - int newGems = (int) (oldGems * GEM_KILL_FACTOR); - - addToStore(killerPlayer, "Killing " + F.name(player.getName()), newGems); + removeFromStore(player, oldGems); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java index 06d50b758..fe2ff3aa2 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/ChestProperties.java @@ -1,5 +1,8 @@ package mineplex.gemhunters.loot; +import java.util.HashMap; +import java.util.Map; + import org.bukkit.Material; public class ChestProperties @@ -10,25 +13,29 @@ public class ChestProperties private final String _dataKey; private final int _minAmount; private final int _maxAmount; + private final int _maxChestPerLoc; private final int _spawnRate; private final int _expireRate; private final int _spawnRadius; private final int _maxActive; + private final Map _spawnedIndexes; private long _lastSpawn; - public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int spawnRate, int expireRate, int spawnRadius, int maxActive) + public ChestProperties(String name, Material blockMaterial, String dataKey, int minAmount, int maxAmount, int maxChestPerLoc, int spawnRate, int expireRate, int spawnRadius, int maxActive) { _name = name; _blockMaterial = blockMaterial; _dataKey = dataKey; _minAmount = minAmount; _maxAmount = maxAmount; + _maxChestPerLoc = maxChestPerLoc; _spawnRate = spawnRate; _expireRate = expireRate; _spawnRadius = spawnRadius; _maxActive = maxActive; + _spawnedIndexes = new HashMap<>(); setLastSpawn(); } @@ -57,6 +64,11 @@ public class ChestProperties return _maxAmount; } + public final int getMaxChestPerLocation() + { + return _maxChestPerLoc; + } + public final int getSpawnRate() { return _spawnRate; @@ -76,7 +88,12 @@ public class ChestProperties { return _maxActive; } - + + public final Map getSpawnIndexes() + { + return _spawnedIndexes; + } + public void setLastSpawn() { _lastSpawn = System.currentTimeMillis(); 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 e1a026e61..95a0ee616 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/InventoryModule.java @@ -9,7 +9,6 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.Inventory; @@ -24,6 +23,7 @@ import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import mineplex.core.itemstack.ItemBuilder; import mineplex.gemhunters.death.events.PlayerCustomRespawnEvent; +import mineplex.gemhunters.debug.DebugModule; @ReflectivelyCreateMiniPlugin public class InventoryModule extends MiniPlugin @@ -31,6 +31,9 @@ public class InventoryModule extends MiniPlugin private static final int START_INDEX = 9; private static final ItemStack LOCKED = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 15).setTitle(C.cGray + "Locked").build(); + private static final String ITEM_METADATA = "UNLOCKER"; + + private final LootModule _loot; private final Map _rowsUnlocked; @@ -38,6 +41,8 @@ public class InventoryModule extends MiniPlugin { super("Unlocker"); + _loot = require(LootModule.class); + _rowsUnlocked = new HashMap<>(); } @@ -92,15 +97,22 @@ public class InventoryModule extends MiniPlugin } Player player = event.getPlayer(); - ItemStack itemStack = event.getItem(); + ItemStack itemStack = player.getItemInHand(); if (itemStack == null) { return; } + LootItem lootItem = _loot.fromItemStack(itemStack); + + if (lootItem == null || lootItem.getMetadata().equals(ITEM_METADATA)) + { + return; + } + Material material = itemStack.getType(); - + if (material == Material.CHEST || material == Material.ENDER_CHEST) { UtilInv.remove(player, material, (byte) 0, 1); @@ -118,6 +130,10 @@ public class InventoryModule extends MiniPlugin int end = Math.min(inv.getSize(), start + rows * 9); int delta = end - start; + DebugModule.getInstance().d("start=" + start); + DebugModule.getInstance().d("end=" + end); + DebugModule.getInstance().d("delta=" + delta); + for (int i = start; i < end; i++) { inv.setItem(i, null); @@ -125,14 +141,4 @@ public class InventoryModule extends MiniPlugin player.sendMessage(F.main(_moduleName, "You unlocked an additional " + F.count(String.valueOf(delta)) + " slots of your inventory!")); } - - @EventHandler - public void test(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/ur")) - { - event.setCancelled(true); - unlockRows(event.getPlayer(), Integer.parseInt(event.getMessage().split(" ")[1])); - } - } } 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 8e3b1c07f..9a1f6ef06 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/LootModule.java @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Material; @@ -36,7 +35,9 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.google.GoogleSheetsManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.economy.PlayerCashOutCompleteEvent; +import mineplex.gemhunters.loot.command.SpawnChestCommand; import mineplex.gemhunters.loot.command.UpdateLootCommand; import mineplex.gemhunters.loot.deserialisers.ChestPropertiesDeserialiser; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; @@ -44,7 +45,6 @@ import mineplex.gemhunters.loot.rewards.LootItemReward; import mineplex.gemhunters.loot.rewards.LootRankReward; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.util.SlackSheetsBot; -import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -54,6 +54,7 @@ public class LootModule extends MiniPlugin private static final String SHEET_FILE_NAME = "GEM_HUNTERS_CHESTS"; private static final String CHEST_MASTER_SHEET_NAME = "CHEST_MASTER"; private static final long CHEST_DESPAWN_TIME_OPENED = TimeUnit.SECONDS.toMillis(15); + private static final float CHESTS_ON_START_FACTOR = 0.333F; private static final int MAX_SEARCH_ATTEMPTS = 40; private static final int MAX_CHEST_CHECK_DISTANCE_SQUARED = 4; private static final LootItemDeserialiser DESERIALISER = new LootItemDeserialiser(); @@ -66,7 +67,6 @@ public class LootModule extends MiniPlugin private final Map> _chestLoot; private final Map _chestProperties; private final Set _spawnedChest; - private final Map> _spawnedIndexes; private final Set _itemRewards; private LootModule() @@ -79,16 +79,31 @@ public class LootModule extends MiniPlugin _chestLoot = new HashMap<>(); _chestProperties = new HashMap<>(); _spawnedChest = new HashSet<>(200); - _spawnedIndexes = new HashMap<>(15); _itemRewards = new HashSet<>(); - runSyncLater(() -> updateChestLoot(), 20); + runSyncLater(() -> { + + updateChestLoot(); + + // Spawn some chests + for (String key : _chestProperties.keySet()) + { + int max = _chestProperties.get(key).getMaxActive(); + + for (int i = 0; i < max * CHESTS_ON_START_FACTOR; i++) + { + addSpawnedChest(key, true); + } + } + + }, 20); } @Override public void addCommands() { addCommand(new UpdateLootCommand(this)); + addCommand(new SpawnChestCommand(this)); } @EventHandler @@ -111,7 +126,7 @@ public class LootModule extends MiniPlugin { if (chest.getID() != -1) { - _spawnedIndexes.get(properties.getDataKey()).remove(chest.getID()); + properties.getSpawnIndexes().put(chest.getID(), properties.getSpawnIndexes().get(chest.getID()) - 1); } Block block = chest.getLocation().getBlock(); @@ -130,87 +145,7 @@ public class LootModule extends MiniPlugin // Spawn new chests for (String key : _chestProperties.keySet()) { - List locations = _worldData.getDataLocation(key); - ChestProperties properties = _chestProperties.get(key); - - if (!UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) - { - continue; - } - - properties.setLastSpawn(); - - // Only spawn more chests if we need to - int max = properties.getMaxActive(); - int spawned = 0; - - for (SpawnedChest chest : _spawnedChest) - { - if (chest.getProperties().getDataKey().equals(key)) - { - spawned++; - } - } - - // If there are too many chests of this type we can ignore it - if (spawned > max) - { - continue; - } - - Set usedIndexes = _spawnedIndexes.get(key); - - if (usedIndexes == null) - { - _spawnedIndexes.put(key, new HashSet<>()); - usedIndexes = _spawnedIndexes.get(key); - } - - if (locations.size() == usedIndexes.size()) - { - continue; - } - - Location randomLocation = null; - int attempts = 0; - int index = -1; - - while (index == -1 || usedIndexes.contains(index) && attempts < MAX_SEARCH_ATTEMPTS) - { - index = UtilMath.r(locations.size()); - - attempts++; - } - - if (index == -1) - { - continue; - } - - usedIndexes.add(index); - randomLocation = locations.get(index); - - int placeRadius = properties.getSpawnRadius(); - Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); - Block block = chestToPlace.getBlock(); - - attempts = 0; - boolean suitable = false; - - while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) - { - suitable = isSuitable(block); - attempts++; - } - - if (!suitable) - { - continue; - } - - UtilDebug.d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); - _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); - block.setType(properties.getBlockMaterial()); + addSpawnedChest(key, false); } } @@ -219,7 +154,7 @@ public class LootModule extends MiniPlugin Block up = block.getRelative(BlockFace.UP); Block down = block.getRelative(BlockFace.DOWN); - if (block.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) + if (block.getType() != Material.AIR || up.getType() != Material.AIR || down.getType() == Material.AIR || UtilBlock.liquid(down) || UtilBlock.liquid(up) || UtilBlock.liquid(block) || _safezone.isInSafeZone(block.getLocation())) { return false; } @@ -287,6 +222,91 @@ public class LootModule extends MiniPlugin log("Finished updating chest loot"); } + public void addSpawnedChest(String key, boolean force) + { + List locations = _worldData.getDataLocation(key); + ChestProperties properties = _chestProperties.get(key); + + if (!force && !UtilTime.elapsed(properties.getLastSpawn(), properties.getSpawnRate())) + { + return; + } + + properties.setLastSpawn(); + + // Only spawn more chests if we need to + int max = properties.getMaxActive(); + int spawned = 0; + + for (SpawnedChest chest : _spawnedChest) + { + if (chest.getProperties().getDataKey().equals(key)) + { + spawned++; + } + } + + // If there are too many chests of this type we can ignore it + if (spawned > max) + { + return; + } + + Map spawnedIndexes = properties.getSpawnIndexes(); + + if (locations.size() == spawnedIndexes.size()) + { + return; + } + + Location randomLocation = null; + boolean found = false; + int attempts = 0; + int index = -1; + + while (index == -1 || !found && attempts < MAX_SEARCH_ATTEMPTS) + { + index = UtilMath.r(locations.size()); + + if (spawnedIndexes.getOrDefault(index, 0) >= properties.getMaxChestPerLocation()) + { + continue; + } + + attempts++; + } + + if (index == -1) + { + return; + } + + spawnedIndexes.put(index, spawnedIndexes.getOrDefault(index, 0) + 1); + randomLocation = locations.get(index); + + int placeRadius = properties.getSpawnRadius(); + Location chestToPlace = UtilAlg.getRandomLocation(randomLocation, placeRadius, 0, placeRadius); + Block block = chestToPlace.getBlock(); + + attempts = 0; + boolean suitable = false; + + while (!suitable && attempts < MAX_SEARCH_ATTEMPTS) + { + suitable = isSuitable(block); + attempts++; + } + + if (!suitable) + { + return; + } + + DebugModule.getInstance().d("Spawned at " + UtilWorld.blockToStrClean(block) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + _spawnedChest.add(new SpawnedChest(chestToPlace, properties, index)); + block.setType(properties.getBlockMaterial()); + } + public void addSpawnedChest(Location location, String colour) { _spawnedChest.add(new SpawnedChest(location, _chestProperties.get(colour), -1)); @@ -299,7 +319,7 @@ public class LootModule extends MiniPlugin ChestProperties properties = _chestProperties.get(key); Inventory inventory = null; - + if (block.getType() == Material.ENDER_CHEST) { inventory = player.getEnderChest(); @@ -367,6 +387,11 @@ public class LootModule extends MiniPlugin public LootItem fromItemStack(ItemStack itemStack) { + if (itemStack == null) + { + return null; + } + for (Set items : _chestLoot.values()) { for (LootItem item : items) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java new file mode 100644 index 000000000..9e0040952 --- /dev/null +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/command/SpawnChestCommand.java @@ -0,0 +1,47 @@ +package mineplex.gemhunters.loot.command; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.gemhunters.loot.LootModule; + +public class SpawnChestCommand extends CommandBase +{ + + public SpawnChestCommand(LootModule plugin) + { + super(plugin, Rank.ADMIN, "spawnchest"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + caller.sendMessage(F.help("/" + _aliasUsed + " ", "Spawns a chest at your location.", GetRequiredRank())); + return; + } + + String colour = args[0].toUpperCase(); + + try + { + DyeColor.valueOf(colour); + } + catch (IllegalArgumentException e) + { + caller.sendMessage(F.main(Plugin.getName(), "That is not a valid colour.")); + return; + } + + caller.sendMessage(F.main(Plugin.getName(), "Spawned a " + colour + " chest at your location.")); + + caller.getLocation().getBlock().setType(Material.CHEST); + Plugin.addSpawnedChest(caller.getLocation(), colour); + } + +} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java index 7d5a63e9c..15898b8fb 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/deserialisers/ChestPropertiesDeserialiser.java @@ -14,7 +14,7 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser int maxAmount = 1; short durability = values[2].equals("") ? 0 : Short.valueOf(values[3]); - String[] numbers = values[3].split("-"); if (numbers.length != 2) @@ -61,17 +60,22 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser builder.setDurability(durability); String title = ChatColor.translateAlternateColorCodes('&', values[4]); - String[] lore = values[5].split(":"); - String[] colouredLore = new String[lore.length]; - - int loreIndex = 0; - for (String line : lore) - { - colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); - } builder.setTitle(title); - builder.setLore(colouredLore); + + if (!values[5].equals("")) + { + String[] lore = values[5].split(":"); + String[] colouredLore = new String[lore.length]; + + int loreIndex = 0; + for (String line : lore) + { + colouredLore[loreIndex++] = ChatColor.translateAlternateColorCodes('&', line); + } + + builder.setLore(colouredLore); + } String[] enchants = String.valueOf(values[6]).split(","); @@ -89,7 +93,7 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser double proability = Double.parseDouble(values[7]); String metadata = values.length > 8 ? values[8] : null; - + return new LootItem(builder.build(), minAmount, maxAmount, proability, metadata); } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java index b9777ef77..8a00d0540 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/loot/rewards/LootItemReward.java @@ -1,6 +1,5 @@ package mineplex.gemhunters.loot.rewards; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.inventory.ItemStack; @@ -11,7 +10,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.recharge.Recharge; -import mineplex.gemhunters.util.UtilDebug; +import mineplex.gemhunters.debug.DebugModule; public abstract class LootItemReward { @@ -70,7 +69,7 @@ public abstract class LootItemReward public final void success() { - UtilDebug.d("Success"); + DebugModule.getInstance().d("Success"); onSuccessful(); } 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 ddd19b1d4..194e55e3a 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/safezone/SafezoneModule.java @@ -6,10 +6,13 @@ import java.util.Map; import java.util.UUID; import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.PlayerQuitEvent; import mineplex.core.MiniPlugin; @@ -89,7 +92,7 @@ public class SafezoneModule extends MiniPlugin @EventHandler public void entityDamage(EntityDamageEvent event) - { + { if (!(event.getEntity() instanceof Player)) { return; @@ -106,6 +109,23 @@ public class SafezoneModule extends MiniPlugin @EventHandler public void entityAttack(EntityDamageByEntityEvent event) { + // Handle people shooting arrows at people outside a safezone + if (event.getDamager() instanceof Projectile) + { + Projectile projectile = (Projectile) event.getDamager(); + + if (projectile.getShooter() instanceof LivingEntity) + { + LivingEntity entity = (LivingEntity) projectile.getShooter(); + + if (isInSafeZone(entity.getLocation())) + { + event.setCancelled(true); + return; + } + } + } + if (!(event.getDamager() instanceof Player)) { return; @@ -119,6 +139,15 @@ public class SafezoneModule extends MiniPlugin } } + @EventHandler + public void hungerChange(FoodLevelChangeEvent event) + { + if (isInSafeZone(event.getEntity().getLocation())) + { + event.setCancelled(true); + } + } + public boolean isInSafeZone(Location location) { return getSafezone(location) != null; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java index 3ca326bce..5bdba8cf0 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/ShopModule.java @@ -22,11 +22,11 @@ import mineplex.core.google.GoogleSheetsManager; import mineplex.core.google.SheetObjectDeserialiser; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.gemhunters.debug.DebugModule; import mineplex.gemhunters.loot.deserialisers.LootItemDeserialiser; import mineplex.gemhunters.safezone.SafezoneModule; import mineplex.gemhunters.shop.deserialisers.VillagerPropertiesDeserialiser; import mineplex.gemhunters.util.SlackSheetsBot; -import mineplex.gemhunters.util.UtilDebug; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -216,9 +216,11 @@ public class ShopModule extends MiniPlugin Location randomLocation = locations.get(index); + randomLocation.setYaw(UtilMath.r(360)); + usedIndexes.add(index); - UtilDebug.d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); + DebugModule.getInstance().d("Trader at " + UtilWorld.locToStrClean(randomLocation) + " with key=" + key + " and index=" + index + " and max=" + spawned + "/" + max); _npcs.add(new TraderNPC(_plugin, randomLocation, Villager.class, NAMES[UtilMath.r(NAMES.length)], _safezone.isInSafeZone(randomLocation), properties, getRandomItemSet(_trades.get(key)))); } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java index 707ce5057..59af93f25 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/shop/TraderNPC.java @@ -16,7 +16,6 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.Managers; import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilItem; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import mineplex.gemhunters.economy.EconomyModule; 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 0ce71a3f5..54607303e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/SupplyDropModule.java @@ -29,7 +29,7 @@ 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.commands.SupplyDropCommand; +import mineplex.gemhunters.supplydrop.command.SupplyDropCommand; import mineplex.gemhunters.world.WorldDataModule; @ReflectivelyCreateMiniPlugin @@ -183,11 +183,19 @@ public class SupplyDropModule extends MiniPlugin { if (key.startsWith(LOCATION_DATA)) { - String splitKey = key.split(" ")[1]; + String[] split = key.split(" "); + String nameKey = ""; - if (!supplyDropKeys.contains(splitKey)) + for (int i = 1; i < split.length - 1; i++) { - supplyDropKeys.add(splitKey); + nameKey += split[i] + " "; + } + + nameKey = nameKey.trim(); + + if (!supplyDropKeys.contains(nameKey)) + { + supplyDropKeys.add(nameKey); } } } diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java similarity index 93% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java index 41de1ab1b..3265371b6 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/EndCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/EndCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java similarity index 91% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java index 233cefa0e..7887b5237 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/StartCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/StartCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; @@ -48,8 +48,15 @@ public class StartCommand extends CommandBase } else { - String input = args[0]; + String input = ""; + + for (int i = 0; i < args.length; i++) + { + input += args[i]; + } + input = input.trim(); + for (String key : Plugin.getLocationKeys()) { if (input.equalsIgnoreCase(key)) diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java similarity index 94% rename from Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java rename to Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java index 65e1c8218..3e0db5ba7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/commands/SupplyDropCommand.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/supplydrop/command/SupplyDropCommand.java @@ -1,4 +1,4 @@ -package mineplex.gemhunters.supplydrop.commands; +package mineplex.gemhunters.supplydrop.command; import org.bukkit.entity.Player; diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java deleted file mode 100644 index 2c95a9b84..000000000 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/util/UtilDebug.java +++ /dev/null @@ -1,27 +0,0 @@ -package mineplex.gemhunters.util; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; - -public class UtilDebug -{ - - public static final void d(String message) - { - for (Player player : Bukkit.getOnlinePlayers()) - { - if (player.getItemInHand() == null || player.getItemInHand().getType() != Material.SPONGE) - { - continue; - } - - if (player.getName().equals("Moppletop")) - { - player.sendMessage(message); - return; - } - } - } - -} diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java index b088867ae..fbac6850e 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/TimeCycle.java @@ -8,7 +8,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; 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 7f9b23ff2..9aafe307d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldDataModule.java @@ -10,26 +10,19 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.WorldCreator; import mineplex.core.MiniPlugin; import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.timing.TimingManager; -import mineplex.core.common.util.WorldUtil; -import mineplex.core.common.util.ZipUtil; -import mineplex.core.common.util.worldgen.WorldGenCleanRoom; @ReflectivelyCreateMiniPlugin public class WorldDataModule extends MiniPlugin { - private static final String MAP_PATH = "../../update/maps/Gem-Hunters/Test.zip"; - - private String folder = null; - public World World; public int MinX = 0; public int MinZ = 0; @@ -53,55 +46,20 @@ public class WorldDataModule extends MiniPlugin public void initialize() { final WorldDataModule worldData = this; - - runAsync(() -> { - - // Unzip - worldData.unzipWorld(); - // Load world data - runSync(() -> { - TimingManager.start("WorldData loading world."); + World = Bukkit.getWorlds().get(0); - WorldCreator creator = new WorldCreator(getFolder()); - creator.generator(new WorldGenCleanRoom()); - World = WorldUtil.LoadWorld(creator); + World.setDifficulty(Difficulty.EASY); + World.setGameRuleValue("showDeathMessages", "false"); - TimingManager.stop("WorldData loading world."); - - World.setDifficulty(Difficulty.EASY); - World.setGameRuleValue("showDeathMessages", "false"); - - TimingManager.start("WorldData loading WorldConfig."); - // Load World Data - worldData.loadWorldConfig(); - TimingManager.stop("WorldData loading WorldConfig."); - }); - }); + TimingManager.start("WorldData loading WorldConfig."); + worldData.loadWorldConfig(); + TimingManager.stop("WorldData loading WorldConfig."); } public String getFolder() { - if (folder == null) - { - folder = "world"; - } - - return folder; - } - - protected void unzipWorld() - { - TimingManager.start("UnzipWorld creating folders"); - String folder = getFolder(); - new File(folder).mkdir(); - new File(folder + File.separator + "region").mkdir(); - new File(folder + File.separator + "data").mkdir(); - TimingManager.stop("UnzipWorld creating folders"); - - TimingManager.start("UnzipWorld UnzipToDirectory"); - ZipUtil.UnzipToDirectory(MAP_PATH, folder); - TimingManager.stop("UnzipWorld UnzipToDirectory"); + return "world"; } public void loadWorldConfig() @@ -302,7 +260,7 @@ public class WorldDataModule extends MiniPlugin return SPAWN_LOCATIONS.get(colour); } - + public List getDataLocation(String colour) { if (!DATA_LOCATIONS.containsKey(colour)) 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 4fc9d54c3..ecf179f6d 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/WorldListeners.java @@ -1,11 +1,16 @@ package mineplex.gemhunters.world; -import org.bukkit.Bukkit; +import java.io.File; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -16,37 +21,56 @@ import org.bukkit.event.block.BlockFadeEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.inventory.BeaconInventory; import org.bukkit.inventory.BrewerInventory; import org.bukkit.plugin.java.JavaPlugin; -import org.spigotmc.SpigotConfig; + +import mineplex.core.common.util.UtilWorld; +import mineplex.core.recharge.Recharge; +import mineplex.gemhunters.debug.DebugModule; public class WorldListeners implements Listener { private static final int VIEW_DISTANCE = 10; - + private static final long HUNGER_RECHARGE = TimeUnit.SECONDS.toMillis(15); + + private final JavaPlugin _plugin; + public WorldListeners(JavaPlugin plugin) { + _plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); - plugin.getServer().getScheduler().runTaskLater(plugin, () -> { for (World world : plugin.getServer().getWorlds()) { - SpigotConfig.config.set("world-settings.world.view-distance", VIEW_DISTANCE); ((CraftWorld) world).getHandle().spigotConfig.viewDistance = VIEW_DISTANCE; - Bukkit.broadcastMessage(((CraftWorld) world).getHandle().spigotConfig.viewDistance + " chunks"); } }, 20); } + @EventHandler + public void deletePlayerData(PlayerQuitEvent event) + { + _plugin.getServer().getScheduler().runTaskLater(_plugin, () -> { + World world = event.getPlayer().getWorld(); + UUID uuid = event.getPlayer().getUniqueId(); + new File(world.getWorldFolder().getPath() + File.separator + "playerdata" + File.separator + uuid + ".dat").delete(); + new File(world.getWorldFolder().getPath() + File.separator + "stats" + File.separator + uuid + ".json").delete(); + }, 20); + } + @EventHandler(priority = EventPriority.LOWEST) public void blockBreak(BlockBreakEvent event) { @@ -98,10 +122,19 @@ public class WorldListeners implements Listener event.setCancelled(true); } + @EventHandler + public void itemFrames(PlayerInteractEntityEvent event) + { + if (shouldBlock(event.getPlayer()) && event.getRightClicked() instanceof ItemFrame) + { + event.setCancelled(true); + } + } + @EventHandler public void inventoryOpen(InventoryOpenEvent event) { - if (event.getInventory() instanceof BrewerInventory) + if (event.getInventory() instanceof BrewerInventory || event.getInventory() instanceof BeaconInventory) { event.setCancelled(true); } @@ -110,6 +143,11 @@ public class WorldListeners implements Listener @EventHandler public void chunkUnload(ChunkUnloadEvent event) { + if (!UtilWorld.inWorldBorder(new Location(event.getWorld(), event.getChunk().getX(), 0, event.getChunk().getZ()))) + { + return; + } + // Sam don't you dare look here, I understand the implications of this // but entities, can I just save by UUID? or does not doing this have // bigger complications?. @@ -121,7 +159,7 @@ public class WorldListeners implements Listener { event.setCancelled(true); } - + @EventHandler public void fireSpread(BlockBurnEvent event) { @@ -134,6 +172,24 @@ public class WorldListeners implements Listener event.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGHEST) + public void hungerChange(FoodLevelChangeEvent event) + { + if (event.isCancelled()) + { + return; + } + + Player player = (Player) event.getEntity(); + + DebugModule.getInstance().d(player.getName() + " hunger " + player.getFoodLevel() + " -> " + event.getFoodLevel()); + + if (event.getFoodLevel() < player.getFoodLevel() && Recharge.Instance.use((Player) event.getEntity(), "Hunger", HUNGER_RECHARGE, false, false)) + { + event.setCancelled(true); + } + } + public boolean shouldBlock(Player player) { return player.getGameMode() != GameMode.CREATIVE;