SteamWar/BauSystem2.0
Archiviert
12
0

Fix SmartPlaceListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-10-03 23:02:11 +02:00
Ursprung 19b99ae8a0
Commit fc8d52cae4

Datei anzeigen

@ -37,6 +37,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@Linked(LinkageType.LISTENER) @Linked(LinkageType.LISTENER)
public class SmartPlaceListener implements Listener { public class SmartPlaceListener implements Listener {
@ -62,9 +64,11 @@ public class SmartPlaceListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
// Reverse repeater
if (event.getPlayer().isSneaking()) { if (event.getPlayer().isSneaking()) {
if (event.getClickedBlock().getType() == Material.REPEATER) { if (event.getClickedBlock().getType() == Material.REPEATER) {
if (event.getItem() != null && event.getMaterial() != Material.REPEATER) { if (event.getItem() != null && event.getMaterial() != Material.REPEATER) {
@ -79,8 +83,8 @@ public class SmartPlaceListener implements Listener {
} }
return; return;
} }
if (!event.getClickedBlock().getType().isInteractable()) return;
if (!event.getClickedBlock().getType().isInteractable()) return;
if (event.getItem() == null) return; if (event.getItem() == null) return;
if (!event.getMaterial().isBlock()) return; if (!event.getMaterial().isBlock()) return;
try { try {
@ -93,24 +97,20 @@ public class SmartPlaceListener implements Listener {
} }
if (event.getClickedBlock().getType() == event.getMaterial()) { if (event.getClickedBlock().getType() == event.getMaterial()) {
switch (event.getMaterial()) { if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) {
case HOPPER:
case DISPENSER:
case DROPPER:
break;
default:
return; return;
} }
} else { } else {
switch (event.getMaterial()) { BlockData blockData = event.getMaterial().createBlockData();
case REPEATER: if (blockData instanceof Directional) {
case COMPARATOR: return;
}
if (blockData instanceof Rotatable) {
return; return;
default:
break;
} }
} }
// TODO: Fix block setting
event.setUseInteractedBlock(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY);
World world = event.getPlayer().getWorld(); World world = event.getPlayer().getWorld();
Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ()); Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ());