commit
7967c1dbe2
@ -19,8 +19,6 @@ import org.bukkit.event.player.PlayerItemHeldEvent;
|
|||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author 坏黑
|
* @Author 坏黑
|
||||||
* @Since 2019-05-21 18:16
|
* @Since 2019-05-21 18:16
|
||||||
@ -37,8 +35,20 @@ class ClickListener implements Listener {
|
|||||||
public void e(InventoryOpenEvent e) {
|
public void e(InventoryOpenEvent e) {
|
||||||
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
||||||
if (builder != null) {
|
if (builder != null) {
|
||||||
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> builder.getBuildTask().run(e.getInventory()), 1);
|
Bukkit.getScheduler().runTaskLater(TabooLib.getPlugin(), () -> {
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(TabooLib.getPlugin(), () -> builder.getBuildTaskAsync().run(e.getInventory()), 1);
|
try {
|
||||||
|
builder.getBuildTask().run(e.getInventory());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(TabooLib.getPlugin(), () -> {
|
||||||
|
try {
|
||||||
|
builder.getBuildTaskAsync().run(e.getInventory());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +60,11 @@ class ClickListener implements Listener {
|
|||||||
if (builder.isLockHand() && (e.getRawSlot() - e.getInventory().getSize() - 27 == e.getWhoClicked().getInventory().getHeldItemSlot() || (e.getClick() == org.bukkit.event.inventory.ClickType.NUMBER_KEY && e.getHotbarButton() == e.getWhoClicked().getInventory().getHeldItemSlot()))) {
|
if (builder.isLockHand() && (e.getRawSlot() - e.getInventory().getSize() - 27 == e.getWhoClicked().getInventory().getHeldItemSlot() || (e.getClick() == org.bukkit.event.inventory.ClickType.NUMBER_KEY && e.getHotbarButton() == e.getWhoClicked().getInventory().getHeldItemSlot()))) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
Optional.ofNullable(builder.getClickTask()).ifPresent(t -> t.run(new ClickEvent(ClickType.CLICK, e, builder.getSlot(e.getRawSlot()))));
|
try {
|
||||||
|
builder.getClickTask().run(new ClickEvent(ClickType.CLICK, e, builder.getSlot(e.getRawSlot())));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
// drop on empty area
|
// drop on empty area
|
||||||
if (!e.isCancelled() && Items.nonNull(e.getCurrentItem()) && e.getClick() == org.bukkit.event.inventory.ClickType.DROP) {
|
if (!e.isCancelled() && Items.nonNull(e.getCurrentItem()) && e.getClick() == org.bukkit.event.inventory.ClickType.DROP) {
|
||||||
Item item = Vectors.itemDrop((Player) e.getWhoClicked(), e.getCurrentItem());
|
Item item = Vectors.itemDrop((Player) e.getWhoClicked(), e.getCurrentItem());
|
||||||
@ -82,7 +96,11 @@ class ClickListener implements Listener {
|
|||||||
public void e(InventoryDragEvent e) {
|
public void e(InventoryDragEvent e) {
|
||||||
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
||||||
if (builder != null) {
|
if (builder != null) {
|
||||||
|
try {
|
||||||
builder.getClickTask().run(new ClickEvent(ClickType.DRAG, e, ' '));
|
builder.getClickTask().run(new ClickEvent(ClickType.DRAG, e, ' '));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +108,11 @@ class ClickListener implements Listener {
|
|||||||
public void e(InventoryCloseEvent e) {
|
public void e(InventoryCloseEvent e) {
|
||||||
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
MenuBuilder builder = MenuHolder.get(e.getInventory());
|
||||||
if (builder != null) {
|
if (builder != null) {
|
||||||
|
try {
|
||||||
builder.getCloseTask().run(e);
|
builder.getCloseTask().run(e);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user