mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-27 04:25:21 +01:00
sorted listeners properly
This commit is contained in:
parent
24addc076a
commit
32237003c5
@ -200,6 +200,8 @@ public class UltimateStacker extends JavaPlugin {
|
||||
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new ShearListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new InteractListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new InventoryListeners(this), this);
|
||||
Bukkit.getPluginManager().registerEvents(new EntityListeners(this), this);
|
||||
|
||||
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::saveToFile, 6000, 6000);
|
||||
|
@ -0,0 +1,47 @@
|
||||
package com.songoda.ultimatestacker.events;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
|
||||
private final UltimateStacker instance;
|
||||
|
||||
public EntityListeners(UltimateStacker instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPickup(PlayerPickupItemEvent event) {
|
||||
event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true));
|
||||
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
|
||||
int amt = item.getAmount();
|
||||
int max = item.getMaxStackSize();
|
||||
|
||||
if (amt <= max) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
item.setAmount(max);
|
||||
amt = amt - max;
|
||||
|
||||
while (amt > max) {
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(max);
|
||||
|
||||
event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem);
|
||||
amt = amt - max;
|
||||
}
|
||||
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(amt);
|
||||
|
||||
event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem);
|
||||
}
|
||||
|
||||
}
|
@ -24,66 +24,6 @@ public class InteractListeners implements Listener {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAccept(InventoryPickupItemEvent event) {
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
if (new ItemStack(item.getType()).getMaxStackSize() == item.getMaxStackSize()) return;
|
||||
|
||||
instance.getStackingTask().setMax(item, 0, true);
|
||||
int amt = item.getAmount();
|
||||
int max = item.getMaxStackSize();
|
||||
|
||||
if (amt <= max) return;
|
||||
|
||||
item.setAmount(max);
|
||||
amt = amt - max;
|
||||
|
||||
while (amt > max) {
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(max);
|
||||
|
||||
event.getInventory().addItem(newItem);
|
||||
amt = amt - max;
|
||||
}
|
||||
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(amt);
|
||||
|
||||
event.getInventory().addItem(newItem);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPickup(PlayerPickupItemEvent event) {
|
||||
event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true));
|
||||
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
|
||||
int amt = item.getAmount();
|
||||
int max = item.getMaxStackSize();
|
||||
|
||||
if (amt <= max) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
item.setAmount(max);
|
||||
amt = amt - max;
|
||||
|
||||
while (amt > max) {
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(max);
|
||||
|
||||
event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem);
|
||||
amt = amt - max;
|
||||
}
|
||||
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(amt);
|
||||
|
||||
event.getItem().getWorld().dropItemNaturally(event.getItem().getLocation(), newItem);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.songoda.ultimatestacker.events;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InventoryListeners implements Listener {
|
||||
|
||||
private final UltimateStacker instance;
|
||||
|
||||
public InventoryListeners(UltimateStacker instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAccept(InventoryPickupItemEvent event) {
|
||||
ItemStack item = event.getItem().getItemStack();
|
||||
if (new ItemStack(item.getType()).getMaxStackSize() == item.getMaxStackSize()) return;
|
||||
|
||||
instance.getStackingTask().setMax(item, 0, true);
|
||||
int amt = item.getAmount();
|
||||
int max = item.getMaxStackSize();
|
||||
|
||||
if (amt <= max) return;
|
||||
|
||||
item.setAmount(max);
|
||||
amt = amt - max;
|
||||
|
||||
while (amt > max) {
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(max);
|
||||
|
||||
event.getInventory().addItem(newItem);
|
||||
amt = amt - max;
|
||||
}
|
||||
|
||||
ItemStack newItem = new ItemStack(item);
|
||||
newItem.setAmount(amt);
|
||||
|
||||
event.getInventory().addItem(newItem);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user