Lots of fixes

This commit is contained in:
Sam 2017-02-11 17:18:39 +00:00
parent e8b5c180ee
commit 16773521b9
22 changed files with 365 additions and 233 deletions

View File

@ -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");
}

View File

@ -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);

View File

@ -60,7 +60,7 @@ public class CashOutModule extends MiniPlugin
@EventHandler
public void playerInteract(PlayerInteractEvent event)
{
{
if (!UtilEvent.isAction(event, ActionType.R))
{
return;

View File

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

View File

@ -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<Integer, Integer> _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<Integer, Integer> getSpawnIndexes()
{
return _spawnedIndexes;
}
public void setLastSpawn()
{
_lastSpawn = System.currentTimeMillis();

View File

@ -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<UUID, Integer> _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]));
}
}
}

View File

@ -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<String, Set<LootItem>> _chestLoot;
private final Map<String, ChestProperties> _chestProperties;
private final Set<SpawnedChest> _spawnedChest;
private final Map<String, Set<Integer>> _spawnedIndexes;
private final Set<LootItemReward> _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<Location> 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<Integer> 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<Location> 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<Integer, Integer> 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<LootItem> items : _chestLoot.values())
{
for (LootItem item : items)

View File

@ -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<LootModule>
{
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 + " <colour>", "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);
}
}

View File

@ -14,7 +14,7 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser<Ches
String name = values[0];
Material blockMaterial = Material.valueOf(values[1]);
String dataKey = values[2];
int minAmount = 1;
int maxAmount = 1;
@ -33,10 +33,11 @@ public class ChestPropertiesDeserialiser implements SheetObjectDeserialiser<Ches
int spawnRate = Integer.parseInt(values[4]);
int expireRate = Integer.parseInt(values[5]);
int spawnRadius = Integer.parseInt(values[6]);
int maxActive = Integer.parseInt(values[7]);
return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, spawnRate, expireRate, spawnRadius, maxActive);
int maxChestsPerLoc = Integer.parseInt(values[6]);
int spawnRadius = Integer.parseInt(values[7]);
int maxActive = Integer.parseInt(values[8]);
return new ChestProperties(name, blockMaterial, dataKey, minAmount, maxAmount, maxChestsPerLoc, spawnRate, expireRate, spawnRadius, maxActive);
}
}

View File

@ -42,7 +42,6 @@ public class LootItemDeserialiser implements SheetObjectDeserialiser<LootItem>
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<LootItem>
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<LootItem>
double proability = Double.parseDouble(values[7]);
String metadata = values.length > 8 ? values[8] : null;
return new LootItem(builder.build(), minAmount, maxAmount, proability, metadata);
}

View File

@ -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();
}

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

@ -1,4 +1,4 @@
package mineplex.gemhunters.supplydrop.commands;
package mineplex.gemhunters.supplydrop.command;
import org.bukkit.entity.Player;

View File

@ -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<SupplyDropModule>
}
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))

View File

@ -1,4 +1,4 @@
package mineplex.gemhunters.supplydrop.commands;
package mineplex.gemhunters.supplydrop.command;
import org.bukkit.entity.Player;

View File

@ -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;
}
}
}
}

View File

@ -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;

View File

@ -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<Location> getDataLocation(String colour)
{
if (!DATA_LOCATIONS.containsKey(colour))

View File

@ -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;