diff --git a/Plugins/Libraries/craftbukkit.jar b/Plugins/Libraries/craftbukkit.jar index e591860d5..74d42a85b 100644 Binary files a/Plugins/Libraries/craftbukkit.jar and b/Plugins/Libraries/craftbukkit.jar differ diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java index e984d3432..0345fbf59 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java @@ -145,7 +145,8 @@ public class Donor public void addGold(int amount) { - _gold += amount; + _gold = Math.max(0, _gold + amount); + } public List getCoinTransactions() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 24d34157c..b27796e68 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -1,5 +1,6 @@ package mineplex.game.clans; +import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; import net.minecraft.server.v1_7_R4.MinecraftServer; @@ -68,7 +69,10 @@ public class Clans extends JavaPlugin PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager); ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); - new Spawn(this, serverStatusManager.getCurrentServerName()); + + // TODO: Add spawn locations to a configuration file of some sort? + Spawn spawn = new Spawn(this, serverStatusManager.getCurrentServerName()); + Teleport teleport = new Teleport(this); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyManager.java index aa14e48e6..95524615c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanEnergyManager.java @@ -32,7 +32,7 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable for (final ClanInfo clanInfo : _clansManager.getClanMap().values()) { - if (clanInfo.isAdmin()) + if (clanInfo.isAdmin() || true) // TODO: Remove || true and implement ability to purchase Energy continue; int energyPerMinute = clanInfo.getEnergyCostPerMinute(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanRole.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanRole.java index 83901e238..3c70a4d80 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanRole.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanRole.java @@ -4,3 +4,4 @@ public enum ClanRole { NONE, RECRUIT, MEMBER, ADMIN, LEADER } + diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 96191b126..65eb96461 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -3,6 +3,7 @@ package mineplex.game.clans.clans; import java.util.HashSet; import java.util.TimeZone; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +11,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.CustomTagFix; @@ -43,6 +45,7 @@ import mineplex.game.clans.clans.repository.tokens.ClanToken; import mineplex.game.clans.clans.war.WarManager; import mineplex.game.clans.fields.Field; import mineplex.game.clans.gameplay.Gameplay; +import mineplex.game.clans.spawn.Spawn; import mineplex.minecraft.game.classcombat.Class.ClassManager; import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken; import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager; @@ -59,6 +62,9 @@ import mineplex.minecraft.game.core.mechanics.Weapon; public class ClansManager extends MiniClientPlugin implements IRelation { + public static final int FIELD_RADIUS = 128; + public static final int CLAIMABLE_RADIUS = 800; + public static final int WORLD_RADIUS = 1200; private static final TimeZone TIME_ZONE = TimeZone.getDefault(); private String _serverName; @@ -90,6 +96,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat private NautHashMap _claimMap = new NautHashMap(); private NautHashMap _unclaimMap = new NautHashMap(); + // Spawn area + public String[] denyClan = new String[] { "neut", "neutral", "sethome", "promote", "demote", "admin", "help", "create", "disband", "delete", "invite", "join", "kick", "ally", "trust", "claim", "unclaim", "territory", "home"}; @@ -121,6 +129,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat Creature creature = new Creature(plugin); new Field(plugin, creature, _condition, energy, serverName); + new Spawn(plugin); DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager); @@ -184,6 +193,23 @@ public class ClansManager extends MiniClientPlugin implements IRelat return _clanMemberMap; } + public static boolean isClaimable(Location location) + { + int x = Math.abs(location.getBlockX()); + int z = Math.abs(location.getBlockZ()); + + return (x > FIELD_RADIUS || z > FIELD_RADIUS) + && (x <= CLAIMABLE_RADIUS && z <= CLAIMABLE_RADIUS); + } + + public static boolean isFields(Location location) + { + int x = Math.abs(location.getBlockX()); + int z = Math.abs(location.getBlockZ()); + + return x <= FIELD_RADIUS && z <= FIELD_RADIUS; + } + public ClanInfo getClan(Player player) { return _clanMemberMap.get(player.getName()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index d6fa99f06..2b0272a6f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -537,8 +537,9 @@ public class ClansUtility return true; } + public boolean isBorderlands(Location loc) { - return (Math.abs(loc.getX()) > 400 || Math.abs(loc.getZ()) > 400); + return Math.abs(loc.getBlockX()) > ClansManager.CLAIMABLE_RADIUS || Math.abs(loc.getBlockZ()) > ClansManager.CLAIMABLE_RADIUS; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index bc5ee1494..11bed4f18 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -25,9 +25,13 @@ import mineplex.game.clans.clans.ClientClan; public class ClansCommand extends CommandBase { + private ClansManager _manager; + public ClansCommand(ClansManager plugin) { super(plugin, Rank.ALL, "c", "clans", "f", "factions"); + + _manager = plugin; } @Override @@ -784,12 +788,9 @@ public class ClansCommand extends CommandBase return; } - if (caller.getLocation().getChunk().getX() < -24 || - caller.getLocation().getChunk().getX() > 23 || - caller.getLocation().getChunk().getZ() < -24 || - caller.getLocation().getChunk().getZ() > 23) + if (!ClansManager.isClaimable(caller.getLocation())) { - UtilPlayer.message(caller, F.main("Clans", "You cannot claim Territory this far away.")); + UtilPlayer.message(caller, F.main("Clans", "You cannot claim territory at this location!")); return; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java index 1d5437992..849f20a5f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java @@ -105,6 +105,7 @@ public class WarManager extends MiniPlugin { Player player = event.getEntity(); Player killer = player.getKiller(); + if (killer == null) return; // Wasn't killed by player ClanInfo playerClan = _clansManager.getClan(player); ClanInfo killerClan = _clansManager.getClan(killer); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java new file mode 100644 index 000000000..3517848cd --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -0,0 +1,106 @@ +package mineplex.game.clans.economy; + +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.CurrencyType; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.creature.Creature; +import mineplex.core.donation.DonationManager; +import mineplex.core.donation.Donor; +import mineplex.core.energy.Energy; +import mineplex.game.clans.Clans; +import mineplex.game.clans.fields.repository.FieldRepository; +import mineplex.game.clans.items.generation.WeightSet; +import mineplex.minecraft.game.core.condition.ConditionFactory; +import mineplex.minecraft.game.core.condition.ConditionManager; + +public class GoldManager extends MiniPlugin +{ + public static final double DEATH_TAX = 0.04d; // Percentage of gold lost on death + + private static GoldManager _instance; + public static GoldManager getInstance() { return _instance; } + + private DonationManager _donationManager; + + public GoldManager(JavaPlugin plugin, DonationManager donationManager) + { + super("Clans Gold", plugin); + + _instance = this; + _donationManager = donationManager; + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent event) + { + Player player = event.getEntity(); + Player killer = player.getKiller(); + + int gold = getGold(player); + int droppedGold = (int) (gold * DEATH_TAX); + + if (droppedGold > 0) + { + deductGold(player, droppedGold); + notify(player, String.format("You dropped %d gold on your death!", droppedGold)); + + if (killer != null) + { + addGold(killer, droppedGold); + notify(killer, String.format("You looted %d gold off of %s's corpse!", droppedGold, player.getName())); + } + } + } + + @EventHandler + public void playerCmd(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().startsWith("/gold")) + { + notify(event.getPlayer(), "Your Balance is " + C.cYellow + getGold(event.getPlayer()) + "g"); + event.setCancelled(true); + } + } + + public int getGold(Player player) + { + return getDonor(player).getGold(); + } + + public void addGold(Player player, int amount) + { + getDonor(player).addGold(amount); + } + + public void deductGold(Player player, int amount) + { + addGold(player, -amount); + } + + private Donor getDonor(Player player) + { + return _donationManager.Get(player.getName()); + } + + private void notify(Player player, String message) + { + UtilPlayer.message(player, F.main("Gold", message)); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/FieldBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/FieldBlock.java index aa98cb5d2..a9fc37918 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/FieldBlock.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/FieldBlock.java @@ -26,6 +26,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.energy.Energy; +import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.fields.commands.FieldBlockCommand; import mineplex.game.clans.fields.commands.FieldOreCommand; import mineplex.game.clans.fields.repository.FieldBlockToken; @@ -206,17 +207,19 @@ public class FieldBlock extends MiniPlugin event.setCancelled(true); } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void BlockBreak(BlockBreakEvent event) - { - if (event.isCancelled()) - return; + { + if (ClansManager.isFields(event.getBlock().getLocation())) + { + event.setCancelled(true); // Cancel all block breaks in fields. Handle custom breaking for FieldBlocks and Ores. - FieldBlockData fieldBlock = getFieldBlock(event.getBlock()); - if (fieldBlock == null) return; - - fieldBlock.handleMined(event.getPlayer()); - event.setCancelled(true); + FieldBlockData fieldBlock = getFieldBlock(event.getBlock()); + if (fieldBlock != null) + { + fieldBlock.handleMined(event.getPlayer()); + } + } } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java index 7933da3ea..8840581ea 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java @@ -50,7 +50,7 @@ public class CustomItem public CustomItem(Material material) { - this(material.toString(), null, material); // TODO: Prettify item materal name + this(prettifyName(material), null, material); } /** @@ -79,15 +79,20 @@ public class CustomItem return display; } + public String getDescription() + { + return _description; + } + public List getLore() { String serialization = GearManager.getItemSerialization(this); List lore = new ArrayList(); - if (_description != null) + if (getDescription() != null) { - lore.add(_description); + lore.add(getDescription()); } // Display attribute descriptions and stats in lore @@ -204,4 +209,18 @@ public class CustomItem _suffix = attribute; } } + + public static String prettifyName(Material material) + { + String name = ""; + String[] words = material.toString().split("_"); + + for (String word : words) + { + word = word.toLowerCase(); + name += word.substring(0, 1).toUpperCase() + word.substring(1) + " "; + } + + return name; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index b3979bee9..2d809d9b4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -38,6 +38,7 @@ import net.minecraft.util.com.google.common.collect.Sets; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -279,20 +280,9 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable public static String getItemSerialization(CustomItem customItem) { - String tempSeri = serialize(customItem); - String serialization = ITEM_SERIALIZATION_TAG; + String serialization = serialize(customItem); - for (int i = 0; i < tempSeri.length(); i++) - { - if (i % 40 == 39) - { - serialization += "\n"; // TODO: Remove this temporary fix to hiding player lore - } - - serialization += tempSeri.charAt(i); - } - - return serialization; + return ITEM_SERIALIZATION_TAG + serialization; } /** @@ -318,7 +308,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable ItemMeta meta = item.getItemMeta(); - /*for (String lore : meta.getLore()) + for (String lore : meta.getLore()) { if (lore.startsWith(ITEM_SERIALIZATION_TAG)) // Found serialization lore-line { @@ -327,30 +317,6 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable return serialization; } - }*/ - - // TODO: Implement packet intercepting to hide json encoded lore - List lore = meta.getLore(); - boolean serialized = false; - String serialization = ""; - for (int i = 0; i < lore.size(); i++) - { - String line = lore.get(i); - - if (line.startsWith(ITEM_SERIALIZATION_TAG)) - { - serialized = true; - serialization += line.substring(ITEM_SERIALIZATION_TAG.length()); - } - else if (serialized) - { - serialization += line; - } - } - - if (serialized) - { - return serialization; } return null; // Unable to find any serialized lore lines, hence not a CustomItem. @@ -384,6 +350,30 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable System.out.println("Item slot packet!"); PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) packet; + net.minecraft.server.v1_7_R4.ItemStack original = slotPacket.c; + CraftItemStack originalItem = CraftItemStack.asCraftMirror(original); + ItemMeta originalMeta = originalItem.getItemMeta(); + if (originalMeta == null || originalMeta.getLore() == null) return; // No need to modify item packets with no lore + + List lore = new ArrayList(); + + for (String line : originalMeta.getLore()) + { + if (!line.startsWith(ITEM_SERIALIZATION_TAG)) // Remove serialization lines from out-going lore + { + lore.add(line); + } + } + + net.minecraft.server.v1_7_R4.ItemStack newItem = CraftItemStack.asNMSCopy(originalItem); + CraftItemStack newCopy = CraftItemStack.asCraftMirror(newItem); + ItemMeta newMeta = newCopy.getItemMeta(); + newMeta.setLore(lore); + newCopy.setItemMeta(newMeta); + //slotPacket.c = newItem; + //CraftItemStack.setItemMeta(slotPacket.c, meta); + + System.out.println("Successfully intercepted item packet! " + CraftItemStack.getItemMeta(original).getLore().size() + " -- " + CraftItemStack.getItemMeta(newItem).getLore().size()); // TODO: Modify spigot build so that slotPacket's itemstack lore can be modified // to 'hide' json-encoded lore from players. } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/economy/GoldToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/economy/GoldToken.java new file mode 100644 index 000000000..1f8fff16d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/economy/GoldToken.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.items.economy; + +import org.bukkit.Material; + +import mineplex.game.clans.items.CustomItem;; + +public class GoldToken extends CustomItem +{ + + private int _goldValue; + public int getGoldValue() { return _goldValue; } + + public GoldToken(int goldValue) + { + super("Gold Token", null, Material.GOLD_INGOT); + + _goldValue = goldValue; + } + + @Override + public String getDescription() + { + return String.format("A gold token worth %s gold coins.", _goldValue); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java index f39503c57..84f1d0e92 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/building/BuildingShop.java @@ -24,14 +24,4 @@ public class BuildingShop extends ShopBase { return new BuildingPage(getPlugin(), this, getClientManager(), getDonationManager(), player); } - - @EventHandler - public void playerCmd(PlayerCommandPreprocessEvent event) - { - if (event.getMessage().startsWith("/gold")) - { - UtilPlayer.message(event.getPlayer(), F.main("Gold", "Your Balance is " + C.cYellow + getDonationManager().Get(event.getPlayer().getName()).getGold() + "g")); - event.setCancelled(true); - } - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java new file mode 100644 index 000000000..15b8c3f33 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java @@ -0,0 +1,120 @@ +package mineplex.game.clans.spawn; + +import java.util.Random; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.creature.Creature; +import mineplex.core.energy.Energy; +import mineplex.game.clans.fields.repository.FieldRepository; +import mineplex.game.clans.items.generation.WeightSet; +import mineplex.minecraft.game.core.condition.ConditionFactory; +import mineplex.minecraft.game.core.condition.ConditionManager; + +public class Spawn extends MiniPlugin +{ + public static final int SPAWN_RADIUS = 32; + + private static Spawn _instance; + public static Spawn getInstance() { return _instance; } + + private WeightSet _spawns; + + public Spawn(JavaPlugin plugin) + { + super("Clan Spawn Zones", plugin); + + _instance = this; + _spawns = new WeightSet(new Location(null, -200, 107, 0), new Location(null, 200, 107, 0)); + } + + @EventHandler + public void onRespawn(PlayerRespawnEvent event) + { + System.out.println("On respawn"); + event.setRespawnLocation(getSpawnLocation()); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if (isInSpawn(event.getBlock().getLocation())) + { + + } + else if (isInSpawn(event.getPlayer())) + { + + } + } + + @EventHandler + public void onPlayerAttacked(EntityDamageByEntityEvent event) + { + Entity defender = event.getEntity(); + + if (defender instanceof Player) + { + Player player = (Player) defender; + + if (isInSpawn(player) && !isCombatTagged(player)) + { + event.setCancelled(true); + } + } + } + + public World getSpawnWorld() + { + return Bukkit.getWorld("world"); + } + + public Location getSpawnLocation() + { + Location spawn = _spawns.generateRandom().clone(); + spawn.setWorld(getSpawnWorld()); + return spawn; + } + + public boolean isInSpawn(Location location) + { + for(Location spawn : _spawns.elements()) + { + int xOffset = Math.abs(location.getBlockX() - spawn.getBlockX()); + int zOffset = Math.abs(location.getBlockZ() - spawn.getBlockZ()); + + if (xOffset <= SPAWN_RADIUS + && zOffset <= SPAWN_RADIUS) + { + return true; + } + } + + return false; + } + + public boolean isInSpawn(Player player) + { + return isInSpawn(player.getLocation()); + } + + private boolean isCombatTagged(Player player) + { + return false; // TODO: Check for implemented combat tagging? + } + + private void notify(Player player, String message) + { + + } +}