diff --git a/BauSystem_15/src/de/steamwar/bausystem/entities/DetonatorEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/entities/DetonatorEntity15.java deleted file mode 100644 index efbd29d8..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/entities/DetonatorEntity15.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class DetonatorEntity15 extends EntityFallingBlock implements AbstractDetonatorEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private final Vector position; - private int references = 0; - - public DetonatorEntity15(World world, Vector position) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.RED_STAINED_GLASS.getBlockData()); - this.position = position; - - this.h(true); - this.setNoGravity(true); - this.ticksLived = -12000; - } - - @Override - public void display(Player player) { - if (references++ > 0) - return; - - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.RED_STAINED_GLASS.getBlockData()), ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && --references > 0) - return false; - - sendDestroy(player); - die(); - return true; - } - - private void sendDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - } - - @Override - public void sendEntity(Player player) { - display(player); - } - - @Override - public void sendEntityDestroy(Player player) { - hide(player, false); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java deleted file mode 100644 index 5f828a33..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.shared.BaseEntity15; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulatorEntity { - - private boolean printed = false; - - public SimulatorEntity15(World world, Vector position, boolean highlight) { - super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); - - this.setNoGravity(true); - this.ticksLived = -12000; - } - - @Override - public void display(Player player) { - if (printed) return; - printed = true; - - sendEntity(player); - } - - @Override - public void setPosition(Vector position) { - this.position = position; - setPosition(position.getX(), position.getY(), position.getZ()); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!printed) return false; - printed = false; - - - sendEntityDestroy(player); - die(); - return true; - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java deleted file mode 100644 index 99873513..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.shared.BaseEntity15; -import de.steamwar.bausystem.shared.ReferenceCounter; -import net.minecraft.server.v1_15_R1.ChatComponentText; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class TraceEntity15 extends BaseEntity15 implements AbstractTraceEntity { - - private boolean exploded = false; - private ReferenceCounter referenceCounter = new ReferenceCounter(); - - public TraceEntity15(World world, Vector position, boolean tnt) { - super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS); - - this.setNoGravity(true); - this.ticksLived = -12000; - } - - @Override - public void display(Player player, boolean exploded, int ticks) { - if (ticks != -1) { - this.setCustomNameVisible(true); - this.setCustomName(new ChatComponentText(ticks + "")); - } - if (!this.exploded && exploded) { - this.setCustomNameVisible(true); - this.setCustomName(new ChatComponentText("Bumm")); - this.exploded = true; - if (referenceCounter.increment() > 0) { - sendEntityDestroy(player); - } - } else if (referenceCounter.increment() > 0) { - return; - } - - sendEntity(player); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } - - sendEntityDestroy(player); - die(); - return true; - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java deleted file mode 100644 index 03929086..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; -import de.steamwar.bausystem.shared.BaseArmorStand15; -import net.minecraft.server.v1_15_R1.ChatComponentText; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityMetadata; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; -import net.minecraft.server.v1_15_R1.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class WarpEntity15 extends BaseArmorStand15 implements AbstractWarpEntity { - - public WarpEntity15(World world, Vector position, String name) { - super(world, position); - setInvisible(true); - setSmall(true); - setName(name); - this.setNoGravity(true); - this.ticksLived = -12000; - } - - @Override - public void display(Player player) { - sendEntity(player); - } - - @Override - public void setName(String name) { - this.setCustomNameVisible(true); - this.setCustomName(new ChatComponentText(name)); - } - - @Override - public boolean hide(Player player) { - sendEntityDestroy(player); - die(); - return true; - } - - @Override - public void sendMetaData(Player player) { - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - playerConnection.sendPacket(packetPlayOutEntityMetadata); - } - - @Override - public void teleport(Player player, Vector position) { - setPositionRaw(position.getX(), position.getY(), position.getZ()); - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityTeleport); - } - - @Override - public Vector getPosition() { - return new Vector(locX(), locY(), locZ()); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java b/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java deleted file mode 100644 index f3e38be3..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.features.tracer.show.Record; - -public class SimulatorPreview15 implements SimulatorPreview { - - @Override - public Record simulate(TNTSimulator tntSimulator) { - return new Record(null); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java b/BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java deleted file mode 100644 index 2e604c77..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class BaseArmorStand15 extends EntityArmorStand implements AbstractEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - protected Vector position; - - public BaseArmorStand15(World world, Vector position) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ()); - - this.position = position; - setNoGravity(true); - ticksLived = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.ARMOR_STAND, 0, ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java b/BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java deleted file mode 100644 index 66480122..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class BaseEntity15 extends EntityFallingBlock implements AbstractEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - private final IBlockData iBlockData; - protected Vector position; - - public BaseEntity15(World world, Vector position, Material blockType) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), ((CraftBlockData) blockType.createBlockData()).getState()); - this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState(); - this.position = position; - - this.setNoGravity(true); - this.ticksLived = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(iBlockData), ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; - playerConnection.sendPacket(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); - playerConnection.sendPacket(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 15756166..b6cd9609 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -20,20 +20,11 @@ package de.steamwar.bausystem.utils; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.bausystem.entities.DetonatorEntity15; -import de.steamwar.bausystem.entities.SimulatorEntity15; -import de.steamwar.bausystem.entities.TraceEntity15; -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; import de.steamwar.bausystem.features.util.NoClipCommand; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; -import de.steamwar.bausystem.entities.WarpEntity15; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; @@ -41,7 +32,6 @@ import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; @@ -162,26 +152,6 @@ public class NMSWrapper15 implements NMSWrapper { return invalid; } - @Override - public AbstractWarpEntity createWarp(World world, Vector position, String name) { - return new WarpEntity15(world, position, name); - } - - @Override - public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) { - return new SimulatorEntity15(world, tntPosition, highlight); - } - - @Override - public AbstractDetonatorEntity constructDetonator(World world, Vector position) { - return new DetonatorEntity15(world, position); - } - - @Override - public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { - return new TraceEntity15(world, tntPosition, tnt); - } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); diff --git a/BauSystem_18/src/de/steamwar/bausystem/entities/DetonatorEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/entities/DetonatorEntity18.java deleted file mode 100644 index 8b28359e..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/entities/DetonatorEntity18.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityFallingBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class DetonatorEntity18 extends EntityFallingBlock implements AbstractDetonatorEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private final Vector position; - private int references = 0; - - public DetonatorEntity18(World world, Vector position) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.du.n()); - this.position = position; - - this.h(true); - this.e(true); - this.S = -12000; - } - - @Override - public int getId() { - return ae(); - } - - @Override - public void display(Player player) { - if (references++ > 0) - return; - - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.C, Block.i(Blocks.du.n()), ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && --references > 0) - return false; - - sendDestroy(player); - ag(); - return true; - } - - private void sendDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } - - @Override - public void sendEntity(Player player) { - display(player); - } - - @Override - public void sendEntityDestroy(Player player) { - hide(player, false); - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java deleted file mode 100644 index 58537b7b..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.shared.BaseEntity18; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulatorEntity { - - private boolean printed = false; - - public SimulatorEntity18(World world, Vector position, boolean highlight) { - super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); - - this.e(true); - this.S = -12000; - } - - @Override - public int getId() { - return ae(); - } - - @Override - public void display(Player player) { - if (printed) return; - printed = true; - - sendEntity(player); - } - - @Override - public void setPosition(Vector position) { - this.position = position; - e(position.getX(), position.getY(), position.getZ()); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!printed) return false; - printed = false; - - sendEntityDestroy(player); - ag(); - return true; - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java deleted file mode 100644 index 437c2620..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.shared.BaseEntity18; -import de.steamwar.bausystem.shared.ReferenceCounter; -import net.minecraft.network.chat.ChatComponentText; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class TraceEntity18 extends BaseEntity18 implements AbstractTraceEntity { - - private boolean exploded = false; - private ReferenceCounter referenceCounter = new ReferenceCounter(); - - public TraceEntity18(World world, Vector position, boolean tnt) { - super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS); - - this.e(true); - this.S = -12000; - } - - @Override - public void display(Player player, boolean exploded, int ticks) { - if (ticks != -1) { - this.n(true); - this.a(new ChatComponentText(ticks + "")); - } - if (!this.exploded && exploded) { - this.n(true); - this.a(new ChatComponentText("Bumm")); - this.exploded = true; - if (referenceCounter.increment() > 0) { - sendEntityDestroy(player); - } - } else if (referenceCounter.increment() > 0) { - return; - } - - sendEntity(player); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } - - sendEntityDestroy(player); - ag(); - return true; - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java deleted file mode 100644 index 35f8287a..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; -import de.steamwar.bausystem.shared.BaseArmorStand18; -import net.minecraft.network.chat.ChatComponentText; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.server.network.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class WarpEntity18 extends BaseArmorStand18 implements AbstractWarpEntity { - - public WarpEntity18(World world, Vector position, String name) { - super(world, position); - this.j(true); - this.a(true); - setName(name); - this.e(true); - this.S = -12000; - } - - @Override - public void display(Player player) { - sendEntity(player); - } - - @Override - public void setName(String name) { - this.n(true); - this.a(new ChatComponentText(name)); - } - - @Override - public boolean hide(Player player) { - sendEntityDestroy(player); - ag(); - return true; - } - - @Override - public void sendMetaData(Player player) { - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutEntityMetadata); - } - - @Override - public void teleport(Player player, Vector position) { - setPosRaw(position.getX(), position.getY(), position.getZ(), false); - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityTeleport); - } - - @Override - public Vector getPosition() { - return new Vector(dc(), de(), di()); - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java b/BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java deleted file mode 100644 index cc0d278c..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class BaseArmorStand18 extends EntityArmorStand implements AbstractEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - protected Vector position; - - public BaseArmorStand18(World world, Vector position) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ()); - - this.position = position; - e(true); - S = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.c, 0, ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java b/BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java deleted file mode 100644 index ef776851..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityFallingBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class BaseEntity18 extends EntityFallingBlock implements AbstractEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - private final IBlockData iBlockData; - protected Vector position; - - public BaseEntity18(World world, Vector position, Material blockType) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), ((CraftBlockData) blockType.createBlockData()).getState()); - this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState(); - this.position = position; - - this.e(true); - this.S = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cm(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.C, Block.i(iBlockData), ZERO); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 4d14fc01..3e9ed190 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -21,15 +21,7 @@ package de.steamwar.bausystem.utils; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.entities.DetonatorEntity18; -import de.steamwar.bausystem.entities.SimulatorEntity18; -import de.steamwar.bausystem.entities.TraceEntity18; -import de.steamwar.bausystem.entities.WarpEntity18; -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; import de.steamwar.bausystem.features.util.NoClipCommand; -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -39,14 +31,16 @@ import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; @@ -167,26 +161,6 @@ public class NMSWrapper18 implements NMSWrapper { return invalid; } - @Override - public AbstractWarpEntity createWarp(World world, Vector position, String name) { - return new WarpEntity18(world, position, name); - } - - @Override - public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) { - return new SimulatorEntity18(world, tntPosition, highlight); - } - - @Override - public AbstractDetonatorEntity constructDetonator(World world, Vector position) { - return new DetonatorEntity18(world, position); - } - - @Override - public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { - return new TraceEntity18(world, tntPosition, tnt); - } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java deleted file mode 100644 index 15b622ac..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityFallingBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.lang.reflect.Field; - -public class DetonatorEntity19 extends EntityFallingBlock implements AbstractDetonatorEntity { - - private static final Field ao; - - static { - try { - ao = EntityFallingBlock.class.getDeclaredField("ao"); - ao.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private final Vector position; - private int references = 0; - private IBlockData iBlockData; - - public DetonatorEntity19(World world, Vector position) { - super(EntityTypes.E, ((CraftWorld) world).getHandle()); - try { - ao.set(this, ((CraftBlockData) Material.RED_STAINED_GLASS.createBlockData()).getState()); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - this.q = true; - e(position.getX(), position.getY(), position.getZ()); - f(Vec3D.b); - t = position.getX(); - u = position.getY(); - v = position.getZ(); - a(this.db()); - - this.iBlockData = ((CraftBlockData) Material.RED_STAINED_GLASS.createBlockData()).getState(); - this.position = position; - - this.e(true); - this.S = -12000; - } - - @Override - public int getId() { - return ae(); - } - - @Override - public void display(Player player) { - if (references++ > 0) - return; - - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), co(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.E, Block.i(iBlockData), ZERO, 0.0); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && --references > 0) - return false; - - sendDestroy(player); - ag(); - return true; - } - - private void sendDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } - - @Override - public void sendEntity(Player player) { - display(player); - } - - @Override - public void sendEntityDestroy(Player player) { - hide(player, false); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java deleted file mode 100644 index 51d3e6eb..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.shared.BaseEntity19; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulatorEntity { - - private boolean printed = false; - - public SimulatorEntity19(World world, Vector position, boolean highlight) { - super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT); - - this.e(true); - this.S = -12000; - } - - @Override - public int getId() { - return ae(); - } - - @Override - public void display(Player player) { - if (printed) return; - printed = true; - - sendEntity(player); - } - - @Override - public void setPosition(Vector position) { - this.position = position; - e(position.getX(), position.getY(), position.getZ()); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!printed) return false; - printed = false; - - sendEntityDestroy(player); - ag(); - return true; - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java deleted file mode 100644 index e70dba55..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.shared.BaseEntity19; -import de.steamwar.bausystem.shared.ReferenceCounter; -import net.minecraft.network.chat.IChatMutableComponent; -import net.minecraft.network.chat.contents.LiteralContents; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class TraceEntity19 extends BaseEntity19 implements AbstractTraceEntity { - - private boolean exploded = false; - private ReferenceCounter referenceCounter = new ReferenceCounter(); - - public TraceEntity19(World world, Vector position, boolean tnt) { - super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS); - - this.e(true); - this.S = -12000; - } - - @Override - public void display(Player player, boolean exploded, int ticks) { - if (ticks != -1) { - this.n(true); - this.b(IChatMutableComponent.a(new LiteralContents(ticks + ""))); - } - if (!this.exploded && exploded) { - this.n(true); - this.b(IChatMutableComponent.a(new LiteralContents("Bumm"))); - this.exploded = true; - if (referenceCounter.increment() > 0) { - sendEntityDestroy(player); - } - } else if (referenceCounter.increment() > 0) { - return; - } - - sendEntity(player); - } - - @Override - public boolean hide(Player player, boolean force) { - if (!force && referenceCounter.decrement() > 0) { - return false; - } - - sendEntityDestroy(player); - ag(); - return true; - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java deleted file mode 100644 index a86a653e..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.entities; - -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; -import de.steamwar.bausystem.shared.BaseArmorStand19; -import net.minecraft.network.chat.IChatMutableComponent; -import net.minecraft.network.chat.contents.LiteralContents; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; -import net.minecraft.server.network.PlayerConnection; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class WarpEntity19 extends BaseArmorStand19 implements AbstractWarpEntity { - - public WarpEntity19(World world, Vector position, String name) { - super(world, position); - this.j(true); - this.a(true); - setName(name); - this.e(true); - this.S = -12000; - } - - @Override - public void display(Player player) { - sendEntity(player); - } - - @Override - public void setName(String name) { - this.n(true); - this.b(IChatMutableComponent.a(new LiteralContents(name))); - } - - @Override - public boolean hide(Player player) { - sendEntityDestroy(player); - ag(); - return true; - } - - @Override - public void sendMetaData(Player player) { - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutEntityMetadata); - } - - @Override - public void teleport(Player player, Vector position) { - setPosRaw(position.getX(), position.getY(), position.getZ(), false); - PacketPlayOutEntityTeleport packetPlayOutEntityTeleport = new PacketPlayOutEntityTeleport(this); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityTeleport); - } - - @Override - public Vector getPosition() { - return new Vector(df(), dh(), dj()); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeExplosion19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeExplosion19.java deleted file mode 100644 index eaa19495..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeExplosion19.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import com.google.common.collect.Maps; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.core.BlockPosition; -import net.minecraft.util.RandomSource; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.ExplosionDamageCalculator; -import net.minecraft.world.level.World; -import net.minecraft.world.level.gameevent.GameEvent; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; - -public class FakeExplosion19 extends Explosion { - - private List fakeTNT19s; - private boolean c; - private Explosion.Effect d; - private RandomSource e; - private World f; - private double g; - private double h; - private double i; - @Nullable - public Entity j; - private float k; - private DamageSource l; - private ExplosionDamageCalculator m; - private ObjectArrayList n; - private Map o; - public boolean wasCanceled; - - public FakeExplosion19(List fakeTNT19s, World world, @Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.Effect destructionType) { - super(world, entity, damageSource, behavior, x, y, z, power, createFire, destructionType); - this.fakeTNT19s = fakeTNT19s; - this.wasCanceled = false; - this.e = RandomSource.a(); - this.n = new ObjectArrayList(); - this.o = Maps.newHashMap(); - this.f = world; - this.j = entity; - this.k = (float) Math.max((double) power, 0.0D); - this.g = x; - this.h = y; - this.i = z; - this.c = createFire; - this.d = destructionType; - this.l = damageSource == null ? DamageSource.a(this) : damageSource; - this.m = new ExplosionDamageCalculator(); - - } - - private float getBlockDensity(Vec3D vec3d, Entity entity) { - return a(vec3d, entity); - } - - - @Override - public void a() { - if ((this.k) >= 0.1F) { - this.f.a(this.j, GameEvent.w, new Vec3D(this.g, this.h, this.i)); - /* - Set set = Sets.newHashSet(); - - int i; - int j; - for (int k = 0; k < 16; ++k) { - for (i = 0; i < 16; ++i) { - for (j = 0; j < 16; ++j) { - if (k == 0 || k == 15 || i == 0 || i == 15 || j == 0 || j == 15) { - double d0 = (double) ((float) k / 15.0F * 2.0F - 1.0F); - double d1 = (double) ((float) i / 15.0F * 2.0F - 1.0F); - double d2 = (double) ((float) j / 15.0F * 2.0F - 1.0F); - double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); - d0 /= d3; - d1 /= d3; - d2 /= d3; - float f = this.k * (0.7F + this.f.w.i() * 0.6F); - double d4 = this.g; - double d5 = this.h; - double d6 = this.i; - - for (float var21 = 0.3F; f > 0.0F; f -= 0.22500001F) { - BlockPosition blockposition = new BlockPosition(d4, d5, d6); - IBlockData iblockdata = this.f.a_(blockposition); - Fluid fluid = iblockdata.p(); - if (!this.f.j(blockposition)) { - break; - } - - Optional optional = this.m.a(this, this.f, blockposition, iblockdata, fluid); - if (optional.isPresent()) { - f -= ((Float) optional.get() + 0.3F) * 0.3F; - } - - if (f > 0.0F && this.m.a(this, this.f, blockposition, iblockdata, f)) { - set.add(blockposition); - } - - d4 += d0 * 0.30000001192092896D; - d5 += d1 * 0.30000001192092896D; - d6 += d2 * 0.30000001192092896D; - } - } - } - } - } - - this.n.addAll(set); - */ - - float f2 = this.k * 2.0F; - Vec3D vec3d = new Vec3D(this.g, this.h, this.i); - for (int l1 = 0; l1 < fakeTNT19s.size(); ++l1) { - Entity entity = (Entity) fakeTNT19s.get(l1); - if (!entity.cF()) { - double d7 = Math.sqrt(entity.e(vec3d)) / (double) f2; - if (d7 <= 1.0D) { - double d8 = entity.df() - this.g; - double d9 = entity.dh() - this.h; - double d10 = entity.dl() - this.i; - double d11 = Math.sqrt(d8 * d8 + d9 * d9 + d10 * d10); - if (d11 != 0.0D) { - d8 /= d11; - d9 /= d11; - d10 /= d11; - double d12 = (double) this.getBlockDensity(vec3d, entity); - - double d13 = (1.0D - d7) * d12; - entity.lastDamageCancelled = false; - CraftEventFactory.entityDamage = null; - entity.f(entity.dd().b(d8 * d13, d9 * d13, d10 * d13)); - } - } - } - } - } - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java deleted file mode 100644 index abf89c09..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import net.minecraft.core.BlockPosition; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.network.syncher.DataWatcher; -import net.minecraft.network.syncher.DataWatcherObject; -import net.minecraft.network.syncher.DataWatcherRegistry; -import net.minecraft.util.MathHelper; -import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.*; -import net.minecraft.world.entity.item.EntityTNTPrimed; -import net.minecraft.world.level.Explosion; -import net.minecraft.world.level.ExplosionDamageCalculator; -import net.minecraft.world.level.World; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.AxisAlignedBB; -import net.minecraft.world.phys.Vec3D; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.bukkit.entity.Explosive; -import org.bukkit.event.entity.ExplosionPrimeEvent; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - -public class FakeTNT19 extends EntityTNTPrimed { - private static final DataWatcherObject b; - private static final int c = 80; - private List fakeTNT19s; - private List spawnList = new ArrayList<>(); - private int count; - @Nullable - public EntityLiving d; - public float yield; - public boolean isIncendiary; - - public FakeTNT19(List fakeTNT19s, EntityTypes type, World world) { - super(type, world); - this.fakeTNT19s = fakeTNT19s; - this.yield = 4.0F; - this.isIncendiary = false; - super.q = true; - } - - public FakeTNT19(List fakeTNT19s, World world, double x, double y, double z, int fuse, int count) { - this(fakeTNT19s, EntityTypes.av, world); - this.e(x, y, z); - double d3 = world.w.j() * 6.2831854820251465D; - this.n(-Math.sin(d3) * 0.02D, 0.20000000298023224D, -Math.cos(d3) * 0.02D); - this.a(fuse); - super.t = x; - super.u = y; - super.v = z; - this.d = null; - this.count = count; - } - - protected void a_() { - super.Y.a(b, 80); - } - - protected MovementEmission aO() { - return MovementEmission.a; - } - - public boolean bl() { - return !this.dt(); - } - - private Vec3D g(Vec3D vec3d) { - AxisAlignedBB axisalignedbb = this.cz(); - List list = this.s.b(this, axisalignedbb.b(vec3d)); - Vec3D vec3d1 = vec3d.g() == 0.0 ? vec3d : a(this, vec3d, axisalignedbb, this.s, list); - boolean flag = vec3d.c != vec3d1.c; - boolean flag1 = vec3d.d != vec3d1.d; - boolean flag2 = vec3d.e != vec3d1.e; - boolean flag3 = this.y || flag1 && vec3d.d < 0.0; - if (this.P > 0.0F && flag3 && (flag || flag2)) { - Vec3D vec3d2 = a(this, new Vec3D(vec3d.c, (double)this.P, vec3d.e), axisalignedbb, this.s, list); - Vec3D vec3d3 = a(this, new Vec3D(0.0, (double)this.P, 0.0), axisalignedbb.b(vec3d.c, 0.0, vec3d.e), this.s, list); - if (vec3d3.d < (double)this.P) { - Vec3D vec3d4 = a(this, new Vec3D(vec3d.c, 0.0, vec3d.e), axisalignedbb.c(vec3d3), this.s, list).e(vec3d3); - if (vec3d4.i() > vec3d2.i()) { - vec3d2 = vec3d4; - } - } - - if (vec3d2.i() > vec3d1.i()) { - return vec3d2.e(a(this, new Vec3D(0.0, -vec3d2.d + vec3d.d, 0.0), axisalignedbb.c(vec3d2), this.s, list)); - } - } - - return vec3d1; - } - - @Override - public void a(EnumMoveType enummovetype, Vec3D vec3d) { - if (this.E.g() > 1.0E-7) { - vec3d = vec3d.h(this.E); - this.E = Vec3D.b; - this.f(Vec3D.b); - } - - Vec3D vec3d1 = this.g(vec3d); - double d0 = vec3d1.g(); - if (d0 > 1.0E-7) { - this.e(this.df() + vec3d1.c, this.dg() + vec3d1.d, this.dl() + vec3d1.e); - } - - boolean flag = !MathHelper.b(vec3d.c, vec3d1.c); - boolean flag1 = !MathHelper.b(vec3d.e, vec3d1.e); - this.z = flag || flag1; - this.A = vec3d.d != vec3d1.d; - this.B = this.A && vec3d.d < 0.0; - if (this.z) { - this.C = this.b(vec3d1); - } else { - this.C = false; - } - - this.y = this.A && vec3d.d < 0.0; - BlockPosition blockposition = this.aA(); - IBlockData iblockdata = this.s.a_(blockposition); - // this.a(vec3d1.d, this.y, iblockdata, blockposition); - if (!this.dt()) { - if (this.z) { - Vec3D vec3d2 = this.dd(); - this.n(flag ? 0.0 : vec3d2.c, vec3d2.d, flag1 ? 0.0 : vec3d2.e); - } - - net.minecraft.world.level.block.Block block = iblockdata.b(); - if (vec3d.d != vec3d1.d) { - block.a(this.s, this); - } - - if (this.y) { - block.a(this.s, blockposition, iblockdata, this); - } - - this.ax(); - float f2 = this.aD(); - this.f(this.dd().d((double)f2, 1.0, (double)f2)); - } - } - - public void k(List spawnList) { - if (!this.aN()) { - this.f(this.dd().b(0.0D, -0.04D, 0.0D)); - } - - this.a(EnumMoveType.a, this.dd()); - this.f(this.dd().a(0.98D)); - if (super.y) { - this.f(this.dd().d(0.7D, -0.5D, 0.7D)); - } - - int i = this.i() - 1; - this.a(i); - if (i <= 0) { - if (!super.s.y) { - this.j1(); - } - - this.ah(); - } else { - this.aY(); - } - - if (i == 1 && count > 1) { - for (int c = 0; c < count - 1; c++) { - FakeTNT19 fakeTNT19 = new FakeTNT19(fakeTNT19s, this.s, this.df(), this.dh(), this.dl(), i, 1); - fakeTNT19.y = this.y; - fakeTNT19.f(new Vec3D(this.dd().c, this.dd().d, this.dd().e)); - spawnList.add(fakeTNT19); - } - count = 1; - } - } - - private void j1() { - ExplosionPrimeEvent event = new ExplosionPrimeEvent((Explosive) this.getBukkitEntity()); - super.s.getCraftServer().getPluginManager().callEvent(event); - if (!event.isCancelled()) { - this.a(this, this.df(), this.e(0.0625D), this.dl(), event.getRadius(), event.getFire(), Explosion.Effect.b); - } - } - - public FakeExplosion19 a(@Nullable Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.Effect destructionType) { - return this.a(entity, (DamageSource) null, (ExplosionDamageCalculator) null, x, y, z, power, createFire, destructionType); - } - - public FakeExplosion19 a(@Nullable Entity entity, @Nullable DamageSource damageSource, @Nullable ExplosionDamageCalculator behavior, double x, double y, double z, float power, boolean createFire, Explosion.Effect destructionType) { - FakeExplosion19 explosion = new FakeExplosion19(fakeTNT19s, SimulatorPreview19.WORLD, entity, damageSource, behavior, x, y, z, power, createFire, destructionType); - explosion.a(); - // explosion.a(true); - return explosion; - } - - - protected void b(NBTTagCompound nbt) { - nbt.a("Fuse", (short) this.i()); - } - - protected void a(NBTTagCompound nbt) { - this.a(nbt.g("Fuse")); - } - - @Nullable - public EntityLiving h() { - return this.d; - } - - protected float a(EntityPose pose, EntitySize dimensions) { - return 0.15F; - } - - public void a(int fuse) { - super.Y.b(b, fuse); - } - - public int i() { - return (Integer) super.Y.a(b); - } - - public Packet S() { - return new PacketPlayOutSpawnEntity(this); - } - - public boolean cr() { - return super.cr(); - } - - static { - b = DataWatcher.a(EntityTNTPrimed.class, DataWatcherRegistry.b); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java b/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java deleted file mode 100644 index 5a06c342..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; -import de.steamwar.bausystem.features.tracer.show.Record; -import de.steamwar.bausystem.shared.Pair; -import net.minecraft.world.level.World; -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.entity.TNTPrimed; - -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -public class SimulatorPreview19 implements SimulatorPreview { - - public static final World WORLD = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); - - @Override - public Record simulate(TNTSimulator tntSimulator) { - if (true) { - return new Record(null); - } - - Map>>> result = new HashMap<>(); - for (SimulatorElement element : tntSimulator.getTntElementList()) { - element.locations(result); - } - - AtomicInteger maxTick = new AtomicInteger(0); - Map>>> toSpawn = new HashMap<>(); - AtomicInteger tntCount = new AtomicInteger(0); - result.forEach((integer, integerSetMap) -> { - List>>> internal = new ArrayList<>(); - integerSetMap.forEach((integer1, pairs) -> { - internal.add(new Pair<>(integer1, pairs)); - }); - internal.sort(Comparator.comparingInt(Pair::getKey)); - - toSpawn.put(integer, internal.stream().map(Pair::getValue).peek(pairs -> { - tntCount.addAndGet(pairs.stream().mapToInt(Pair::getValue).sum()); - }).map(ArrayList::new).peek(Collections::shuffle).collect(Collectors.toList())); - - if (maxTick.get() < integer) { - maxTick.set(integer); - } - }); - if (tntCount.get() > 500) { - return new Record(null); - } - - List fakeTNT19s = new ArrayList<>(); - Record record = new Record(null); - Map tntRecords = new HashMap<>(); - - int maxTickToCalc = maxTick.get() + 160; - for (int tick = 0; tick < maxTickToCalc; tick++) { - List>> toSpawnInTick = toSpawn.get(tick); - try { - if (toSpawnInTick == null) continue; - toSpawnInTick.forEach(pairs -> { - AtomicBoolean hasSomeLeft = new AtomicBoolean(true); - while(hasSomeLeft.get()) { - hasSomeLeft.set(false); - pairs.forEach(pair -> { - SimulatorPreview.SimulatorPreviewTNTData previewTNTData = pair.getKey(); - if (!previewTNTData.isXVelocity() && !previewTNTData.isZVelocity()) { - FakeTNT19 fakeTNT19 = new FakeTNT19(fakeTNT19s, WORLD, previewTNTData.getX(), previewTNTData.getY(), previewTNTData.getZ(), previewTNTData.getFuseTicks(), pair.getValue()); - TNTPrimed tntPrimed = (TNTPrimed) fakeTNT19.getBukkitEntity(); - if (!previewTNTData.isXVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!previewTNTData.isYVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!previewTNTData.isZVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - fakeTNT19s.add(fakeTNT19); - pair.setValue(0); - } else if (pair.getValue() > 0) { - hasSomeLeft.set(true); - FakeTNT19 fakeTNT19 = new FakeTNT19(fakeTNT19s, WORLD, previewTNTData.getX(), previewTNTData.getY(), previewTNTData.getZ(), previewTNTData.getFuseTicks(), 1); - TNTPrimed tntPrimed = (TNTPrimed) fakeTNT19.getBukkitEntity(); - if (!previewTNTData.isXVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); - if (!previewTNTData.isYVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); - if (!previewTNTData.isZVelocity()) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); - fakeTNT19s.add(fakeTNT19); - pair.setValue(pair.getValue() - 1); - } - }); - } - }); - } finally { - calculateTick(fakeTNT19s, record, tntRecords); - } - } - return record; - } - - private void calculateTick(List fakeTNT19s, Record record, Map tntRecords) { - int i = 0; - while (i < fakeTNT19s.size()) { - List spawnList = new ArrayList<>(); - FakeTNT19 fakeTNT19 = fakeTNT19s.get(i); - fakeTNT19.k(spawnList); - TNTPrimed tntPrimed = ((TNTPrimed) (fakeTNT19.getBukkitEntity())); - if (tntPrimed.getFuseTicks() <= 0) { - tntRecords.computeIfAbsent(fakeTNT19, ignore -> record.spawn(0)).explode(tntPrimed); - fakeTNT19s.remove(i); - i--; - } else { - tntRecords.computeIfAbsent(fakeTNT19, ignore -> record.spawn(0)).explode(tntPrimed); - } - if (!spawnList.isEmpty()) { - fakeTNT19s.addAll(i, spawnList); - i += spawnList.size(); - } - i++; - } - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java b/BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java deleted file mode 100644 index fcc0ef9f..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.decoration.EntityArmorStand; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public class BaseArmorStand19 extends EntityArmorStand implements AbstractEntity { - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - protected Vector position; - - public BaseArmorStand19(World world, Vector position) { - super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ()); - - this.position = position; - e(true); - S = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), co(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.d, 0, ZERO, 0.0); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java deleted file mode 100644 index df65d56a..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy; -import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; -import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; -import net.minecraft.server.network.PlayerConnection; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.item.EntityFallingBlock; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.IBlockData; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.lang.reflect.Field; - -public class BaseEntity19 extends EntityFallingBlock implements AbstractEntity { - - private static final Field ao; - - static { - try { - ao = EntityFallingBlock.class.getDeclaredField("ao"); - ao.setAccessible(true); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } - - private static final Vec3D ZERO = new Vec3D(0, 0, 0); - - private final IBlockData iBlockData; - protected Vector position; - - public BaseEntity19(World world, Vector position, Material blockType) { - super(EntityTypes.E, ((CraftWorld) world).getHandle()); - try { - ao.set(this, ((CraftBlockData) blockType.createBlockData()).getState()); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - this.q = true; - e(position.getX(), position.getY(), position.getZ()); - f(Vec3D.b); - t = position.getX(); - u = position.getY(); - v = position.getZ(); - a(this.db()); - - this.iBlockData = ((CraftBlockData) blockType.createBlockData()).getState(); - this.position = position; - - this.e(true); - this.S = -12000; - } - - public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), co(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.E, Block.i(iBlockData), ZERO, 0.0); - PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; - playerConnection.a(packetPlayOutSpawnEntity); - - PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(ae(), Y, true); - playerConnection.a(packetPlayOutEntityMetadata); - } - - public void sendEntityDestroy(Player player) { - PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(ae()); - ((CraftPlayer) player).getHandle().b.a(packetPlayOutEntityDestroy); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 4d184f6f..f0d11ff1 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -21,15 +21,7 @@ package de.steamwar.bausystem.utils; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.entities.DetonatorEntity19; -import de.steamwar.bausystem.entities.SimulatorEntity19; -import de.steamwar.bausystem.entities.TraceEntity19; -import de.steamwar.bausystem.entities.WarpEntity19; -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; import de.steamwar.bausystem.features.util.NoClipCommand; -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -39,14 +31,16 @@ import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; @@ -167,26 +161,6 @@ public class NMSWrapper19 implements NMSWrapper { return invalid; } - @Override - public AbstractWarpEntity createWarp(World world, Vector position, String name) { - return new WarpEntity19(world, position, name); - } - - @Override - public AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight) { - return new SimulatorEntity19(world, tntPosition, highlight); - } - - @Override - public AbstractDetonatorEntity constructDetonator(World world, Vector position) { - return new DetonatorEntity19(world, position); - } - - @Override - public AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt) { - return new TraceEntity19(world, tntPosition, tnt); - } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/BlockAttribute_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/BlockAttribute_GENERIC.java deleted file mode 100644 index b898485b..00000000 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/BlockAttribute_GENERIC.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.linkage.types; - -import de.steamwar.linkage.LinkageType; -import de.steamwar.linkage.plan.BuildPlan; -import de.steamwar.linkage.plan.MethodBuilder; - -import javax.lang.model.element.TypeElement; - -public class BlockAttribute_GENERIC implements LinkageType { - - @Override - public String method() { - return "linkBlockAttributes"; - } - - @Override - public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { - buildPlan.addImport("de.steamwar.bausystem.features.attributescopy.*"); - methodBuilder.addLine("AttributesCopyCommand.add(" + s + ");"); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 565f368f..1d1e6362 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -121,19 +121,4 @@ public class BauSystem extends JavaPlugin implements Listener { } })); } - - private void createLink(String source, String destination) { - try { - Bukkit.getLogger().log(Level.INFO, "Executing: ln -s /home/minecraft/server/Bau15/{0} {1}", new String[]{source, destination}); - ProcessBuilder processBuilder = new ProcessBuilder("ln", "-s", "/home/minecraft/server/Bau15/" + source, destination); - processBuilder.directory(world.getWorldFolder()); - processBuilder.inheritIO(); - - Process process = processBuilder.start(); - process.waitFor(); - } catch (IOException | InterruptedException e) { - Thread.currentThread().interrupt(); - Bukkit.shutdown(); - } - } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java index f9217497..902d7c59 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java @@ -36,7 +36,6 @@ import java.util.List; import java.util.stream.Collectors; @Linked -@MinVersion(18) public class AttributeRemoveCommand extends SWCommand { public AttributeRemoveCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeUtils.java new file mode 100644 index 00000000..246e4ab9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeUtils.java @@ -0,0 +1,128 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.attributescopy; + +import lombok.experimental.UtilityClass; +import org.bukkit.block.data.BlockData; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@UtilityClass +public class AttributeUtils { + + private Map names = new HashMap<>(); + private Map, List> getters = new HashMap<>(); + private Map, Map> setters = new HashMap<>(); + + private void generate(BlockData blockData) { + Class clazz = blockData.getClass(); + if (getters.containsKey(clazz) && setters.containsKey(clazz)) return; + + Map> methods = new HashMap<>(); + for (Method declaredMethod : clazz.getMethods()) { + String s = declaredMethod.getName(); + if (s.startsWith("get") && declaredMethod.getParameterCount() == 0) { + methods.computeIfAbsent(s.substring(3), aClass -> new ArrayList<>()).add(declaredMethod); + } else if (s.startsWith("is") && declaredMethod.getParameterCount() == 0) { + methods.computeIfAbsent(s.substring(2), aClass -> new ArrayList<>()).add(declaredMethod); + } else if (s.startsWith("set") && declaredMethod.getParameterCount() == 1) { + methods.computeIfAbsent(s.substring(3), aClass -> new ArrayList<>()).add(declaredMethod); + } + } + for (Map.Entry> entry : methods.entrySet()) { + if (entry.getValue().size() != 2) continue; + for (Method method : entry.getValue()) { + names.put(method, entry.getKey()); + if (method.getName().startsWith("is") || method.getName().startsWith("get")) { + getters.computeIfAbsent(clazz, aClass -> new ArrayList<>()).add(method); + } else { + setters.computeIfAbsent(clazz, aClass -> new HashMap<>()).put(entry.getKey(), method); + } + } + } + } + + public void copy(BlockData blockData, List attributes) { + generate(blockData); + + getters.getOrDefault(blockData.getClass(), new ArrayList<>()).forEach(method -> { + try { + Object invoke = method.invoke(blockData); + if (invoke != null) { + attributes.add("§8-§7 " + names.get(method) + "§8:§7 " + convert(invoke)); + } + } catch (Exception e) { + // ignore + } + }); + } + + public void paste(BlockData blockData, List attributes) { + generate(blockData); + + for (String attribute : attributes) { + String[] split = attribute.split("§8:§7 "); + if (split.length != 2) continue; + String name = split[0].substring(6); + String value = split[1]; + Method method = setters.getOrDefault(blockData.getClass(), new HashMap<>()).get(name); + if (method == null) continue; + try { + method.invoke(blockData, convert(value, method.getParameterTypes()[0])); + } catch (Exception e) { + // ignore + } + } + } + + private String convert(Object o) { + if (o.getClass().isEnum()) { + return ((Enum) o).name(); + } else { + return o.toString(); + } + } + + private Object convert(String s, Class type) { + if (type.isEnum()) { + return Enum.valueOf((Class) type, s); + } else if (type == int.class || type == Integer.class) { + return Integer.parseInt(s); + } else if (type == double.class || type == Double.class) { + return Double.parseDouble(s); + } else if (type == float.class || type == Float.class) { + return Float.parseFloat(s); + } else if (type == long.class || type == Long.class) { + return Long.parseLong(s); + } else if (type == short.class || type == Short.class) { + return Short.parseShort(s); + } else if (type == byte.class || type == Byte.class) { + return Byte.parseByte(s); + } else if (type == boolean.class || type == Boolean.class) { + return Boolean.parseBoolean(s); + } else { + return s; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java index d63204f3..01d652b4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesCopyCommand.java @@ -20,10 +20,8 @@ package de.steamwar.bausystem.features.attributescopy; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.linkage.LinkageUtils; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; import org.bukkit.FluidCollisionMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -36,40 +34,29 @@ import java.util.ArrayList; import java.util.List; @Linked -@MinVersion(18) public class AttributesCopyCommand extends SWCommand { - static List> blockAttributeList = new ArrayList<>(); - - public static void add(BlockAttribute blockAttribute) { - blockAttributeList.add(blockAttribute); - } - public AttributesCopyCommand() { super("copyattributes", "attributescopy", "ac"); } @Register public void genericCommand(Player player) { - linkIfNeeded(); - Block block = player.getTargetBlockExact(8, FluidCollisionMode.ALWAYS); if (block == null) return; ItemStack mainHand = player.getInventory().getItemInMainHand(); - if (!isSame(block, mainHand)) { + + if (!(block.getType().isItem() && block.getType() == mainHand.getType() || isSame(block, mainHand))) { BauSystem.MESSAGE.send("ATTRIBUTES_CANT_COPY", player); return; } + BlockData blockData = block.getBlockData(); List attributesToCopy = new ArrayList<>(); - if (needsType(block)) { - attributesToCopy.add("§8-§7 material " + block.getType().name().toLowerCase()); - } - for (BlockAttribute blockAttribute : blockAttributeList) { - if (blockAttribute.type().isInstance(blockData)) { - blockAttribute.copy(attributesToCopy, blockData); - } + if (block.getType() != mainHand.getType()) { + attributesToCopy.add("§8-§7 Material§8:§7 " + block.getType().name()); } + AttributeUtils.copy(blockData, attributesToCopy); if (attributesToCopy.isEmpty()) { BauSystem.MESSAGE.send("ATTRIBUTES_NO_COPY", player); return; @@ -83,15 +70,7 @@ public class AttributesCopyCommand extends SWCommand { BauSystem.MESSAGE.send("ATTRIBUTES_COPIED", player); } - private static boolean isLinked = false; - static void linkIfNeeded() { - if (isLinked) return; - LinkageUtils.linkBlockAttributes(); - isLinked = true; - } - private boolean isSame(Block block, ItemStack itemStack) { - if (block.getType() == itemStack.getType()) return true; if (itemStack.getType() == Material.REDSTONE && block.getType() == Material.REDSTONE_WIRE) return true; if (itemStack.getType() == Material.PLAYER_HEAD && block.getType() == Material.PLAYER_WALL_HEAD) return true; if (itemStack.getType() == Material.ZOMBIE_HEAD && block.getType() == Material.ZOMBIE_WALL_HEAD) return true; @@ -102,22 +81,8 @@ public class AttributesCopyCommand extends SWCommand { if (itemStack.getType() == Material.TORCH && block.getType() == Material.WALL_TORCH) return true; if (itemStack.getType() == Material.SOUL_TORCH && block.getType() == Material.SOUL_WALL_TORCH) return true; if (itemStack.getType() == Material.REDSTONE_TORCH && block.getType() == Material.REDSTONE_WALL_TORCH) return true; + if (itemStack.getType() == Material.WHEAT_SEEDS && block.getType() == Material.WHEAT) return true; if (itemStack.getType().name().contains("_BANNER") && block.getType().name().contains("_WALL_BANNER")) return true; return false; } - - private boolean needsType(Block block) { - if (block.getType().name().contains("WALL")) return true; - if (block.getType() == Material.PLAYER_HEAD) return true; - if (block.getType() == Material.ZOMBIE_HEAD) return true; - if (block.getType() == Material.CREEPER_HEAD) return true; - if (block.getType() == Material.DRAGON_HEAD) return true; - if (block.getType() == Material.SKELETON_SKULL) return true; - if (block.getType() == Material.WITHER_SKELETON_SKULL) return true; - if (block.getType() == Material.TORCH) return true; - if (block.getType() == Material.SOUL_TORCH) return true; - if (block.getType() == Material.REDSTONE_TORCH) return true; - if (block.getType().name().contains("_BANNER")) return true; - return false; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java index 0daed5af..de4b192a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.attributescopy; import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -33,21 +32,14 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.profile.PlayerProfile; -import java.util.HashSet; import java.util.List; -import java.util.Set; - -import static de.steamwar.bausystem.features.attributescopy.AttributesCopyCommand.blockAttributeList; @Linked -@MinVersion(18) public class AttributesPlaceListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - AttributesCopyCommand.linkIfNeeded(); ItemStack itemStack = event.getItemInHand(); ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta == null) return; @@ -65,12 +57,12 @@ public class AttributesPlaceListener implements Listener { event.setCancelled(true); Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { Material material = strings.stream() - .filter(s -> s.startsWith("§8-§7 material ")) - .map(s -> s.replace("§8-§7 material ", "")) + .filter(s -> s.startsWith("§8-§7 Material§8:§7 ")) + .map(s -> s.replace("§8-§7 Material§8:§7 ", "")) .map(String::toUpperCase) .map(s -> { try { - return Material.valueOf(s.toUpperCase()); + return Material.valueOf(s); } catch (Exception e) { return null; } @@ -78,7 +70,6 @@ public class AttributesPlaceListener implements Listener { .findFirst() .orElse(type); event.getBlock().setType(material, false); - Set attributesToPaste = new HashSet<>(strings); Block block = event.getBlock(); BlockData blockData = block.getBlockData(); Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { @@ -88,11 +79,7 @@ public class AttributesPlaceListener implements Listener { skull.update(true, false); } }, 1); - for (BlockAttribute blockAttribute : blockAttributeList) { - if (blockAttribute.type().isInstance(blockData)) { - blockAttribute.paste(attributesToPaste, blockData); - } - } + AttributeUtils.paste(blockData, strings); block.setBlockData(blockData, false); }, 1); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/BlockAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/BlockAttribute.java deleted file mode 100644 index 13fbf86c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/BlockAttribute.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy; - -import org.bukkit.block.data.BlockData; - -import java.util.List; -import java.util.Set; - -public interface BlockAttribute { - Class type(); - void copy(List attributes, T blockData); - void paste(Set attributes, T blockData); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AgeableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AgeableAttribute.java deleted file mode 100644 index a52d6819..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AgeableAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Ageable; - -import java.util.List; -import java.util.Set; - -@Linked -public class AgeableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 age "; - - @Override - public Class type() { - return Ageable.class; - } - - @Override - public void copy(List attributes, Ageable blockData) { - attributes.add(attribute + blockData.getAge()); - } - - @Override - public void paste(Set attributes, Ageable blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setAge); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AnaloguePowerableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AnaloguePowerableAttribute.java deleted file mode 100644 index 6d9c7df0..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AnaloguePowerableAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.AnaloguePowerable; - -import java.util.List; -import java.util.Set; - -@Linked -public class AnaloguePowerableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 power "; - - @Override - public Class type() { - return AnaloguePowerable.class; - } - - @Override - public void copy(List attributes, AnaloguePowerable blockData) { - attributes.add(attribute + blockData.getPower()); - } - - @Override - public void paste(Set attributes, AnaloguePowerable blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setPower); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AttachableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AttachableAttribute.java deleted file mode 100644 index 05a716e9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AttachableAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Attachable; - -import java.util.List; -import java.util.Set; - -@Linked -public class AttachableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 attached"; - - @Override - public Class type() { - return Attachable.class; - } - - @Override - public void copy(List attributes, Attachable blockData) { - if (blockData.isAttached()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Attachable blockData) { - blockData.setAttached(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/BisectedAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/BisectedAttribute.java deleted file mode 100644 index 31849b40..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/BisectedAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Bisected; - -import java.util.List; -import java.util.Set; - -@Linked -public class BisectedAttribute implements BlockAttribute { - - private String attribute = "§8-§7 half "; - - @Override - public Class type() { - return Bisected.class; - } - - @Override - public void copy(List attributes, Bisected blockData) { - attributes.add(attribute + blockData.getHalf().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, Bisected blockData) { - for (Bisected.Half half : Bisected.Half.values()) { - if (attributes.contains(attribute + half.name().toLowerCase())) { - blockData.setHalf(half); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/DirectionalAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/DirectionalAttribute.java deleted file mode 100644 index c0e11fc8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/DirectionalAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Directional; - -import java.util.List; -import java.util.Set; - -@Linked -public class DirectionalAttribute implements BlockAttribute { - - private String attribute = "§8-§7 facing "; - - @Override - public Class type() { - return Directional.class; - } - - @Override - public void copy(List attributes, Directional blockData) { - attributes.add(attribute + blockData.getFacing().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, Directional blockData) { - for (BlockFace blockFace : blockData.getFaces()) { - if (attributes.contains(attribute + blockFace.name().toLowerCase())) { - blockData.setFacing(blockFace); - break; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/FaceAttachableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/FaceAttachableAttribute.java deleted file mode 100644 index 59f79a19..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/FaceAttachableAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.FaceAttachable; - -import java.util.List; -import java.util.Set; - -@Linked -public class FaceAttachableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 attached "; - - @Override - public Class type() { - return FaceAttachable.class; - } - - @Override - public void copy(List attributes, FaceAttachable blockData) { - attributes.add(attribute + blockData.getAttachedFace().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, FaceAttachable blockData) { - for (FaceAttachable.AttachedFace attachedFace : FaceAttachable.AttachedFace.values()) { - if (attributes.contains(attribute + attachedFace.name().toLowerCase())) { - blockData.setAttachedFace(attachedFace); - break; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/HangableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/HangableAttribute.java deleted file mode 100644 index 8e26bb31..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/HangableAttribute.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; -import org.bukkit.block.data.Hangable; - -import java.util.List; -import java.util.Set; - -@Linked -@MinVersion(19) -public class HangableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 hanging"; - - @Override - public Class type() { - return Hangable.class; - } - - @Override - public void copy(List attributes, Hangable blockData) { - if (!blockData.isHanging()) return; - attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Hangable blockData) { - blockData.setHanging(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LevelledAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LevelledAttribute.java deleted file mode 100644 index 6e60b601..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LevelledAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Levelled; - -import java.util.List; -import java.util.Set; - -@Linked -public class LevelledAttribute implements BlockAttribute { - - private String attribute = "§8-§7 level "; - - @Override - public Class type() { - return Levelled.class; - } - - @Override - public void copy(List attributes, Levelled blockData) { - attributes.add(attribute + blockData.getLevel()); - } - - @Override - public void paste(Set attributes, Levelled blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setLevel); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LightableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LightableAttribute.java deleted file mode 100644 index aa55a054..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LightableAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Lightable; - -import java.util.List; -import java.util.Set; - -@Linked -public class LightableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 lit"; - - @Override - public Class type() { - return Lightable.class; - } - - @Override - public void copy(List attributes, Lightable blockData) { - if (blockData.isLit()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Lightable blockData) { - blockData.setLit(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/MultipleFacingAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/MultipleFacingAttribute.java deleted file mode 100644 index 262de53c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/MultipleFacingAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.MultipleFacing; - -import java.util.List; -import java.util.Set; - -@Linked -public class MultipleFacingAttribute implements BlockAttribute { - - private String attribute = "§8-§7 connected "; - - @Override - public Class type() { - return MultipleFacing.class; - } - - @Override - public void copy(List attributes, MultipleFacing blockData) { - blockData.getFaces().forEach(blockFace -> { - attributes.add(attribute + blockFace.name().toLowerCase()); - }); - } - - @Override - public void paste(Set attributes, MultipleFacing blockData) { - for (BlockFace blockFace : BlockFace.values()) { - blockData.setFace(blockFace, attributes.contains(attribute + blockFace.name().toLowerCase())); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OpenableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OpenableAttribute.java deleted file mode 100644 index 2e440e67..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OpenableAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Openable; - -import java.util.List; -import java.util.Set; - -@Linked -public class OpenableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 open"; - - @Override - public Class type() { - return Openable.class; - } - - @Override - public void copy(List attributes, Openable blockData) { - if (blockData.isOpen()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Openable blockData) { - blockData.setOpen(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OrientableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OrientableAttribute.java deleted file mode 100644 index e70d8ab3..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OrientableAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.Axis; -import org.bukkit.block.data.Orientable; - -import java.util.List; -import java.util.Set; - -@Linked -public class OrientableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 orientation "; - - @Override - public Class type() { - return Orientable.class; - } - - @Override - public void copy(List attributes, Orientable blockData) { - attributes.add(attribute + blockData.getAxis().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, Orientable blockData) { - for (Axis axis : Axis.values()) { - if (attributes.contains(attribute + axis.name().toLowerCase())) { - blockData.setAxis(axis); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/PowerableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/PowerableAttribute.java deleted file mode 100644 index 3aabee78..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/PowerableAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Powerable; - -import java.util.List; -import java.util.Set; - -@Linked -public class PowerableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 powered"; - - @Override - public Class type() { - return Powerable.class; - } - - @Override - public void copy(List attributes, Powerable blockData) { - if (blockData.isPowered()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Powerable blockData) { - blockData.setPowered(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RailAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RailAttribute.java deleted file mode 100644 index e7ab4e76..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RailAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Rail; - -import java.util.List; -import java.util.Set; - -@Linked -public class RailAttribute implements BlockAttribute { - - private String attribute = "§8-§7 rail shape "; - - @Override - public Class type() { - return Rail.class; - } - - @Override - public void copy(List attributes, Rail blockData) { - attributes.add(attribute + blockData.getShape().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, Rail blockData) { - for (Rail.Shape shape : Rail.Shape.values()) { - if (attributes.contains(attribute + shape)) { - blockData.setShape(shape); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RotatableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RotatableAttribute.java deleted file mode 100644 index 94a1fa8d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RotatableAttribute.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Rotatable; - -import java.util.List; -import java.util.Set; - -@Linked -public class RotatableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 rotation "; - - @Override - public Class type() { - return Rotatable.class; - } - - @Override - public void copy(List attributes, Rotatable blockData) { - attributes.add(attribute + blockData.getRotation().name()); - } - - @Override - public void paste(Set attributes, Rotatable blockData) { - for (BlockFace face : BlockFace.values()) { - if (attributes.contains(attribute + face.name())) { - blockData.setRotation(face); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/SnowableAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/SnowableAttribute.java deleted file mode 100644 index 71358651..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/SnowableAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Snowable; - -import java.util.List; -import java.util.Set; - -@Linked -public class SnowableAttribute implements BlockAttribute { - - private String attribute = "§8-§7 snowy"; - - @Override - public Class type() { - return Snowable.class; - } - - @Override - public void copy(List attributes, Snowable blockData) { - if (blockData.isSnowy()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Snowable blockData) { - blockData.setSnowy(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/WaterloggedAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/WaterloggedAttribute.java deleted file mode 100644 index bd010c01..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/WaterloggedAttribute.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.Waterlogged; - -import java.util.List; -import java.util.Set; - -@Linked -public class WaterloggedAttribute implements BlockAttribute { - - private String attribute = "§8-§7 waterlogged"; - - @Override - public Class type() { - return Waterlogged.class; - } - - @Override - public void copy(List attributes, Waterlogged waterlogged) { - if (!waterlogged.isWaterlogged()) return; - attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Waterlogged waterlogged) { - waterlogged.setWaterlogged(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BambooAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BambooAttribute.java deleted file mode 100644 index c2182b03..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BambooAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Bamboo; - -import java.util.List; -import java.util.Set; - -@Linked -public class BambooAttribute implements BlockAttribute { - - private String attribute = "§8-§7 leaves "; - - @Override - public Class type() { - return Bamboo.class; - } - - @Override - public void copy(List attributes, Bamboo blockData) { - attributes.add(attribute + blockData.getLeaves()); - } - - @Override - public void paste(Set attributes, Bamboo blockData) { - for (Bamboo.Leaves leaves : Bamboo.Leaves.values()) { - if (attributes.contains(attribute + leaves)) { - blockData.setLeaves(leaves); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BellAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BellAttribute.java deleted file mode 100644 index b5fcb280..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BellAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Bell; - -import java.util.List; -import java.util.Set; - -@Linked -public class BellAttribute implements BlockAttribute { - - private String attribute = "§8-§7 attachament "; - - @Override - public Class type() { - return Bell.class; - } - - @Override - public void copy(List attributes, Bell blockData) { - attributes.add(attribute + blockData.getAttachment()); - } - - @Override - public void paste(Set attributes, Bell blockData) { - for (Bell.Attachment attachment : Bell.Attachment.values()) { - if (attributes.contains(attribute + attachment)) { - blockData.setAttachment(attachment); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BigDripleafAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BigDripleafAttribute.java deleted file mode 100644 index a1ebef35..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BigDripleafAttribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.MinVersion; -import org.bukkit.block.data.type.BigDripleaf; - -import java.util.List; -import java.util.Set; - -@Linked -@MinVersion(18) -public class BigDripleafAttribute implements BlockAttribute { - - private String attribute = "§8-§7 tilt "; - - @Override - public Class type() { - return BigDripleaf.class; - } - - @Override - public void copy(List attributes, BigDripleaf blockData) { - attributes.add(attribute + blockData.getTilt()); - } - - @Override - public void paste(Set attributes, BigDripleaf blockData) { - for (BigDripleaf.Tilt tilt : BigDripleaf.Tilt.values()) { - if (attributes.contains(attribute + tilt)) { - blockData.setTilt(tilt); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CakeAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CakeAttribute.java deleted file mode 100644 index 0e44b938..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CakeAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Cake; - -import java.util.List; -import java.util.Set; - -@Linked -public class CakeAttribute implements BlockAttribute { - - private String attribute = "§8-§7 bites "; - - @Override - public Class type() { - return Cake.class; - } - - @Override - public void copy(List attributes, Cake blockData) { - attributes.add(attribute + blockData.getBites()); - } - - @Override - public void paste(Set attributes, Cake blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setBites); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CampfireAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CampfireAttribute.java deleted file mode 100644 index 9d5d9e3e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CampfireAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Campfire; - -import java.util.List; -import java.util.Set; - -@Linked -public class CampfireAttribute implements BlockAttribute { - - private String attribute = "§8-§7 signal fire"; - - @Override - public Class type() { - return Campfire.class; - } - - @Override - public void copy(List attributes, Campfire blockData) { - if (blockData.isSignalFire()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Campfire blockData) { - blockData.setSignalFire(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CandleAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CandleAttribute.java deleted file mode 100644 index a8e054d8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CandleAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Candle; - -import java.util.List; -import java.util.Set; - -@Linked -public class CandleAttribute implements BlockAttribute { - - private String attribute = "§8-§7 candles "; - - @Override - public Class type() { - return Candle.class; - } - - @Override - public void copy(List attributes, Candle blockData) { - if (blockData.getCandles() > 0) attributes.add(attribute + blockData.getCandles()); - } - - @Override - public void paste(Set attributes, Candle blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setCandles); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CaveVinesPlantAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CaveVinesPlantAttribute.java deleted file mode 100644 index ecbaf271..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CaveVinesPlantAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.CaveVinesPlant; - -import java.util.List; -import java.util.Set; - -@Linked -public class CaveVinesPlantAttribute implements BlockAttribute { - - private String attribute = "§8-§7 berries"; - - @Override - public Class type() { - return CaveVinesPlant.class; - } - - @Override - public void copy(List attributes, CaveVinesPlant blockData) { - if (blockData.isBerries()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, CaveVinesPlant blockData) { - blockData.setBerries(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ComparatorAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ComparatorAttribute.java deleted file mode 100644 index 4342008e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ComparatorAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Comparator; - -import java.util.List; -import java.util.Set; - -@Linked -public class ComparatorAttribute implements BlockAttribute { - - private String attribute = "§8-§7 mode "; - - @Override - public Class type() { - return Comparator.class; - } - - @Override - public void copy(List attributes, Comparator blockData) { - attributes.add(attribute + blockData.getMode().name()); - } - - @Override - public void paste(Set attributes, Comparator blockData) { - for (Comparator.Mode mode : Comparator.Mode.values()) { - if (attributes.contains(attribute + mode.name())) { - blockData.setMode(mode); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DaylightDetectorAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DaylightDetectorAttribute.java deleted file mode 100644 index 3c319987..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DaylightDetectorAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.DaylightDetector; - -import java.util.List; -import java.util.Set; - -@Linked -public class DaylightDetectorAttribute implements BlockAttribute { - - private String attribute = "§8-§7 inverted"; - - @Override - public Class type() { - return DaylightDetector.class; - } - - @Override - public void copy(List attributes, DaylightDetector blockData) { - if (blockData.isInverted()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, DaylightDetector blockData) { - blockData.setInverted(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DoorAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DoorAttribute.java deleted file mode 100644 index 1c7885af..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DoorAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Door; - -import java.util.List; -import java.util.Set; - -@Linked -public class DoorAttribute implements BlockAttribute { - - private String attribute = "§8-§7 hinge "; - - @Override - public Class type() { - return Door.class; - } - - @Override - public void copy(List attributes, Door blockData) { - attributes.add(attribute + blockData.getHinge().toString().toLowerCase()); - } - - @Override - public void paste(Set attributes, Door blockData) { - for (Door.Hinge hinge : Door.Hinge.values()) { - if (attributes.contains(attribute + hinge.toString().toLowerCase())) { - blockData.setHinge(hinge); - break; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/EndPortalFrameAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/EndPortalFrameAttribute.java deleted file mode 100644 index 25f790a6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/EndPortalFrameAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.EndPortalFrame; - -import java.util.List; -import java.util.Set; - -@Linked -public class EndPortalFrameAttribute implements BlockAttribute { - - private String attribute = "§8-§7 eye"; - - @Override - public Class type() { - return EndPortalFrame.class; - } - - @Override - public void copy(List attributes, EndPortalFrame blockData) { - if (blockData.hasEye()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, EndPortalFrame blockData) { - blockData.setEye(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/FarmlandAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/FarmlandAttribute.java deleted file mode 100644 index b55971d4..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/FarmlandAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Farmland; - -import java.util.List; -import java.util.Set; - -@Linked -public class FarmlandAttribute implements BlockAttribute { - - private String attribute = "§8-§7 moisture "; - - @Override - public Class type() { - return Farmland.class; - } - - @Override - public void copy(List attributes, Farmland blockData) { - attributes.add(attribute + blockData.getMoisture()); - } - - @Override - public void paste(Set attributes, Farmland blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setMoisture); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/GateAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/GateAttribute.java deleted file mode 100644 index 3f853135..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/GateAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Gate; - -import java.util.List; -import java.util.Set; - -@Linked -public class GateAttribute implements BlockAttribute { - - private String attribute = "§8-§7 inWall"; - - @Override - public Class type() { - return Gate.class; - } - - @Override - public void copy(List attributes, Gate blockData) { - if (blockData.isInWall()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Gate blockData) { - blockData.setInWall(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/HopperAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/HopperAttribute.java deleted file mode 100644 index b64266a8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/HopperAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Hopper; - -import java.util.List; -import java.util.Set; - -@Linked -public class HopperAttribute implements BlockAttribute { - - private String attribute = "§8-§7 enabled"; - - @Override - public Class type() { - return Hopper.class; - } - - @Override - public void copy(List attributes, Hopper blockData) { - if (blockData.isEnabled()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Hopper blockData) { - blockData.setEnabled(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/JigsawAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/JigsawAttribute.java deleted file mode 100644 index 492e2543..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/JigsawAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Jigsaw; - -import java.util.List; -import java.util.Set; - -@Linked -public class JigsawAttribute implements BlockAttribute { - - private String attribute = "§8-§7 orientation "; - - @Override - public Class type() { - return Jigsaw.class; - } - - @Override - public void copy(List attributes, Jigsaw blockData) { - attributes.add(attribute + blockData.getOrientation()); - } - - @Override - public void paste(Set attributes, Jigsaw blockData) { - for (Jigsaw.Orientation orientation : Jigsaw.Orientation.values()) { - if (attributes.contains(attribute + orientation)) { - blockData.setOrientation(orientation); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LanternAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LanternAttribute.java deleted file mode 100644 index 3ea0d701..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LanternAttribute.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Lantern; - -import java.util.List; -import java.util.Set; - -@Linked -public class LanternAttribute implements BlockAttribute { - - private String attribute = "§8-§7 lantern"; - - @Override - public Class type() { - return Lantern.class; - } - - @Override - public void copy(List attributes, Lantern lantern) { - if (!lantern.isHanging()) return; - attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Lantern lantern) { - lantern.setHanging(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LeavesAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LeavesAttribute.java deleted file mode 100644 index 74f445f6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LeavesAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Leaves; - -import java.util.List; -import java.util.Set; - -@Linked -public class LeavesAttribute implements BlockAttribute { - - private String attribute = "§8-§7 persistent"; - - @Override - public Class type() { - return Leaves.class; - } - - @Override - public void copy(List attributes, Leaves blockData) { - if (blockData.isPersistent()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Leaves blockData) { - blockData.setPersistent(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/PointedDripstoneAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/PointedDripstoneAttribute.java deleted file mode 100644 index 5b25834a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/PointedDripstoneAttribute.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.type.PointedDripstone; - -import java.util.List; -import java.util.Set; - -@Linked -public class PointedDripstoneAttribute implements BlockAttribute { - - private String attribute1 = "§8-§7 vertialDirection "; - private String attribute2 = "§8-§7 thickness "; - - @Override - public Class type() { - return PointedDripstone.class; - } - - @Override - public void copy(List attributes, PointedDripstone blockData) { - attributes.add(attribute1 + " " + blockData.getVerticalDirection().name().toLowerCase()); - attributes.add(attribute2 + " " + blockData.getThickness().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, PointedDripstone blockData) { - for (BlockFace blockFace : blockData.getVerticalDirections()) { - if (attributes.contains(attribute1 + " " + blockFace.name().toLowerCase())) { - blockData.setVerticalDirection(blockFace); - break; - } - } - for (PointedDripstone.Thickness thickness : PointedDripstone.Thickness.values()) { - if (attributes.contains(attribute2 + " " + thickness.name().toLowerCase())) { - blockData.setThickness(thickness); - break; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java deleted file mode 100644 index a3049f2b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.type.RedstoneWire; - -import java.util.List; -import java.util.Set; - -@Linked -public class RedstoneWireAttribute implements BlockAttribute { - - private String attribute = "§8-§7 connection "; - - @Override - public Class type() { - return RedstoneWire.class; - } - - @Override - public void copy(List attributes, RedstoneWire blockData) { - for (BlockFace blockFace : blockData.getAllowedFaces()) { - attributes.add(attribute + blockFace.name().toLowerCase() + " " + blockData.getFace(blockFace).name().toLowerCase()); - } - } - - @Override - public void paste(Set attributes, RedstoneWire blockData) { - for (BlockFace blockFace : blockData.getAllowedFaces()) { - for (RedstoneWire.Connection connection : RedstoneWire.Connection.values()) { - if (attributes.contains(attribute + blockFace.name().toLowerCase() + " " + connection.name().toLowerCase())) { - blockData.setFace(blockFace, connection); - } - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java deleted file mode 100644 index 1f25d655..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Repeater; - -import java.util.List; -import java.util.Set; - -@Linked -public class RepeaterAttribute implements BlockAttribute { - - private String attribute1 = "§8-§7 delay "; - private String attribute2 = "§8-§7 locked"; - - @Override - public Class type() { - return Repeater.class; - } - - @Override - public void copy(List attributes, Repeater blockData) { - attributes.add(attribute1 + blockData.getDelay()); - if (blockData.isLocked()) attributes.add(attribute2); - } - - @Override - public void paste(Set attributes, Repeater blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute1)) - .map(s -> s.replace(attribute1, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setDelay); - blockData.setLocked(attributes.contains(attribute2)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RespawnAnchorAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RespawnAnchorAttribute.java deleted file mode 100644 index 646a14d8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RespawnAnchorAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.RespawnAnchor; - -import java.util.List; -import java.util.Set; - -@Linked -public class RespawnAnchorAttribute implements BlockAttribute { - - private String attribute = "§8-§7 charges "; - - @Override - public Class type() { - return RespawnAnchor.class; - } - - @Override - public void copy(List attributes, RespawnAnchor blockData) { - attributes.add(attribute + blockData.getCharges()); - } - - @Override - public void paste(Set attributes, RespawnAnchor blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setCharges); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SaplingAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SaplingAttribute.java deleted file mode 100644 index 3a15fc35..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SaplingAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Sapling; - -import java.util.List; -import java.util.Set; - -@Linked -public class SaplingAttribute implements BlockAttribute { - - private String attribute = "§8-§7 stage "; - - @Override - public Class type() { - return Sapling.class; - } - - @Override - public void copy(List attributes, Sapling blockData) { - attributes.add(attribute + blockData.getStage()); - } - - @Override - public void paste(Set attributes, Sapling blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setStage); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ScaffoldingAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ScaffoldingAttribute.java deleted file mode 100644 index 8da631d8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ScaffoldingAttribute.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Scaffolding; - -import java.util.List; -import java.util.Set; - -@Linked -public class ScaffoldingAttribute implements BlockAttribute { - - private String attribute1 = "§8-§7 bottom"; - private String attribute2 = "§8-§7 distance "; - - @Override - public Class type() { - return Scaffolding.class; - } - - @Override - public void copy(List attributes, Scaffolding blockData) { - if (blockData.isBottom()) attributes.add(attribute1); - attributes.add(attribute2 + blockData.getDistance()); - } - - @Override - public void paste(Set attributes, Scaffolding blockData) { - blockData.setBottom(attributes.contains(attribute1)); - attributes.stream() - .filter(s -> s.startsWith(attribute2)) - .map(s -> s.replace(attribute2, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setDistance); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SculkSensorAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SculkSensorAttribute.java deleted file mode 100644 index 8f974f40..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SculkSensorAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.SculkSensor; - -import java.util.List; -import java.util.Set; - -@Linked -public class SculkSensorAttribute implements BlockAttribute { - - private String attribute = "§8-§7 phase "; - - @Override - public Class type() { - return SculkSensor.class; - } - - @Override - public void copy(List attributes, SculkSensor blockData) { - attributes.add(attribute + blockData.getPhase()); - } - - @Override - public void paste(Set attributes, SculkSensor blockData) { - for (SculkSensor.Phase phase : SculkSensor.Phase.values()) { - if (attributes.contains(attribute + phase)) { - blockData.setPhase(phase); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SeaPickleAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SeaPickleAttribute.java deleted file mode 100644 index 7b3ddf57..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SeaPickleAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.SeaPickle; - -import java.util.List; -import java.util.Set; - -@Linked -public class SeaPickleAttribute implements BlockAttribute { - - private String attribute = "§8-§7 pickles "; - - @Override - public Class type() { - return SeaPickle.class; - } - - @Override - public void copy(List attributes, SeaPickle blockData) { - attributes.add(attribute + blockData.getPickles()); - } - - @Override - public void paste(Set attributes, SeaPickle blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setPickles); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SlabAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SlabAttribute.java deleted file mode 100644 index eca81bf4..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SlabAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Slab; - -import java.util.List; -import java.util.Set; - -@Linked -public class SlabAttribute implements BlockAttribute { - - private String attribute = "§8-§7 type "; - - @Override - public Class type() { - return Slab.class; - } - - @Override - public void copy(List attributes, Slab blockData) { - attributes.add(attribute + blockData.getType()); - } - - @Override - public void paste(Set attributes, Slab blockData) { - for (Slab.Type type : Slab.Type.values()) { - if (attributes.contains(attribute + type)) { - blockData.setType(type); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SnowAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SnowAttribute.java deleted file mode 100644 index 935e975d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SnowAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Snow; - -import java.util.List; -import java.util.Set; - -@Linked -public class SnowAttribute implements BlockAttribute { - - private String attribute = "§8-§7 layers "; - - @Override - public Class type() { - return Snow.class; - } - - @Override - public void copy(List attributes, Snow blockData) { - attributes.add(attribute + blockData.getLayers()); - } - - @Override - public void paste(Set attributes, Snow blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute)) - .map(s -> s.replace(attribute, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setLayers); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StairsAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StairsAttribute.java deleted file mode 100644 index 3686b506..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StairsAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Stairs; - -import java.util.List; -import java.util.Set; - -@Linked -public class StairsAttribute implements BlockAttribute { - - private String attribute = "§8-§7 shape "; - - @Override - public Class type() { - return Stairs.class; - } - - @Override - public void copy(List attributes, Stairs blockData) { - attributes.add(attribute + blockData.getShape().name().toLowerCase()); - } - - @Override - public void paste(Set attributes, Stairs blockData) { - for (Stairs.Shape shape : Stairs.Shape.values()) { - if (attributes.contains(attribute + shape.name().toLowerCase())) { - blockData.setShape(shape); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StructureBlockAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StructureBlockAttribute.java deleted file mode 100644 index 34055ce9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StructureBlockAttribute.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.StructureBlock; - -import java.util.List; -import java.util.Set; - -@Linked -public class StructureBlockAttribute implements BlockAttribute { - - private String attribute = "§8-§7 mode "; - - @Override - public Class type() { - return StructureBlock.class; - } - - @Override - public void copy(List attributes, StructureBlock blockData) { - attributes.add(attribute + blockData.getMode().name()); - } - - @Override - public void paste(Set attributes, StructureBlock blockData) { - for (StructureBlock.Mode mode : StructureBlock.Mode.values()) { - if (attributes.contains(attribute + mode.name())) { - blockData.setMode(mode); - return; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TNTAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TNTAttribute.java deleted file mode 100644 index 14192eac..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TNTAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.TNT; - -import java.util.List; -import java.util.Set; - -@Linked -public class TNTAttribute implements BlockAttribute { - - private String attribute = "§8-§7 unstable"; - - @Override - public Class type() { - return TNT.class; - } - - @Override - public void copy(List attributes, TNT blockData) { - if (blockData.isUnstable()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, TNT blockData) { - blockData.setUnstable(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TripwireAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TripwireAttribute.java deleted file mode 100644 index 27257568..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TripwireAttribute.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.Tripwire; - -import java.util.List; -import java.util.Set; - -@Linked -public class TripwireAttribute implements BlockAttribute { - - private String attribute = "§8-§7 disarmed"; - - @Override - public Class type() { - return Tripwire.class; - } - - @Override - public void copy(List attributes, Tripwire blockData) { - if (blockData.isDisarmed()) attributes.add(attribute); - } - - @Override - public void paste(Set attributes, Tripwire blockData) { - blockData.setDisarmed(attributes.contains(attribute)); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TurtleEggAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TurtleEggAttribute.java deleted file mode 100644 index 478d1f75..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TurtleEggAttribute.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.data.type.TurtleEgg; - -import java.util.List; -import java.util.Set; - -@Linked -public class TurtleEggAttribute implements BlockAttribute { - - private String attribute1 = "§8-§7 eggs "; - private String attribute2 = "§8-§7 hatch "; - - @Override - public Class type() { - return TurtleEgg.class; - } - - @Override - public void copy(List attributes, TurtleEgg blockData) { - attributes.add(attribute1 + blockData.getEggs()); - attributes.add(attribute2 + blockData.getHatch()); - } - - @Override - public void paste(Set attributes, TurtleEgg blockData) { - attributes.stream() - .filter(s -> s.startsWith(attribute1)) - .map(s -> s.replace(attribute1, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setEggs); - attributes.stream() - .filter(s -> s.startsWith(attribute2)) - .map(s -> s.replace(attribute2, "")) - .map(Integer::parseInt) - .findFirst() - .ifPresent(blockData::setHatch); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/WallAttribute.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/WallAttribute.java deleted file mode 100644 index a72ed734..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/WallAttribute.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.attributescopy.impl.type; - -import de.steamwar.bausystem.features.attributescopy.BlockAttribute; -import de.steamwar.linkage.Linked; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.type.Wall; - -import java.util.List; -import java.util.Set; - -@Linked -public class WallAttribute implements BlockAttribute { - - private BlockFace[] faces = new BlockFace[] {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST}; - - private String attribute1 = "§8-§7 up"; - private String attribute2 = "§8-§7 connected "; - - @Override - public Class type() { - return Wall.class; - } - - @Override - public void copy(List attributes, Wall blockData) { - if (blockData.isUp()) attributes.add(attribute1); - for (BlockFace face : faces) { - if (blockData.getHeight(face) == Wall.Height.NONE) continue; - attributes.add(attribute2 + face.name().toLowerCase() + " " + blockData.getHeight(face).name().toLowerCase()); - } - } - - @Override - public void paste(Set attributes, Wall blockData) { - blockData.setUp(attributes.contains(attribute1)); - for (BlockFace face : faces) { - for (Wall.Height height : Wall.Height.values()) { - if (attributes.contains(attribute2 + face.name().toLowerCase() + " " + height.name().toLowerCase())) { - blockData.setHeight(face, height); - break; - } - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/AbstractDetonatorEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/AbstractDetonatorEntity.java deleted file mode 100644 index 1f1a5b8b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/AbstractDetonatorEntity.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.detonator; - -import de.steamwar.bausystem.shared.AbstractEntity; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public interface AbstractDetonatorEntity extends AbstractEntity { - - void display(Player player); - - boolean hide(Player player, boolean always); - - int getId(); - - Entity getBukkitEntity(); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java index c1ffd756..80d5b33b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java @@ -25,7 +25,8 @@ import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.autostart.AutostartListener; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; import de.steamwar.bausystem.features.detonator.storage.ItemStorage; -import de.steamwar.bausystem.utils.NMSWrapper; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -44,7 +45,7 @@ import java.util.*; @UtilityClass public class Detonator { - private static final Map> ENTITIES_MAP = new HashMap<>(); + private static final Map ENTITIES_MAP = new HashMap<>(); private static final Vector HALF = new Vector(0.5, 0, 0.5); public static boolean isDetonator(ItemStack itemStack) { @@ -52,18 +53,24 @@ public class Detonator { } public static void showDetonator(Player p, List locs) { - List entities = new LinkedList<>(); - locs.stream().map(Location::toVector).forEach(vector -> entities.add(NMSWrapper.impl.constructDetonator(p.getWorld(), vector.add(HALF)))); - entities.forEach(abstractDetonatorEntity -> abstractDetonatorEntity.display(p)); - ENTITIES_MAP.putIfAbsent(p, entities); + if (ENTITIES_MAP.containsKey(p)) return; + REntityServer entities = new REntityServer(); + entities.setCallback((player, rEntity, entityAction) -> { + Vector vector = new Vector(rEntity.getX(), rEntity.getY(), rEntity.getZ()); + DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player); + DetonatorListener.HAS_UPDATED.add(player); + }); + entities.addPlayer(p); + ENTITIES_MAP.put(p, entities); + + locs.forEach(location -> { + RFallingBlockEntity entity = new RFallingBlockEntity(entities, location.clone().add(HALF), Material.RED_STAINED_GLASS); + entity.setNoGravity(true); + }); } public static void hideDetonator(Player p) { - ENTITIES_MAP.remove(p).forEach(abstractDetonatorEntity -> abstractDetonatorEntity.hide(p, true)); - } - - public static List getDetoEntities(Player p) { - return ENTITIES_MAP.getOrDefault(p, new ArrayList<>()); + ENTITIES_MAP.remove(p).close(); } public static boolean hasActiveDetonatorShow(Player p) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 2e0cbf38..be8e8ce9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -19,8 +19,6 @@ package de.steamwar.bausystem.features.detonator; -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; @@ -38,39 +36,14 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; import java.util.HashSet; -import java.util.List; import java.util.Set; @Linked public class DetonatorListener implements Listener { - public static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); - private static final Reflection.FieldAccessor entityIdFieldAccessor = Reflection.getField(useEntity, int.class, 0); + static final Set HAS_UPDATED = new HashSet<>(); - private static final Set HAS_UPDATED = new HashSet<>(); - - public DetonatorListener() { - TinyProtocol.instance.addFilter(useEntity, (player, o) -> { - List entities = Detonator.getDetoEntities(player); - if (entities.isEmpty()) { - return o; - } - - int entityId = entityIdFieldAccessor.get(o); - AbstractDetonatorEntity entity = entities.stream().filter(abstractDetonatorEntity -> abstractDetonatorEntity.getId() == entityId).findFirst().orElse(null); - - if (entity == null) { - return o; - } - - Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation(); - addLocationToDetonator(location, player); - HAS_UPDATED.add(player); - return null; - }); - } - - private static void addLocationToDetonator(Location location, Player p) { + static void addLocationToDetonator(Location location, Player p) { Detoblock detoblock = Detonator.getBlock(location.getBlock()); if (detoblock == Detoblock.INVALID) { SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("DETONATOR_INVALID_BLOCK", p)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 168b1893..e97f4a30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -33,7 +33,10 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; public class KillcheckerVisualizer { @@ -207,7 +210,7 @@ public class KillcheckerVisualizer { public boolean hide(Player player) { rEntityServer.removePlayer(player); players.remove(player); - if (player.isEmpty()) { + if (players.isEmpty()) { rEntityServer.close(); return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/AbstractSimulatorEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/AbstractSimulatorEntity.java deleted file mode 100644 index faf81588..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/AbstractSimulatorEntity.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.shared.AbstractEntity; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public interface AbstractSimulatorEntity extends AbstractEntity { - - void display(Player player); - - void setPosition(Vector position); - - boolean hide(Player player, boolean always); - - int getId(); - - Entity getBukkitEntity(); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index fcc11942..caa3af54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -20,13 +20,17 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; +import de.steamwar.bausystem.utils.RayTraceUtils; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; import java.util.HashMap; @@ -36,13 +40,14 @@ import java.util.Map; @UtilityClass public class SimulatorCursor { - private Map cursors = new HashMap<>(); + private static final World WORLD = Bukkit.getWorlds().get(0); + private Map rEntityServerMap = new HashMap<>(); - public void show(Player player, TNTSimulator tntSimulator, RayTraceResult result) { - AbstractSimulatorEntity cursor = cursors.get(player); + public void show(Player player, TNTSimulator tntSimulator, RayTraceUtils.RRayTraceResult result) { + REntityServer cursor = rEntityServerMap.get(player); if (cursor != null) - cursor.hide(player, false); + cursor.close(); tntSimulator.show(player); @@ -51,11 +56,13 @@ public class SimulatorCursor { if (result.getHitEntity() != null) { List elements = tntSimulator.getEntity(result.getHitEntity()); - tntSimulator.hide(player, elements); - cursor = SimulatorEntityShowMode.createEntity(elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition(), true); - cursor.display(player); - cursors.put(player, cursor); + cursor = new REntityServer(); + RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.TNT); + entity.setNoGravity(true); + entity.setGlowing(true); + cursor.addPlayer(player); + rEntityServerMap.put(player, cursor); BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR); return; } @@ -64,25 +71,27 @@ public class SimulatorCursor { return; } - cursor = SimulatorEntityShowMode.createEntity(getPos(player, result), false); - cursor.display(player); - cursors.put(player, cursor); + cursor = new REntityServer(); + RFallingBlockEntity entity = new RFallingBlockEntity(cursor, getPos(player, result).toLocation(WORLD), Material.TNT); + entity.setNoGravity(true); + cursor.addPlayer(player); + rEntityServerMap.put(player, cursor); BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_ADD", player, ChatMessageType.ACTION_BAR); } public void hide(Player player, TNTSimulator tntSimulator) { - AbstractSimulatorEntity cursor = cursors.get(player); + REntityServer cursor = rEntityServerMap.get(player); if (cursor != null) - cursor.hide(player, false); + cursor.close(); if (tntSimulator != null) { - tntSimulator.remove(player); + tntSimulator.hide(player); } - cursors.remove(player); + rEntityServerMap.remove(player); } - public static Vector getPos(Player player, RayTraceResult result) { + public static Vector getPos(Player player, RayTraceUtils.RRayTraceResult result) { Vector pos = result.getHitPosition(); BlockFace face = result.getHitBlockFace(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreview.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreview.java deleted file mode 100644 index 422bb075..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreview.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.tracer.show.Record; -import de.steamwar.core.VersionDependent; -import lombok.AllArgsConstructor; -import lombok.Data; - -public interface SimulatorPreview { - SimulatorPreview impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); - - @Data - @AllArgsConstructor - class SimulatorPreviewTNTData { - private double x; - private double y; - private double z; - private int fuseTicks; - private boolean xVelocity; - private boolean yVelocity; - private boolean zVelocity; - } - - Record simulate(TNTSimulator tntSimulator); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java deleted file mode 100644 index 43024440..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.features.simulator.show.PreviewEntityShowMode; -import de.steamwar.bausystem.features.tracer.TNTPosition; -import de.steamwar.bausystem.features.tracer.show.Record; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.shared.Pair; -import de.steamwar.bausystem.shared.ShowMode; -import lombok.experimental.UtilityClass; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -@UtilityClass -public class SimulatorPreviewStorage { - private Map>> previews = new HashMap<>(); - private Map>> showModes = new HashMap<>(); - - public void show(Player player, TNTSimulator tntSimulator) { - if (showModes.containsKey(player)) { - Pair> pair = showModes.get(player); - if (pair.getKey() != tntSimulator) { - pair.getValue().hide(); - Pair> setPair = previews.get(pair.getKey()); - setPair.getValue().remove(player); - if (setPair.getValue().isEmpty()) { - previews.remove(pair.getKey()); - } - } else { - return; - } - } - - Pair> pair = previews.computeIfAbsent(tntSimulator, k -> new Pair<>(SimulatorPreview.impl.simulate(k), new HashSet<>())); - pair.getValue().add(player); - - ShowModeParameter showModeParameter = new ShowModeParameter(); - PreviewEntityShowMode showMode = new PreviewEntityShowMode(player, showModeParameter); - pair.getKey().showAll(showMode); - showModes.put(player, new Pair<>(tntSimulator, showMode)); - } - - public void hide(Player player) { - if (showModes.containsKey(player)) { - Pair> pair = showModes.get(player); - pair.getValue().hide(); - Pair> setPair = previews.get(pair.getKey()); - setPair.getValue().remove(player); - if (setPair.getValue().isEmpty()) { - previews.remove(pair.getKey()); - } - showModes.remove(player); - } - } - - public void recalculate(TNTSimulator tntSimulator) { - Pair> pair = previews.get(tntSimulator); - if (pair == null) return; - pair.setKey(SimulatorPreview.impl.simulate(tntSimulator)); - pair.getValue().forEach(player -> { - Pair> setPair = showModes.get(player); - setPair.getValue().hide(); - pair.getKey().showAll(setPair.getValue()); - }); - } - - public void recalculateAll() { - previews.keySet().forEach(SimulatorPreviewStorage::recalculate); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java index 8c965f97..0b7b312b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -105,10 +105,7 @@ public class SimulatorStorage implements Enable, Disable { public static void delete(String name) { TNTSimulator tntSimulator = tntSimulators.remove(name); if (tntSimulator != null) { - new HashMap<>(tntSimulator.getPlayerShowMode()).forEach((player, simulatorEntityShowMode) -> { - SimulatorCursor.hide(player, tntSimulator); - }); - tntSimulator.hide(); + tntSimulator.close(); } new File(simulatorsDir, name + ".simulator").delete(); } @@ -181,7 +178,7 @@ public class SimulatorStorage implements Enable, Disable { if (content.isEmpty()) continue; TNTSimulator tntSimulator = new TNTSimulator(); for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) { - tntSimulator.getTntElementList().add(new TNTElement(element)); + tntSimulator.getTntElementList().add(new TNTElement(element, tntSimulator.getEntityServer())); } tntSimulators.put(newName, tntSimulator); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 4a92058a..39057f99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -23,7 +23,6 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI; import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui; -import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulator.tnt.TNTElement; import de.steamwar.bausystem.features.simulator.tnt.TNTGroup; @@ -31,12 +30,13 @@ import de.steamwar.bausystem.features.tracer.record.Recorder; import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.bausystem.utils.RayTraceUtils; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.util.RayTraceResult; import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONType; @@ -49,7 +49,8 @@ import java.util.stream.Collectors; @Getter public class TNTSimulator { - private Map playerShowMode = new HashMap<>(); + private Set players = new HashSet<>(); + private REntityServer entityServer = new REntityServer(); private Material material = Material.TNT; @@ -64,9 +65,9 @@ public class TNTSimulator { YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray()); for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) { if (element.containsKey("elements", YAPIONType.ARRAY)) { - tntElementList.add(new TNTGroup(element)); + tntElementList.add(new TNTGroup(element, entityServer)); } else { - tntElementList.add(new TNTElement(element)); + tntElementList.add(new TNTElement(element, entityServer)); } } } @@ -82,74 +83,25 @@ public class TNTSimulator { return yapionObject; } - public void hide() { - playerShowMode.forEach((player, simulatorEntityShowMode) -> { - simulatorEntityShowMode.hide(); - }); - } - - public void show() { - playerShowMode.forEach((player, simulatorEntityShowMode) -> { - for (SimulatorElement element : tntElementList) { - element.show(simulatorEntityShowMode); - } - }); - } - - public void hide(Player player) { - SimulatorEntityShowMode showMode = playerShowMode.get(player); - if (showMode == null) { - return; - } - tntElementList.forEach(simulatorElement -> { - simulatorElement.hide(showMode); - }); - } - - public void remove(Player player) { - SimulatorEntityShowMode showMode = playerShowMode.remove(player); - if (showMode == null) { - return; - } - tntElementList.forEach(simulatorElement -> { - simulatorElement.hide(showMode); - }); - } - - public void hide(Player player, List simulatorElements) { - SimulatorEntityShowMode showMode = playerShowMode.get(player); - if (showMode == null) { - return; - } - simulatorElements.forEach(simulatorElement -> { - simulatorElement.hide(showMode); - }); - } - - public void hide(SimulatorElement simulatorElement) { - playerShowMode.forEach((player, simulatorEntityShowMode) -> { - simulatorElement.hide(simulatorEntityShowMode); - }); + public void close() { + entityServer.close(); } public void show(Player player) { - SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new); - tntElementList.forEach(simulatorElement -> { - simulatorElement.show(showMode); - }); + entityServer.addPlayer(player); + players.add(player); } - public void show(SimulatorElement simulatorElement) { - playerShowMode.forEach((player, simulatorEntityShowMode) -> { - simulatorElement.show(simulatorEntityShowMode); - }); + public void hide(Player player) { + entityServer.removePlayer(player); + players.remove(player); } - public List getEntities() { + public List getEntities() { return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); } - public List getEntity(Entity entity) { + public List getEntity(REntity entity) { List tntSpawns = new ArrayList<>(); for (SimulatorElement spawn : tntElementList) { spawn.getEntity(tntSpawns, entity); @@ -158,7 +110,6 @@ public class TNTSimulator { } public void remove(SimulatorElement element) { - hide(element); tntElementList.remove(element); Set toRemove = new HashSet<>(); for (SimulatorElement spawn : tntElementList) { @@ -185,7 +136,7 @@ public class TNTSimulator { }); } - public void edit(Player player, RayTraceResult result) { + public void edit(Player player, RayTraceUtils.RRayTraceResult result) { if (result == null) { TNTSimulatorGui.open(player, this, null, this::getTntElementList, null); return; @@ -209,12 +160,9 @@ public class TNTSimulator { return; } - TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result)); + TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), entityServer); tntElementList.add(tntElement); TNTElementGUI.open(player, tntElement, null); - playerShowMode.forEach((p, simulatorEntityShowMode) -> { - show(p); - }); } public void start(Player p) { @@ -230,7 +178,7 @@ public class TNTSimulator { } AtomicBoolean needsAutoTrace = new AtomicBoolean(); - playerShowMode.forEach((player, simulatorEntityShowMode) -> { + players.forEach(player -> { boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); if (simulatorAutoTrace) { needsAutoTrace.set(true); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index d057fd76..491f37c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -25,13 +25,10 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -50,19 +47,14 @@ public class TNTSimulatorListener implements Listener { return true; } - static RayTraceResult trace(Player player, Location to, TNTSimulator simulator) { - return RayTraceUtils.trace(player, to, simulator.getEntities()); + static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) { + return RayTraceUtils.traceREntity(player, to, simulator.getEntities()); } @EventHandler public void onPlayerMove(PlayerMoveEvent e) { if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) { simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo()); - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(e.getPlayer().getInventory().getItemInOffHand()); - if (tntSimulator == null) SimulatorPreviewStorage.hide(e.getPlayer()); - } else { - TNTSimulator tntSimulator = simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInOffHand, e.getTo()); - if (tntSimulator != null) SimulatorPreviewStorage.show(e.getPlayer(), tntSimulator); } } @@ -91,11 +83,6 @@ public class TNTSimulatorListener implements Listener { public void onPlayerJoin(PlayerJoinEvent e) { if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) { simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getPlayer().getLocation()); - } else { - TNTSimulator tntSimulator = simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInOffHand, e.getPlayer().getLocation()); - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (tntSimulator != null) SimulatorPreviewStorage.show(e.getPlayer(), tntSimulator); - }, 10); } } @@ -103,29 +90,8 @@ public class TNTSimulatorListener implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { SimulatorCursor.hide(event.getPlayer(), null); SimulatorStorage.getSimulatorNames().forEach(s -> { - SimulatorStorage.getSimulator(s).remove(event.getPlayer()); + SimulatorStorage.getSimulator(s).hide(event.getPlayer()); }); - SimulatorPreviewStorage.hide(event.getPlayer()); - } - - @EventHandler - public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(event.getOffHandItem()); - if (tntSimulator == null) { - SimulatorPreviewStorage.hide(event.getPlayer()); - return; - } - SimulatorPreviewStorage.show(event.getPlayer(), tntSimulator); - } - - @EventHandler - public void onBlockPlace(BlockPlaceEvent event) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), SimulatorPreviewStorage::recalculateAll, 1); - } - - @EventHandler - public void onBlockBreak(BlockBreakEvent event) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), SimulatorPreviewStorage::recalculateAll, 1); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java index b442088a..2ca90d2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorSelectionGUI.java @@ -49,7 +49,7 @@ public class SimulatorSelectionGUI { SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> { TNTSimulator current = SimulatorStorage.getSimulator(hand); if (current != null) { - current.remove(player); + current.hide(player); } SimulatorStorage.setSimulator(player, hand, tntSimulator); player.getInventory().setItemInMainHand(hand); @@ -64,7 +64,7 @@ public class SimulatorSelectionGUI { if (SimulatorCommand.createSimulator(player, s)) { TNTSimulator current = SimulatorStorage.getSimulator(hand); if (current != null) { - current.remove(player); + current.hide(player); } TNTSimulator tntSimulator = SimulatorStorage.getSimulator(s); SimulatorStorage.setSimulator(player, hand, tntSimulator); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java index 24a1a3a7..bfd0312b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulator.OrderUtils; -import de.steamwar.bausystem.features.simulator.SimulatorPreviewStorage; import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.TNTSimulator; import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial; @@ -42,7 +41,6 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; @@ -66,7 +64,6 @@ public class TNTElementGUI { } TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { List locationLore = new ArrayList<>(); locationLore.add(""); @@ -76,7 +73,6 @@ public class TNTElementGUI { inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_LOCATION", player), locationLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; editLocation(player, tntElement, () -> open(player, tntElement, back)); - recalculate.set(true); })); List propertiesLore = new ArrayList<>(); @@ -91,7 +87,6 @@ public class TNTElementGUI { inv.setItem(22, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_PROPERTIES", player), propertiesLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; editProperties(player, tntElement, () -> open(player, tntElement, back)); - recalculate.set(true); })); List otherLore = new ArrayList<>(); @@ -105,13 +100,11 @@ public class TNTElementGUI { inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; editOther(player, tntElement, () -> open(player, tntElement, back)); - recalculate.set(true); })); // Delete tnt inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntSimulator.remove(tntElement); player.closeInventory(); })); @@ -120,9 +113,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); @@ -134,61 +124,49 @@ public class TNTElementGUI { inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { - ChangePosition.show(inv, player, recalculate, tntSimulator, tntElement, tntElement::getOwnPosition, x -> x - tntElement.getParentPosition().getX(), y -> y - tntElement.getParentPosition().getY(), z -> z - tntElement.getParentPosition().getZ(), () -> editLocation(player, tntElement, back)); + ChangePosition.show(inv, player, tntElement, vectorUnaryOperator -> { + if (tntElement.getParent() == null) { + tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition())); + } else { + tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition()).subtract(tntElement.getParent().getPosition())); + } + }, () -> editLocation(player, tntElement, back)); // Alignment inv.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - tntSimulator.hide(tntElement); - Vector position = tntElement.getPosition(); + Vector position = tntElement.getOwnPosition(); align(position, new Vector(0, 0, 0.49)); - tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - tntSimulator.show(tntElement); + tntElement.setPosition(position); tntElement.change(); })); inv.setItem(25, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - tntSimulator.hide(tntElement); - Vector position = tntElement.getPosition(); + Vector position = tntElement.getOwnPosition(); align(position, new Vector(0, 0, 0.51)); - tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - tntSimulator.show(tntElement); + tntElement.setPosition(position); tntElement.change(); })); inv.setItem(15, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - tntSimulator.hide(tntElement); - Vector position = tntElement.getPosition(); + Vector position = tntElement.getOwnPosition(); align(position, new Vector(0.51, 0, 0)); - tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); - tntSimulator.show(tntElement); + tntElement.setPosition(position); tntElement.change(); })); inv.setItem(33, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - tntSimulator.hide(tntElement); - Vector position = tntElement.getPosition(); + Vector position = tntElement.getOwnPosition(); align(position, new Vector(0.49, 0, 0)); - tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); - tntSimulator.show(tntElement); + tntElement.setPosition(position); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - tntSimulator.hide(tntElement); - Vector position = tntElement.getPosition(); + Vector position = tntElement.getOwnPosition(); align(position, new Vector(0.5, 0, 0.5)); - tntElement.getOwnPosition().setX(position.getX() - tntElement.getParentPosition().getX()); - tntElement.getOwnPosition().setZ(position.getZ() - tntElement.getParentPosition().getZ()); - tntSimulator.show(tntElement); + tntElement.setPosition(position); tntElement.change(); })); }; @@ -196,9 +174,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); @@ -236,18 +211,15 @@ public class TNTElementGUI { List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { // Change Count of spawned TNT inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setCount(tntElement.getCount() + ((clickType.isShiftClick()) ? 5 : 1)); tntElement.change(); }))); SWItem countItem = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, tntElement.getCount()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT_ANVIL_GUI_NAME", player), tntElement.getCount(), c -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setCount(c); tntElement.change(); editProperties(player, tntElement, back); @@ -256,7 +228,6 @@ public class TNTElementGUI { inv.setItem(19, countItem); inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setCount(tntElement.getCount() - ((clickType.isShiftClick()) ? 5 : 1)); tntElement.change(); }))); @@ -264,13 +235,11 @@ public class TNTElementGUI { // Change TickOffset inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setTickOffset(tntElement.getOwnTickOffset() + (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); }))); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntElement.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntElement.getTickOffset(), tick -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setTickOffset(tick - tntElement.getParentTickOffset()); tntElement.change(); editProperties(player, tntElement, back); @@ -279,7 +248,6 @@ public class TNTElementGUI { inv.setItem(20, tickItem); inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setTickOffset(tntElement.getOwnTickOffset() - (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); }))); @@ -287,13 +255,11 @@ public class TNTElementGUI { // Change FuseTicks inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setFuseTicks(tntElement.getFuseTicks() + (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); }))); SWItem fuseTickItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, tntElement.getFuseTicks()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE_ANVIL_GUI_NAME", player), tntElement.getFuseTicks(), tick -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setFuseTicks(tick); tntElement.change(); editProperties(player, tntElement, back); @@ -302,7 +268,6 @@ public class TNTElementGUI { inv.setItem(21, fuseTickItem); inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setFuseTicks(tntElement.getFuseTicks() - (clickType.isShiftClick() ? 5 : 1)); tntElement.change(); }))); @@ -310,7 +275,6 @@ public class TNTElementGUI { // Velocity Settings inv.setItem(24, Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_NAME", player), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); if (tntElement.isXVelocity() || tntElement.isYVelocity() || tntElement.isZVelocity()) { tntElement.setXVelocity(false); tntElement.setYVelocity(false); @@ -324,19 +288,16 @@ public class TNTElementGUI { }); inv.setItem(32, new SWItem(getWool(tntElement.isXVelocity()), getColor(tntElement.isXVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, active(player, tntElement.isXVelocity())), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setXVelocity(!tntElement.isXVelocity()); tntElement.change(); })); inv.setItem(15, new SWItem(getWool(tntElement.isYVelocity()), getColor(tntElement.isYVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, active(player, tntElement.isYVelocity())), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setYVelocity(!tntElement.isYVelocity()); tntElement.change(); })); inv.setItem(34, new SWItem(getWool(tntElement.isZVelocity()), getColor(tntElement.isZVelocity()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, active(player, tntElement.isZVelocity())), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntElement.setZVelocity(!tntElement.isZVelocity()); tntElement.change(); })); @@ -345,9 +306,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); @@ -360,11 +318,9 @@ public class TNTElementGUI { } TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { inv.setItem(19, new SWItem(tntElement.getOrder(), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_NAME", player), OrderUtils.orderList(tntElement.getOrder(), player), false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); if (clickType.isShiftClick()) { tntElement.setOrder(OrderUtils.previous(tntElement.getOrder())); } else { @@ -374,12 +330,11 @@ public class TNTElementGUI { })); ChangeMaterial.show(inv, player, 21, tntElement, Material.BARREL, () -> editOther(player, tntElement, back)); - Disabled.show(inv, player, recalculate, 22, tntSimulator, tntElement); + Disabled.show(inv, player, 22, tntSimulator, tntElement); if (!tntElement.hasParent()) { inv.setItem(24, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE", player), Arrays.asList(), false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); // Create TNTGroup tntSimulator.getTntElementList().remove(tntElement); Vector vector = tntElement.getOwnPosition().clone(); @@ -394,7 +349,7 @@ public class TNTElementGUI { tntSimulator.getTntElementList().add(tntGroup); // Add new TNT - TNTElement newElement = new TNTElement(new Vector(0, 0, 0)); + TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntSimulator.getEntityServer()); newElement.setTickOffset(1); tntGroup.add(newElement); @@ -409,9 +364,8 @@ public class TNTElementGUI { inv.setItem(25, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); Vector vector = tntElement.getOwnPosition().clone(); - TNTElement newElement = new TNTElement(vector); + TNTElement newElement = new TNTElement(vector, tntSimulator.getEntityServer()); if (tntElement.hasParent()) { newElement.setTickOffset(tntElement.getOwnTickOffset() + 1); tntElement.getParent().add(newElement); @@ -427,7 +381,6 @@ public class TNTElementGUI { // Delete tnt inv.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntSimulator.remove(tntElement); player.closeInventory(); })); @@ -436,9 +389,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java index 3f2cc7e8..9c4aa70a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTGroupEditGUI.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.SimulatorPreviewStorage; import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.TNTSimulator; import de.steamwar.bausystem.features.simulator.gui.components.ChangeMaterial; @@ -41,7 +40,6 @@ import org.bukkit.util.Vector; import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.UnaryOperator; import static de.steamwar.bausystem.features.simulator.gui.ItemUtils.unique; @@ -80,51 +78,39 @@ public class TNTGroupEditGUI { // X Position inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, vector.getX()), lore, false, clickType -> {})); inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); - tntSimulator.show(); tntSimulator.change(); }))); // Y Position inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, vector.getY()), lore, false, clickType -> {})); inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); - tntSimulator.show(); tntSimulator.change(); }))); // Z Position inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, vector.getZ()), lore, false, clickType -> {})); inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(simulatorElements, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); - tntSimulator.show(); }))); inv.open(); @@ -134,10 +120,10 @@ public class TNTGroupEditGUI { for (SimulatorElement element : simulatorElements) { if (element instanceof TNTGroup) { TNTGroup group = (TNTGroup) element; - group.getPosition().add(vector); + group.setPosition(group.getPosition().add(vector)); } else if (element instanceof TNTElement) { TNTElement tntElement = (TNTElement) element; - tntElement.getOwnPosition().add(vector); + tntElement.setPosition(tntElement.getOwnPosition().add(vector)); } } } @@ -161,22 +147,21 @@ public class TNTGroupEditGUI { List lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player)); TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); - AtomicBoolean recalculate = new AtomicBoolean(false); Runnable editObserver = () -> { - ChangePosition.show(inv, player, recalculate, tntSimulator, tntGroup, tntGroup::getPosition, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity(), () -> open(player, tntGroup, back)); + ChangePosition.show(inv, player, tntGroup, vectorUnaryOperator -> { + tntGroup.setPosition(vectorUnaryOperator.apply(tntGroup.getPosition())); + }, () -> open(player, tntGroup, back)); ChangeMaterial.show(inv, player, 14, tntGroup, Material.BARREL, () -> open(player, tntGroup, back)); - Disabled.show(inv, player, recalculate, 32, tntSimulator, tntGroup); + Disabled.show(inv, player, 32, tntSimulator, tntGroup); // Change TickOffset inv.setItem(16, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntGroup.setTickOffset(tntGroup.getTickOffset() + (clickType.isShiftClick() ? 5 : 1)); tntGroup.change(); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tntGroup.getTickOffset()), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tntGroup.getTickOffset(), tick -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntGroup.setTickOffset(tick); tntGroup.change(); open(player, tntGroup, back); @@ -185,7 +170,6 @@ public class TNTGroupEditGUI { inv.setItem(25, tickItem); inv.setItem(34, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); tntGroup.setTickOffset(tntGroup.getTickOffset() - (clickType.isShiftClick() ? 5 : 1)); tntGroup.change(); })); @@ -194,7 +178,6 @@ public class TNTGroupEditGUI { tntGroup.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntGroup.unregister(editObserver); - SimulatorPreviewStorage.recalculate(tntSimulator); }); inv.open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java index d87b36d5..aed364bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTSimulatorGui.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.simulator.gui; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.configplayer.Config; -import de.steamwar.bausystem.features.simulator.SimulatorPreviewStorage; import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.TNTSimulator; import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement; @@ -76,19 +75,6 @@ public class TNTSimulatorGui { if (back != null) { inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } - if (currentTntSimulator != null) { - if (totalTNTCount > 0) { - inv.setItem(48, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> { - moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); - })); - } - - boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); - inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> { - Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace); - open(player, currentTntSimulator, currentTntGroup, simulatorElements, back); - })); - } SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TOTAL_TNT", player, totalTNTCount), clickType -> { }); swItem.getItemStack().setAmount(totalTNTCount); @@ -117,7 +103,6 @@ public class TNTSimulatorGui { currentTntGroup.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { currentTntGroup.unregister(editObserver); - SimulatorPreviewStorage.recalculate(currentTntSimulator); }); } else { if (!elements.isEmpty()) { @@ -126,15 +111,24 @@ public class TNTSimulatorGui { TNTGroupEditGUI.open(player, tntSimulator, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); })); } - inv.addCloseCallback(clickType -> { - SimulatorPreviewStorage.recalculate(currentTntSimulator); - }); + } + if (currentTntSimulator != null) { + if (totalTNTCount > 0) { + inv.setItem(48, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> { + moveAll(player, currentTntSimulator, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); + })); + } + + boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); + inv.setItem(47, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> { + Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace); + open(player, currentTntSimulator, currentTntGroup, simulatorElements, back); + })); } if (currentTntSimulator != null || currentTntGroup != null) { inv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> { if (currentTntSimulator != null) { - currentTntSimulator.hide(); currentTntSimulator.getTntElementList().forEach(SimulatorElement::close); currentTntSimulator.getTntElementList().clear(); player.closeInventory(); @@ -169,51 +163,40 @@ public class TNTSimulatorGui { // X Position inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), lore, false, clickType -> {})); inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? X_VECTOR : FX_VECTOR).clone().multiply(-1)); - tntSimulator.show(); tntSimulator.change(); }))); // Y Position inv.setItem(13, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), lore, false, clickType -> {})); inv.setItem(31, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR).clone().multiply(-1)); - tntSimulator.show(); tntSimulator.change(); }))); // Z Position inv.setItem(14, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - tntSimulator.show(); tntSimulator.change(); }))); inv.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), lore, false, clickType -> {})); inv.setItem(32, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - tntSimulator.hide(); moveAll(tntSimulator, (clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR).clone().multiply(-1)); - tntSimulator.show(); + tntSimulator.change(); }))); inv.open(); @@ -223,10 +206,10 @@ public class TNTSimulatorGui { for (SimulatorElement element : tntSimulator.getTntElementList()) { if (element instanceof TNTGroup) { TNTGroup group = (TNTGroup) element; - group.getPosition().add(vector); + group.setPosition(group.getPosition().add(vector)); } else if (element instanceof TNTElement) { TNTElement tntElement = (TNTElement) element; - tntElement.getOwnPosition().add(vector); + tntElement.setPosition(tntElement.getOwnPosition().add(vector)); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java index 88b849d6..16f1090c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/ChangePosition.java @@ -35,6 +35,7 @@ import org.bukkit.util.Vector; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -51,7 +52,7 @@ public class ChangePosition { private static final Vector FY_VECTOR = new Vector(0, 1, 0); private static final Vector FZ_VECTOR = new Vector(0, 0, 1); - public void show(SWInventory inv, Player player, AtomicBoolean recalculate, TNTSimulator tntSimulator, SimulatorElement simulatorElement, Supplier toChangeVector, UnaryOperator calculatePositionX, UnaryOperator calculatePositionY, UnaryOperator calculatePositionZ, Runnable back) { + public void show(SWInventory inv, Player player, SimulatorElement simulatorElement, Consumer> toChangeVector, Runnable back) { String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player); String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player); List plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player)); @@ -61,84 +62,84 @@ public class ChangePosition { // X Position inv.setItem(10, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); + return vector; + }); simulatorElement.change(); }))); inv.setItem(19, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, simulatorElement.getPosition().getX()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getX(), x -> { - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().setX(clamp(calculatePositionX.apply(x))); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.setX(clamp(x)); + return vector; + }); simulatorElement.change(); back.run(); }, back); })); inv.setItem(28, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); + return vector; + }); simulatorElement.change(); }))); // Y Position inv.setItem(11, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); + return vector; + }); simulatorElement.change(); }))); inv.setItem(20, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, simulatorElement.getPosition().getY()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getY(), y -> { - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().setY(clamp(calculatePositionY.apply(y))); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.setY(clamp(y)); + return vector; + }); simulatorElement.change(); back.run(); }, back); })); inv.setItem(29, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); + return vector; + }); simulatorElement.change(); }))); // Z Position inv.setItem(12, unique(new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); + return vector; + }); simulatorElement.change(); }))); inv.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, simulatorElement.getPosition().getZ()), lore, false, clickType -> { changePosition(player, simulatorElement.getPosition().getZ(), z -> { - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().setZ(clamp(calculatePositionZ.apply(z))); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.setZ(clamp(z)); + return vector; + }); simulatorElement.change(); back.run(); }, back); })); inv.setItem(30, unique(new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> { if (clickType == ClickType.DOUBLE_CLICK) return; - recalculate.set(true); - if (tntSimulator != null) tntSimulator.hide(simulatorElement); - toChangeVector.get().subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); - if (tntSimulator != null) tntSimulator.show(simulatorElement); + toChangeVector.accept(vector -> { + vector.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); + return vector; + }); simulatorElement.change(); }))); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java index dcb0b8bb..a6798165 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/components/Disabled.java @@ -29,21 +29,13 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicBoolean; @UtilityClass public class Disabled { - public void show(SWInventory inv, Player player, AtomicBoolean recalculate, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) { + public void show(SWInventory inv, Player player, int position, TNTSimulator tntSimulator, SimulatorElement simulatorElement) { inv.setItem(position, new SWItem(simulatorElement.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, BauSystem.MESSAGE.parse(simulatorElement.isDisabled() ? "SIMULATOR_TNT_SPAWN_DISABLED" : "SIMULATOR_TNT_SPAWN_ENABLED", player), new ArrayList<>(), !simulatorElement.isDisabled(), clickType -> { - recalculate.set(true); - if (!simulatorElement.isDisabled()) { - tntSimulator.hide(simulatorElement); - } simulatorElement.setDisabled(!simulatorElement.isDisabled()); - if (!simulatorElement.isDisabled()) { - tntSimulator.show(simulatorElement); - } simulatorElement.change(); })); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/PreviewEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/PreviewEntityShowMode.java deleted file mode 100644 index b03a8a29..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/PreviewEntityShowMode.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.simulator.show; - -import de.steamwar.bausystem.features.tracer.TNTPosition; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.features.tracer.show.mode.FactoredEntityShowMode; -import org.bukkit.entity.Player; - -public class PreviewEntityShowMode extends FactoredEntityShowMode { - - public PreviewEntityShowMode(Player player, ShowModeParameter showModeParameter) { - super(player, showModeParameter, 10); - } - - @Override - public void show(TNTPosition position) { - super.show(position); - } - - @Override - public void hide() { - super.hide(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/SimulatorEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/SimulatorEntityShowMode.java deleted file mode 100644 index 8cdb228c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/SimulatorEntityShowMode.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.steamwar.bausystem.features.simulator.show; - -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.shared.Position; -import de.steamwar.bausystem.shared.RoundedPosition; -import de.steamwar.bausystem.shared.ShowMode; -import de.steamwar.bausystem.utils.NMSWrapper; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.util.HashMap; -import java.util.Map; - -public class SimulatorEntityShowMode implements ShowMode { - - protected final Player player; - - private final Map entityMap = new HashMap<>(); - - public SimulatorEntityShowMode(Player player) { - this.player = player; - } - - @Override - public void show(Position position) { - RoundedPosition roundedPosition = new RoundedPosition(position); - AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(position.getLocation(), false)); - entity.display(player); - } - - public static AbstractSimulatorEntity createEntity(Vector position, boolean highlight) { - return NMSWrapper.impl.createSimulator(SimulatorStorage.WORLD, position, highlight); - } - - public void hide(Position position) { - RoundedPosition roundedPosition = new RoundedPosition(position); - AbstractSimulatorEntity abstractSimulatorEntity = entityMap.get(roundedPosition); - if (abstractSimulatorEntity == null) { - return; - } - if (abstractSimulatorEntity.hide(player, false)) { - entityMap.remove(roundedPosition); - } - } - - @Override - public void hide() { - entityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - entityMap.clear(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java index c4c48e4e..181e3389 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/SimulatorElement.java @@ -19,14 +19,12 @@ package de.steamwar.bausystem.features.simulator.tnt; -import de.steamwar.bausystem.features.simulator.SimulatorPreview; -import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.entity.REntity; import de.steamwar.inventory.SWItem; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONObject; @@ -39,19 +37,16 @@ public interface SimulatorElement { Map closeObserver = new HashMap<>(); YAPIONObject toYAPION(); - List getEntities(); - void getEntity(List elements, Entity entity); - default Vector getPosition() { - return new Vector(0, 0, 0); - } + List getEntities(); + void getEntity(List elements, REntity entity); + + Vector getPosition(); + void setPosition(Vector position); void remove(TNTElement tntElement); - void show(SimulatorEntityShowMode showMode); - void hide(SimulatorEntityShowMode showMode); SWItem menu(Player p); boolean locations(Map>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations - void locations(Map>>> result); int tntCount(); int tick(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index 29fcd778..df762600 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -20,24 +20,24 @@ package de.steamwar.bausystem.features.simulator.tnt; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.simulator.OrderUtils; -import de.steamwar.bausystem.features.simulator.SimulatorPreview; import de.steamwar.bausystem.features.simulator.SimulatorStorage; -import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.shared.Pair; -import de.steamwar.bausystem.shared.Position; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.Entity; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; @@ -48,7 +48,9 @@ import java.util.*; @Getter public class TNTElement implements SimulatorElement { - private final AbstractSimulatorEntity entity; + private static final World WORLD = Bukkit.getWorlds().get(0); + + private final RFallingBlockEntity entity; TNTGroup tntGroup = null; private final Vector position; @@ -68,14 +70,18 @@ public class TNTElement implements SimulatorElement { private Material material = Material.TNT; private boolean disabled = false; - public TNTElement(Vector position) { + public TNTElement(Vector position, REntityServer entityServer) { this.position = position; - this.entity = SimulatorEntityShowMode.createEntity(position, false); + this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); + this.entity.setNoGravity(true); } - public TNTElement(YAPIONObject yapionObject) { + public TNTElement(YAPIONObject yapionObject, REntityServer entityServer) { this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0))); - this.entity = SimulatorEntityShowMode.createEntity(position, false); + this.disabled = yapionObject.getBooleanOrDefault("disabled", false); + this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); + this.entity.setNoGravity(true); + this.entity.setInvisible(disabled); this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80); this.count = yapionObject.getIntOrDefault("count", 1); this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); @@ -100,21 +106,20 @@ public class TNTElement implements SimulatorElement { yapionObject.add("zVelocity", zVelocity); yapionObject.add("order", order.name()); yapionObject.add("material", material.name()); + yapionObject.add("disabled", disabled); return yapionObject; } @Override - public List getEntities() { + public List getEntities() { if (disabled) return new ArrayList<>(); - entity.setPosition(getPosition()); - return Arrays.asList(entity.getBukkitEntity()); + return Arrays.asList(entity); } @Override - public void getEntity(List elements, Entity entity) { + public void getEntity(List elements, REntity entity) { if (disabled) return; - this.entity.setPosition(getPosition()); - if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) { + if (this.entity.getEntityId() == entity.getEntityId() || getPosition().equals(new Vector(entity.getX(), entity.getY(), entity.getZ()))) { elements.add(this); } } @@ -127,6 +132,19 @@ public class TNTElement implements SimulatorElement { return position.clone(); } + @Override + public void setPosition(Vector position) { + this.position.setX(position.getX()); + this.position.setY(position.getY()); + this.position.setZ(position.getZ()); + _updatePosition(); + } + + void _updatePosition() { + Vector position = getPosition(); + entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); + } + public int getTickOffset() { if (tntGroup != null) { return tntGroup.getTickOffset() + tickOffset; @@ -136,20 +154,7 @@ public class TNTElement implements SimulatorElement { @Override public void remove(TNTElement tntElement) { - } - - @Override - public void show(SimulatorEntityShowMode showMode) { - if (disabled) return; - entity.setPosition(getPosition()); - showMode.show(new Position(getPosition())); - } - - @Override - public void hide(SimulatorEntityShowMode showMode) { - if (disabled) return; - entity.setPosition(getPosition()); - showMode.hide(new Position(getPosition())); + entity.die(); } @Override @@ -199,17 +204,6 @@ public class TNTElement implements SimulatorElement { return false; } - @Override - public void locations(Map>>> result) { - if (disabled) return; - Location location = getPosition().toLocation(SimulatorStorage.WORLD); - result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>()) - .computeIfAbsent(OrderUtils.order(order), ignore -> new HashSet<>()) - .add(new Pair<>( - new SimulatorPreview.SimulatorPreviewTNTData(location.getX(), location.getY(), location.getZ(), fuseTicks, xVelocity, yVelocity, zVelocity), - count)); - } - @Override public int tntCount() { return disabled ? 0 : count; @@ -256,14 +250,7 @@ public class TNTElement implements SimulatorElement { } public Vector getOwnPosition() { - return position; - } - - public Vector getParentPosition() { - if (tntGroup != null) { - return tntGroup.getPosition(); - } - return new Vector(0, 0, 0); + return position.clone(); } public void setOrder(Material material) { @@ -284,5 +271,10 @@ public class TNTElement implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; + entity.setInvisible(disabled); + } + + void _setDisabled(boolean disabled) { + entity.setInvisible(disabled); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java index 4b75fef4..3ab48778 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTGroup.java @@ -20,15 +20,14 @@ package de.steamwar.bausystem.features.simulator.tnt; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.simulator.SimulatorPreview; -import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.Pair; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; import de.steamwar.inventory.SWItem; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONArray; @@ -53,14 +52,14 @@ public class TNTGroup implements SimulatorElement { this.position = position; } - public TNTGroup(YAPIONObject yapionObject) { + public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) { this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0)); this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL")); this.disabled = yapionObject.getBooleanOrDefault("disabled", false); YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray()); for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) { - TNTElement tntElement = new TNTElement(element); + TNTElement tntElement = new TNTElement(element, entityServer); tntElement.tntGroup = this; this.elements.add(tntElement); } @@ -89,38 +88,37 @@ public class TNTGroup implements SimulatorElement { } @Override - public List getEntities() { + public List getEntities() { if (disabled) new ArrayList<>(); return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList()); } @Override - public void getEntity(List elements, Entity entity) { + public void getEntity(List elements, REntity entity) { if (disabled) return; for (TNTElement tntElement : this.elements) { tntElement.getEntity(elements, entity); } } + @Override + public Vector getPosition() { + return position.clone(); + } + + @Override + public void setPosition(Vector position) { + this.position.setX(position.getX()); + this.position.setY(position.getY()); + this.position.setZ(position.getZ()); + elements.forEach(TNTElement::_updatePosition); + } + @Override public void remove(TNTElement tntElement) { - elements.remove(tntElement); - } - - @Override - public void show(SimulatorEntityShowMode showMode) { - if (disabled) return; - elements.forEach(tntElement -> { - tntElement.show(showMode); - }); - } - - @Override - public void hide(SimulatorEntityShowMode showMode) { - if (disabled) return; - elements.forEach(tntElement -> { - tntElement.hide(showMode); - }); + if (elements.remove(tntElement)) { + tntElement.remove(tntElement); + } } @Override @@ -152,14 +150,6 @@ public class TNTGroup implements SimulatorElement { return false; } - @Override - public void locations(Map>>> result) { - if (disabled) return; - for (TNTElement element : elements) { - element.locations(result); - } - } - @Override public int tntCount() { if (disabled) return 0; @@ -191,5 +181,8 @@ public class TNTGroup implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; + elements.forEach(tntElement -> { + tntElement._setDisabled(disabled); + }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java index bde0c16f..e3fc265a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.slaves.laufbau.states; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; -import de.steamwar.bausystem.features.slaves.laufbau.states.LaufbauState; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.region.Point; import lombok.Getter; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java deleted file mode 100644 index 10179551..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.tracer; - -import de.steamwar.bausystem.shared.AbstractEntity; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; - -public interface AbstractTraceEntity extends AbstractEntity { - - void display(Player player, boolean exploded, int ticks); - - boolean hide(Player player, boolean always); - - Entity getBukkitEntity(); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 77775134..b24ec012 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -25,8 +25,7 @@ import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.record.*; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.*; -import de.steamwar.bausystem.features.tracer.show.mode.RawEntityShowMode; -import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; +import de.steamwar.bausystem.features.tracer.show.EntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.command.PreviousArguments; @@ -210,8 +209,8 @@ public class TraceCommand extends SWCommand { @AllArgsConstructor private enum ShowModeType { - ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}), - RAW(RawEntityShowMode::new, new ShowModeParameterType[]{}); + ENTITY((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, 10), new ShowModeParameterType[]{}), + RAW((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, -1), new ShowModeParameterType[]{}); private BiFunction> showModeBiFunction; private ShowModeParameterType[] removedTypes; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java deleted file mode 100644 index 5974d50e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.tracer; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.tracer.show.TraceShowManager; -import de.steamwar.bausystem.utils.RayTraceUtils; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.api.Plain; -import net.md_5.bungee.api.chat.ClickEvent; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.util.RayTraceResult; - -import java.util.HashSet; -import java.util.Set; - -@Linked -public class TraceTNTClickListener implements Plain { - - private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); - - { - Set playerSet = new HashSet<>(); - - TinyProtocol.instance.addFilter(useEntity, (player, o) -> { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (!playerSet.add(player)) return; - RayTraceResult rayTraceResult = RayTraceUtils.trace(player, player.getLocation(), TraceShowManager.getEntities(player)); - if (rayTraceResult == null) return; - if (rayTraceResult.getHitEntity() == null) return; - TNTPosition tntPosition = TraceShowManager.getTNTPosition(player, rayTraceResult.getHitEntity()); - if (tntPosition == null) return; - - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks()); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId())); - }, 1); - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - playerSet.remove(player); - }, 2); - return o; - }); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java new file mode 100644 index 00000000..bfcd15e5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -0,0 +1,247 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer.show; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.TNTPosition; +import de.steamwar.bausystem.shared.RoundedPosition; +import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.bausystem.utils.FlatteningWrapper; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import net.md_5.bungee.api.chat.ClickEvent; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.*; +import java.util.function.BiConsumer; +import java.util.stream.Stream; + +public class EntityShowMode implements ShowMode { + + private final int factor; + private final Player player; + private final ShowModeParameter showModeParameter; + + private REntityServer entityServer; + + private final Map tntEntityMap = new HashMap<>(); + private final Map explodeEntityMap = new HashMap<>(); + private final Map updateEntityMap = new HashMap<>(); + + public EntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) { + this.player = player; + this.showModeParameter = showModeParameter; + this.factor = factor; + } + + @Override + public void show(TNTPosition position) { + if (entityServer == null) { + entityServer = new REntityServer(); + entityServer.setCallback((player, rEntity, entityAction) -> { + if (entityAction != REntityServer.EntityAction.INTERACT) return; + TNTPosition tntPosition = Stream.concat(tntEntityMap.values().stream(), explodeEntityMap.values().stream()) + .filter(entityStack -> entityStack.entity == rEntity) + .findFirst() + .map(entityStack -> entityStack.tntPosition) + .orElse(null); + if (tntPosition == null) return; + + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks()); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId())); + }); + entityServer.addPlayer(player); + } + + if (showModeParameter.isBuildDestroyOnly() && !position.getRecord().isInBuildArea()) { + return; + } + + if (showModeParameter.isExplodeOnly()) { + if (position.isExploded()) { + generatePositions(position, false, false); + } + if (!showModeParameter.isSourceOnly()) { + return; + } + } + + if (showModeParameter.isSourceOnly()) { + if (position.isSource()) { + generatePositions(position, false, false); + } + return; + } + + boolean exploded = position.getRecord().getPositions().stream().anyMatch(TNTPosition::isExploded); + if (!showModeParameter.isWater() && exploded && checkWater(position.getLocation())) { + if (position.isExploded()) { + for (TNTPosition pos : position.getRecord().getPositions()) { + generatePositions(pos, showModeParameter.isInterpolateY(), showModeParameter.isInterpolateXZ(), (positionType, vector) -> { + RoundedPosition roundedPosition = new RoundedPosition(vector, factor); + Map map; + if (positionType == PositionType.TNT) { + map = tntEntityMap; + } else if (positionType == PositionType.EXPLODE) { + map = explodeEntityMap; + } else { + map = updateEntityMap; + } + map.computeIfPresent(roundedPosition, (roundedPosition1, entityStack) -> { + if (!entityStack.remove(pos.getRecord())) { + return null; + } + return entityStack; + }); + }); + } + } + return; + } + + generatePositions(position, showModeParameter.isInterpolateY(), showModeParameter.isInterpolateXZ()); + } + + @Override + public void hide() { + tntEntityMap.clear(); + explodeEntityMap.clear(); + updateEntityMap.clear(); + if (entityServer != null) { + entityServer.close(); + entityServer = null; + } + } + + private void generatePositions(TNTPosition position, boolean interpolateY, boolean interpolateXZ) { + generatePositions(position, interpolateY, interpolateXZ, (positionType, vector) -> { + RoundedPosition roundedPosition = new RoundedPosition(vector, factor); + EntityStack entityStack; + if (positionType == PositionType.TNT) { + entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); + } else if (positionType == PositionType.EXPLODE) { + entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); + } else { + entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); + } + entityStack.add(position.getRecord()); + }); + } + + private boolean checkWater(Vector position) { + return FlatteningWrapper.impl.inWater(player.getWorld(), position); + } + + private REntity createEntity(Vector position, PositionType positionType) { + Material material; + if (positionType == PositionType.TNT) { + material = Material.TNT; + } else if (positionType == PositionType.EXPLODE) { + material = Material.RED_STAINED_GLASS; + } else { + material = Material.WHITE_STAINED_GLASS; + } + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material); + entity.setNoGravity(true); + return entity; + } + + private class EntityStack { + + private final TNTPosition tntPosition; + private final Vector position; + private final PositionType positionType; + private final int fuseTicks; + + private REntity entity; + private int count; + private List records = new ArrayList<>(); + + public EntityStack(TNTPosition tntPosition, Vector position, PositionType positionType, int fuseTicks) { + this.tntPosition = tntPosition; + this.position = position; + this.positionType = positionType; + this.fuseTicks = fuseTicks; + } + + public void add(Record.TNTRecord record) { + records.add(record); + if (entity == null) { + entity = createEntity(position, positionType); + } + count++; + if (showModeParameter.isTicks()) { + entity.setDisplayName(fuseTicks + ""); + } else if (showModeParameter.isCount()) { + entity.setDisplayName(new HashSet<>(records).size() + ""); + } + } + + public boolean remove(Record.TNTRecord record) { + if (entity == null) return false; + records.remove(record); + count--; + if (count == 0) { + entity.die(); + entity = null; + return false; + } + return true; + } + } + + public static void generatePositions(TNTPosition position, boolean interpolateY, boolean interpolateXZ, BiConsumer positionCallback) { + positionCallback.accept(position.isExploded() ? PositionType.EXPLODE : PositionType.TNT, position.getLocation()); + if (position.getPreviousLocation() == null) return; + + if (interpolateY) { + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); + if (!position.getLocation().equals(updatePointY)) { + positionCallback.accept(PositionType.UPDATE, updatePointY); + } + } + + if (interpolateXZ) { + Vector updatePointXZ = Math.abs(position.getUpdateVelocity().getX()) >= Math.abs(position.getUpdateVelocity().getZ()) + ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) + : position.getLocation().clone().setX(position.getPreviousLocation().getX()); + if (!position.getLocation().equals(updatePointXZ)) { + positionCallback.accept(PositionType.UPDATE, updatePointXZ); + } + } + } + + public enum PositionType { + TNT, + EXPLODE, + UPDATE + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityTraceShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityTraceShowMode.java deleted file mode 100644 index 2b73a40b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityTraceShowMode.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.tracer.show; - -import de.steamwar.bausystem.features.tracer.TNTPosition; -import de.steamwar.bausystem.shared.ShowMode; -import org.bukkit.entity.Entity; - -import java.util.List; - -public interface EntityTraceShowMode extends ShowMode { - List getEntities(); - TNTPosition getTNTPosition(Entity entity); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java index 100e58c3..d8e3a75f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -29,6 +29,7 @@ public class ShowModeParameter { private boolean sourceOnly = false; private boolean explodeOnly = false; private boolean ticks = false; + private boolean count = false; private boolean buildDestroyOnly = false; public void enableWater() { @@ -55,6 +56,10 @@ public class ShowModeParameter { this.ticks = true; } + public void enableCount() { + this.count = true; + } + public void enableBuildDestroyOnly() { this.buildDestroyOnly = true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index 5f4bcb46..3d28237d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -35,10 +35,11 @@ public enum ShowModeParameterType { ADVANCED(showModeParameter -> { showModeParameter.enableInterpolateY(); showModeParameter.enableInterpolateXZ(); - }, Arrays.asList("-advanced", "-a", "advanced"), "INTERPOLATE_Y", "INTERPOLATE_XZ"), - SOURCE(ShowModeParameter::enableSourceOnly, Arrays.asList("-source", "-sourceonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), + }, Arrays.asList("-advanced", "-a"), "INTERPOLATE_Y", "INTERPOLATE_XZ"), + SOURCE(ShowModeParameter::enableSourceOnly, Arrays.asList("-source", "-sourceonly", "-ignite"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), EXPLODE(ShowModeParameter::enableExplodeOnly, Arrays.asList("-explode", "-explodeonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), - TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE"), + TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT"), + COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "COUNT"), BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"); @Getter diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index 565db661..44ac27c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.entity.REntity; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -63,51 +64,13 @@ public class TraceShowManager implements Listener { if (regionalShowModes == null) { return; } - ShowMode showMode = regionalShowModes.get(player); + ShowMode showMode = regionalShowModes.remove(player); if (showMode == null) { return; } showMode.hide(); } - public static List getEntities(Player player) { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return Collections.emptyList(); - } - Map> regionalShowModes = showModes.get(region); - if (regionalShowModes == null) { - return Collections.emptyList(); - } - ShowMode showMode = regionalShowModes.get(player); - if (showMode == null) { - return Collections.emptyList(); - } - if (showMode instanceof EntityTraceShowMode) { - return ((EntityTraceShowMode) showMode).getEntities(); - } - return Collections.emptyList(); - } - - public static TNTPosition getTNTPosition(Player player, Entity entity) { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return null; - } - Map> regionalShowModes = showModes.get(region); - if (regionalShowModes == null) { - return null; - } - ShowMode showMode = regionalShowModes.get(player); - if (showMode == null) { - return null; - } - if (showMode instanceof EntityTraceShowMode) { - return ((EntityTraceShowMode) showMode).getTNTPosition(entity); - } - return null; - } - public static void reshow(Region region, Player p) { Map> regionalShowModes = showModes.get(region); if (regionalShowModes == null) { @@ -160,13 +123,10 @@ public class TraceShowManager implements Listener { @EventHandler public void onLeave(PlayerQuitEvent event) { - Region region = Region.getRegion(event.getPlayer().getLocation()); - if (!region.isGlobal()) { - Map> regionalShowModes = showModes.get(region); - if (regionalShowModes != null) { - regionalShowModes.remove(event.getPlayer()); - } - } + showModes.forEach((region, playerShowModeMap) -> { + ShowMode showMode = playerShowModeMap.remove(event.getPlayer()); + if (showMode != null) showMode.hide(); + }); StoredRecords.cleanup(event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java deleted file mode 100644 index 93dbaa0c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.tracer.show.mode; - -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.features.tracer.TNTPosition; -import de.steamwar.bausystem.features.tracer.show.EntityTraceShowMode; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.shared.RoundedPosition; -import de.steamwar.bausystem.utils.FlatteningWrapper; -import de.steamwar.bausystem.utils.NMSWrapper; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.util.Consumer; -import org.bukkit.util.Vector; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public abstract class FactoredEntityShowMode implements EntityTraceShowMode { - - private int factor; - - protected final Player player; - protected final ShowModeParameter showModeParameter; - - private final Map tntEntityMap = new HashMap<>(); - private final Map updateEntityMap = new HashMap<>(); - private final Map tntPositionMap = new HashMap<>(); - - protected FactoredEntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) { - this.player = player; - this.showModeParameter = showModeParameter; - this.factor = factor; - } - - @Override - public void show(TNTPosition position) { - if (showModeParameter.isBuildDestroyOnly() && !position.getRecord().isInBuildArea()) { - return; - } - if (showModeParameter.isExplodeOnly()) { - if (position.isExploded()) { - RoundedPosition roundedPosition = new RoundedPosition(position, factor); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); - tntPositionMap.put(entity.getBukkitEntity(), position); - entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1); - } - if (!showModeParameter.isSourceOnly()) { - return; - } - } - if (showModeParameter.isSourceOnly()) { - if (position.isSource()) { - RoundedPosition roundedPosition = new RoundedPosition(position, factor); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); - tntPositionMap.put(entity.getBukkitEntity(), position); - entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1); - } - return; - } - if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { - // Basic - for (TNTPosition pos : position.getRecord().getPositions()) { - RoundedPosition roundedPosition = new RoundedPosition(pos, factor); - tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> { - return tnt.hide(player, false) ? null : tnt; - }); - } - // Advanced - for (TNTPosition pos : position.getRecord().getPositions()) { - applyOnPosition(pos, updatePointPosition -> { - updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition, factor), (p, point) -> { - return point.hide(player, false) ? null : point; - }); - }); - } - return; - } - - RoundedPosition roundedPosition = new RoundedPosition(position, factor); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); - tntPositionMap.put(entity.getBukkitEntity(), position); - entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1); - - applyOnPosition(position, updatePointPosition -> { - updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> { - return createEntity(player, updatePointPosition, false); - }).display(player, false, showModeParameter.isTicks() ? position.getFuseTicks() : -1); - }); - } - - private boolean checkWater(Vector position) { - return FlatteningWrapper.impl.inWater(player.getWorld(), position); - } - - public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) { - return NMSWrapper.impl.createTrace(player.getWorld(), position, tnt); - } - - private void applyOnPosition(TNTPosition position, Consumer function) { - if (position.getPreviousLocation() == null) return; - - if (showModeParameter.isInterpolateY()) { - Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); - if (!position.getLocation().equals(updatePointY)) { - function.accept(updatePointY); - } - } - - if (showModeParameter.isInterpolateXZ()) { - Vector updatePointXZ = Math.abs(position.getUpdateVelocity().getX()) >= Math.abs(position.getUpdateVelocity().getZ()) - ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) - : position.getLocation().clone().setX(position.getPreviousLocation().getX()); - if (!position.getLocation().equals(updatePointXZ)) { - function.accept(updatePointXZ); - } - } - } - - @Override - public void hide() { - tntPositionMap.clear(); - tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - tntEntityMap.clear(); - updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - updateEntityMap.clear(); - } - - @Override - public List getEntities() { - return new ArrayList<>(tntPositionMap.keySet()); - } - - @Override - public TNTPosition getTNTPosition(Entity entity) { - return tntPositionMap.get(entity); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java deleted file mode 100644 index 22952c0d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.features.tracer.show.mode; - -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import org.bukkit.entity.Player; - -public class RawEntityShowMode extends FactoredEntityShowMode { - - public RawEntityShowMode(Player player, ShowModeParameter showModeParameter) { - super(player, showModeParameter, -1); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java deleted file mode 100644 index a5decb5c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * / - */ - -package de.steamwar.bausystem.features.tracer.show.mode; - -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import org.bukkit.entity.Player; - -public class TraceEntityShowMode extends FactoredEntityShowMode { - - public TraceEntityShowMode(Player player, ShowModeParameter showModeParameter) { - super(player, showModeParameter, 10); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/AbstractWarpEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/AbstractWarpEntity.java deleted file mode 100644 index 4671d2f0..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/AbstractWarpEntity.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.warp; - -import de.steamwar.bausystem.shared.AbstractEntity; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -public interface AbstractWarpEntity extends AbstractEntity { - - void display(Player player); - - void setName(String name); - - boolean hide(Player player); - - void sendMetaData(Player player); - - void teleport(Player player, Vector position); - - Vector getPosition(); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java index 33f437c4..953d709a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java @@ -20,7 +20,8 @@ package de.steamwar.bausystem.features.warp; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.utils.NMSWrapper; +import de.steamwar.entity.RArmorStand; +import de.steamwar.entity.REntityServer; import de.steamwar.linkage.Linked; import org.bukkit.*; import org.bukkit.entity.Player; @@ -32,74 +33,51 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import java.util.*; -import java.util.function.Consumer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Linked public class WarpListener implements Listener { - private Map> warpsShown = new HashMap<>(); + private Map warpEntityServer = new HashMap<>(); private Map> selected = new HashMap<>(); @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent e) { ItemStack itemStack = e.getPlayer().getInventory().getItem(e.getNewSlot()); Material material = itemStack == null ? Material.AIR : itemStack.getType(); - createStuff(e.getPlayer(), material, e.getPlayer().isSneaking()); + reshow(e.getPlayer(), material, e.getPlayer().isSneaking()); } @EventHandler public void onPlayerMove(PlayerMoveEvent event) { for (Player p : Bukkit.getOnlinePlayers()) { - createStuff(p, p.getInventory().getItemInMainHand().getType(), p.isSneaking()); + reshow(p, p.getInventory().getItemInMainHand().getType(), p.isSneaking()); } } @EventHandler public void onPlayerToggleSneak(PlayerToggleSneakEvent event) { - createStuff(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking()); + reshow(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand().getType(), event.isSneaking()); } - private static final class WarpEntityIterator { - - private final List warps; - - public WarpEntityIterator(List warps) { - this.warps = warps == null ? Collections.emptyList() : warps; + private void reshow(Player p, Material material, boolean sneaking) { + REntityServer entityServer = warpEntityServer.get(p); + if (entityServer != null) { + entityServer.close(); } - - public AbstractWarpEntity next(Player p, Vector position, String name) { - if (!warps.isEmpty()) { - AbstractWarpEntity abstractWarpEntity = warps.stream().min(Comparator.comparingDouble(o -> o.getPosition().distanceSquared(position))).get(); - warps.remove(abstractWarpEntity); - abstractWarpEntity.teleport(p, position); - abstractWarpEntity.setName(name); - abstractWarpEntity.sendMetaData(p); - return abstractWarpEntity; - } else { - AbstractWarpEntity warp = createEntity(p, position, name); - warp.display(p); - return warp; - } - } - - public void forEach(Consumer consumer) { - warps.forEach(consumer); - } - } - - private void createStuff(Player p, Material material, boolean sneaking) { - WarpEntityIterator it = new WarpEntityIterator(warpsShown.remove(p)); if (material != Material.COMPASS) { - it.forEach(abstractWarpEntity -> { - abstractWarpEntity.teleport(p, new Vector(0, 100000, 0)); - abstractWarpEntity.hide(p); - }); + warpEntityServer.remove(p); return; } selected.remove(p); - List warps = warpsShown.getOrDefault(p, new ArrayList<>()); + entityServer = new REntityServer(); + entityServer.addPlayer(p); + warpEntityServer.put(p, entityServer); + Vector current = p.getLocation().clone().add(p.getLocation().getDirection().multiply(5)).toVector(); current.setY(p.getLocation().getY() - 1); @@ -121,6 +99,7 @@ public class WarpListener implements Listener { } } + REntityServer finalEntityServer = entityServer; locations.forEach((name, location) -> { Vector vector = location.toVector().subtract(p.getLocation().toVector()); if (vector.getX() * vector.getX() + vector.getZ() * vector.getZ() < 25) { @@ -135,14 +114,11 @@ public class WarpListener implements Listener { name = "§a§l" + name; selected.computeIfAbsent(p, player -> new ArrayList<>()).add(location); } - warps.add(it.next(p, position, name)); + RArmorStand armorStand = new RArmorStand(finalEntityServer, position.toLocation(p.getWorld()), RArmorStand.Size.MARKER); + armorStand.setDisplayName(name); + armorStand.setNoGravity(true); + armorStand.setInvisible(true); }); - - it.forEach(abstractWarpEntity -> { - abstractWarpEntity.teleport(p, new Vector(0, 100000, 0)); - abstractWarpEntity.hide(p); - }); - warpsShown.put(p, warps); } @EventHandler(priority = EventPriority.LOWEST) @@ -163,13 +139,12 @@ public class WarpListener implements Listener { event.setCancelled(true); } - public static AbstractWarpEntity createEntity(Player player, Vector position, String name) { - return NMSWrapper.impl.createWarp(player.getWorld(), position, name); - } - @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - warpsShown.remove(event.getPlayer()); + warpEntityServer.computeIfPresent(event.getPlayer(), (player, rEntityServer) -> { + rEntityServer.close(); + return null; + }); selected.remove(event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/shared/AbstractEntity.java b/BauSystem_Main/src/de/steamwar/bausystem/shared/AbstractEntity.java deleted file mode 100644 index a187531b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/shared/AbstractEntity.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.shared; - -import org.bukkit.entity.Player; - -public interface AbstractEntity { - void sendEntity(Player player); - void sendEntityDestroy(Player player); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java index ffdc6438..f80d8451 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java @@ -20,17 +20,12 @@ package de.steamwar.bausystem.utils; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.features.warp.AbstractWarpEntity; import de.steamwar.core.VersionDependent; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import java.util.function.LongSupplier; @@ -51,10 +46,5 @@ public interface NMSWrapper { boolean checkItemStack(ItemStack item); - AbstractWarpEntity createWarp(World world, Vector position, String name); - AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight); - AbstractDetonatorEntity constructDetonator(World world, Vector position); - AbstractTraceEntity createTrace(World world, Vector tntPosition, boolean tnt); - Object resetExplosionKnockback(Object packet); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index 2145e442..013aff47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -19,13 +19,15 @@ package de.steamwar.bausystem.utils; +import de.steamwar.entity.REntity; +import lombok.Data; import lombok.experimental.UtilityClass; import org.bukkit.FluidCollisionMode; import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.entity.Entity; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.util.BoundingBox; import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; @@ -34,7 +36,7 @@ import java.util.List; @UtilityClass public class RayTraceUtils { - public static RayTraceResult trace(Player player, Location to, List entityList) { + public static RRayTraceResult traceREntity(Player player, Location to, List entityList) { if (player.getGameMode() == GameMode.SPECTATOR) { return null; } @@ -43,32 +45,56 @@ public class RayTraceUtils { Vector direction = to.getDirection(); RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true); - Entity nearestHitEntity = null; - RayTraceResult nearestHitResult = null; + REntity nearestHitEntity = null; + RRayTraceResult nearestHitResult = null; double nearestDistanceSq = Double.MAX_VALUE; - for (Entity entity : entityList) { - BoundingBox boundingBox = entity.getBoundingBox(); - RayTraceResult hitResult = boundingBox.rayTrace(startPos.toVector(), direction, 10.0); - if (hitResult != null) { - double distanceSq = startPos.toVector().distanceSquared(hitResult.getHitPosition()); - if (distanceSq < nearestDistanceSq) { - nearestHitEntity = entity; - nearestHitResult = hitResult; - nearestDistanceSq = distanceSq; - } + for (REntity entity: entityList) { + if (!isOccluded(startPos.toVector(), direction, new Vector(entity.getX(), entity.getY() + 0.5, entity.getZ()))) continue; + double distanceSq = new Vector(entity.getX(), entity.getY() + 0.5, entity.getZ()).distanceSquared(startPos.toVector()); + if (distanceSq > 100.0) continue; + if (distanceSq < nearestDistanceSq) { + nearestHitEntity = entity; + nearestHitResult = new RRayTraceResult(new Vector(entity.getX(), entity.getY() + 0.5, entity.getZ()), null, null, entity); + nearestDistanceSq = distanceSq; } } - RayTraceResult entities = nearestHitEntity == null ? null : new RayTraceResult(nearestHitResult.getHitPosition(), nearestHitEntity, nearestHitResult.getHitBlockFace()); + RRayTraceResult entities = nearestHitEntity == null ? null : new RRayTraceResult(nearestHitResult.getHitPosition(), nearestHitResult.getHitBlock(), nearestHitResult.getHitBlockFace(), nearestHitEntity); if (blocks == null) { return entities; } else if (entities == null) { - return blocks; + return RRayTraceResult.fromRayTraceResult(blocks); } else { Vector startVec = startPos.toVector(); double blockHitDistance = startVec.distance(blocks.getHitPosition()); double entityHitDistanceSquared = startVec.distanceSquared(entities.getHitPosition()); - return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : blocks; + return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : RRayTraceResult.fromRayTraceResult(blocks); } } + + @Data + public static class RRayTraceResult { + private final Vector hitPosition; + private final Block hitBlock; + private final BlockFace hitBlockFace; + private final REntity hitEntity; + + public static RRayTraceResult fromRayTraceResult(RayTraceResult rayTraceResult) { + return new RRayTraceResult(rayTraceResult.getHitPosition(), rayTraceResult.getHitBlock(), rayTraceResult.getHitBlockFace(), null); + } + } + + public static boolean isOccluded(Vector a, Vector n, Vector b) { + // a = Head pos, n = View direction (normalized), b = entity center + // https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line#Vector_formulation + + double abX = b.getX() - a.getX(); + double abY = b.getY() - a.getY(); + double abZ = b.getZ() - a.getZ(); + double lambda = abX * n.getX() + abY * n.getY() + abZ * n.getZ(); + double distX = abX - n.getX() * lambda; + double distY = abY - n.getY() * lambda; + double distZ = abZ - n.getZ() * lambda; + return Math.abs(distX) < 0.5 && Math.abs(distY) < 0.5 && Math.abs(distZ) < 0.5; + } } diff --git a/ignoredlog b/ignoredlog index b28379ba..6e12febe 100644 --- a/ignoredlog +++ b/ignoredlog @@ -1,2 +1,2 @@ -SteamWar? Unbekannter Befehl. +Unbekannter Befehl. moved too quickly! \ No newline at end of file