SteamWar/BauSystem2.0
Archiviert
12
0

Fix TNTSimulatorListener

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-10 12:35:31 +02:00
Ursprung ba4d8e5a28
Commit 0811f41b45

Datei anzeigen

@ -32,12 +32,18 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.BoundingBox; import org.bukkit.util.BoundingBox;
import org.bukkit.util.RayTraceResult; import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.function.Function;
import static de.steamwar.bausystem.features.simulator.TNTSimulator.WAND; import static de.steamwar.bausystem.features.simulator.TNTSimulator.WAND;
import static de.steamwar.bausystem.features.simulator.TNTSimulator.get; import static de.steamwar.bausystem.features.simulator.TNTSimulator.get;
@ -88,14 +94,22 @@ public class TNTSimulatorListener implements Listener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {
Player player = e.getPlayer(); simulatorShowHide(e.getPlayer(), PlayerInventory::getItemInMainHand, e.getTo());
}
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
}
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> itemStackFunction, Location location) {
TNTSimulator simulator = get(player); TNTSimulator simulator = get(player);
if (!player.getInventory().getItemInMainHand().isSimilar(WAND)) { if (!itemStackFunction.apply(player.getInventory()).isSimilar(WAND)) {
simulator.hide(); simulator.hide();
return; return;
} }
simulator.show(trace(player, e.getTo())); simulator.show(trace(player, location));
} }
@EventHandler @EventHandler