Skip to content

Commit

Permalink
fix: 修复 NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Oct 4, 2024
1 parent 7634b4f commit 2b54310
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<dependency>
<groupId>com.github.Slimefun</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-28</version>
<version>RC-37</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand All @@ -102,7 +102,7 @@
<dependency>
<groupId>net.guizhanss</groupId>
<artifactId>GuizhanLibPlugin</artifactId>
<version>1.7.0</version>
<version>1.8.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public EnderCargoAdvancedOutput(EnderCargo enderCargo) {
public void onDispense(BlockDispenseEvent event) {
if (event.getBlock().getType() == blockMaterial) {
Dispenser d = (Dispenser) event.getBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(d.getCustomName()))
event.setCancelled(true);
}
}
Expand All @@ -38,7 +38,7 @@ public void onDispense(BlockDispenseEvent event) {
public void onBreak(BlockBreakEvent event) {
if (event.getBlock().getType() == blockMaterial) {
Dispenser d = (Dispenser) event.getBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(blockName)) {
if (blockName.equalsIgnoreCase(d.getCustomName())) {
Container container = (Container) event.getBlock().getState();
container.getInventory().clear();
EnderCargoData.unlinkCargo(event.getBlock().getLocation());
Expand All @@ -50,11 +50,11 @@ public void onBreak(BlockBreakEvent event) {
public void onMove(InventoryMoveItemEvent event) {
if (event.getSource().getType() == InventoryType.HOPPER && event.getDestination().getType() == InventoryType.DISPENSER) {
Container destinationContainer = (Container) event.getDestination().getHolder();
if (destinationContainer.getCustomName() != null && destinationContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(destinationContainer.getCustomName()))
event.setCancelled(true);
} else if (event.getDestination().getType() == InventoryType.HOPPER && event.getSource().getType() == InventoryType.DISPENSER) {
Container sourceContainer = (Container) event.getSource().getHolder();
if (sourceContainer.getCustomName() != null && sourceContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(sourceContainer.getCustomName()))
event.setCancelled(true);
}
}
Expand All @@ -72,7 +72,7 @@ public void onInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!event.getPlayer().isSneaking() || event.getItem() == null) {
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName)) {
if (blockName.equalsIgnoreCase(container.getCustomName())) {
event.setCancelled(true);
Inventory inventory = Bukkit.createInventory(null, InventoryType.DISPENSER, "§3末影节点视图 (输出)");
inventory.setContents(container.getInventory().getContents());
Expand All @@ -82,7 +82,7 @@ public void onInteract(PlayerInteractEvent event) {
if (event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasDisplayName()) {
String displayName = event.getItem().getItemMeta().getDisplayName();
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(container.getCustomName()))
if (displayName.equalsIgnoreCase("§7节点模式 §c(输出)") || displayName.equalsIgnoreCase("§6高级节点模式 §c(输出)"))
event.setCancelled(true);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/fr/birdo/endercargo/items/EnderCargoInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public EnderCargoInput(EnderCargo enderCargo) {
public void onDispense(BlockDispenseEvent event) {
if (event.getBlock().getType() == blockMaterial) {
Dispenser d = (Dispenser) event.getBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(d.getCustomName()))
event.setCancelled(true);
}
}
Expand All @@ -39,7 +39,7 @@ public void onDispense(BlockDispenseEvent event) {
public void onBreak(BlockBreakEvent event) {
if (event.getBlock().getType() == blockMaterial) {
Dispenser d = (Dispenser) event.getBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(blockName)) {
if (blockName.equalsIgnoreCase(d.getCustomName())) {
for (String string : EnderCargoData.getLinkedCargo()) {
String[] str = string.split(" ");
Location location = new Location(Bukkit.getWorld(str[0]), Integer.parseInt(str[1]), Integer.parseInt(str[2]), Integer.parseInt(str[3]));
Expand All @@ -57,11 +57,11 @@ public void onBreak(BlockBreakEvent event) {
public void onMove(InventoryMoveItemEvent event) {
if (event.getSource().getType() == InventoryType.HOPPER && event.getDestination().getType() == InventoryType.DISPENSER) {
Container destinationContainer = (Container) event.getDestination().getHolder();
if (destinationContainer.getCustomName() != null && destinationContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(destinationContainer.getCustomName()))
event.setCancelled(true);
} else if (event.getDestination().getType() == InventoryType.HOPPER && event.getSource().getType() == InventoryType.DISPENSER) {
Container sourceContainer = (Container) event.getSource().getHolder();
if (sourceContainer.getCustomName() != null && sourceContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(sourceContainer.getCustomName()))
event.setCancelled(true);
}
}
Expand All @@ -79,7 +79,7 @@ public void onInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!event.getPlayer().isSneaking() || event.getItem() == null) {
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName)) {
if (blockName.equalsIgnoreCase(container.getCustomName())) {
event.setCancelled(true);
Inventory inventory = Bukkit.createInventory(null, InventoryType.DISPENSER, "§3末影节点视图 (输入)");
inventory.setContents(container.getInventory().getContents());
Expand All @@ -89,7 +89,7 @@ public void onInteract(PlayerInteractEvent event) {
if (event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasDisplayName()) {
String displayName = event.getItem().getItemMeta().getDisplayName();
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(container.getCustomName()))
if (displayName.equalsIgnoreCase("§7节点模式 §c(输入)"))
event.setCancelled(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/birdo/endercargo/items/EnderCargoLinker.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onClick(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().isSneaking()) {
if (event.getClickedBlock().getType() == Material.DISPENSER) {
Dispenser d = (Dispenser) event.getClickedBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(EnderCargoInput.blockName)) {//Ender Input
if (EnderCargoInput.blockName.equalsIgnoreCase(d.getCustomName())) {//Ender Input
boolean linked = false;
for (String string : EnderCargoData.getLinkedCargo()) {
String[] str = string.split(" ");
Expand All @@ -51,7 +51,7 @@ public void onClick(PlayerInteractEvent event) {
event.getPlayer().sendMessage(ChatColor.GREEN + "输入选定的末影节点!");
}
}
if (d.getCustomName().equalsIgnoreCase(EnderCargoOutput.blockName) || d.getCustomName().equalsIgnoreCase(EnderCargoAdvancedOutput.blockName)) {//Output
if (EnderCargoOutput.blockName.equalsIgnoreCase(d.getCustomName()) || EnderCargoAdvancedOutput.blockName.equalsIgnoreCase(d.getCustomName())) {//Output
boolean linked = false;
if (input.get(event.getPlayer()) == null) {
event.getPlayer().sendMessage(ChatColor.RED + "请输入下一个末影节点!");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fr/birdo/endercargo/items/EnderCargoOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onDispense(BlockDispenseEvent event) {
public void onBreak(BlockBreakEvent event) {
if (event.getBlock().getType() == blockMaterial) {
Dispenser d = (Dispenser) event.getBlock().getState();
if (d.getCustomName() != null && d.getCustomName().equalsIgnoreCase(blockName)) {
if (blockName.equalsIgnoreCase(d.getCustomName())) {
Container container = (Container) event.getBlock().getState();
container.getInventory().clear();
EnderCargoData.unlinkCargo(event.getBlock().getLocation());
Expand All @@ -51,11 +51,11 @@ public void onBreak(BlockBreakEvent event) {
public void onMove(InventoryMoveItemEvent event) {
if (event.getSource().getType() == InventoryType.HOPPER && event.getDestination().getType() == InventoryType.DISPENSER) {
Container destinationContainer = (Container) event.getDestination().getHolder();
if (destinationContainer.getCustomName() != null && destinationContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(destinationContainer.getCustomName()))
event.setCancelled(true);
} else if (event.getDestination().getType() == InventoryType.HOPPER && event.getSource().getType() == InventoryType.DISPENSER) {
Container sourceContainer = (Container) event.getSource().getHolder();
if (sourceContainer.getCustomName() != null && sourceContainer.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(sourceContainer.getCustomName()))
event.setCancelled(true);
}
}
Expand All @@ -67,13 +67,13 @@ public void onInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!event.getPlayer().isSneaking() || event.getItem() == null) {
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(container.getCustomName()))
event.setCancelled(true);
} else if (event.getPlayer().isSneaking() && event.getItem() != null) {
if (event.getItem().hasItemMeta() && event.getItem().getItemMeta().hasDisplayName()) {
String displayName = event.getItem().getItemMeta().getDisplayName();
Container container = (Container) event.getClickedBlock().getState();
if (container.getCustomName() != null && container.getCustomName().equalsIgnoreCase(blockName))
if (blockName.equalsIgnoreCase(container.getCustomName()))
if (displayName.equalsIgnoreCase("§7节点模式 §c(输出)") || displayName.equalsIgnoreCase("§6高级节点模式 §c(输出)"))
event.setCancelled(true);
}
Expand Down

0 comments on commit 2b54310

Please sign in to comment.