Skip to content

Commit

Permalink
fix: 修复递归Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0XPYEX0 committed Aug 5, 2024
1 parent 45ed13b commit 84b2c14
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ public class DynamicLight extends RootModule {
private static final String[] LIGHTS = {"LANTERN", "TORCH", "GLOW", "ShroomLight", "FrogLight", "END_ROD", "CampFire", "LAVA"};
private static BlockData LIGHT_DATA;

@Override
public void registerCustomListener() {
registerTask();
//
}

@Override
protected boolean canLoad() {
try {
Block.class.getMethod("getBlockData"); //1.13+
Material light = Material.getMaterial("LIGHT"); //1.17的光源方块.
LIGHT_DATA = Bukkit.createBlockData(light != null ? light : Material.TORCH); //除了火把外的大部分光源都有碰撞箱,所以选火把
registerTask();
return true;
} catch (NoSuchMethodError | NoSuchMethodException ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ public class QuickShulkerBox extends RootModule {
@EventHandler(ignoreCancelled = true)
public void onInvClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) return;
if (serverEnabled()) {
if (playerEnabled((Player) event.getWhoClicked())) {
if (event.isShiftClick() && event.isRightClick()) {
if (event.getCursor() != null || event.getCursor().getType() != Material.AIR)
return;
if (event.getCurrentItem() == null) return;
if (event.getCurrentItem().getAmount() != 1) return;
ItemMeta meta = event.getCurrentItem().getItemMeta();
if (meta instanceof BlockStateMeta) { //此处同时判断 != null
BlockState state = ((BlockStateMeta) meta).getBlockState();
if (state instanceof ShulkerBox) {
event.setCancelled(true);
if (serverEnabled() && playerEnabled((Player) event.getWhoClicked())) {
if (event.isShiftClick() && event.isRightClick()) {
if (event.getCursor() != null || event.getCursor().getType() != Material.AIR)
return;
if (event.getCurrentItem() == null) return;
if (event.getCurrentItem().getAmount() != 1) return;
ItemMeta meta = event.getCurrentItem().getItemMeta();
if (meta instanceof BlockStateMeta) { //此处同时判断 != null
BlockState state = ((BlockStateMeta) meta).getBlockState();
if (state instanceof ShulkerBox) {
event.setCancelled(true);
Inventory boxInv = ((ShulkerBox) state).getInventory();
try {
event.getWhoClicked().openInventory(boxInv);
} catch (Throwable e) {
Inventory inventory = Bukkit.createInventory(event.getWhoClicked(), 27);
inventory.setContents(((ShulkerBox) state).getInventory().getContents());
inventory.setContents(boxInv.getContents());
event.getWhoClicked().openInventory(inventory);
event.getWhoClicked().setMetadata(METADATA_KEY, new FixedMetadataValue(InvActions.getInstance(), event.getCurrentItem()));
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 1f, 1f);
}
event.getWhoClicked().setMetadata(METADATA_KEY, new FixedMetadataValue(InvActions.getInstance(), event.getCurrentItem()));
((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 1f, 1f);
}
}
}
Expand All @@ -50,23 +53,25 @@ public void onInvClick(InventoryClickEvent event) {

@EventHandler
public void onRightClick(PlayerInteractEvent event) {
if (!serverEnabled()) {
return;
}
if (!playerEnabled(event.getPlayer())) {
if (!serverEnabled() || !playerEnabled(event.getPlayer())) {
return;
}
if (event.getPlayer().isSneaking() && event.getAction().toString().startsWith("RIGHT_")) {
if (event.getItem() != null && event.getItem().hasItemMeta()) {
if (event.getItem() != null) {
if (event.getItem().getAmount() != 1) return;
ItemMeta meta = event.getItem().getItemMeta();
if (meta instanceof BlockStateMeta) {
if (meta instanceof BlockStateMeta) { //判断not null
BlockState state = ((BlockStateMeta) meta).getBlockState();
if (state instanceof ShulkerBox) {
event.setCancelled(true);
Inventory inventory = Bukkit.createInventory(event.getPlayer(), 27);
inventory.setContents(((ShulkerBox) state).getInventory().getContents());
event.getPlayer().openInventory(inventory);
Inventory boxInv = ((ShulkerBox) state).getInventory();
try {
event.getPlayer().openInventory(boxInv);
} catch (Throwable e) {
Inventory inventory = Bukkit.createInventory(event.getPlayer(), 27);
inventory.setContents(boxInv.getContents());
event.getPlayer().openInventory(inventory);
}
event.getPlayer().setMetadata(METADATA_KEY, new FixedMetadataValue(InvActions.getInstance(), event.getItem()));
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_SHULKER_BOX_OPEN, 1f, 1f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public class RootModule implements Listener {
ValueUtil.ifPresent(LangUtil.getMessage(InvActions.getInstance(), "ActionBarSuffix"), s -> SETTING_HELP = s);
}

public void registerCustomListener() {}

public RootModule() {
if (canLoad()) {
try {
InvActions.getInstance().registerListener(this);
registerCustomListener();
} catch (Throwable e) {
InvActions.getInstance().getLogger().severe("无法为模块 " + getName() + " 注册监听器: " + e);
e.printStackTrace();
Expand Down

0 comments on commit 84b2c14

Please sign in to comment.