diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/worldedit/SteamEditWand.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/worldedit/SteamEditWand.java index cb478827..eb1f180a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/worldedit/SteamEditWand.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/worldedit/SteamEditWand.java @@ -30,16 +30,13 @@ import com.sk89q.worldedit.regions.selector.limit.PermissiveSelectorLimits; import com.sk89q.worldedit.world.World; import de.steamwar.core.Core; import de.steamwar.core.SWPlayer; -import de.steamwar.entity.CWireframe; -import de.steamwar.entity.REntityServer; import de.steamwar.inventory.SWItem; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; -import org.bukkit.Bukkit; -import org.bukkit.FluidCollisionMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -47,6 +44,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.RayTraceResult; @@ -65,6 +63,16 @@ public class SteamEditWand implements Listener { }; public static final ItemStack ITEM = new SWItem(MATERIAL, NAME).setLore(LORE).getItemStack(); + static { + ItemMeta itemMeta = ITEM.getItemMeta(); + itemMeta.addAttributeModifier(Attribute.BLOCK_INTERACTION_RANGE, new AttributeModifier( + NamespacedKey.fromString("range", Core.getInstance()), + 35.0, + AttributeModifier.Operation.ADD_NUMBER + )); + ITEM.setItemMeta(itemMeta); + } + private boolean noWand(Player player) { return player.getInventory().getItemInMainHand().getType() != SteamEditWand.MATERIAL; } @@ -87,15 +95,6 @@ public class SteamEditWand implements Listener { TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::rightClick); TinyProtocol.instance.addFilter(ServerboundPickItemFromBlockPacket.class, this::middleClick); TinyProtocol.instance.addFilter(ServerboundPlayerActionPacket.class, this::swapHands); - TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, this::movePlayerPacket); - TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Rot.class, this::movePlayerPacket); - TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, this::movePlayerPacket); - - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { - for (Player player : Bukkit.getOnlinePlayers()) { - if (noWand(player)) SWPlayer.of(player).removeComponent(SWEditCursor.class); - } - }, 1, 1); } @EventHandler @@ -104,29 +103,6 @@ public class SteamEditWand implements Listener { event.setCancelled(true); } - public static class SWEditCursor implements SWPlayer.Component { - private Player player; - private REntityServer entityServer = new REntityServer(); - private CWireframe wireframe; - - @Override - public void onMount(SWPlayer player) { - this.player = player.getPlayer(); - entityServer.addPlayer(player.getPlayer()); - wireframe = new CWireframe(entityServer); - } - - @Override - public void onUnmount(SWPlayer player) { - entityServer.close(); - } - - public void setLocation(Location location) { - wireframe.setPos1And2(location, location); - wireframe.setBlock(WorldEditRendererCUIEditor.Type.CURSOR.getMaterial(player).createBlockData()); - } - } - private Packet leftClick(Player player, Packet packet) { if (noWand(player)) return packet; if (player.getOpenInventory().getType() != InventoryType.CREATIVE) return packet; @@ -380,30 +356,4 @@ public class SteamEditWand implements Listener { }); return null; } - - public ServerboundMovePlayerPacket movePlayerPacket(Player player, ServerboundMovePlayerPacket packet) { - SWPlayer swPlayer = SWPlayer.of(player); - - if (noWand(player)) { - swPlayer.removeComponent(SWEditCursor.class); - return packet; - } - - double distance = WorldEditRendererCUIEditor.Type.CURSOR.getWidth(player).blocks; - RayTraceResult result = player.rayTraceBlocks(distance, FluidCollisionMode.NEVER); - Block block = result == null ? null : result.getHitBlock(); - if (result == null || block == null) { - swPlayer.removeComponent(SWEditCursor.class); - return packet; - } - - if (!swPlayer.hasComponent(SWEditCursor.class)) { - swPlayer.setComponent(new SWEditCursor()); - } - - swPlayer.getComponent(SWEditCursor.class).ifPresent(cursor -> { - cursor.setLocation(block.getLocation()); - }); - return packet; - } }