Update spigot version to Shaun's changed. Add separate spawn locations at (200,0) and (-200,0) on the map as well as safe-zone regions surrounding spawns. Temporary halt energy deduction until energy shop is enabled. Fixed issues related to field zones being claimable/breakable, as well as borderlands. Define claimable areas. Add GoldToken item for storing currency into physical items. Add gold management for checking economic status for players.

This commit is contained in:
Ty Sayers 2015-06-01 15:51:22 -04:00
parent 2e19aabfa1
commit 155b078c49
16 changed files with 357 additions and 69 deletions

Binary file not shown.

View File

@ -145,7 +145,8 @@ public class Donor
public void addGold(int amount) public void addGold(int amount)
{ {
_gold += amount; _gold = Math.max(0, _gold + amount);
} }
public List<CoinTransactionToken> getCoinTransactions() public List<CoinTransactionToken> getCoinTransactions()

View File

@ -1,5 +1,6 @@
package mineplex.game.clans; package mineplex.game.clans;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_7_R4.MinecraftServer; import net.minecraft.server.v1_7_R4.MinecraftServer;
@ -68,7 +69,10 @@ public class Clans extends JavaPlugin
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager); PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager)); 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); Teleport teleport = new Teleport(this);
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName()); Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion()); new FileUpdater(this, portal, serverStatusManager.getCurrentServerName(), serverStatusManager.getRegion());

View File

@ -32,7 +32,7 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
for (final ClanInfo clanInfo : _clansManager.getClanMap().values()) for (final ClanInfo clanInfo : _clansManager.getClanMap().values())
{ {
if (clanInfo.isAdmin()) if (clanInfo.isAdmin() || true) // TODO: Remove || true and implement ability to purchase Energy
continue; continue;
int energyPerMinute = clanInfo.getEnergyCostPerMinute(); int energyPerMinute = clanInfo.getEnergyCostPerMinute();

View File

@ -4,3 +4,4 @@ public enum ClanRole
{ {
NONE, RECRUIT, MEMBER, ADMIN, LEADER NONE, RECRUIT, MEMBER, ADMIN, LEADER
} }

View File

@ -3,6 +3,7 @@ package mineplex.game.clans.clans;
import java.util.HashSet; import java.util.HashSet;
import java.util.TimeZone; import java.util.TimeZone;
import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; 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.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.CustomTagFix; 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.clans.war.WarManager;
import mineplex.game.clans.fields.Field; import mineplex.game.clans.fields.Field;
import mineplex.game.clans.gameplay.Gameplay; 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.ClassManager;
import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken; import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager; import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
@ -59,6 +62,9 @@ import mineplex.minecraft.game.core.mechanics.Weapon;
public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelation public class ClansManager extends MiniClientPlugin<ClientClan> 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 static final TimeZone TIME_ZONE = TimeZone.getDefault();
private String _serverName; private String _serverName;
@ -90,6 +96,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
private NautHashMap<String, ClanTerritory> _claimMap = new NautHashMap<String, ClanTerritory>(); private NautHashMap<String, ClanTerritory> _claimMap = new NautHashMap<String, ClanTerritory>();
private NautHashMap<String, Long> _unclaimMap = new NautHashMap<String, Long>(); private NautHashMap<String, Long> _unclaimMap = new NautHashMap<String, Long>();
// Spawn area
public String[] denyClan = new String[] { public String[] denyClan = new String[] {
"neut", "neutral", "sethome", "promote", "demote", "admin", "help", "create", "disband", "delete", "invite", "join", "kick", "ally", "trust", "claim", "unclaim", "territory", "home"}; "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<ClientClan> implements IRelat
Creature creature = new Creature(plugin); Creature creature = new Creature(plugin);
new Field(plugin, creature, _condition, energy, serverName); new Field(plugin, creature, _condition, energy, serverName);
new Spawn(plugin);
DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager); DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager);
@ -184,6 +193,23 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
return _clanMemberMap; 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) public ClanInfo getClan(Player player)
{ {
return _clanMemberMap.get(player.getName()); return _clanMemberMap.get(player.getName());

View File

@ -537,8 +537,9 @@ public class ClansUtility
return true; return true;
} }
public boolean isBorderlands(Location loc) 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;
} }
} }

View File

@ -25,9 +25,13 @@ import mineplex.game.clans.clans.ClientClan;
public class ClansCommand extends CommandBase<ClansManager> public class ClansCommand extends CommandBase<ClansManager>
{ {
private ClansManager _manager;
public ClansCommand(ClansManager plugin) public ClansCommand(ClansManager plugin)
{ {
super(plugin, Rank.ALL, "c", "clans", "f", "factions"); super(plugin, Rank.ALL, "c", "clans", "f", "factions");
_manager = plugin;
} }
@Override @Override
@ -784,12 +788,9 @@ public class ClansCommand extends CommandBase<ClansManager>
return; return;
} }
if (caller.getLocation().getChunk().getX() < -24 || if (!ClansManager.isClaimable(caller.getLocation()))
caller.getLocation().getChunk().getX() > 23 ||
caller.getLocation().getChunk().getZ() < -24 ||
caller.getLocation().getChunk().getZ() > 23)
{ {
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; return;
} }

View File

@ -105,6 +105,7 @@ public class WarManager extends MiniPlugin
{ {
Player player = event.getEntity(); Player player = event.getEntity();
Player killer = player.getKiller(); Player killer = player.getKiller();
if (killer == null) return; // Wasn't killed by player
ClanInfo playerClan = _clansManager.getClan(player); ClanInfo playerClan = _clansManager.getClan(player);
ClanInfo killerClan = _clansManager.getClan(killer); ClanInfo killerClan = _clansManager.getClan(killer);

View File

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

View File

@ -26,6 +26,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.energy.Energy; import mineplex.core.energy.Energy;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.fields.commands.FieldBlockCommand; import mineplex.game.clans.fields.commands.FieldBlockCommand;
import mineplex.game.clans.fields.commands.FieldOreCommand; import mineplex.game.clans.fields.commands.FieldOreCommand;
import mineplex.game.clans.fields.repository.FieldBlockToken; import mineplex.game.clans.fields.repository.FieldBlockToken;
@ -206,17 +207,19 @@ public class FieldBlock extends MiniPlugin
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void BlockBreak(BlockBreakEvent event) public void BlockBreak(BlockBreakEvent event)
{ {
if (event.isCancelled()) if (ClansManager.isFields(event.getBlock().getLocation()))
return; {
event.setCancelled(true); // Cancel all block breaks in fields. Handle custom breaking for FieldBlocks and Ores.
FieldBlockData fieldBlock = getFieldBlock(event.getBlock()); FieldBlockData fieldBlock = getFieldBlock(event.getBlock());
if (fieldBlock == null) return; if (fieldBlock != null)
{
fieldBlock.handleMined(event.getPlayer()); fieldBlock.handleMined(event.getPlayer());
event.setCancelled(true); }
}
} }
@EventHandler @EventHandler

View File

@ -50,7 +50,7 @@ public class CustomItem
public CustomItem(Material material) 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; return display;
} }
public String getDescription()
{
return _description;
}
public List<String> getLore() public List<String> getLore()
{ {
String serialization = GearManager.getItemSerialization(this); String serialization = GearManager.getItemSerialization(this);
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
if (_description != null) if (getDescription() != null)
{ {
lore.add(_description); lore.add(getDescription());
} }
// Display attribute descriptions and stats in lore // Display attribute descriptions and stats in lore
@ -204,4 +209,18 @@ public class CustomItem
_suffix = attribute; _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;
}
} }

View File

@ -38,6 +38,7 @@ import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -279,20 +280,9 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
public static String getItemSerialization(CustomItem customItem) public static String getItemSerialization(CustomItem customItem)
{ {
String tempSeri = serialize(customItem); String serialization = serialize(customItem);
String serialization = ITEM_SERIALIZATION_TAG;
for (int i = 0; i < tempSeri.length(); i++) return ITEM_SERIALIZATION_TAG + serialization;
{
if (i % 40 == 39)
{
serialization += "\n"; // TODO: Remove this temporary fix to hiding player lore
}
serialization += tempSeri.charAt(i);
}
return serialization;
} }
/** /**
@ -318,7 +308,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
/*for (String lore : meta.getLore()) for (String lore : meta.getLore())
{ {
if (lore.startsWith(ITEM_SERIALIZATION_TAG)) // Found serialization lore-line if (lore.startsWith(ITEM_SERIALIZATION_TAG)) // Found serialization lore-line
{ {
@ -327,30 +317,6 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable
return serialization; return serialization;
} }
}*/
// TODO: Implement packet intercepting to hide json encoded lore
List<String> 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. 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!"); System.out.println("Item slot packet!");
PacketPlayOutSetSlot slotPacket = (PacketPlayOutSetSlot) 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<String> lore = new ArrayList<String>();
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 // TODO: Modify spigot build so that slotPacket's itemstack lore can be modified
// to 'hide' json-encoded lore from players. // to 'hide' json-encoded lore from players.
} }

View File

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

View File

@ -24,14 +24,4 @@ public class BuildingShop extends ShopBase<ClansManager>
{ {
return new BuildingPage(getPlugin(), this, getClientManager(), getDonationManager(), player); 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);
}
}
} }

View File

@ -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<Location> _spawns;
public Spawn(JavaPlugin plugin)
{
super("Clan Spawn Zones", plugin);
_instance = this;
_spawns = new WeightSet<Location>(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)
{
}
}