Fix purple/black item bug, fix clans/ally chat bug with no clan, murder changes, drop player gold as items on death, add lore to crafted items

This commit is contained in:
Shaun Bennett 2015-08-27 13:57:57 -07:00
parent adfc451e9f
commit b0ee2bb669
9 changed files with 224 additions and 53 deletions

View File

@ -708,6 +708,11 @@ public class ItemStackFactory extends MiniPlugin
return CreateStack(type.getId(), data, amount, (short)0, name, new String[] {}, null);
}
public ItemStack CreateStack(Material type, byte data, int amount, String name, boolean unbreakable)
{
return CreateStack(type.getId(), data, amount, (short)0, name, new String[] {}, null, unbreakable);
}
public ItemStack CreateStack(int id, byte data, int amount, String name)
{
return CreateStack(id, data, amount, (short)0, name, new String[] {}, null);
@ -763,6 +768,11 @@ public class ItemStackFactory extends MiniPlugin
return CreateStack(type.getId(), data, amount, (short)0, name, ArrayToList(lore), owner);
}
public ItemStack CreateStack(Material type, byte data, int amount, String name, String[] lore, String owner, boolean unbreakable)
{
return CreateStack(type.getId(), data, amount, (short)0, name, ArrayToList(lore), owner, unbreakable);
}
public ItemStack CreateStack(int id, byte data, int amount, String name, String[] lore, String owner)
{
return CreateStack(id, data, amount, (short)0, name, ArrayToList(lore), owner);
@ -778,15 +788,26 @@ public class ItemStackFactory extends MiniPlugin
return CreateStack(id, data, amount, damage, name, ArrayToList(lore), owner);
}
public ItemStack CreateStack(int id, byte data, int amount, short damage, String name, String[] lore, String owner, boolean unbreakable)
{
return CreateStack(id, data, amount, damage, name, ArrayToList(lore), owner, unbreakable);
}
public ItemStack CreateStack(Material type, byte data, int amount, short damage, String name, List<String> lore, String owner)
{
return CreateStack(type.getId(), data, amount, damage, name, lore, owner);
}
public ItemStack CreateStack(int id, byte data, int amount, short damage, String name, List<String> lore, String owner)
{
return CreateStack(id, data, amount, damage, name, lore, owner, true);
}
//XXX Owner Variant End
@SuppressWarnings("deprecation")
public ItemStack CreateStack(int id, byte data, int amount, short damage, String name, List<String> lore, String owner)
public ItemStack CreateStack(int id, byte data, int amount, short damage, String name, List<String> lore, String owner, boolean unbreakable)
{
ItemStack stack;
if (data == 0)
@ -855,16 +876,45 @@ public class ItemStackFactory extends MiniPlugin
stack.setItemMeta(itemMeta);
//Unbreakable
if (stack.getType().getMaxDurability() > 1)
if (unbreakable)
{
ItemMeta meta = stack.getItemMeta();
meta.spigot().setUnbreakable(true);
stack.setItemMeta(meta);
if (stack.getType().getMaxDurability() > 1)
{
ItemMeta meta = stack.getItemMeta();
meta.spigot().setUnbreakable(true);
stack.setItemMeta(meta);
}
}
return stack;
}
public void addOwnerLore(ItemStack item, String owner)
{
if (owner != null)
{
ItemMeta itemMeta = item.getItemMeta();
String[] tokens = owner.split(" ");
String[] ownerLore = new String[tokens.length + 2];
ownerLore[0] = C.cGray + "Owner: " + C.cAqua + tokens[0];
if (ownerLore.length >= 3)
ownerLore[1] = C.cGray + "Source: " + C.cAqua + tokens[1];
ownerLore[ownerLore.length - 2] = C.cGray + "Created: " + C.cAqua + UtilTime.date();
ownerLore[ownerLore.length - 1] = "";
if (itemMeta.getLore() != null) itemMeta.setLore(CombineLore(itemMeta.getLore(), ArrayToList(ownerLore)));
else itemMeta.setLore(ArrayToList(ownerLore));
item.setItemMeta(itemMeta);
}
}
private List<String> CombineLore(List<String> A, List<String> B)
{
for (String b : B)

View File

@ -1,48 +1,55 @@
package mineplex.game.clans;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilGear;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
public class Recipes extends MiniPlugin
{
public Recipes(JavaPlugin plugin)
public Recipes(JavaPlugin plugin)
{
super("Recipes", plugin);
ItemStack boosterAxe = ItemStackFactory.Instance.CreateStack(Material.GOLD_AXE, (byte) 0, 1, "Booster Axe");
ItemStack boosterAxe = ItemStackFactory.Instance.CreateStack(Material.GOLD_AXE, (byte) 0, 1, "Booster Axe", false);
ShapedRecipe goldAxe = new ShapedRecipe(boosterAxe);
goldAxe.shape("#MM","#SM","#S#");
goldAxe.setIngredient('M', Material.GOLD_BLOCK);
goldAxe.setIngredient('S', Material.STICK);
UtilServer.getServer().addRecipe(goldAxe);
ItemStack powerAxe = ItemStackFactory.Instance.CreateStack(Material.DIAMOND_AXE, (byte) 0, 1, "Power Axe");
ItemStack powerAxe = ItemStackFactory.Instance.CreateStack(Material.DIAMOND_AXE, (byte) 0, 1, "Power Axe", false);
ShapedRecipe diamondAxe = new ShapedRecipe(powerAxe);
diamondAxe.shape("#MM","#SM","#S#");
diamondAxe.setIngredient('M', Material.DIAMOND_BLOCK);
diamondAxe.setIngredient('S', Material.STICK);
UtilServer.getServer().addRecipe(diamondAxe);
ItemStack boosterSword = ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte) 0, 1, "Booster Sword");
ItemStack boosterSword = ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte) 0, 1, "Booster Sword", false);
ShapedRecipe goldSword = new ShapedRecipe(boosterSword);
goldSword.shape("M","M","S");
goldSword.setIngredient('M', Material.GOLD_BLOCK);
goldSword.setIngredient('S', Material.STICK);
UtilServer.getServer().addRecipe(goldSword);
ItemStack powerSword = ItemStackFactory.Instance.CreateStack(Material.DIAMOND_SWORD, (byte) 0, 1, "Power Sword");
ItemStack powerSword = ItemStackFactory.Instance.CreateStack(Material.DIAMOND_SWORD, (byte) 0, 1, "Power Sword", false);
ShapedRecipe diamondSword = new ShapedRecipe(powerSword);
diamondSword.shape("M","M","S");
diamondSword.setIngredient('M', Material.DIAMOND_BLOCK);
@ -135,6 +142,24 @@ public class Recipes extends MiniPlugin
UtilServer.getServer().addRecipe(chainBoots2);
}
@EventHandler(priority = EventPriority.LOW)
public void addLore(PrepareItemCraftEvent event)
{
if (event.getView().getPlayer() instanceof Player)
{
Player player = ((Player) event.getView().getPlayer());
CraftingInventory inv = (CraftingInventory)event.getInventory();
ItemStack itemStack = inv.getResult();
if (UtilGear.isWeapon(itemStack))
{
ItemStackFactory.Instance.addOwnerLore(itemStack, player.getName() + " Crafting");
inv.setResult(itemStack);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void ReplaceDoor(PrepareItemCraftEvent event)

View File

@ -122,6 +122,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
private Chat _chat;
private ItemMapManager _itemMapManager;
private Explosion _explosion;
private GoldManager _goldManager;
private int _inviteExpire = 2;
private int _nameMin = 3;
@ -153,8 +154,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_teleport = teleport;
_warManager = new WarManager(plugin, this);
GoldManager goldManager = new GoldManager(this, _clientManager, donationManager);
LootManager lootManager = new LootManager(gearManager, goldManager);
_goldManager = new GoldManager(this, _clientManager, donationManager);
LootManager lootManager = new LootManager(gearManager, _goldManager);
PacketHandler packetHandler = new PacketHandler(plugin);
DisguiseManager disguiseManager = new DisguiseManager(plugin, packetHandler);
Creature creature = new Creature(plugin);
@ -430,14 +431,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
ClanInfo clan = _clanUtility.getClanByPlayer(event.getPlayer());
if (client.isClanChat())
if (client.isClanChat() && clan != null)
{
if (clan == null)
{
Get(event.getPlayer()).setClanChat(false);
return;
}
event.setFormat(C.cAqua + "%1$s " + C.cDAqua + "%2$s");
event.getRecipients().clear();
@ -451,14 +446,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
event.getRecipients().add(player);
}
}
else if (client.isAllyChat())
else if (client.isAllyChat() && clan != null)
{
if (clan == null)
{
Get(event.getPlayer()).setAllyChat(false);
return;
}
event.setFormat(C.cDGreen + clan.getName() + " " + C.cDGreen + "%1$s " + C.cGreen + "%2$s");
event.getRecipients().clear();
@ -686,6 +675,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
// This is so that we can prevent any permanent world changes with events
_blockRestore.onDisable();
_worldEvent.onDisable();
_goldManager.onDisable();
}
// @EventHandler
@ -697,6 +687,19 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
}
@EventHandler
public void onBreak(BlockBreakEvent event)
{
if (event.getPlayer().getName().equals("Eniloo"))
{
ItemStack item = event.getPlayer().getItemInHand();
event.getPlayer().sendMessage("Item: " + item.getType().toString());
event.getPlayer().sendMessage("Id: " + item.getTypeId());
event.getPlayer().sendMessage("Durability: " + item.getDurability());
event.getPlayer().sendMessage("Data: " + ((CraftItemStack) item).getHandle().getData());
}
}
// @EventHandler
public void blockBreak(BlockBreakEvent event)
{
@ -722,8 +725,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
}
Bukkit.broadcastMessage("name: " + item.getName() + " max dur: " + item.getMaxDurability());
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -21,8 +21,16 @@ public class ClansAllyChatCommand extends CommandBase<ClansManager>
{
if (args == null || args.length == 0)
{
Plugin.Get(caller).setAllyChat(!Plugin.Get(caller).isAllyChat());
UtilPlayer.message(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat())));
ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller);
if (clan == null)
{
UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan."));
}
else
{
Plugin.Get(caller).setAllyChat(!Plugin.Get(caller).isAllyChat());
UtilPlayer.message(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat())));
}
return;
}

View File

@ -21,8 +21,16 @@ public class ClansChatCommand extends CommandBase<ClansManager>
{
if (args == null || args.length == 0)
{
Plugin.Get(caller).setClanChat(!Plugin.Get(caller).isClanChat());
UtilPlayer.message(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat())));
ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller);
if (clan == null)
{
UtilPlayer.message(caller, F.main("Clans", "You are not in a Clan."));
}
else
{
Plugin.Get(caller).setClanChat(!Plugin.Get(caller).isClanChat());
UtilPlayer.message(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat())));
}
return;
}

View File

@ -5,7 +5,9 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInventoryEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@ -70,6 +72,18 @@ public class MurderManager extends MiniClientPlugin<WeaklingStatus>
}
}
@EventHandler
public void onPickup(PlayerPickupItemEvent event)
{
refreshWeaklingStatus(event.getPlayer());
}
@EventHandler
public void onDrop(PlayerDropItemEvent event)
{
refreshWeaklingStatus(event.getPlayer());
}
@EventHandler
public void onInventoryEvent(InventoryMoveItemEvent event)
{
@ -106,7 +120,10 @@ public class MurderManager extends MiniClientPlugin<WeaklingStatus>
{
if (other.equals(player)) continue;
UtilParticle.PlayParticle(UtilParticle.ParticleType.ANGRY_VILLAGER, player.getEyeLocation().add(0, 0.25, 0), 0, 0, 0, 0, 1, UtilParticle.ViewDist.NORMAL, other);
if (!isWeakling(other) && canMurderOccur(other, player, other.getLocation()))
{
UtilParticle.PlayParticle(UtilParticle.ParticleType.ANGRY_VILLAGER, player.getEyeLocation().add(0, 0.25, 0), 0, 0, 0, 0, 1, UtilParticle.ViewDist.NORMAL, other);
}
}
}
}

View File

@ -1,8 +1,10 @@
package mineplex.game.clans.economy;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
@ -48,6 +50,7 @@ public class GoldManager extends MiniPlugin
private DonationManager _donationManager;
private TransferTracker _transferTracker;
private Set<Item> _itemSet;
private HashMap<Player, Integer> _playerPickupMap;
private BankShop _bankShop;
public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
@ -58,6 +61,7 @@ public class GoldManager extends MiniPlugin
_donationManager = donationManager;
_transferTracker = new TransferTracker();
_itemSet = new HashSet<Item>();
_playerPickupMap = new HashMap<Player, Integer>();
_bankShop = new BankShop(plugin, clientManager, donationManager);
}
@ -69,6 +73,7 @@ public class GoldManager extends MiniPlugin
int gold = getGold(player);
final int droppedGold = (int) (gold * DEATH_TAX);
final Location deathLocation = player.getLocation();
if (droppedGold > 0)
{
@ -76,15 +81,23 @@ public class GoldManager extends MiniPlugin
{
public void run(Boolean success)
{
GoldManager.notify(player, String.format("You dropped %d gold on your death!", droppedGold));
if (killer != null)
runSync(new Runnable()
{
addGold(killer, droppedGold);
GoldManager.notify(killer, String.format("You looted %d gold off of %s's corpse!", droppedGold, player.getName()));
}
@Override
public void run()
{
GoldManager.notify(player, "You dropped " + F.elem(droppedGold + "") + " gold on your death!");
dropGold(deathLocation, droppedGold);
}
});
// if (killer != null)
// {
// addGold(killer, droppedGold);
// GoldManager.notify(killer, String.format("You looted %d gold off of %s's corpse!", droppedGold, player.getName()));
// }
}
},player, droppedGold);
}, player, droppedGold);
}
}
@ -115,9 +128,32 @@ public class GoldManager extends MiniPlugin
event.getItem().remove();
event.getPlayer().playSound(event.getPlayer().getEyeLocation(), Sound.ORB_PICKUP, 1F, 2F);
addGold(event.getPlayer(), goldAmount);
int pickupMapGold = goldAmount;
if (_playerPickupMap.containsKey(event.getPlayer()))
pickupMapGold += _playerPickupMap.get(event.getPlayer());
_playerPickupMap.put(event.getPlayer(), pickupMapGold);
}
}
@EventHandler
public void notifyPickup(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
for (Map.Entry<Player, Integer> entry : _playerPickupMap.entrySet())
{
if (entry.getKey().isOnline())
{
notify(entry.getKey(), "You picked up " + F.elem(entry.getValue() + " gold"));
}
}
_playerPickupMap.clear();
}
@EventHandler
public void cleanItems(UpdateEvent event)
{
@ -192,25 +228,39 @@ public class GoldManager extends MiniPlugin
public void dropGold(Location location, int amount)
{
dropGold(location, amount, true, 0.2);
dropGold(location, amount, 0.1);
}
public void dropGold(Location location, int amount, boolean stacking, double velMult)
public void dropGold(Location location, int amount, double velMult)
{
// TODO Stacking
int count = amount / 1000;
int extraGold = amount % 1000;
for (int i = 0; i < amount; i++)
for (int i = 0; i < count; i++)
{
Item item = location.getWorld().dropItem(location, new ItemStack(Material.GOLD_INGOT));
item.setPickupDelay(40);
item.setMetadata(META_STRING, new FixedMetadataValue(getPlugin(), 1));
_itemSet.add(item);
// Velocity
double x = Math.random() * 2 * Math.PI;
Vector velocity = new Vector(Math.sin(x), 0, Math.cos(x));
UtilAction.velocity(item, velocity, velMult, false, 0, 0.2, 0.2, false);
dropGold(location, 1000, velocity, velMult);
}
// Drop Extra
if (extraGold > 0)
{
double x = Math.random() * 2 * Math.PI;
Vector velocity = new Vector(Math.sin(x), 0, Math.cos(x));
dropGold(location, extraGold, velocity, velMult);
}
}
private void dropGold(Location location, int amount, Vector velocity, double velMult)
{
Item item = location.getWorld().dropItem(location, new ItemStack(Material.GOLD_NUGGET));
item.setPickupDelay(40);
item.setMetadata(META_STRING, new FixedMetadataValue(getPlugin(), amount));
_itemSet.add(item);
// Velocity
UtilAction.velocity(item, velocity, velMult, false, 0, 0.2, 0.2, false);
}
public void purchaseToken(final Player player, final int tokenValue)
@ -252,4 +302,13 @@ public class GoldManager extends MiniPlugin
{
UtilPlayer.message(player, F.main("Gold", message));
}
@Override
public void disable()
{
for (Item item : _itemSet)
{
item.remove();
}
}
}

View File

@ -61,8 +61,7 @@ public class PvpShopButton<PageType extends ShopPageBase<ClansManager, ?>> imple
Page.playAcceptSound(player);
ShopItem item = Item.clone();
item.setAmount(deliveryAmount);
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Item.getType(), Item.getData().getData(), Item.getAmount(), Item.GetName()));
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Item.getType(), Item.getData().getData(), Item.getAmount(), Item.GetName(), new String[] {}, player.getName() + " Shop", false));
}
else
{

View File

@ -110,6 +110,10 @@ public class Weapon extends MiniPlugin
if (item.getType().getMaxDurability() == 0)
return;
// Don't mess with unbreakable items
if (item.getItemMeta() != null && item.getItemMeta().spigot().isUnbreakable())
return;
item.setDurability((short) (item.getDurability() + 1));
if (item.getDurability() >= item.getType().getMaxDurability())