Fletcher data fix

Minestrike stuff
This commit is contained in:
Chiss 2014-09-05 15:45:14 +10:00
parent b691b1bad0
commit 8c1e0c3e9e
7 changed files with 73 additions and 30 deletions

View File

@ -54,6 +54,12 @@ public class UtilInv
public static boolean contains(Player player, Material item, byte data, int required)
{
return contains(player, null, item, data, required);
}
public static boolean contains(Player player, String itemNameContains, Material item, byte data, int required)
{
for (int i : player.getInventory().all(item).keySet())
{
if (required <= 0)
@ -61,10 +67,21 @@ public class UtilInv
ItemStack stack = player.getInventory().getItem(i);
if (stack != null && stack.getAmount() > 0 && (stack.getData() == null || stack.getData().getData() == data))
{
required -= stack.getAmount();
}
if (stack == null)
continue;
if (stack.getAmount() <= 0)
continue;
if (data >=0 &&
stack.getData() != null && stack.getData().getData() != data)
continue;
if (itemNameContains != null &&
(stack.getItemMeta().getDisplayName() == null || !stack.getItemMeta().getDisplayName().contains(itemNameContains)))
continue;
required -= stack.getAmount();
}
if (required <= 0)
@ -196,10 +213,15 @@ public class UtilInv
public static boolean IsItem(ItemStack item, Material type, byte data)
{
return IsItem(item, type.getId(), data);
return IsItem(item, null, type.getId(), data);
}
public static boolean IsItem(ItemStack item, int id, byte data)
public static boolean IsItem(ItemStack item, String name, Material type, byte data)
{
return IsItem(item, name, type.getId(), data);
}
public static boolean IsItem(ItemStack item, String name, int id, byte data)
{
if (item == null)
return false;
@ -210,6 +232,9 @@ public class UtilInv
if (data != -1 && GetData(item) != data)
return false;
if (name != null && (item.getItemMeta().getDisplayName() == null || !item.getItemMeta().getDisplayName().contains(name)))
return false;
return true;
}
@ -247,12 +272,12 @@ public class UtilInv
{
boolean match = false;
if (IsItem(event.getCurrentItem(), type, data))
if (IsItem(event.getCurrentItem(), name, type, data))
match = true;
if (IsItem(event.getWhoClicked().getInventory().getItem(event.getHotbarButton()), type, data))
if (IsItem(event.getWhoClicked().getInventory().getItem(event.getHotbarButton()), name, type, data))
match = true;
if (!match)
return;
@ -266,10 +291,10 @@ public class UtilInv
if (event.getCurrentItem() == null)
return;
IsItem(event.getCurrentItem(), type, data);
IsItem(event.getCurrentItem(), name, type, data);
//Type
if (!IsItem(event.getCurrentItem(), type, data))
if (!IsItem(event.getCurrentItem(), name, type, data))
return;
//Inform
UtilPlayer.message(event.getWhoClicked(), F.main("Inventory", "You cannot move " + F.item(name) + "."));

View File

@ -196,6 +196,7 @@ public class MineStrike extends TeamGame
"Burst Fire for greater accuracy",
"Sniper Rifles are only accurate while scoped",
"Rifles have 30% recoil reduction while scoped",
"Pick up better weapons from dead players"
};
}

View File

@ -140,8 +140,8 @@ public abstract class Grenade extends StrikeItem
*/
//X Rebound
if ((_vel.getX() > 0 && ent.getLocation().getX() - _lastLoc.getX() <= 0) ||
(_vel.getX() < 0 && ent.getLocation().getX() - _lastLoc.getX() >= 0))
if ((_vel.getX() > 0.05 && ent.getLocation().getX() - _lastLoc.getX() <= 0) ||
(_vel.getX() < 0.05 && ent.getLocation().getX() - _lastLoc.getX() >= 0))
{
_vel = _velHistory.get(0);
_vel.setX(-_vel.getX());
@ -153,8 +153,8 @@ public abstract class Grenade extends StrikeItem
}
//Z Rebound
else if ((_vel.getZ() > 0 && ent.getLocation().getZ() - _lastLoc.getZ() <= 0) ||
(_vel.getZ() < 0 && ent.getLocation().getZ() - _lastLoc.getZ() >= 0))
else if ((_vel.getZ() > 0.05 && ent.getLocation().getZ() - _lastLoc.getZ() <= 0) ||
(_vel.getZ() < 0.05 && ent.getLocation().getZ() - _lastLoc.getZ() >= 0))
{
_vel = _velHistory.get(0);
_vel.setZ(-_vel.getZ());

View File

@ -34,8 +34,7 @@ public class HighExplosive extends Grenade
ent.getWorld().playSound(ent.getLocation(),
Sound.EXPLODE, 3f, 0.8f);
HashMap<Player, Double> players = UtilPlayer.getInRadius(
ent.getLocation(), 8);
HashMap<Player, Double> players = UtilPlayer.getInRadius(ent.getLocation(), 10);
for (Player player : players.keySet())
{
if (!game.IsAlive(player))

View File

@ -50,7 +50,7 @@ public abstract class OrderCraft extends Order
if (event.getSlotType() != SlotType.RESULT)
return;
if (!UtilInv.IsItem(event.getCurrentItem(), _id, _data))
if (!UtilInv.IsItem(event.getCurrentItem(), null, _id, _data))
return;
if (!(event.getWhoClicked() instanceof Player))

View File

@ -45,7 +45,7 @@ public abstract class OrderGather extends Order
@EventHandler
public void Pickup(PlayerPickupItemEvent event)
{
if (!UtilInv.IsItem(event.getItem().getItemStack(), _id, _data))
if (!UtilInv.IsItem(event.getItem().getItemStack(), null, _id, _data))
return;
if (Has(event.getPlayer()))

View File

@ -14,9 +14,12 @@ import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -45,6 +48,22 @@ public class PerkFletcher extends Perk
_max = max;
_remove = remove;
}
public boolean isFletchedArrow(ItemStack stack)
{
if (!UtilGear.isMat(stack, Material.ARROW))
return false;
ItemMeta meta = stack.getItemMeta();
if (meta.getDisplayName() == null)
return false;
if (!meta.getDisplayName().contains("Fletched Arrow"))
return false;
return true;
}
@EventHandler
public void FletchShootBow(EntityShootBowEvent event)
@ -58,12 +77,11 @@ public class PerkFletcher extends Perk
return;
for (int i=0 ; i<=8 ; i++)
if (player.getInventory().getItem(i) != null)
if (UtilInv.IsItem(player.getInventory().getItem(i), Material.ARROW, (byte)1))
{
_fletchArrows.add(event.getProjectile());
return;
}
if (isFletchedArrow(player.getInventory().getItem(i)))
{
_fletchArrows.add(event.getProjectile());
return;
}
}
@EventHandler
@ -94,11 +112,11 @@ public class PerkFletcher extends Perk
if (!Recharge.Instance.use(cur, GetName(), _time * 1000, false, false))
continue;
if (UtilInv.contains(cur, Material.ARROW, (byte)1, _max))
if (UtilInv.contains(cur, "Fletched Arrow", Material.ARROW, (byte)0, _max))
continue;
//Add
cur.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)1, 1, F.item("Fletched Arrow")));
cur.getInventory().addItem(ItemStackFactory.Instance.CreateStack(262, (byte)0, 1, F.item("Fletched Arrow")));
cur.playSound(cur.getLocation(), Sound.ITEM_PICKUP, 2f, 1f);
}
@ -110,7 +128,7 @@ public class PerkFletcher extends Perk
if (event.isCancelled())
return;
if (!UtilInv.IsItem(event.getItemDrop().getItemStack(), Material.ARROW, (byte)1))
if (!isFletchedArrow(event.getItemDrop().getItemStack()))
return;
//Cancel
@ -126,7 +144,7 @@ public class PerkFletcher extends Perk
HashSet<org.bukkit.inventory.ItemStack> remove = new HashSet<org.bukkit.inventory.ItemStack>();
for (org.bukkit.inventory.ItemStack item : event.getDrops())
if (UtilInv.IsItem(item, Material.ARROW, (byte)1))
if (isFletchedArrow(item))
remove.add(item);
for (org.bukkit.inventory.ItemStack item : remove)
@ -136,7 +154,7 @@ public class PerkFletcher extends Perk
@EventHandler
public void FletchInvClick(InventoryClickEvent event)
{
UtilInv.DisallowMovementOf(event, "Fletched Arrow", Material.ARROW, (byte)1, true);
UtilInv.DisallowMovementOf(event, "Fletched Arrow", Material.ARROW, (byte)0, true);
}
@EventHandler