Skip to content

Commit

Permalink
refactor dataValueMatters boolean
Browse files Browse the repository at this point in the history
as it is no longer used in itemsAreSimilar
  • Loading branch information
RoboMWM committed Oct 19, 2019
1 parent cc05d1c commit e378326
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/me/ryanhamshire/AutomaticInventory/AIEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class AIEventHandler implements Listener
{
private EquipmentSlot getSlotWithItemStack(PlayerInventory inventory, ItemStack brokenItem)
{
if(itemsAreSimilar(inventory.getItemInMainHand(), brokenItem, false))
if(itemsAreSimilar(inventory.getItemInMainHand(), brokenItem))
{
return EquipmentSlot.HAND;
}
if(itemsAreSimilar(inventory.getItemInOffHand(), brokenItem, false))
if(itemsAreSimilar(inventory.getItemInOffHand(), brokenItem))
{
return EquipmentSlot.OFF_HAND;
}
Expand All @@ -53,14 +53,14 @@ public void onToolBreak(PlayerItemBreakEvent event)
PlayerInventory inventory = player.getInventory();
EquipmentSlot slot = this.getSlotWithItemStack(inventory, event.getBrokenItem());

tryRefillStackInHand(player, slot, false);
tryRefillStackInHand(player, slot);
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event)
{
Player player = event.getPlayer();
tryRefillStackInHand(player, event.getHand(), true);
tryRefillStackInHand(player, event.getHand());
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
Expand All @@ -69,7 +69,7 @@ public void onFertilize(BlockFertilizeEvent event)
Player player = event.getPlayer();
PlayerInventory inventory = player.getInventory();
EquipmentSlot slot = this.getSlotWithItemStack(inventory, new ItemStack(Material.BONE_MEAL));
tryRefillStackInHand(player, slot, true);
tryRefillStackInHand(player, slot);
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
Expand All @@ -78,7 +78,7 @@ public void onConsumeItem(PlayerItemConsumeEvent event)
Player player = event.getPlayer();
PlayerInventory inventory = player.getInventory();
EquipmentSlot slot = this.getSlotWithItemStack(inventory, event.getItem());
tryRefillStackInHand(player, slot, true);
tryRefillStackInHand(player, slot);
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
Expand All @@ -88,24 +88,24 @@ public void onProjectileLaunch(ProjectileLaunchEvent event)
if(!(source instanceof Player)) return;

Player player = (Player)source;
tryRefillStackInHand(player, EquipmentSlot.HAND, false);
tryRefillStackInHand(player, EquipmentSlot.HAND);
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onFeedAnimal(PlayerInteractEntityEvent event)
{
Player player = event.getPlayer();
tryRefillStackInHand(player, event.getHand(), true);
tryRefillStackInHand(player, event.getHand());
}

private void tryRefillStackInHand(Player player, EquipmentSlot slot, boolean dataValueMatters)
private void tryRefillStackInHand(Player player, EquipmentSlot slot)
{
if(slot == null) return;

if(!featureEnabled(Features.RefillStacks, player)) return;

ItemStack stack = null;
int slotIndex = 0;
ItemStack stack;
int slotIndex;
if(slot == EquipmentSlot.HAND)
{
stack = player.getInventory().getItemInMainHand();
Expand All @@ -122,12 +122,12 @@ else if(slot == EquipmentSlot.OFF_HAND)
}

if (AutomaticInventory.instance.config_noAutoRefill.contains(stack.getType())) return;
if(!dataValueMatters || stack.getAmount() == 1)
if(stack.getAmount() == 1)
{
PlayerInventory inventory = player.getInventory();
AutomaticInventory.instance.getServer().getScheduler().scheduleSyncDelayedTask(
AutomaticInventory.instance,
new AutoRefillHotBarTask(player, inventory, slotIndex, stack.clone(), dataValueMatters),
new AutoRefillHotBarTask(player, inventory, slotIndex, stack.clone()),
2L);
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ static boolean featureEnabled(Features feature, Player player)
return false;
}

private static boolean itemsAreSimilar(ItemStack a, ItemStack b, boolean dataValueMatters)
private static boolean itemsAreSimilar(ItemStack a, ItemStack b)
{
if(a.getType() == b.getType())
{
Expand Down Expand Up @@ -194,15 +194,13 @@ class AutoRefillHotBarTask implements Runnable
private PlayerInventory targetInventory;
private int slotToRefill;
private ItemStack stackToReplace;
private boolean dataValueMatters;

public AutoRefillHotBarTask(Player player, PlayerInventory targetInventory, int slotToRefill, ItemStack stackToReplace, boolean dataValueMatters)

public AutoRefillHotBarTask(Player player, PlayerInventory targetInventory, int slotToRefill, ItemStack stackToReplace)
{
this.player = player;
this.targetInventory = targetInventory;
this.slotToRefill = slotToRefill;
this.stackToReplace = stackToReplace;
this.dataValueMatters = dataValueMatters;
}

@Override
Expand All @@ -218,7 +216,7 @@ public void run()
{
ItemStack itemInSlot = this.targetInventory.getItem(i);
if(itemInSlot == null) continue;
if(itemsAreSimilar(itemInSlot, this.stackToReplace, dataValueMatters))
if(itemsAreSimilar(itemInSlot, this.stackToReplace))
{
int stackSize = itemInSlot.getAmount();
if(stackSize < bestMatchStackSize)
Expand Down

0 comments on commit e378326

Please sign in to comment.