From 6e56ecdc99039bd84be1de6ca9ef578b9339121f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 19 Jan 2023 16:57:23 +0100 Subject: [PATCH 001/174] Add Permission.Perm Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/Permission.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 539a0f80..fb1902f4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -20,12 +20,17 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.config.BauServer; +import de.steamwar.command.CommandMetaData; +import de.steamwar.command.TypeValidator; import de.steamwar.sql.BauweltMember; -import de.steamwar.sql.SteamwarUser; import lombok.AllArgsConstructor; -import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.function.Predicate; @AllArgsConstructor @@ -54,4 +59,33 @@ public enum Permission { public static boolean hasPermission(Player member, Permission permission) { return permission.hasPermission(member); } + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.PARAMETER) + @CommandMetaData.Parameter({Player.class}) + @CommandMetaData.ImplicitValidator(handler = Perm.Handler.class, order = -10) + public @interface Perm { + Permission value(); + String message() default ""; + + class Handler implements TypeValidator { + + private Permission permission; + private String message; + + public Handler(Perm perm) { + this.permission = perm.value(); + this.message = perm.message(); + if (message != null && message.isEmpty()) message = null; + } + + @Override + public boolean validate(CommandSender commandSender, Player player, MessageSender messageSender) { + if (message == null) { + return permission.hasPermission(player); + } + return !messageSender.send(!permission.hasPermission((Player) commandSender), message); + } + } + } } \ No newline at end of file From 41391df882e84bb243e219880366b972dc36574a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Feb 2023 19:20:34 +0100 Subject: [PATCH 002/174] Update tracer to REntityServer Signed-off-by: yoyosource --- .../show/mode/FactoredEntityShowMode.java | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) 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 index 93dbaa0c..cb79d65b 100644 --- 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 @@ -19,13 +19,15 @@ 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 de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Consumer; @@ -42,15 +44,17 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { protected final Player player; protected final ShowModeParameter showModeParameter; + protected final REntityServer entityServer = new REntityServer(); // TODO: Needs to be closed - private final Map tntEntityMap = new HashMap<>(); - private final Map updateEntityMap = new HashMap<>(); - private final Map tntPositionMap = new HashMap<>(); + 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) { + protected FactoredEntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) { // TODO: Fix factor this.player = player; this.showModeParameter = showModeParameter; this.factor = factor; + entityServer.addPlayer(player); } @Override @@ -61,9 +65,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { 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); + REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); + tntPositionMap.put(entity, position); } if (!showModeParameter.isSourceOnly()) { return; @@ -72,9 +75,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { 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); + REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); + tntPositionMap.put(entity, position); } return; } @@ -83,14 +85,16 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { for (TNTPosition pos : position.getRecord().getPositions()) { RoundedPosition roundedPosition = new RoundedPosition(pos, factor); tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> { - return tnt.hide(player, false) ? null : tnt; + tnt.die(); + return null; }); } // 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; + point.die(); + return null; }); }); } @@ -98,14 +102,13 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { } 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); + REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); + tntPositionMap.put(entity, position); applyOnPosition(position, updatePointPosition -> { updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> { - return createEntity(player, updatePointPosition, false); - }).display(player, false, showModeParameter.isTicks() ? position.getFuseTicks() : -1); + return createEntity(player, updatePointPosition, false, false, -1); + }); }); } @@ -113,8 +116,15 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { 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 REntity createEntity(Player player, Vector position, boolean tnt, boolean explode, int ticks) { + Material material = tnt ? Material.TNT : Material.WHITE_STAINED_GLASS; + if (tnt && explode) material = Material.RED_STAINED_GLASS; + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material); + entity.setNoGravity(true); + if (ticks != -1) { + entity.setDisplayName(ticks + ""); + } + return entity; } private void applyOnPosition(TNTPosition position, Consumer function) { @@ -140,19 +150,21 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode { @Override public void hide() { tntPositionMap.clear(); - tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die()); tntEntityMap.clear(); - updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die()); updateEntityMap.clear(); } @Override public List getEntities() { - return new ArrayList<>(tntPositionMap.keySet()); + // return new ArrayList<>(tntPositionMap.keySet()); + return new ArrayList<>(); } @Override public TNTPosition getTNTPosition(Entity entity) { - return tntPositionMap.get(entity); + // return tntPositionMap.get(entity); + return null; } } From b4f4a2fe13d44f38c9d388f23ca6307205e21902 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 14:31:24 +0100 Subject: [PATCH 003/174] Update tracer to REntityServer Update warp to REntityServer Signed-off-by: yoyosource --- .../bausystem/entities/TraceEntity15.java | 73 ------ .../bausystem/entities/WarpEntity15.java | 80 ------ .../bausystem/shared/BaseArmorStand15.java | 56 ----- .../bausystem/utils/NMSWrapper15.java | 17 +- .../bausystem/entities/TraceEntity18.java | 73 ------ .../bausystem/entities/WarpEntity18.java | 80 ------ .../bausystem/shared/BaseArmorStand18.java | 62 ----- .../bausystem/utils/NMSWrapper18.java | 19 +- .../bausystem/entities/TraceEntity19.java | 74 ------ .../bausystem/entities/WarpEntity19.java | 81 ------- .../bausystem/shared/BaseArmorStand19.java | 62 ----- .../bausystem/utils/NMSWrapper19.java | 19 +- .../simulator/SimulatorPreviewStorage.java | 4 +- .../simulator/show/PreviewEntityShowMode.java | 42 ---- .../laufbau/states/ProcessingTracesState.java | 1 - .../features/tracer/AbstractTraceEntity.java | 33 --- .../features/tracer/TraceCommand.java | 7 +- .../features/tracer/show/EntityShowMode.java | 229 ++++++++++++++++++ .../tracer/show/EntityTraceShowMode.java | 31 --- .../tracer/show/ShowModeParameter.java | 5 + .../tracer/show/ShowModeParameterType.java | 7 +- .../tracer/show/TraceShowManager.java | 10 +- .../show/mode/FactoredEntityShowMode.java | 170 ------------- .../tracer/show/mode/RawEntityShowMode.java | 32 --- .../tracer/show/mode/TraceEntityShowMode.java | 32 --- .../features/warp/AbstractWarpEntity.java | 39 --- .../bausystem/features/warp/WarpListener.java | 78 ++---- .../steamwar/bausystem/utils/NMSWrapper.java | 4 - 28 files changed, 282 insertions(+), 1138 deletions(-) delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/entities/TraceEntity15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/entities/WarpEntity15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/shared/BaseArmorStand15.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/entities/TraceEntity18.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/entities/WarpEntity18.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/shared/BaseArmorStand18.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/entities/WarpEntity19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/shared/BaseArmorStand19.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/PreviewEntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/AbstractTraceEntity.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityTraceShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/warp/AbstractWarpEntity.java 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/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/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 15756166..e27b9147 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -22,18 +22,13 @@ 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 de.steamwar.bausystem.features.util.NoClipCommand; 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; @@ -162,11 +157,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); @@ -177,11 +167,6 @@ public class NMSWrapper15 implements NMSWrapper { 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/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/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 4d14fc01..932d37d7 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -23,13 +23,9 @@ 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,7 +35,10 @@ 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; @@ -167,11 +166,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); @@ -182,11 +176,6 @@ public class NMSWrapper18 implements NMSWrapper { 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/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/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/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 4d184f6f..bd6e3b53 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -23,13 +23,9 @@ 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,7 +35,10 @@ 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; @@ -167,11 +166,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); @@ -182,11 +176,6 @@ public class NMSWrapper19 implements NMSWrapper { 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_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java index 43024440..363a9162 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java @@ -19,10 +19,10 @@ 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.features.tracer.show.EntityShowMode; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.ShowMode; import lombok.experimental.UtilityClass; @@ -57,7 +57,7 @@ public class SimulatorPreviewStorage { pair.getValue().add(player); ShowModeParameter showModeParameter = new ShowModeParameter(); - PreviewEntityShowMode showMode = new PreviewEntityShowMode(player, showModeParameter); + EntityShowMode showMode = new EntityShowMode(player, showModeParameter, 10); pair.getKey().showAll(showMode); showModes.put(player, new Pair<>(tntSimulator, showMode)); } 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/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/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java new file mode 100644 index 00000000..0dcf1187 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -0,0 +1,229 @@ +/* + * 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.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 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; + +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.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(); + 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(vector, positionType, position.getFuseTicks())); + } else if (positionType == PositionType.EXPLODE) { + entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + } else { + entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(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; + } + + public List getEntities() { + return new ArrayList<>(); + } + + public TNTPosition getTNTPosition(Entity entity) { + return null; + } + + private class EntityStack { + + 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(Vector position, PositionType positionType, int fuseTicks) { + 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..2544a28b 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 @@ -30,6 +30,7 @@ public class ShowModeParameter { private boolean explodeOnly = false; private boolean ticks = false; private boolean buildDestroyOnly = false; + private boolean count = false; public void enableWater() { this.water = true; @@ -58,4 +59,8 @@ public class ShowModeParameter { public void enableBuildDestroyOnly() { this.buildDestroyOnly = true; } + + public void enableCount() { + this.count = 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..82ca5673 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 @@ -83,8 +83,8 @@ public class TraceShowManager implements Listener { if (showMode == null) { return Collections.emptyList(); } - if (showMode instanceof EntityTraceShowMode) { - return ((EntityTraceShowMode) showMode).getEntities(); + if (showMode instanceof EntityShowMode) { + return ((EntityShowMode) showMode).getEntities(); } return Collections.emptyList(); } @@ -102,8 +102,8 @@ public class TraceShowManager implements Listener { if (showMode == null) { return null; } - if (showMode instanceof EntityTraceShowMode) { - return ((EntityTraceShowMode) showMode).getTNTPosition(entity); + if (showMode instanceof EntityShowMode) { + return ((EntityShowMode) showMode).getTNTPosition(entity); } return null; } @@ -164,7 +164,7 @@ public class TraceShowManager implements Listener { if (!region.isGlobal()) { Map> regionalShowModes = showModes.get(region); if (regionalShowModes != null) { - regionalShowModes.remove(event.getPlayer()); + regionalShowModes.remove(event.getPlayer()).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 cb79d65b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java +++ /dev/null @@ -1,170 +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.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.entity.REntity; -import de.steamwar.entity.REntityServer; -import de.steamwar.entity.RFallingBlockEntity; -import org.bukkit.Material; -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; - protected final REntityServer entityServer = new REntityServer(); // TODO: Needs to be closed - - 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) { // TODO: Fix factor - this.player = player; - this.showModeParameter = showModeParameter; - this.factor = factor; - entityServer.addPlayer(player); - } - - @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); - REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); - tntPositionMap.put(entity, position); - } - if (!showModeParameter.isSourceOnly()) { - return; - } - } - if (showModeParameter.isSourceOnly()) { - if (position.isSource()) { - RoundedPosition roundedPosition = new RoundedPosition(position, factor); - REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); - tntPositionMap.put(entity, position); - } - 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) -> { - tnt.die(); - return null; - }); - } - // Advanced - for (TNTPosition pos : position.getRecord().getPositions()) { - applyOnPosition(pos, updatePointPosition -> { - updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition, factor), (p, point) -> { - point.die(); - return null; - }); - }); - } - return; - } - - RoundedPosition roundedPosition = new RoundedPosition(position, factor); - REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1)); - tntPositionMap.put(entity, position); - - applyOnPosition(position, updatePointPosition -> { - updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> { - return createEntity(player, updatePointPosition, false, false, -1); - }); - }); - } - - private boolean checkWater(Vector position) { - return FlatteningWrapper.impl.inWater(player.getWorld(), position); - } - - private REntity createEntity(Player player, Vector position, boolean tnt, boolean explode, int ticks) { - Material material = tnt ? Material.TNT : Material.WHITE_STAINED_GLASS; - if (tnt && explode) material = Material.RED_STAINED_GLASS; - RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material); - entity.setNoGravity(true); - if (ticks != -1) { - entity.setDisplayName(ticks + ""); - } - return entity; - } - - 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.die()); - tntEntityMap.clear(); - updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die()); - updateEntityMap.clear(); - } - - @Override - public List getEntities() { - // return new ArrayList<>(tntPositionMap.keySet()); - return new ArrayList<>(); - } - - @Override - public TNTPosition getTNTPosition(Entity entity) { - // return tntPositionMap.get(entity); - return null; - } -} 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..ea48383e 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,9 @@ 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.remove(event.getPlayer()).close(); selected.remove(event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java index ffdc6438..96e38a05 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java @@ -22,8 +22,6 @@ 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; @@ -51,10 +49,8 @@ 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); } From cb474ea75bdf50d01e3c27072a428d13a3c9a23c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 21:52:22 +0100 Subject: [PATCH 004/174] Fix some trace errors Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/BauSystem.java | 15 --------------- .../features/tracer/show/EntityShowMode.java | 6 ++++-- .../features/tracer/show/ShowModeParameter.java | 10 +++++----- .../features/tracer/show/TraceShowManager.java | 13 +++++-------- .../steamwar/bausystem/utils/RayTraceUtils.java | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 30 deletions(-) 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/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java index 0dcf1187..62eb765d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -113,8 +113,10 @@ public class EntityShowMode implements ShowMode { tntEntityMap.clear(); explodeEntityMap.clear(); updateEntityMap.clear(); - entityServer.close(); - entityServer = null; + if (entityServer != null) { + entityServer.close(); + entityServer = null; + } } private void generatePositions(TNTPosition position, boolean interpolateY, boolean interpolateXZ) { 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 2544a28b..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,8 +29,8 @@ public class ShowModeParameter { private boolean sourceOnly = false; private boolean explodeOnly = false; private boolean ticks = false; - private boolean buildDestroyOnly = false; private boolean count = false; + private boolean buildDestroyOnly = false; public void enableWater() { this.water = true; @@ -56,11 +56,11 @@ public class ShowModeParameter { this.ticks = true; } - public void enableBuildDestroyOnly() { - this.buildDestroyOnly = 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/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index 82ca5673..856513ff 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 @@ -63,7 +63,7 @@ public class TraceShowManager implements Listener { if (regionalShowModes == null) { return; } - ShowMode showMode = regionalShowModes.get(player); + ShowMode showMode = regionalShowModes.remove(player); if (showMode == null) { return; } @@ -160,13 +160,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()).hide(); - } - } + 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/utils/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index 2145e442..463820f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -71,4 +71,18 @@ public class RayTraceUtils { return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : blocks; } } + + 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; + } } From 11593c6aa89595b140866b65af7edd73a89de3d9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 5 Feb 2023 12:24:34 +0100 Subject: [PATCH 005/174] Fix some trace errors Signed-off-by: yoyosource --- .../features/attributescopy/AttributesPlaceListener.java | 1 - .../de/steamwar/bausystem/features/warp/WarpListener.java | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) 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..adcf545c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributesPlaceListener.java @@ -33,7 +33,6 @@ 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; 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 ea48383e..953d709a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java @@ -141,7 +141,10 @@ public class WarpListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - warpEntityServer.remove(event.getPlayer()).close(); + warpEntityServer.computeIfPresent(event.getPlayer(), (player, rEntityServer) -> { + rEntityServer.close(); + return null; + }); selected.remove(event.getPlayer()); } } From 1352b5eab73a1d78389403edad78dee923bde85f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Feb 2023 16:10:47 +0100 Subject: [PATCH 006/174] Update stome stuff Signed-off-by: yoyosource --- .../linkage/types/BlockAttribute_GENERIC.java | 40 ------ .../AttributeRemoveCommand.java | 1 - .../attributescopy/AttributeUtils.java | 128 ++++++++++++++++++ .../attributescopy/AttributesCopyCommand.java | 49 +------ .../AttributesPlaceListener.java | 20 +-- .../attributescopy/BlockAttribute.java | 31 ----- .../attributescopy/impl/AgeableAttribute.java | 53 -------- .../impl/AnaloguePowerableAttribute.java | 53 -------- .../impl/AttachableAttribute.java | 48 ------- .../impl/BisectedAttribute.java | 53 -------- .../impl/DirectionalAttribute.java | 54 -------- .../impl/FaceAttachableAttribute.java | 53 -------- .../impl/HangableAttribute.java | 51 ------- .../impl/LevelledAttribute.java | 53 -------- .../impl/LightableAttribute.java | 48 ------- .../impl/MultipleFacingAttribute.java | 53 -------- .../impl/OpenableAttribute.java | 48 ------- .../impl/OrientableAttribute.java | 54 -------- .../impl/PowerableAttribute.java | 48 ------- .../attributescopy/impl/RailAttribute.java | 53 -------- .../impl/RotatableAttribute.java | 54 -------- .../impl/SnowableAttribute.java | 48 ------- .../impl/WaterloggedAttribute.java | 49 ------- .../impl/type/BambooAttribute.java | 53 -------- .../impl/type/BellAttribute.java | 53 -------- .../impl/type/BigDripleafAttribute.java | 55 -------- .../impl/type/CakeAttribute.java | 53 -------- .../impl/type/CampfireAttribute.java | 48 ------- .../impl/type/CandleAttribute.java | 53 -------- .../impl/type/CaveVinesPlantAttribute.java | 48 ------- .../impl/type/ComparatorAttribute.java | 53 -------- .../impl/type/DaylightDetectorAttribute.java | 48 ------- .../impl/type/DoorAttribute.java | 53 -------- .../impl/type/EndPortalFrameAttribute.java | 48 ------- .../impl/type/FarmlandAttribute.java | 53 -------- .../impl/type/GateAttribute.java | 48 ------- .../impl/type/HopperAttribute.java | 48 ------- .../impl/type/JigsawAttribute.java | 53 -------- .../impl/type/LanternAttribute.java | 49 ------- .../impl/type/LeavesAttribute.java | 48 ------- .../impl/type/PointedDripstoneAttribute.java | 62 --------- .../impl/type/RedstoneWireAttribute.java | 57 -------- .../impl/type/RepeaterAttribute.java | 56 -------- .../impl/type/RespawnAnchorAttribute.java | 53 -------- .../impl/type/SaplingAttribute.java | 53 -------- .../impl/type/ScaffoldingAttribute.java | 56 -------- .../impl/type/SculkSensorAttribute.java | 53 -------- .../impl/type/SeaPickleAttribute.java | 53 -------- .../impl/type/SlabAttribute.java | 53 -------- .../impl/type/SnowAttribute.java | 53 -------- .../impl/type/StairsAttribute.java | 53 -------- .../impl/type/StructureBlockAttribute.java | 53 -------- .../impl/type/TNTAttribute.java | 48 ------- .../impl/type/TripwireAttribute.java | 48 ------- .../impl/type/TurtleEggAttribute.java | 61 --------- .../impl/type/WallAttribute.java | 64 --------- 56 files changed, 139 insertions(+), 2743 deletions(-) delete mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/BlockAttribute_GENERIC.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeUtils.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/BlockAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AgeableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AnaloguePowerableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/AttachableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/BisectedAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/DirectionalAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/FaceAttachableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/HangableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LevelledAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/LightableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/MultipleFacingAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OpenableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/OrientableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/PowerableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RailAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/RotatableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/SnowableAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/WaterloggedAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BambooAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BellAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/BigDripleafAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CakeAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CampfireAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CandleAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/CaveVinesPlantAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ComparatorAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DaylightDetectorAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/DoorAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/EndPortalFrameAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/FarmlandAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/GateAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/HopperAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/JigsawAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LanternAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/LeavesAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/PointedDripstoneAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RedstoneWireAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RepeaterAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/RespawnAnchorAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SaplingAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/ScaffoldingAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SculkSensorAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SeaPickleAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SlabAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/SnowAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StairsAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/StructureBlockAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TNTAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TripwireAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/TurtleEggAttribute.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/impl/type/WallAttribute.java 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/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 adcf545c..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; @@ -34,19 +33,13 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -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; @@ -64,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; } @@ -77,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(), () -> { @@ -87,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; - } - } - } - } -} From b2ddc1ef2d73043f10fa5f3e8e932b0bbe70bd3e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Feb 2023 18:52:30 +0100 Subject: [PATCH 007/174] Add KillcheckerCommand and KillcheckerVisualizer Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 + BauSystem_Main/src/BauSystem_de.properties | 7 + .../killchecker/KillcheckerCommand.java | 102 +++++++++ .../killchecker/KillcheckerVisualizer.java | 216 ++++++++++++++++++ build.gradle | 6 - 5 files changed, 332 insertions(+), 6 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 690fcb6d..8d03d0ca 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -651,6 +651,13 @@ INVENTORY_FILL_INFO = §7Helps you fill containers by looking at them while snea INVENTORY_FILL_ENABLE = §aInventoryFiller activated INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated +# Killchecker +KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Enables Killchecker / Recalculates kills +KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Disables Killchecker +KILLCHECKER_INFO = §7Shows the overlaps of cannon kills in your build area. +KILLCHECKER_ENABLE = §aKillchecker activated +KILLCHECKER_DISABLE = §cKillchecker deactivated + # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Toggles BlockCounter on diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 7320b18d..f49f1fc6 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -624,6 +624,13 @@ INVENTORY_FILL_INFO = §7Hilft dir, Behälter zu füllen, indem du sie beim snea INVENTORY_FILL_ENABLE = §aInventoryFiller activated INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated +# Killchecker +KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Aktiviert Killchecker / Berechnet kills neu +KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Deaktiviert Killchecker +KILLCHECKER_INFO = §7Zeigt Überlappungen der Kanonen Kills im Baubereich an. +KILLCHECKER_ENABLE = §aKillchecker aktiviert +KILLCHECKER_DISABLE = §cKillchecker deaktiviert + # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java new file mode 100644 index 00000000..fee15416 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -0,0 +1,102 @@ +/* + * 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.killchecker; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +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.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Linked +public class KillcheckerCommand extends SWCommand implements Listener { + + private Map visualizers = new HashMap<>(); + + public KillcheckerCommand() { + super("killchecker"); + addDefaultHelpMessage("KILLCHECKER_INFO"); + } + + @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") + public void genericCommand(Player player) { + Region region = Region.getRegion(player.getLocation()); + KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, KillcheckerVisualizer::new); + killcheckerVisualizer.recalc(); + killcheckerVisualizer.show(player); + BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); + } + + @Register(value = "disable", description = "KILLCHECKER_HELP_DISABLE") + public void disableCommand(Player player) { + Region region = Region.getRegion(player.getLocation()); + KillcheckerVisualizer killcheckerVisualizer = visualizers.get(region); + if (killcheckerVisualizer != null) { + if (killcheckerVisualizer.hide(player)) { + visualizers.remove(region); + } + } + BauSystem.MESSAGE.send("KILLCHECKER_DISABLE", player); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + Set regions = new HashSet<>(); + visualizers.forEach((region, visualizer) -> { + if (visualizer.hide(player)) { + regions.add(region); + } + }); + regions.forEach(visualizers::remove); + } + + private void recalc(Block block) { + Region region = Region.getRegion(block.getLocation()); + KillcheckerVisualizer killcheckerVisualizer = visualizers.get(region); + if (killcheckerVisualizer != null) { + killcheckerVisualizer.recalc(); + } + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + recalc(event.getBlock()); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent event) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + recalc(event.getBlock()); + }, 1); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java new file mode 100644 index 00000000..168b1893 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -0,0 +1,216 @@ +/* + * 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.killchecker; + +import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; +import de.steamwar.bausystem.region.Point; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.*; + +public class KillcheckerVisualizer { + + private static final Material[] materials = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS}; + private static final World WORLD = Bukkit.getWorlds().get(0); + + private Point minPoint; + private Point maxPoint; + + private Set players = new HashSet<>(); + + public KillcheckerVisualizer(Region region) { + this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL); + this.maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL); + } + + private REntityServer rEntityServer = new REntityServer(); + + private Map killCount = new HashMap<>(); + private Map rEntities = new HashMap<>(); + + public void recalc() { + Set cuboids = new HashSet<>(); + Set points = new HashSet<>(); + for (int x = minPoint.getX() + 1; x < maxPoint.getX() - 1; x++) { + for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { + for (int z = minPoint.getZ() + 1; z < maxPoint.getZ() - 1; z++) { + if (points.contains(new Point(x, y, z))) continue; + Block block = WORLD.getBlockAt(x, y, z); + if (block.getType().isAir()) continue; + Cuboid cuboid = create(block.getType(), x, y, z); + cuboids.add(cuboid); + for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { + for (int dy = (int) cuboid.getY(); dy <= cuboid.getDy(); dy++) { + for (int dz = (int) cuboid.getZ(); dz <= cuboid.getDz(); dz++) { + points.add(new Point(dx, dy, dz)); + } + } + } + } + } + } + + Map kill = new HashMap<>(); + for (int x = minPoint.getX(); x < maxPoint.getX(); x++) { + for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) { + Set cuboidSet = new HashSet<>(); + for (Cuboid cuboid : cuboids) { + if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) { + cuboidSet.add(cuboid); + } + } + if (cuboidSet.size() > 1) { + Point p1 = new Point(x, minPoint.getY(), z); + kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); + Point p2 = new Point(x, maxPoint.getY(), z); + kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); + } + } + } + + for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { + for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) { + Set cuboidSet = new HashSet<>(); + for (Cuboid cuboid : cuboids) { + if (y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) { + cuboidSet.add(cuboid); + } + } + if (cuboidSet.size() > 1) { + Point p1 = new Point(minPoint.getX(), y, z); + kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); + Point p2 = new Point(maxPoint.getX(), y, z); + kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); + } + } + } + + for (int x = minPoint.getX(); x < maxPoint.getX(); x++) { + for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { + Set cuboidSet = new HashSet<>(); + for (Cuboid cuboid : cuboids) { + if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5) { + cuboidSet.add(cuboid); + } + } + if (cuboidSet.size() > 1) { + Point p1 = new Point(x, y, minPoint.getZ()); + kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); + Point p2 = new Point(x, y, maxPoint.getZ()); + kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); + } + } + } + + Set pointSet = new HashSet<>(killCount.keySet()); + for (Point point : pointSet) { + if (!kill.containsKey(point)) { + rEntities.get(point).die(); + rEntities.remove(point); + killCount.remove(point); + } + } + kill.forEach((point, count) -> { + if (rEntities.containsKey(point)) { + if (killCount.get(point) == count) return; + rEntities.get(point).die(); + } + RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]); + entity.setNoGravity(true); + rEntities.put(point, entity); + killCount.put(point, count); + }); + } + + private Cuboid create(Material type, int x, int y, int z) { + Set checked = new HashSet<>(); + Set points = new HashSet<>(); + points.add(new Point(x, y, z)); + while (!points.isEmpty()) { + Point point = points.iterator().next(); + points.remove(point); + if (!checked.add(point)) continue; + if (point.getX() < minPoint.getX() || point.getX() > maxPoint.getX()) continue; + if (point.getY() < minPoint.getY() || point.getY() > maxPoint.getY()) continue; + if (point.getZ() < minPoint.getZ() || point.getZ() > maxPoint.getZ()) continue; + + if (WORLD.getBlockAt(point.getX() + 1, point.getY(), point.getZ()).getType() == type) { + points.add(new Point(point.getX() + 1, point.getY(), point.getZ())); + } + if (WORLD.getBlockAt(point.getX(), point.getY() + 1, point.getZ()).getType() == type) { + points.add(new Point(point.getX(), point.getY() + 1, point.getZ())); + } + if (WORLD.getBlockAt(point.getX(), point.getY(), point.getZ() + 1).getType() == type) { + points.add(new Point(point.getX(), point.getY(), point.getZ() + 1)); + } + if (WORLD.getBlockAt(point.getX() - 1, point.getY(), point.getZ()).getType() == type) { + points.add(new Point(point.getX() - 1, point.getY(), point.getZ())); + } + if (WORLD.getBlockAt(point.getX(), point.getY() - 1, point.getZ()).getType() == type) { + points.add(new Point(point.getX(), point.getY() - 1, point.getZ())); + } + if (WORLD.getBlockAt(point.getX(), point.getY(), point.getZ() - 1).getType() == type) { + points.add(new Point(point.getX(), point.getY(), point.getZ() - 1)); + } + } + + int minX = Integer.MAX_VALUE; + int maxX = Integer.MIN_VALUE; + int minY = Integer.MAX_VALUE; + int maxY = Integer.MIN_VALUE; + int minZ = Integer.MAX_VALUE; + int maxZ = Integer.MIN_VALUE; + for (Point point : checked) { + if (point.getX() < minX) minX = point.getX(); + if (point.getX() > maxX) maxX = point.getX(); + if (point.getY() < minY) minY = point.getY(); + if (point.getY() > maxY) maxY = point.getY(); + if (point.getZ() < minZ) minZ = point.getZ(); + if (point.getZ() > maxZ) maxZ = point.getZ(); + } + + return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); + } + + public boolean show(Player player) { + rEntityServer.addPlayer(player); + return players.add(player); + } + + public boolean hide(Player player) { + rEntityServer.removePlayer(player); + players.remove(player); + if (player.isEmpty()) { + rEntityServer.close(); + return true; + } + return false; + } +} diff --git a/build.gradle b/build.gradle index c00c8a83..653fbc20 100644 --- a/build.gradle +++ b/build.gradle @@ -118,12 +118,6 @@ dependencies { } } -task buildResources(type: Copy) { - from("BauSystem_Main/build/classes/java/main/META-INF/annotations/") - into("build/resources/main/de.steamwar.bausystem") -} -classes.finalizedBy(buildResources) - task buildProject { description 'Build this project' group "Steamwar" From 9bf04d309379d89a910aa18e215f685333a56968 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 11:26:04 +0100 Subject: [PATCH 008/174] Add REntity RayTrace Signed-off-by: yoyosource --- .../bausystem/utils/RayTraceUtils.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index 463820f7..7bec2cbb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -19,10 +19,15 @@ package de.steamwar.bausystem.utils; +import de.steamwar.entity.REntity; +import de.steamwar.entity.RFallingBlockEntity; +import lombok.Data; import lombok.experimental.UtilityClass; import org.bukkit.FluidCollisionMode; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.BoundingBox; @@ -72,6 +77,53 @@ public class RayTraceUtils { } } + public static RRayTraceResult traceREntity(Player player, Location to, List entityList) { + if (player.getGameMode() == GameMode.SPECTATOR) { + return null; + } + + Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0); + Vector direction = to.getDirection(); + RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true); + + REntity nearestHitEntity = null; + RRayTraceResult nearestHitResult = null; + double nearestDistanceSq = Double.MAX_VALUE; + 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 < nearestDistanceSq) { + nearestHitEntity = entity; + nearestHitResult = new RRayTraceResult(new Vector(entity.getX(), entity.getY() + 0.5, entity.getZ()), null, null, entity); + nearestDistanceSq = distanceSq; + } + } + RRayTraceResult entities = nearestHitEntity == null ? null : new RRayTraceResult(nearestHitResult.getHitPosition(), nearestHitResult.getHitBlock(), nearestHitResult.getHitBlockFace(), nearestHitEntity); + + if (blocks == null) { + return entities; + } else if (entities == null) { + 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 : 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 From c2ab476c22ce3b521e7c2e761ed8bd335b39bc43 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 15:54:46 +0100 Subject: [PATCH 009/174] Update Detonator Update some part or simulator Signed-off-by: yoyosource --- .../bausystem/entities/DetonatorEntity15.java | 82 ------ .../bausystem/entities/SimulatorEntity15.java | 64 ----- .../simulator/SimulatorPreview15.java | 30 -- .../bausystem/shared/BaseEntity15.java | 60 ---- .../bausystem/entities/DetonatorEntity18.java | 95 ------- .../bausystem/entities/SimulatorEntity18.java | 68 ----- .../bausystem/shared/BaseEntity18.java | 68 ----- .../bausystem/entities/DetonatorEntity19.java | 124 --------- .../bausystem/entities/SimulatorEntity19.java | 68 ----- .../features/simulator/FakeExplosion19.java | 165 ----------- .../features/simulator/FakeTNT19.java | 257 ------------------ .../simulator/SimulatorPreview19.java | 136 --------- .../bausystem/shared/BaseEntity19.java | 94 ------- .../detonator/AbstractDetonatorEntity.java | 35 --- .../features/detonator/Detonator.java | 24 +- .../features/detonator/DetonatorListener.java | 27 -- .../simulator/AbstractSimulatorEntity.java | 38 --- .../features/simulator/SimulatorCursor.java | 43 +-- .../features/simulator/SimulatorPreview.java | 44 --- .../simulator/SimulatorPreviewStorage.java | 92 ------- .../features/simulator/TNTSimulator.java | 52 +--- .../simulator/TNTSimulatorListener.java | 40 +-- .../simulator/gui/SimulatorSelectionGUI.java | 4 +- .../features/simulator/gui/TNTElementGUI.java | 48 +--- .../simulator/gui/TNTGroupEditGUI.java | 23 +- .../simulator/gui/TNTSimulatorGui.java | 19 +- .../gui/components/ChangePosition.java | 11 +- .../simulator/gui/components/Disabled.java | 4 +- .../show/SimulatorEntityShowMode.java | 71 ----- .../simulator/tnt/SimulatorElement.java | 2 - .../features/simulator/tnt/TNTElement.java | 14 +- .../features/simulator/tnt/TNTGroup.java | 8 - .../bausystem/shared/AbstractEntity.java | 27 -- .../bausystem/utils/RayTraceUtils.java | 1 + 34 files changed, 67 insertions(+), 1871 deletions(-) delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/entities/DetonatorEntity15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/entities/SimulatorEntity15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/features/simulator/SimulatorPreview15.java delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/shared/BaseEntity15.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/entities/DetonatorEntity18.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/entities/SimulatorEntity18.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/shared/BaseEntity18.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/entities/DetonatorEntity19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/entities/SimulatorEntity19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeExplosion19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/features/simulator/FakeTNT19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/features/simulator/SimulatorPreview19.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/detonator/AbstractDetonatorEntity.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/AbstractSimulatorEntity.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreview.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorPreviewStorage.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/show/SimulatorEntityShowMode.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/shared/AbstractEntity.java 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/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/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_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/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_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/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/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_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..9e68f016 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java @@ -26,6 +26,9 @@ 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.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -44,7 +47,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 +55,19 @@ 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.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..f7577e14 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,38 +36,13 @@ 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); - 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) { Detoblock detoblock = Detonator.getBlock(location.getBlock()); if (detoblock == Detoblock.INVALID) { 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..cc3873f2 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); @@ -53,9 +58,11 @@ public class SimulatorCursor { 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.WHITE_STAINED_GLASS); + entity.setNoGravity(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 363a9162..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.tracer.TNTPosition; -import de.steamwar.bausystem.features.tracer.show.Record; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.features.tracer.show.EntityShowMode; -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(); - EntityShowMode showMode = new EntityShowMode(player, showModeParameter, 10); - 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/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 4a92058a..27988cdc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -31,12 +31,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.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 +50,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; @@ -82,38 +84,13 @@ 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 close() { + entityServer.close(); } 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); - }); + entityServer.removePlayer(player); + players.remove(player); } public void hide(Player player, List simulatorElements) { @@ -133,10 +110,8 @@ public class TNTSimulator { } 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) { @@ -185,7 +160,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; @@ -212,9 +187,6 @@ public class TNTSimulator { TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result)); tntElementList.add(tntElement); TNTElementGUI.open(player, tntElement, null); - playerShowMode.forEach((p, simulatorEntityShowMode) -> { - show(p); - }); } public void start(Player p) { @@ -230,7 +202,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..aa849447 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(); @@ -135,14 +125,12 @@ public class TNTElementGUI { } 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, tntSimulator, tntElement, tntElement::getOwnPosition, x -> x - tntElement.getParentPosition().getX(), y -> y - tntElement.getParentPosition().getY(), z -> z - tntElement.getParentPosition().getZ(), () -> 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(); align(position, new Vector(0, 0, 0.49)); @@ -152,7 +140,6 @@ public class TNTElementGUI { })); 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(); align(position, new Vector(0, 0, 0.51)); @@ -162,7 +149,6 @@ public class TNTElementGUI { })); 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(); align(position, new Vector(0.51, 0, 0)); @@ -172,7 +158,6 @@ public class TNTElementGUI { })); 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(); align(position, new Vector(0.49, 0, 0)); @@ -182,7 +167,6 @@ public class TNTElementGUI { })); 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(); align(position, new Vector(0.5, 0, 0.5)); @@ -196,9 +180,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); @@ -236,18 +217,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 +234,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 +241,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 +254,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 +261,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 +274,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 +281,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 +294,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 +312,6 @@ public class TNTElementGUI { tntElement.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { tntElement.unregister(editObserver); - if (recalculate.get()) { - SimulatorPreviewStorage.recalculate(tntSimulator); - } }); inv.open(); @@ -360,11 +324,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 +336,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(); @@ -409,7 +370,6 @@ 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); if (tntElement.hasParent()) { @@ -427,7 +387,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 +395,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..7c53f610 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(); @@ -161,22 +147,19 @@ 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, tntSimulator, tntGroup, tntGroup::getPosition, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity(), () -> 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 +168,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 +176,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..0030d2a4 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; @@ -117,7 +116,6 @@ public class TNTSimulatorGui { currentTntGroup.register(editObserver, player::closeInventory); inv.addCloseRunnable(() -> { currentTntGroup.unregister(editObserver); - SimulatorPreviewStorage.recalculate(currentTntSimulator); }); } else { if (!elements.isEmpty()) { @@ -126,15 +124,11 @@ public class TNTSimulatorGui { TNTGroupEditGUI.open(player, tntSimulator, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back)); })); } - inv.addCloseCallback(clickType -> { - SimulatorPreviewStorage.recalculate(currentTntSimulator); - }); } 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(); 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..221ced49 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 @@ -51,7 +51,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, TNTSimulator tntSimulator, SimulatorElement simulatorElement, Supplier toChangeVector, UnaryOperator calculatePositionX, UnaryOperator calculatePositionY, UnaryOperator calculatePositionZ, 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,7 +61,6 @@ 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); @@ -69,7 +68,6 @@ public class ChangePosition { }))); 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); @@ -79,7 +77,6 @@ public class ChangePosition { })); 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); @@ -89,7 +86,6 @@ public class ChangePosition { // 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); @@ -97,7 +93,6 @@ public class ChangePosition { }))); 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); @@ -107,7 +102,6 @@ public class ChangePosition { })); 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); @@ -117,7 +111,6 @@ public class ChangePosition { // 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); @@ -125,7 +118,6 @@ public class ChangePosition { }))); 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); @@ -135,7 +127,6 @@ public class ChangePosition { })); 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); 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..3ac98483 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,14 +29,12 @@ 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); } 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..10ce5cd2 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,7 +19,6 @@ 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; @@ -51,7 +50,6 @@ public interface SimulatorElement { 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..7b2cc3f5 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 @@ -32,6 +32,7 @@ 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.RFallingBlockEntity; import de.steamwar.inventory.SWItem; import lombok.Getter; import lombok.Setter; @@ -48,7 +49,7 @@ import java.util.*; @Getter public class TNTElement implements SimulatorElement { - private final AbstractSimulatorEntity entity; + private final RFallingBlockEntity entity; TNTGroup tntGroup = null; private final Vector position; @@ -199,17 +200,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; 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..30a69044 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 @@ -152,14 +152,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; 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/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index 7bec2cbb..cbd307cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -92,6 +92,7 @@ public class RayTraceUtils { 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); From 75b822ece19a7dc6b8a8ae21cb3a7505a44822ef Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 17:40:57 +0100 Subject: [PATCH 010/174] Fix KillcheckerVisualizer Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerVisualizer.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; } From bb5312ee92f9f118f959eabcbc027ade65ccb497 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 17:54:14 +0100 Subject: [PATCH 011/174] Add TraceTNTClickListener back Signed-off-by: yoyosource --- .../tracer/TraceTNTClickListener.java | 70 ------------------- .../features/tracer/show/EntityShowMode.java | 40 +++++++---- .../tracer/show/TraceShowManager.java | 39 +---------- 3 files changed, 29 insertions(+), 120 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java 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 index 62eb765d..bfcd15e5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -19,6 +19,7 @@ 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; @@ -26,6 +27,7 @@ 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; @@ -33,6 +35,7 @@ import org.bukkit.util.Vector; import java.util.*; import java.util.function.BiConsumer; +import java.util.stream.Stream; public class EntityShowMode implements ShowMode { @@ -56,6 +59,25 @@ public class EntityShowMode implements ShowMode { 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); } @@ -124,11 +146,11 @@ public class EntityShowMode implements ShowMode { RoundedPosition roundedPosition = new RoundedPosition(vector, factor); EntityStack entityStack; if (positionType == PositionType.TNT) { - entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } else if (positionType == PositionType.EXPLODE) { - entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } else { - entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } entityStack.add(position.getRecord()); }); @@ -152,16 +174,9 @@ public class EntityShowMode implements ShowMode { return entity; } - public List getEntities() { - return new ArrayList<>(); - } - - public TNTPosition getTNTPosition(Entity entity) { - return null; - } - private class EntityStack { + private final TNTPosition tntPosition; private final Vector position; private final PositionType positionType; private final int fuseTicks; @@ -170,7 +185,8 @@ public class EntityShowMode implements ShowMode { private int count; private List records = new ArrayList<>(); - public EntityStack(Vector position, PositionType positionType, int fuseTicks) { + public EntityStack(TNTPosition tntPosition, Vector position, PositionType positionType, int fuseTicks) { + this.tntPosition = tntPosition; this.position = position; this.positionType = positionType; this.fuseTicks = fuseTicks; 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 856513ff..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; @@ -70,44 +71,6 @@ public class TraceShowManager implements Listener { 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 EntityShowMode) { - return ((EntityShowMode) 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 EntityShowMode) { - return ((EntityShowMode) showMode).getTNTPosition(entity); - } - return null; - } - public static void reshow(Region region, Player p) { Map> regionalShowModes = showModes.get(region); if (regionalShowModes == null) { From fe82e38a0d5ff523441cd3ee5df4a0e200c14654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 17:58:29 +0100 Subject: [PATCH 012/174] Add Detonator click back Signed-off-by: yoyosource --- .../steamwar/bausystem/features/detonator/Detonator.java | 7 +++++-- .../bausystem/features/detonator/DetonatorListener.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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 9e68f016..54f0af6c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java @@ -25,8 +25,6 @@ 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.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import lombok.experimental.UtilityClass; @@ -57,6 +55,11 @@ public class Detonator { public static void showDetonator(Player p, List locs) { 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()), player); + DetonatorListener.HAS_UPDATED.add(player); + }); entities.addPlayer(p); ENTITIES_MAP.put(p, entities); 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 f7577e14..be8e8ce9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -41,9 +41,9 @@ import java.util.Set; @Linked public class DetonatorListener implements Listener { - private static final Set HAS_UPDATED = new HashSet<>(); + static final Set HAS_UPDATED = new HashSet<>(); - 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)); From 74d8f008a3cf9a392ddbffc10ec09db2fedce036 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 18:09:19 +0100 Subject: [PATCH 013/174] Remove entity creation methods Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/utils/NMSWrapper15.java | 10 ---------- .../src/de/steamwar/bausystem/utils/NMSWrapper18.java | 10 ---------- .../src/de/steamwar/bausystem/utils/NMSWrapper19.java | 10 ---------- .../src/de/steamwar/bausystem/utils/NMSWrapper.java | 6 ------ 4 files changed, 36 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index e27b9147..01403c3b 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -157,16 +157,6 @@ public class NMSWrapper15 implements NMSWrapper { return invalid; } - @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); - } - 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/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 932d37d7..0aab7427 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -166,16 +166,6 @@ public class NMSWrapper18 implements NMSWrapper { return invalid; } - @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); - } - 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/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index bd6e3b53..4655d738 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -166,16 +166,6 @@ public class NMSWrapper19 implements NMSWrapper { return invalid; } - @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); - } - 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_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java index 96e38a05..f80d8451 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/NMSWrapper.java @@ -20,15 +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.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; @@ -49,8 +46,5 @@ public interface NMSWrapper { boolean checkItemStack(ItemStack item); - AbstractSimulatorEntity createSimulator(World world, Vector tntPosition, boolean highlight); - AbstractDetonatorEntity constructDetonator(World world, Vector position); - Object resetExplosionKnockback(Object packet); } From 81df1e02be718e6bf717b7834099d0ce00e9580d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 18:12:31 +0100 Subject: [PATCH 014/174] Fix NMSWrapper imports Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/utils/NMSWrapper15.java | 5 ----- .../src/de/steamwar/bausystem/utils/NMSWrapper18.java | 5 ----- .../src/de/steamwar/bausystem/utils/NMSWrapper19.java | 5 ----- 3 files changed, 15 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 01403c3b..b6cd9609 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -20,10 +20,6 @@ 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.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; @@ -36,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; diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index 0aab7427..3e9ed190 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -21,10 +21,6 @@ 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.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; @@ -45,7 +41,6 @@ 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; diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 4655d738..f0d11ff1 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -21,10 +21,6 @@ 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.features.detonator.AbstractDetonatorEntity; -import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; @@ -45,7 +41,6 @@ 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; From cc2668a49bcb274c72f6a4a51eae99d8f63134c2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 18:13:53 +0100 Subject: [PATCH 015/174] Remove unused RayTraceUtils Signed-off-by: yoyosource --- .../bausystem/utils/RayTraceUtils.java | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index cbd307cc..3bbf8310 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -39,44 +39,6 @@ import java.util.List; @UtilityClass public class RayTraceUtils { - public static RayTraceResult trace(Player player, Location to, List entityList) { - if (player.getGameMode() == GameMode.SPECTATOR) { - return null; - } - - Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0); - Vector direction = to.getDirection(); - RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true); - - Entity nearestHitEntity = null; - RayTraceResult 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; - } - } - } - RayTraceResult entities = nearestHitEntity == null ? null : new RayTraceResult(nearestHitResult.getHitPosition(), nearestHitEntity, nearestHitResult.getHitBlockFace()); - - if (blocks == null) { - return entities; - } else if (entities == null) { - return blocks; - } else { - Vector startVec = startPos.toVector(); - double blockHitDistance = startVec.distance(blocks.getHitPosition()); - double entityHitDistanceSquared = startVec.distanceSquared(entities.getHitPosition()); - return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : blocks; - } - } - public static RRayTraceResult traceREntity(Player player, Location to, List entityList) { if (player.getGameMode() == GameMode.SPECTATOR) { return null; From a8b34107495e0633aec1647acafb4e8ae11a9685 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 09:36:03 +0100 Subject: [PATCH 016/174] Update simulator internals to use REntityServer Signed-off-by: yoyosource --- .../features/simulator/SimulatorStorage.java | 7 +- .../features/simulator/TNTSimulator.java | 22 +++--- .../simulator/tnt/SimulatorElement.java | 15 ++-- .../features/simulator/tnt/TNTElement.java | 76 ++++++++++--------- .../features/simulator/tnt/TNTGroup.java | 49 ++++++------ .../bausystem/utils/RayTraceUtils.java | 5 +- 6 files changed, 84 insertions(+), 90 deletions(-) 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 27988cdc..5a62e119 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -32,11 +32,11 @@ 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 yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; @@ -66,9 +66,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)); } } } @@ -88,6 +88,11 @@ public class TNTSimulator { entityServer.close(); } + public void show(Player player) { + entityServer.addPlayer(player); + players.add(player); + } + public void hide(Player player) { entityServer.removePlayer(player); players.remove(player); @@ -109,22 +114,17 @@ public class TNTSimulator { }); } - public void show(Player player) { - entityServer.addPlayer(player); - players.add(player); - } - public void show(SimulatorElement simulatorElement) { playerShowMode.forEach((player, simulatorEntityShowMode) -> { simulatorElement.show(simulatorEntityShowMode); }); } - 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); @@ -184,7 +184,7 @@ 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); } 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 10ce5cd2..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,13 +19,12 @@ package de.steamwar.bausystem.features.simulator.tnt; -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; @@ -38,15 +37,13 @@ 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 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 7b2cc3f5..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,25 +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; @@ -49,6 +48,8 @@ import java.util.*; @Getter public class TNTElement implements SimulatorElement { + private static final World WORLD = Bukkit.getWorlds().get(0); + private final RFallingBlockEntity entity; TNTGroup tntGroup = null; @@ -69,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); @@ -101,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); } } @@ -128,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; @@ -137,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 @@ -246,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) { @@ -274,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 30a69044..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 @@ -183,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/utils/RayTraceUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java index 3bbf8310..013aff47 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/RayTraceUtils.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.utils; import de.steamwar.entity.REntity; -import de.steamwar.entity.RFallingBlockEntity; import lombok.Data; import lombok.experimental.UtilityClass; import org.bukkit.FluidCollisionMode; @@ -28,9 +27,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.util.BoundingBox; import org.bukkit.util.RayTraceResult; import org.bukkit.util.Vector; @@ -39,7 +36,7 @@ import java.util.List; @UtilityClass public class RayTraceUtils { - public static RRayTraceResult traceREntity(Player player, Location to, List entityList) { + public static RRayTraceResult traceREntity(Player player, Location to, List entityList) { if (player.getGameMode() == GameMode.SPECTATOR) { return null; } From 0f69d4acb15b6dc95f8addbbdbd7c89945ccf9fa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 17:50:53 +0100 Subject: [PATCH 017/174] Update some code Signed-off-by: yoyosource --- .../features/simulator/SimulatorCursor.java | 2 +- .../features/simulator/TNTSimulator.java | 24 ------------------- 2 files changed, 1 insertion(+), 25 deletions(-) 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 cc3873f2..ab3eba86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -56,11 +56,11 @@ public class SimulatorCursor { if (result.getHitEntity() != null) { List elements = tntSimulator.getEntity(result.getHitEntity()); - tntSimulator.hide(player, elements); cursor = new REntityServer(); RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.WHITE_STAINED_GLASS); entity.setNoGravity(true); + entity.setGlowing(true); cursor.addPlayer(player); rEntityServerMap.put(player, cursor); BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR); 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 5a62e119..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; @@ -98,28 +97,6 @@ public class TNTSimulator { players.remove(player); } - 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 show(SimulatorElement simulatorElement) { - playerShowMode.forEach((player, simulatorEntityShowMode) -> { - simulatorElement.show(simulatorEntityShowMode); - }); - } - public List getEntities() { return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); } @@ -133,7 +110,6 @@ public class TNTSimulator { } public void remove(SimulatorElement element) { - hide(element); tntElementList.remove(element); Set toRemove = new HashSet<>(); for (SimulatorElement spawn : tntElementList) { From f149ccce93d5771738f335dcfce50c5f0f978f04 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 18:03:57 +0100 Subject: [PATCH 018/174] First buildable version Signed-off-by: yoyosource --- .../features/simulator/gui/TNTElementGUI.java | 40 +++++------ .../simulator/gui/TNTGroupEditGUI.java | 4 +- .../gui/components/ChangePosition.java | 66 +++++++++++-------- .../simulator/gui/components/Disabled.java | 6 -- 4 files changed, 56 insertions(+), 60 deletions(-) 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 aa849447..fed35fa6 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 @@ -124,55 +124,45 @@ public class TNTElementGUI { inv.setItem(36, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run())); } - TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); Runnable editObserver = () -> { - ChangePosition.show(inv, player, 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 -> { + 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; - 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; - 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; - 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; - 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; - 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(); })); }; @@ -355,7 +345,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); @@ -371,7 +361,7 @@ 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; 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); 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 7c53f610..f34a10fe 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 @@ -148,7 +148,9 @@ public class TNTGroupEditGUI { TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); Runnable editObserver = () -> { - ChangePosition.show(inv, player, 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, 32, tntSimulator, tntGroup); 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 221ced49..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, 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,75 +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; - 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 -> { - 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; - 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; - 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 -> { - 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; - 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; - 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 -> { - 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; - 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 3ac98483..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 @@ -35,13 +35,7 @@ public class Disabled { 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 -> { - if (!simulatorElement.isDisabled()) { - tntSimulator.hide(simulatorElement); - } simulatorElement.setDisabled(!simulatorElement.isDisabled()); - if (!simulatorElement.isDisabled()) { - tntSimulator.show(simulatorElement); - } simulatorElement.change(); })); } From 070a58651bb5421550d759e090000cce66d2d224 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 20:25:27 +0100 Subject: [PATCH 019/174] Last Hotfixes Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/detonator/Detonator.java | 2 +- .../bausystem/features/simulator/SimulatorCursor.java | 2 +- .../bausystem/features/simulator/gui/TNTElementGUI.java | 6 +++++- .../bausystem/features/simulator/gui/TNTGroupEditGUI.java | 4 ++-- .../bausystem/features/simulator/gui/TNTSimulatorGui.java | 4 ++-- ignoredlog | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) 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 54f0af6c..80d5b33b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/Detonator.java @@ -57,7 +57,7 @@ public class Detonator { 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()), player); + DetonatorListener.addLocationToDetonator(vector.toLocation(player.getWorld()).getBlock().getLocation(), player); DetonatorListener.HAS_UPDATED.add(player); }); entities.addPlayer(p); 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 ab3eba86..caa3af54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -58,7 +58,7 @@ public class SimulatorCursor { List elements = tntSimulator.getEntity(result.getHitEntity()); cursor = new REntityServer(); - RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.WHITE_STAINED_GLASS); + 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); 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 fed35fa6..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 @@ -126,7 +126,11 @@ public class TNTElementGUI { Runnable editObserver = () -> { ChangePosition.show(inv, player, tntElement, vectorUnaryOperator -> { - tntElement.setPosition(vectorUnaryOperator.apply(tntElement.getPosition()).subtract(tntElement.getParent().getPosition())); + 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 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 f34a10fe..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 @@ -120,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)); } } } 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 0030d2a4..89803582 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 @@ -206,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/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 From 162e3f16b799912bb7ca0b67f8ba22d4534e12fc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 20:30:04 +0100 Subject: [PATCH 020/174] Fix TNTSimulatorGui Signed-off-by: yoyosource --- .../simulator/gui/TNTSimulatorGui.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) 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 89803582..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 @@ -75,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); @@ -125,6 +112,19 @@ public class TNTSimulatorGui { })); } } + 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 -> { From 73bdfe28f16ac0431b051b1dfb1df101928fad28 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 20:54:29 +0100 Subject: [PATCH 021/174] Hotfix TNTSimulator.remove Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) 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 39057f99..34efb4fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -110,21 +110,18 @@ public class TNTSimulator { } public void remove(SimulatorElement element) { - tntElementList.remove(element); - Set toRemove = new HashSet<>(); - for (SimulatorElement spawn : tntElementList) { - if (element instanceof TNTElement) { - spawn.remove((TNTElement) element); - } - if (spawn instanceof TNTGroup) { - if (((TNTGroup) spawn).getElements().isEmpty()) { - toRemove.add(spawn); - spawn.close(); + if (element instanceof TNTElement) { + TNTElement tntElement = (TNTElement) element; + element.remove(tntElement); + if (tntElement.hasParent()) { + tntElement.getParent().remove(tntElement); + if (tntElement.getParent().getElements().isEmpty()) { + remove(tntElement.getParent()); } } } - tntElementList.removeAll(toRemove); element.close(); + tntElementList.remove(element); } public void change() { From 7ab25a6ddb87e53e3cf3ec20a480c4a954ce1b53 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:09:14 +0100 Subject: [PATCH 022/174] Hotfix TNTSimulator other sim stuff Signed-off-by: yoyosource --- .../bausystem/features/simulator/TNTSimulator.java | 9 ++++++++- .../features/simulator/TNTSimulatorListener.java | 4 ---- 2 files changed, 8 insertions(+), 5 deletions(-) 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 34efb4fb..f7c2ff71 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -112,13 +112,20 @@ public class TNTSimulator { public void remove(SimulatorElement element) { if (element instanceof TNTElement) { TNTElement tntElement = (TNTElement) element; - element.remove(tntElement); if (tntElement.hasParent()) { tntElement.getParent().remove(tntElement); if (tntElement.getParent().getElements().isEmpty()) { remove(tntElement.getParent()); } + } else { + element.remove(tntElement); } + } else if (element instanceof TNTGroup) { + TNTGroup tntGroup = (TNTGroup) element; + tntGroup.getElements().forEach(tntElement -> { + tntElement.remove(tntElement); + }); + tntGroup.getElements().clear(); } element.close(); tntElementList.remove(element); 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 491f37c6..e877fc90 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -32,7 +32,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import org.bukkit.util.RayTraceResult; import java.util.function.Function; @@ -89,9 +88,6 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { SimulatorCursor.hide(event.getPlayer(), null); - SimulatorStorage.getSimulatorNames().forEach(s -> { - SimulatorStorage.getSimulator(s).hide(event.getPlayer()); - }); } @EventHandler From fce5b9c4934c42c2cfc3069c53edd0b67b09ad54 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:39:00 +0100 Subject: [PATCH 023/174] Hotfix some more stuff Signed-off-by: yoyosource --- .../features/simulator/tnt/TNTElement.java | 23 +++++++++++-------- .../features/simulator/tnt/TNTGroup.java | 7 +++--- 2 files changed, 16 insertions(+), 14 deletions(-) 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 df762600..fadffe21 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 @@ -50,7 +50,8 @@ public class TNTElement implements SimulatorElement { private static final World WORLD = Bukkit.getWorlds().get(0); - private final RFallingBlockEntity entity; + private final REntityServer entityServer; + private RFallingBlockEntity entity; TNTGroup tntGroup = null; private final Vector position; @@ -71,12 +72,14 @@ public class TNTElement implements SimulatorElement { private boolean disabled = false; public TNTElement(Vector position, REntityServer entityServer) { + this.entityServer = entityServer; this.position = position; this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); this.entity.setNoGravity(true); } public TNTElement(YAPIONObject yapionObject, REntityServer entityServer) { + this.entityServer = 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.disabled = yapionObject.getBooleanOrDefault("disabled", false); this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); @@ -119,7 +122,7 @@ public class TNTElement implements SimulatorElement { @Override public void getEntity(List elements, REntity entity) { if (disabled) return; - if (this.entity.getEntityId() == entity.getEntityId() || getPosition().equals(new Vector(entity.getX(), entity.getY(), entity.getZ()))) { + if (this.entity.getEntityId() == entity.getEntityId() || getPosition().distanceSquared(new Vector(entity.getX(), entity.getY(), entity.getZ())) < 0.01) { elements.add(this); } } @@ -141,8 +144,12 @@ public class TNTElement implements SimulatorElement { } void _updatePosition() { - Vector position = getPosition(); - entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); + if (disabled || (getParent() != null && getParent().isDisabled())) { + entity.move(-200000, 0, -200000, 0F, 0F, (byte) 0); + } else { + Vector position = getPosition(); + entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0); + } } public int getTickOffset() { @@ -172,7 +179,7 @@ public class TNTElement implements SimulatorElement { lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(tntCount()); + if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); return swItem; } @@ -271,10 +278,6 @@ public class TNTElement implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; - entity.setInvisible(disabled); - } - - void _setDisabled(boolean disabled) { - entity.setInvisible(disabled); + _updatePosition(); } } 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 3ab48778..9485cefa 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 @@ -62,6 +62,7 @@ public class TNTGroup implements SimulatorElement { TNTElement tntElement = new TNTElement(element, entityServer); tntElement.tntGroup = this; this.elements.add(tntElement); + tntElement._updatePosition(); } } @@ -135,7 +136,7 @@ public class TNTGroup implements SimulatorElement { lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", p)); } SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_GROUP_NAME", p), lore, disabled, null); - if (!disabled) swItem.getItemStack().setAmount(tntCount()); + if (!disabled) swItem.getItemStack().setAmount(Math.max(tntCount(), 1)); return swItem; } @@ -181,8 +182,6 @@ public class TNTGroup implements SimulatorElement { public void setDisabled(boolean disabled) { this.disabled = disabled; - elements.forEach(tntElement -> { - tntElement._setDisabled(disabled); - }); + elements.forEach(TNTElement::_updatePosition); } } From 137bf5eeca20b487b4d7f54d01b3fe83651de657 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:40:43 +0100 Subject: [PATCH 024/174] Hotfix some more stuff Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/simulator/tnt/TNTElement.java | 1 + 1 file changed, 1 insertion(+) 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 fadffe21..a9df556e 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 @@ -93,6 +93,7 @@ public class TNTElement implements SimulatorElement { this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false); this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name())); this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); + _updatePosition(); } @Override From fb920902f051469635e565310d5882dd4434da39 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:59:28 +0100 Subject: [PATCH 025/174] Hotfix the last one Signed-off-by: yoyosource --- .../features/simulator/SimulatorCursor.java | 1 + .../features/simulator/SimulatorStorage.java | 2 +- .../features/simulator/TNTSimulator.java | 4 ++-- .../features/simulator/gui/TNTElementGUI.java | 10 ++++------ .../features/simulator/tnt/TNTElement.java | 18 +++++++++++------- .../features/simulator/tnt/TNTGroup.java | 3 +-- 6 files changed, 20 insertions(+), 18 deletions(-) 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 caa3af54..d6a5fb2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -56,6 +56,7 @@ public class SimulatorCursor { if (result.getHitEntity() != null) { List elements = tntSimulator.getEntity(result.getHitEntity()); + System.out.println(elements); cursor = new REntityServer(); RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.TNT); 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 0b7b312b..a549e0a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -178,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.getEntityServer())); + tntSimulator.getTntElementList().add(new TNTElement(element, null, 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 f7c2ff71..1f51b10b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -67,7 +67,7 @@ public class TNTSimulator { if (element.containsKey("elements", YAPIONType.ARRAY)) { tntElementList.add(new TNTGroup(element, entityServer)); } else { - tntElementList.add(new TNTElement(element, entityServer)); + tntElementList.add(new TNTElement(element, null, entityServer)); } } } @@ -164,7 +164,7 @@ public class TNTSimulator { return; } - TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), entityServer); + TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), null, entityServer); tntElementList.add(tntElement); TNTElementGUI.open(player, tntElement, null); } 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 bfd0312b..875482a4 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 @@ -341,15 +341,13 @@ public class TNTElementGUI { int tickOffset = tntElement.getOwnTickOffset(); TNTGroup tntGroup = new TNTGroup(vector); tntGroup.setTickOffset(tickOffset); - tntElement.setTickOffset(0); - tntElement.getOwnPosition().setX(0); - tntElement.getOwnPosition().setY(0); - tntElement.getOwnPosition().setZ(0); tntGroup.add(tntElement); + tntElement.setTickOffset(0); + tntElement.setPosition(new Vector(0, 0, 0)); tntSimulator.getTntElementList().add(tntGroup); // Add new TNT - TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntSimulator.getEntityServer()); + TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntGroup, tntSimulator.getEntityServer()); newElement.setTickOffset(1); tntGroup.add(newElement); @@ -365,7 +363,7 @@ 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; Vector vector = tntElement.getOwnPosition().clone(); - TNTElement newElement = new TNTElement(vector, tntSimulator.getEntityServer()); + TNTElement newElement = new TNTElement(vector, null, tntSimulator.getEntityServer()); if (tntElement.hasParent()) { newElement.setTickOffset(tntElement.getOwnTickOffset() + 1); tntElement.getParent().add(newElement); 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 a9df556e..e7b358a9 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 @@ -71,20 +71,18 @@ public class TNTElement implements SimulatorElement { private Material material = Material.TNT; private boolean disabled = false; - public TNTElement(Vector position, REntityServer entityServer) { + public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) { this.entityServer = entityServer; + this.tntGroup = tntGroup; this.position = position; - this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT); - this.entity.setNoGravity(true); + initEntity(); } - public TNTElement(YAPIONObject yapionObject, REntityServer entityServer) { + public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) { this.entityServer = entityServer; + this.tntGroup = tntGroup; 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.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); @@ -93,6 +91,12 @@ public class TNTElement implements SimulatorElement { this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false); this.order = Material.valueOf(yapionObject.getStringOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? Material.COMPARATOR.name() : Material.REPEATER.name())); this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); + initEntity(); + } + + private void initEntity() { + this.entity = new RFallingBlockEntity(entityServer, getPosition().toLocation(WORLD), Material.TNT); + this.entity.setNoGravity(true); _updatePosition(); } 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 9485cefa..f3327578 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 @@ -59,8 +59,7 @@ public class TNTGroup implements SimulatorElement { 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, entityServer); - tntElement.tntGroup = this; + TNTElement tntElement = new TNTElement(element, this, entityServer); this.elements.add(tntElement); tntElement._updatePosition(); } From 20e30627dd150dff60a34f4f13bc300e5b0433c2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 21:59:40 +0100 Subject: [PATCH 026/174] Remove sout Signed-off-by: yoyosource --- .../steamwar/bausystem/features/simulator/SimulatorCursor.java | 1 - 1 file changed, 1 deletion(-) 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 d6a5fb2a..caa3af54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -56,7 +56,6 @@ public class SimulatorCursor { if (result.getHitEntity() != null) { List elements = tntSimulator.getEntity(result.getHitEntity()); - System.out.println(elements); cursor = new REntityServer(); RFallingBlockEntity entity = new RFallingBlockEntity(cursor, (elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition()).toLocation(WORLD), Material.TNT); From d3609dd2a03de1daa97dbbc386567c842a994c03 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 22:13:34 +0100 Subject: [PATCH 027/174] Remove yellow color replace Signed-off-by: yoyosource --- .../bausystem/utils/FlatteningWrapper15.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java index cadcb72a..bcb52882 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/FlatteningWrapper15.java @@ -110,16 +110,11 @@ public class FlatteningWrapper15 implements FlatteningWrapper { } private static final BaseBlock WOOL = Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock(); - private static final BaseBlock WOOL2 = Objects.requireNonNull(BlockTypes.YELLOW_WOOL).getDefaultState().toBaseBlock(); private static final BaseBlock CLAY = Objects.requireNonNull(BlockTypes.PINK_TERRACOTTA).getDefaultState().toBaseBlock(); - private static final BaseBlock CLAY2 = Objects.requireNonNull(BlockTypes.YELLOW_TERRACOTTA).getDefaultState().toBaseBlock(); private static final BaseBlock GLAZED = Objects.requireNonNull(BlockTypes.PINK_GLAZED_TERRACOTTA).getDefaultState().toBaseBlock(); private static final BaseBlock GLASS = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS).getDefaultState().toBaseBlock(); private static final BaseBlock GLASS_PANE = Objects.requireNonNull(BlockTypes.PINK_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); - private static final BaseBlock GLASS_PANE2 = Objects.requireNonNull(BlockTypes.YELLOW_STAINED_GLASS_PANE).getDefaultState().toBaseBlock(); private static final BaseBlock CONCRETE = Objects.requireNonNull(BlockTypes.PINK_CONCRETE).getDefaultState().toBaseBlock(); - private static final BaseBlock CONCRETE2 = Objects.requireNonNull(BlockTypes.YELLOW_CONCRETE).getDefaultState().toBaseBlock(); private static final BaseBlock CONCRETE_POWDER = Objects.requireNonNull(BlockTypes.PINK_CONCRETE_POWDER).getDefaultState().toBaseBlock(); private static final BaseBlock CARPET = Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock(); @@ -139,7 +134,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper { @Override public EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { - if (pasteOptions.getColor() != Color.YELLOW) { + if (pasteOptions.getColor() != Color.PINK) { changeColor(clipboard, pasteOptions.getColor()); } if (pasteOptions.isOnlyColors()) { @@ -216,28 +211,18 @@ public class FlatteningWrapper15 implements FlatteningWrapper { BaseBlock block = clipboard.getFullBlock(pos); if (block.equals(WOOL)) { clipboard.setBlock(pos, wool); - } else if (block.equals(WOOL2)) { - clipboard.setBlock(pos, wool); } else if (block.equals(CLAY)) { clipboard.setBlock(pos, clay); - } else if (block.equals(CLAY2)) { - clipboard.setBlock(pos, clay); } else if (block.equals(GLAZED)) { clipboard.setBlock(pos, glazed); } else if (block.equals(GLASS)) { clipboard.setBlock(pos, glass); - } else if (block.equals(GLASS2)) { - clipboard.setBlock(pos, glass); } else if (block.equals(GLASS_PANE)) { clipboard.setBlock(pos, glassPane); - } else if (block.equals(GLASS_PANE2)) { - clipboard.setBlock(pos, glassPane); } else if (block.equals(CARPET)) { clipboard.setBlock(pos, carpet); } else if (block.equals(CONCRETE)) { clipboard.setBlock(pos, concrete); - } else if (block.equals(CONCRETE2)) { - clipboard.setBlock(pos, concrete); } else if (block.equals(CONCRETE_POWDER)) { clipboard.setBlock(pos, concretePowder); } From dbde27d66b9939564bbeefb3d800f59b93fbdba5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 09:55:49 +0100 Subject: [PATCH 028/174] Add 1.19.3 support Signed-off-by: yoyosource --- .../features/tracer/record/TNTPrimedIterator19.java | 2 +- .../de/steamwar/bausystem/utils/NMSWrapper19.java | 13 +++++++------ .../bausystem/utils/PlayerMovementWrapper19.java | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java b/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java index b56e04b3..17498269 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/features/tracer/record/TNTPrimedIterator19.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.features.tracer.record; import net.minecraft.world.entity.item.EntityTNTPrimed; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld; import org.bukkit.entity.TNTPrimed; import java.util.stream.Stream; diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index f0d11ff1..24edeb9a 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -35,15 +35,16 @@ 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.craftbukkit.v1_19_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.LongSupplier; public class NMSWrapper19 implements NMSWrapper { @@ -90,7 +91,7 @@ public class NMSWrapper19 implements NMSWrapper { if (entity instanceof TNTPrimed) { net.minecraft.world.entity.Entity serverEntity = ((CraftEntity) entity).getHandle(); - packets.add(new PacketPlayOutEntityMetadata(serverEntity.ae(), serverEntity.ai(), true)); + packets.add(new PacketPlayOutEntityMetadata(serverEntity.ah(), Objects.requireNonNull(serverEntity.al().c()))); } }); } @@ -113,8 +114,8 @@ public class NMSWrapper19 implements NMSWrapper { @Override public void setPlayerBuildAbilities(Player player) { - ((CraftPlayer) player).getHandle().fB().d = true; - ((CraftPlayer) player).getHandle().fB().e = true; + ((CraftPlayer) player).getHandle().fF().d = true; + ((CraftPlayer) player).getHandle().fF().e = true; } @Override diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index 4b9f7939..fd9a892e 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -19,10 +19,9 @@ package de.steamwar.bausystem.utils; -import de.steamwar.bausystem.utils.PlayerMovementWrapper; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; public class PlayerMovementWrapper19 implements PlayerMovementWrapper { From 599d717602ba67511d4dfba8209ee197482389fa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 13:27:33 +0100 Subject: [PATCH 029/174] Add darkness skins back Signed-off-by: yoyosource --- yapion/prototypes19.yapion | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/yapion/prototypes19.yapion b/yapion/prototypes19.yapion index 265b628f..18dc773a 100644 --- a/yapion/prototypes19.yapion +++ b/yapion/prototypes19.yapion @@ -7,6 +7,11 @@ name(WarGear) schematic(sections19/Normal/WGArena.schem) testblockSchematic(sections19/Normal/WGTestblock.schem) + }, + { + name(Darkness) + schematic(sections19/Darkness/WGArena.schem) + testblockSchematic(sections19/Darkness/WGTestblock.schem) } ] sizeX(178) @@ -135,6 +140,11 @@ name(AirShip) schematic(sections19/Normal/ASArena.schem) testblockSchematic(sections19/Normal/ASTestblock.schem) + }, + { + name(Darkness) + schematic(sections19/Darkness/ASArena.schem) + testblockSchematic(sections19/Darkness/ASTestblock.schem) } ] sizeX(158) @@ -174,6 +184,11 @@ name(WarShip) schematic(sections19/Normal/WSArena.schem) testblockSchematic(sections19/Normal/WSTestblock.schem) + }, + { + name(Darkness) + schematic(sections19/Darkness/WSArena.schem) + testblockSchematic(sections19/Darkness/WSTestblock.schem) } ] sizeX(250) @@ -212,8 +227,14 @@ skins[ { name(WarShip) - schematic(sections19/Normal/WSInnerArena.schem) - testblockSchematic(sections19/Normal/WSInnerTestblock.schem) + schematic(sections19/Normal/WSINNERArena.schem) + testblockSchematic(sections19/Normal/WSINNERTestblock.schem) + }, + { + name(Darkness) + type(WSINNER) + schematic(sections19/Darkness/WSINNERArena.schem) + testblockSchematic(sections19/Darkness/WSINNERTestblock.schem) } ] sizeX(250) @@ -248,7 +269,7 @@ } ws_rumpf{ displayName(WarShip Rumpf) - schematic(sections19/Normal/WSRumpf.schem) + schematic(sections19/Normal/WSRUMPFArena.schem) sizeX(240) sizeY(67) sizeZ(47) @@ -258,7 +279,7 @@ } ws_rahmen{ displayName(WarShip Rahmen) - schematic(sections19/Normal/WSRahmen.schem) + schematic(sections19/Normal/WSRAHMENArena.schem) sizeX(240) sizeY(67) sizeZ(48) From 2dd5e16bda1c73b59bedf655b60b7dd340c732f0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 13:58:42 +0100 Subject: [PATCH 030/174] Fix alignment Signed-off-by: yoyosource --- .../bausystem/features/simulator/gui/TNTElementGUI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 875482a4..7ea6ac31 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 @@ -137,28 +137,28 @@ public class TNTElementGUI { 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; Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0, 0, 0.49)); + align(position, new Vector(0.5, 0, 0.49)); 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; Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0, 0, 0.51)); + align(position, new Vector(0.5, 0, 0.51)); 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; Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.51, 0, 0)); + align(position, new Vector(0.51, 0, 0.5)); 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; Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.49, 0, 0)); + align(position, new Vector(0.49, 0, 0.5)); tntElement.setPosition(position); tntElement.change(); })); From 1086808cf080a5fe2000b7a8552fb98af2123e26 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 14:29:26 +0100 Subject: [PATCH 031/174] Fix some NPE's Signed-off-by: yoyosource --- .../bausystem/features/simulator/TNTSimulator.java | 14 +++++++++++--- .../features/simulator/TNTSimulatorListener.java | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) 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 1f51b10b..fb6a91cd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -88,12 +88,20 @@ public class TNTSimulator { } public void show(Player player) { - entityServer.addPlayer(player); - players.add(player); + if (!players.contains(player)) { + entityServer.addPlayer(player); + players.add(player); + } } public void hide(Player player) { - entityServer.removePlayer(player); + if (players.contains(player)) { + entityServer.removePlayer(player); + players.remove(player); + } + } + + void _hide(Player player) { players.remove(player); } 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 e877fc90..48285d78 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -88,6 +88,9 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { SimulatorCursor.hide(event.getPlayer(), null); + SimulatorStorage.getSimulatorNames().forEach(s -> { + SimulatorStorage.getSimulator(s)._hide(event.getPlayer()); + }); } @EventHandler From 5d1fb567efaf408f38f6209ea440e25744637070 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 15:12:49 +0100 Subject: [PATCH 032/174] Fix alignment the second time Signed-off-by: yoyosource --- .../features/simulator/gui/TNTElementGUI.java | 39 +++---------------- .../features/simulator/tnt/TNTElement.java | 27 +++++++++++++ 2 files changed, 32 insertions(+), 34 deletions(-) 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 7ea6ac31..e87640d0 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 @@ -136,37 +136,27 @@ public class TNTElementGUI { // 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; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.49)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.49)); 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; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.51)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.51)); 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; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.51, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.51, 0, 0.5)); 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; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.49, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.49, 0, 0.5)); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER if (clickType == ClickType.DOUBLE_CLICK) return; - Vector position = tntElement.getOwnPosition(); - align(position, new Vector(0.5, 0, 0.5)); - tntElement.setPosition(position); + tntElement.align(new Vector(0.5, 0, 0.5)); tntElement.change(); })); }; @@ -179,25 +169,6 @@ public class TNTElementGUI { inv.open(); } - private void align(Vector vector, Vector offset) { - if (vector.getX() - (int) vector.getX() == 0.49) { - vector.setX(vector.getX() + 0.02); - } - if (vector.getX() - (int) vector.getX() == -0.49) { - vector.setX(vector.getX() - 0.02); - } - if (vector.getZ() - (int) vector.getZ() == 0.49) { - vector.setZ(vector.getZ() + 0.02); - } - if (vector.getZ() - (int) vector.getZ() == -0.49) { - vector.setZ(vector.getZ() - 0.02); - } - - vector.setX(vector.getBlockX() + offset.getX()); - vector.setY(vector.getBlockY() + offset.getY()); - vector.setZ(vector.getBlockZ() + offset.getZ()); - } - private void editProperties(Player player, TNTElement tntElement, Runnable back) { SWInventory inv = open(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_EDIT_PROPERTIES", player)); if (back != null) { 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 e7b358a9..af6e3045 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 @@ -285,4 +285,31 @@ public class TNTElement implements SimulatorElement { this.disabled = disabled; _updatePosition(); } + + public void align(Vector offset) { + Vector vector = getPosition(); + Vector parentVector = new Vector(0, 0, 0); + if (tntGroup != null) { + parentVector = tntGroup.getPosition(); + } + + if (vector.getX() - (int) vector.getX() == 0.49) { + vector.setX(vector.getX() + 0.02); + } + if (vector.getX() - (int) vector.getX() == -0.49) { + vector.setX(vector.getX() - 0.02); + } + if (vector.getZ() - (int) vector.getZ() == 0.49) { + vector.setZ(vector.getZ() + 0.02); + } + if (vector.getZ() - (int) vector.getZ() == -0.49) { + vector.setZ(vector.getZ() - 0.02); + } + + vector.setX(vector.getBlockX() + offset.getX()); + vector.setY(vector.getBlockY() + offset.getY()); + vector.setZ(vector.getBlockZ() + offset.getZ()); + + setPosition(vector.subtract(parentVector)); + } } From d9385691e40f549126ab260dce68ce2ef0581a77 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 15:16:03 +0100 Subject: [PATCH 033/174] Hotfix clear simulator Signed-off-by: yoyosource --- .../steamwar/bausystem/features/simulator/TNTSimulator.java | 4 ++++ .../bausystem/features/simulator/gui/TNTSimulatorGui.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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 fb6a91cd..f9513cd4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -117,6 +117,10 @@ public class TNTSimulator { return tntSpawns; } + public void clear() { + new ArrayList<>(tntElementList).forEach(this::remove); + } + public void remove(SimulatorElement element) { if (element instanceof TNTElement) { TNTElement tntElement = (TNTElement) element; 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 aed364bc..e813580a 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 @@ -130,7 +130,7 @@ public class TNTSimulatorGui { inv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> { if (currentTntSimulator != null) { currentTntSimulator.getTntElementList().forEach(SimulatorElement::close); - currentTntSimulator.getTntElementList().clear(); + currentTntSimulator.clear(); player.closeInventory(); } else { TNTSimulator tntSimulator = SimulatorStorage.getSimulator(player); From de067103cb8e1a9d40f5ad896b5afbf2712a9662 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 27 Feb 2023 20:27:30 +0100 Subject: [PATCH 034/174] Hotfix AttributeRemoveCommand Signed-off-by: yoyosource --- .../features/attributescopy/AttributeRemoveCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 902d7c59..4f1bdd92 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java @@ -99,13 +99,15 @@ public class AttributeRemoveCommand extends SWCommand { return lore.stream() .skip(1) .map(s1 -> s1.substring(6)) + .map(s1 -> s1.replace('§', '&')) .map(s1 -> s1.replace(' ', '_')) .collect(Collectors.toList()); } @Override public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - return s.replace('_', ' '); + return s.replace('_', ' ') + .replace('&', '§'); } }; } From 9e31f05d83a3c9a5819a57bf3ef8a47bd57a08fe Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 28 Feb 2023 16:51:17 +0100 Subject: [PATCH 035/174] Add /sl as alias for FreezeCommand Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/region/FreezeCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java index 303bc49a..339ea122 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeCommand.java @@ -33,7 +33,7 @@ import org.bukkit.entity.Player; public class FreezeCommand extends SWCommand { public FreezeCommand() { - super("freeze", "stoplag"); + super("freeze", "stoplag", "sl"); } @Register(description = "REGION_FREEZE_HELP") From b6730eca0efd6878e79b9caeac5a682a9f11bad5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Mar 2023 16:31:13 +0100 Subject: [PATCH 036/174] Hotfix NoClipCommand Signed-off-by: yoyosource --- .../bausystem/features/util/NoClipCommand.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 46fdf535..3aab2cca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -46,14 +46,6 @@ import java.util.function.BiFunction; @Linked public class NoClipCommand extends SWCommand implements Listener { - public static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); - private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); - public static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); - public static final Class enumGamemode = Reflection.getClass("{nms.world.level}.EnumGamemode"); - private static final Object spectator = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4]; public static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); @@ -160,13 +152,6 @@ public class NoClipCommand extends SWCommand implements Listener { } private static void pseudoSpectator(Player player) { - TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), spectator)); - } - - private static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { - Object packet = Reflection.newInstance(playerInfoPacket); - playerInfoAction.set(packet, action); - playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode))); - return packet; + TinyProtocol.instance.sendPacket(player, de.steamwar.core.ProtocolWrapper.impl.playerInfoPacketConstructor(de.steamwar.core.ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), GameMode.CREATIVE)); } } \ No newline at end of file From 91255be7572e926c53f09fc27f4ffb37cb9e4f99 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Mar 2023 16:34:40 +0100 Subject: [PATCH 037/174] Hotfix NoClipCommand Signed-off-by: yoyosource --- .../bausystem/utils/ProtocolWrapper15.java | 33 ------------------- .../bausystem/utils/ProtocolWrapper18.java | 33 ------------------- .../bausystem/utils/ProtocolWrapper19.java | 33 ------------------- .../features/util/NoClipCommand.java | 14 ++++---- .../bausystem/utils/ProtocolWrapper.java | 30 ----------------- 5 files changed, 8 insertions(+), 135 deletions(-) delete mode 100644 BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java delete mode 100644 BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java delete mode 100644 BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java deleted file mode 100644 index 57ba7259..00000000 --- a/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.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.utils; - -import com.comphenix.tinyprotocol.Reflection; -import com.mojang.authlib.GameProfile; -import de.steamwar.bausystem.features.util.NoClipCommand; - -public class ProtocolWrapper15 implements ProtocolWrapper { - - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, NoClipCommand.playerInfoPacket, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent); - @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null); - } -} diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java deleted file mode 100644 index 962b8181..00000000 --- a/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.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.utils; - -import com.comphenix.tinyprotocol.Reflection; -import com.mojang.authlib.GameProfile; -import de.steamwar.bausystem.features.util.NoClipCommand; - -public class ProtocolWrapper18 implements ProtocolWrapper { - - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent); - @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(profile, 0, mode, null); - } -} diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java deleted file mode 100644 index 3a21ab08..00000000 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java +++ /dev/null @@ -1,33 +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.utils; - -import com.comphenix.tinyprotocol.Reflection; -import com.mojang.authlib.GameProfile; -import de.steamwar.bausystem.features.util.NoClipCommand; - -public class ProtocolWrapper19 implements ProtocolWrapper { - - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a")); - @Override - public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { - return playerInfoDataConstructor.invoke(profile, 0, mode, null, null); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 3aab2cca..42caa32e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -25,9 +25,8 @@ import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.utils.NMSWrapper; -import de.steamwar.bausystem.utils.ProtocolWrapper; import de.steamwar.command.SWCommand; -import de.steamwar.core.Core; +import de.steamwar.core.ProtocolWrapper; import de.steamwar.linkage.Linked; import lombok.Getter; import org.bukkit.Bukkit; @@ -40,7 +39,10 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.BiFunction; @Linked @@ -112,7 +114,7 @@ public class NoClipCommand extends SWCommand implements Listener { NOCLIPS.add(player); BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player); TinyProtocol.instance.sendPacket(player, gameStateChangeObject); - pseudoSpectator(player); + pseudoGameMode(player, GameMode.CREATIVE); } } @@ -151,7 +153,7 @@ public class NoClipCommand extends SWCommand implements Listener { } } - private static void pseudoSpectator(Player player) { - TinyProtocol.instance.sendPacket(player, de.steamwar.core.ProtocolWrapper.impl.playerInfoPacketConstructor(de.steamwar.core.ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), GameMode.CREATIVE)); + private static void pseudoGameMode(Player player, GameMode gameMode) { + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), gameMode)); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java deleted file mode 100644 index 536dec51..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.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.utils; - -import com.mojang.authlib.GameProfile; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.core.VersionDependent; - -public interface ProtocolWrapper { - ProtocolWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); - - Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode); -} From 4cfd7402a4c3c6d61031adfaaa19a12f6ee7d68f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Mar 2023 17:04:21 +0100 Subject: [PATCH 038/174] Hotfix everything that does not work Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/features/detonator/DetonatorCommand.java | 2 +- .../features/detonator/DetonatorListener.java | 2 +- .../features/killchecker/KillcheckerCommand.java | 2 +- .../bausystem/features/script/variables/Constants.java | 4 ++++ .../bausystem/features/simulator/SimulatorCommand.java | 2 +- .../bausystem/features/simulator/SimulatorStorage.java | 2 +- .../features/simulator/TNTSimulatorListener.java | 2 +- .../bausystem/features/tracer/TraceCommand.java | 2 +- .../bausystem/features/tracer/record/Recorder.java | 10 +--------- .../steamwar/bausystem/features/warp/WarpCommand.java | 2 +- .../steamwar/bausystem/features/warp/WarpListener.java | 2 +- 12 files changed, 15 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 1d1e6362..44ad2b3a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -94,7 +94,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void onDisable() { - LinkageUtils.unlink(); + // LinkageUtils.unlink(); WorldData.write(); Config.getInstance().saveAll(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java index bb71245d..f703729f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java @@ -34,7 +34,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.Arrays; -@Linked +// @Linked public class DetonatorCommand extends SWCommand { public static ItemStack getWAND(Player player) { 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 be8e8ce9..f0ced4e5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -38,7 +38,7 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent; import java.util.HashSet; import java.util.Set; -@Linked +// @Linked public class DetonatorListener implements Listener { static final Set HAS_UPDATED = new HashSet<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index fee15416..74fae22f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -37,7 +37,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -@Linked +// @Linked public class KillcheckerCommand extends SWCommand implements Listener { private Map visualizers = new HashMap<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index e0ec0872..576a8fc1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -171,6 +171,7 @@ public class Constants { static { CONSTANTS.put("trace", player -> { + if (true) return new ConstantBooleanValue(() -> false); Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { return new ConstantBooleanValue(() -> false); @@ -178,6 +179,7 @@ public class Constants { return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof ActiveTracer); }); CONSTANTS.put("autotrace", player -> { + if (true) return new ConstantBooleanValue(() -> false); Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { return new ConstantBooleanValue(() -> false); @@ -185,10 +187,12 @@ public class Constants { return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder); }); CONSTANTS.put("trace_status", player -> { + if (true) return new ConstantStringValue(() -> ""); TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); return new ConstantStringValue(recorder::scriptState); }); CONSTANTS.put("trace_time", player -> { + if (true) return new ConstantLongValue(() -> 0L); TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); return new ConstantLongValue(recorder::scriptTime); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 640d0360..c4462dc9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.ItemStack; import java.util.Collection; -@Linked +// @Linked public class SimulatorCommand extends SWCommand { public SimulatorCommand() { 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 a549e0a2..5103136a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -48,7 +48,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -@Linked +// @Linked public class SimulatorStorage implements Enable, Disable { public static final World WORLD = Bukkit.getWorlds().get(0); 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 48285d78..df76dc5b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.PlayerInventory; import java.util.function.Function; -@Linked +// @Linked public class TNTSimulatorListener implements Listener { private boolean permissionCheck(Player player) { 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 b24ec012..a3c3cc71 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -43,7 +43,7 @@ import java.util.function.BiFunction; import java.util.function.Supplier; import java.util.stream.Collectors; -@Linked +// @Linked public class TraceCommand extends SWCommand { public TraceCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 2d74492d..7e037875 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -39,7 +39,7 @@ import org.bukkit.event.entity.EntitySpawnEvent; import java.util.*; import java.util.stream.Collectors; -@Linked +// @Linked public class Recorder implements Listener { public static Recorder INSTANCE; @@ -108,14 +108,6 @@ public class Recorder implements Listener { } private static final DisabledTracerRecorder DISABLED = new DisabledTracerRecorder(); - static Recorder instance; - - { - instance = this; - } - - private final World world = Bukkit.getWorlds().get(0); - private Map regionTraceRecorderMap = new HashMap<>(); private Map tntTraceRecorderMap = new HashMap<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java index cf44f51f..ac21b447 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -40,7 +40,7 @@ import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; -@Linked +// @Linked public class WarpCommand extends SWCommand implements Disable, Enable { private static final String[] FORBIDDEN_NAMES = new String[]{ 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 953d709a..fa040556 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java @@ -38,7 +38,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@Linked +// @Linked public class WarpListener implements Listener { private Map warpEntityServer = new HashMap<>(); From 43f1ecc985ad52caa83cca3db7b646e022b18418 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Mar 2023 17:10:45 +0100 Subject: [PATCH 039/174] Revert "Hotfix everything that does not work" This reverts commit 4cfd7402a4c3c6d61031adfaaa19a12f6ee7d68f. --- .../src/de/steamwar/bausystem/BauSystem.java | 2 +- .../bausystem/features/detonator/DetonatorCommand.java | 2 +- .../features/detonator/DetonatorListener.java | 2 +- .../features/killchecker/KillcheckerCommand.java | 2 +- .../bausystem/features/script/variables/Constants.java | 4 ---- .../bausystem/features/simulator/SimulatorCommand.java | 2 +- .../bausystem/features/simulator/SimulatorStorage.java | 2 +- .../features/simulator/TNTSimulatorListener.java | 2 +- .../bausystem/features/tracer/TraceCommand.java | 2 +- .../bausystem/features/tracer/record/Recorder.java | 10 +++++++++- .../steamwar/bausystem/features/warp/WarpCommand.java | 2 +- .../steamwar/bausystem/features/warp/WarpListener.java | 2 +- 12 files changed, 19 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 44ad2b3a..1d1e6362 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -94,7 +94,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void onDisable() { - // LinkageUtils.unlink(); + LinkageUtils.unlink(); WorldData.write(); Config.getInstance().saveAll(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java index f703729f..bb71245d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorCommand.java @@ -34,7 +34,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.Arrays; -// @Linked +@Linked public class DetonatorCommand extends SWCommand { public static ItemStack getWAND(Player player) { 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 f0ced4e5..be8e8ce9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -38,7 +38,7 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent; import java.util.HashSet; import java.util.Set; -// @Linked +@Linked public class DetonatorListener implements Listener { static final Set HAS_UPDATED = new HashSet<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 74fae22f..fee15416 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -37,7 +37,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -// @Linked +@Linked public class KillcheckerCommand extends SWCommand implements Listener { private Map visualizers = new HashMap<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index 576a8fc1..e0ec0872 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -171,7 +171,6 @@ public class Constants { static { CONSTANTS.put("trace", player -> { - if (true) return new ConstantBooleanValue(() -> false); Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { return new ConstantBooleanValue(() -> false); @@ -179,7 +178,6 @@ public class Constants { return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof ActiveTracer); }); CONSTANTS.put("autotrace", player -> { - if (true) return new ConstantBooleanValue(() -> false); Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { return new ConstantBooleanValue(() -> false); @@ -187,12 +185,10 @@ public class Constants { return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder); }); CONSTANTS.put("trace_status", player -> { - if (true) return new ConstantStringValue(() -> ""); TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); return new ConstantStringValue(recorder::scriptState); }); CONSTANTS.put("trace_time", player -> { - if (true) return new ConstantLongValue(() -> 0L); TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); return new ConstantLongValue(recorder::scriptTime); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index c4462dc9..640d0360 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.ItemStack; import java.util.Collection; -// @Linked +@Linked public class SimulatorCommand extends SWCommand { public SimulatorCommand() { 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 5103136a..a549e0a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorStorage.java @@ -48,7 +48,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -// @Linked +@Linked public class SimulatorStorage implements Enable, Disable { public static final World WORLD = Bukkit.getWorlds().get(0); 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 df76dc5b..48285d78 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -35,7 +35,7 @@ import org.bukkit.inventory.PlayerInventory; import java.util.function.Function; -// @Linked +@Linked public class TNTSimulatorListener implements Listener { private boolean permissionCheck(Player player) { 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 a3c3cc71..b24ec012 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -43,7 +43,7 @@ import java.util.function.BiFunction; import java.util.function.Supplier; import java.util.stream.Collectors; -// @Linked +@Linked public class TraceCommand extends SWCommand { public TraceCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 7e037875..2d74492d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -39,7 +39,7 @@ import org.bukkit.event.entity.EntitySpawnEvent; import java.util.*; import java.util.stream.Collectors; -// @Linked +@Linked public class Recorder implements Listener { public static Recorder INSTANCE; @@ -108,6 +108,14 @@ public class Recorder implements Listener { } private static final DisabledTracerRecorder DISABLED = new DisabledTracerRecorder(); + static Recorder instance; + + { + instance = this; + } + + private final World world = Bukkit.getWorlds().get(0); + private Map regionTraceRecorderMap = new HashMap<>(); private Map tntTraceRecorderMap = new HashMap<>(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java index ac21b447..cf44f51f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -40,7 +40,7 @@ import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; -// @Linked +@Linked public class WarpCommand extends SWCommand implements Disable, Enable { private static final String[] FORBIDDEN_NAMES = new String[]{ 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 fa040556..953d709a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpListener.java @@ -38,7 +38,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -// @Linked +@Linked public class WarpListener implements Listener { private Map warpEntityServer = new HashMap<>(); From ae1e10ecc6dcfb91101ca208594bc28b53dc0c8a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 5 Mar 2023 11:07:50 +0100 Subject: [PATCH 040/174] Remove unused code Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/util/NoClipCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 42caa32e..54709275 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -48,8 +48,6 @@ import java.util.function.BiFunction; @Linked public class NoClipCommand extends SWCommand implements Listener { - public static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); From 106a1a8fb0fc3ef2c1267ec9e1fa380c0e315654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 6 Mar 2023 21:17:42 +0100 Subject: [PATCH 041/174] Hotfix TNTElement alignment Author: PSIRobot Signed-off-by: yoyosource --- .../features/simulator/gui/TNTElementGUI.java | 8 ++--- .../features/simulator/tnt/TNTElement.java | 31 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) 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 e87640d0..93181f90 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 @@ -136,22 +136,22 @@ public class TNTElementGUI { // 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; - tntElement.align(new Vector(0.5, 0, 0.49)); + tntElement.align(new Vector(0, 0, 0.49)); 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; - tntElement.align(new Vector(0.5, 0, 0.51)); + tntElement.align(new Vector(0, 0, 0.51)); 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; - tntElement.align(new Vector(0.51, 0, 0.5)); + tntElement.align(new Vector(0.51, 0, 0)); 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; - tntElement.align(new Vector(0.49, 0, 0.5)); + tntElement.align(new Vector(0.49, 0, 0)); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER 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 af6e3045..666c3359 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 @@ -293,22 +293,25 @@ public class TNTElement implements SimulatorElement { parentVector = tntGroup.getPosition(); } - if (vector.getX() - (int) vector.getX() == 0.49) { - vector.setX(vector.getX() + 0.02); - } - if (vector.getX() - (int) vector.getX() == -0.49) { - vector.setX(vector.getX() - 0.02); - } - if (vector.getZ() - (int) vector.getZ() == 0.49) { - vector.setZ(vector.getZ() + 0.02); - } - if (vector.getZ() - (int) vector.getZ() == -0.49) { - vector.setZ(vector.getZ() - 0.02); + if (offset.getX() != 0) { + if (vector.getX() - (int) vector.getX() == 0.49) { + vector.setX(vector.getX() + 0.02); + } + if (vector.getX() - (int) vector.getX() == -0.49) { + vector.setX(vector.getX() - 0.02); + } + vector.setX(vector.getBlockX() + offset.getX()); } - vector.setX(vector.getBlockX() + offset.getX()); - vector.setY(vector.getBlockY() + offset.getY()); - vector.setZ(vector.getBlockZ() + offset.getZ()); + if (offset.getZ() != 0) { + if (vector.getZ() - (int) vector.getZ() == 0.49) { + vector.setZ(vector.getZ() + 0.02); + } + if (vector.getZ() - (int) vector.getZ() == -0.49) { + vector.setZ(vector.getZ() - 0.02); + } + vector.setZ(vector.getBlockZ() + offset.getZ()); + } setPosition(vector.subtract(parentVector)); } From d4727d5ed94a1a7dd0b4c9c5fe4382e64dc72ee2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 07:43:22 +0100 Subject: [PATCH 042/174] Add CuboidColorization filter option Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerCommand.java | 8 +++++++- .../features/killchecker/KillcheckerVisualizer.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index fee15416..a6442669 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -48,9 +48,10 @@ public class KillcheckerCommand extends SWCommand implements Listener { } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") - public void genericCommand(Player player) { + public void genericCommand(Player player, @OptionalValue("ALL_CUBOIDS") ColorizedCuboidsOnly colorizedCuboidsOnly) { Region region = Region.getRegion(player.getLocation()); KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, KillcheckerVisualizer::new); + killcheckerVisualizer.setOnlyColorizedBlocks(colorizedCuboidsOnly == ColorizedCuboidsOnly.ONLY_COLORIZED_CUBOIDS); killcheckerVisualizer.recalc(); killcheckerVisualizer.show(player); BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); @@ -99,4 +100,9 @@ public class KillcheckerCommand extends SWCommand implements Listener { recalc(event.getBlock()); }, 1); } + + public enum ColorizedCuboidsOnly { + ONLY_COLORIZED_CUBOIDS, + ALL_CUBOIDS + } } 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 e97f4a30..638cc955 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -55,6 +56,9 @@ public class KillcheckerVisualizer { private REntityServer rEntityServer = new REntityServer(); + @Setter + private boolean onlyColorizedBlocks = false; + private Map killCount = new HashMap<>(); private Map rEntities = new HashMap<>(); @@ -67,6 +71,10 @@ public class KillcheckerVisualizer { if (points.contains(new Point(x, y, z))) continue; Block block = WORLD.getBlockAt(x, y, z); if (block.getType().isAir()) continue; + if (onlyColorizedBlocks) { + String name = block.getType().name(); + if (!name.endsWith("_WOOL") && name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue; + } Cuboid cuboid = create(block.getType(), x, y, z); cuboids.add(cuboid); for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { From 22b3da59e8d0e0ada094f14904d056d2ee682273 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 19:04:54 +0100 Subject: [PATCH 043/174] Update Killchecker Signed-off-by: yoyosource --- .../killchecker/KillcheckerCommand.java | 10 +- .../killchecker/KillcheckerVisualizer.java | 211 +++++++++++++++--- 2 files changed, 185 insertions(+), 36 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index a6442669..6a0fe5b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -48,12 +48,11 @@ public class KillcheckerCommand extends SWCommand implements Listener { } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") - public void genericCommand(Player player, @OptionalValue("ALL_CUBOIDS") ColorizedCuboidsOnly colorizedCuboidsOnly) { + public void genericCommand(Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) { Region region = Region.getRegion(player.getLocation()); KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, KillcheckerVisualizer::new); - killcheckerVisualizer.setOnlyColorizedBlocks(colorizedCuboidsOnly == ColorizedCuboidsOnly.ONLY_COLORIZED_CUBOIDS); killcheckerVisualizer.recalc(); - killcheckerVisualizer.show(player); + killcheckerVisualizer.show(player, onlyOutline); BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); } @@ -100,9 +99,4 @@ public class KillcheckerCommand extends SWCommand implements Listener { recalc(event.getBlock()); }, 1); } - - public enum ColorizedCuboidsOnly { - ONLY_COLORIZED_CUBOIDS, - ALL_CUBOIDS - } } 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 638cc955..b66dff69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -27,11 +27,13 @@ import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; -import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; import org.bukkit.entity.Player; import java.util.HashMap; @@ -44,37 +46,50 @@ public class KillcheckerVisualizer { private static final Material[] materials = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS}; private static final World WORLD = Bukkit.getWorlds().get(0); + private static final double SURROUND = 4; + private Point minPoint; private Point maxPoint; + private int yArea; + private int zArea; + private int xArea; + private Set players = new HashSet<>(); + private Set areaPlayers = new HashSet<>(); public KillcheckerVisualizer(Region region) { this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL); this.maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL); + + yArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getZ() - minPoint.getZ()); + zArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getY() - minPoint.getY()); + xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ()); } - private REntityServer rEntityServer = new REntityServer(); - - @Setter - private boolean onlyColorizedBlocks = false; + private REntityServer outline = new REntityServer(); + private REntityServer inner = new REntityServer(); private Map killCount = new HashMap<>(); + private Set outlinePointsCache = new HashSet<>(); private Map rEntities = new HashMap<>(); + private Map bossBars = new HashMap<>(); + + private double percent = 0; + private int kills = 0; + private int cannonCount = 0; public void recalc() { Set cuboids = new HashSet<>(); Set points = new HashSet<>(); - for (int x = minPoint.getX() + 1; x < maxPoint.getX() - 1; x++) { + for (int x = minPoint.getX() + 1; x < maxPoint.getX(); x++) { for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { - for (int z = minPoint.getZ() + 1; z < maxPoint.getZ() - 1; z++) { + for (int z = minPoint.getZ() + 1; z < maxPoint.getZ(); z++) { if (points.contains(new Point(x, y, z))) continue; Block block = WORLD.getBlockAt(x, y, z); if (block.getType().isAir()) continue; - if (onlyColorizedBlocks) { - String name = block.getType().name(); - if (!name.endsWith("_WOOL") && name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue; - } + String name = block.getType().name(); + if (!name.endsWith("_WOOL") && !name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue; Cuboid cuboid = create(block.getType(), x, y, z); cuboids.add(cuboid); for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { @@ -87,60 +102,164 @@ public class KillcheckerVisualizer { } } } + cannonCount = cuboids.size(); Map kill = new HashMap<>(); - for (int x = minPoint.getX(); x < maxPoint.getX(); x++) { - for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) { + int yKills = 0; + int yCount = 0; + Set yPoints = new HashSet<>(); + for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) { + for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) { Set cuboidSet = new HashSet<>(); for (Cuboid cuboid : cuboids) { - if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) { + if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) { cuboidSet.add(cuboid); } } if (cuboidSet.size() > 1) { - Point p1 = new Point(x, minPoint.getY(), z); - kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); + yCount++; + yKills += splitIntoDoubleKills(cuboidSet.size()); Point p2 = new Point(x, maxPoint.getY(), z); + yPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } } } - for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { - for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) { + int xKills = 0; + int xCount = 0; + Set xPoints = new HashSet<>(); + for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) { + for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) { Set cuboidSet = new HashSet<>(); for (Cuboid cuboid : cuboids) { - if (y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) { + if (y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) { cuboidSet.add(cuboid); } } if (cuboidSet.size() > 1) { + xCount++; + xKills += splitIntoDoubleKills(cuboidSet.size()); Point p1 = new Point(minPoint.getX(), y, z); + xPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); Point p2 = new Point(maxPoint.getX(), y, z); + xPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } } } - for (int x = minPoint.getX(); x < maxPoint.getX(); x++) { - for (int y = minPoint.getY(); y < maxPoint.getY(); y++) { + int zKills = 0; + int zCount = 0; + Set zPoints = new HashSet<>(); + for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) { + for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) { Set cuboidSet = new HashSet<>(); for (Cuboid cuboid : cuboids) { - if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5) { + if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND) { cuboidSet.add(cuboid); } } if (cuboidSet.size() > 1) { + zCount++; + zKills += splitIntoDoubleKills(cuboidSet.size()); Point p1 = new Point(x, y, minPoint.getZ()); + zPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); Point p2 = new Point(x, y, maxPoint.getZ()); + zPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } } } + Set outlinePoints = new HashSet<>(); + yPoints.forEach(point -> { + Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ()); + Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ()); + Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1); + Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1); + + Point p5 = new Point(point.getX() - 1, point.getY(), point.getZ() - 1); + Point p6 = new Point(point.getX() - 1, point.getY(), point.getZ() + 1); + Point p7 = new Point(point.getX() + 1, point.getY(), point.getZ() - 1); + Point p8 = new Point(point.getX() + 1, point.getY(), point.getZ() + 1); + + int count = kill.get(point); + + int surrounded = 0; + if (kill.getOrDefault(p1, 0) == count) surrounded++; + if (kill.getOrDefault(p2, 0) == count) surrounded++; + if (kill.getOrDefault(p3, 0) == count) surrounded++; + if (kill.getOrDefault(p4, 0) == count) surrounded++; + if (surrounded != 4) outlinePoints.add(point); + if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point); + }); + xPoints.forEach(point -> { + Point p1 = new Point(point.getX(), point.getY() - 1, point.getZ()); + Point p2 = new Point(point.getX(), point.getY() + 1, point.getZ()); + Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1); + Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1); + + Point p5 = new Point(point.getX(), point.getY() - 1, point.getZ() - 1); + Point p6 = new Point(point.getX(), point.getY() - 1, point.getZ() + 1); + Point p7 = new Point(point.getX(), point.getY() + 1, point.getZ() - 1); + Point p8 = new Point(point.getX(), point.getY() + 1, point.getZ() + 1); + + int count = kill.get(point); + + int surrounded = 0; + if (kill.getOrDefault(p1, 0) == count) surrounded++; + if (kill.getOrDefault(p2, 0) == count) surrounded++; + if (kill.getOrDefault(p3, 0) == count) surrounded++; + if (kill.getOrDefault(p4, 0) == count) surrounded++; + if (surrounded != 4) outlinePoints.add(point); + if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point); + }); + zPoints.forEach(point -> { + Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ()); + Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ()); + Point p3 = new Point(point.getX(), point.getY() - 1, point.getZ()); + Point p4 = new Point(point.getX(), point.getY() + 1, point.getZ()); + + Point p5 = new Point(point.getX() - 1, point.getY() - 1, point.getZ()); + Point p6 = new Point(point.getX() - 1, point.getY() + 1, point.getZ()); + Point p7 = new Point(point.getX() + 1, point.getY() - 1, point.getZ()); + Point p8 = new Point(point.getX() + 1, point.getY() + 1, point.getZ()); + + int count = kill.get(point); + + int surrounded = 0; + if (kill.getOrDefault(p1, 0) == count) surrounded++; + if (kill.getOrDefault(p2, 0) == count) surrounded++; + if (kill.getOrDefault(p3, 0) == count) surrounded++; + if (kill.getOrDefault(p4, 0) == count) surrounded++; + if (surrounded != 4) outlinePoints.add(point); + if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point); + if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point); + }); + + double xPercent = zCount / (double) xArea; + double yPercent = yCount / (double) yArea; + double zPercent = xCount / (double) zArea; + percent = (xPercent + yPercent + zPercent) / 3; + kills = zKills + yKills + xKills; + for (Map.Entry entry : bossBars.entrySet()) { + updateBossBar(entry.getKey(), entry.getValue()); + } + Set pointSet = new HashSet<>(killCount.keySet()); + Set outlinePointsCacheLast = new HashSet<>(outlinePointsCache); + outlinePointsCache.clear(); for (Point point : pointSet) { if (!kill.containsKey(point)) { rEntities.get(point).die(); @@ -150,16 +269,35 @@ public class KillcheckerVisualizer { } kill.forEach((point, count) -> { if (rEntities.containsKey(point)) { - if (killCount.get(point) == count) return; + if (killCount.get(point) == count && outlinePoints.contains(point) == outlinePointsCacheLast.contains(point)) return; rEntities.get(point).die(); } - RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]); + RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]); entity.setNoGravity(true); rEntities.put(point, entity); + if (outlinePoints.contains(point)) outlinePointsCache.add(point); killCount.put(point, count); }); } + private int splitIntoDoubleKills(int kills) { + return kills * (kills - 1) / 2; + } + + private void updateBossBar(Player player, BossBar bossBar) { + bossBar.setTitle("§c§l" + kills + " §7(" + ((int) (percent * 1000) / 10.0) + "%) §e§l" + cannonCount + "§7 Kanonen"); + bossBar.setProgress(percent); + if (percent >= 0.35) { + bossBar.setColor(BarColor.RED); + } else if (percent >= 0.25) { + bossBar.setColor(BarColor.PURPLE); + } else if (percent >= 0.15) { + bossBar.setColor(BarColor.YELLOW); + } else { + bossBar.setColor(BarColor.GREEN); + } + } + private Cuboid create(Material type, int x, int y, int z) { Set checked = new HashSet<>(); Set points = new HashSet<>(); @@ -210,16 +348,33 @@ public class KillcheckerVisualizer { return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); } - public boolean show(Player player) { - rEntityServer.addPlayer(player); + public boolean show(Player player, boolean onlyOutline) { + outline.addPlayer(player); + if (!onlyOutline) { + inner.addPlayer(player); + areaPlayers.add(player); + } else if (areaPlayers.contains(player)) { + inner.removePlayer(player); + areaPlayers.remove(player); + } + bossBars.computeIfAbsent(player, player1 -> { + BossBar bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SOLID); + updateBossBar(player1, bossBar); + bossBar.addPlayer(player1); + bossBar.setVisible(true); + return bossBar; + }); return players.add(player); } public boolean hide(Player player) { - rEntityServer.removePlayer(player); + outline.removePlayer(player); + inner.removePlayer(player); players.remove(player); + areaPlayers.remove(player); + bossBars.remove(player).removePlayer(player); if (players.isEmpty()) { - rEntityServer.close(); + outline.close(); return true; } return false; From 4b3b8691b5495fe0067eb410de8024a475a4eec1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:02:32 +0100 Subject: [PATCH 044/174] Finalize everything Add Cuboid for killchecker Signed-off-by: yoyosource --- .../features/killchecker/Cuboid.java | 34 +++++++++++++++++++ .../killchecker/KillcheckerVisualizer.java | 32 ++++++++--------- 2 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java new file mode 100644 index 00000000..08632a9c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java @@ -0,0 +1,34 @@ +/* + * 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.killchecker; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Cuboid { + private double x; + private double y; + private double z; + private double dx; + private double dy; + private double dz; +} \ No newline at end of file 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 b66dff69..2edf614d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.killchecker; -import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; +import de.steamwar.bausystem.features.killchecker.Cuboid; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; @@ -43,20 +43,20 @@ import java.util.Set; public class KillcheckerVisualizer { - private static final Material[] materials = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS}; + private static final Material[] MATERIALS = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS}; private static final World WORLD = Bukkit.getWorlds().get(0); private static final double SURROUND = 4; - private Point minPoint; - private Point maxPoint; + private final Point minPoint; + private final Point maxPoint; - private int yArea; - private int zArea; - private int xArea; + private final int yArea; + private final int zArea; + private final int xArea; - private Set players = new HashSet<>(); - private Set areaPlayers = new HashSet<>(); + private final Set players = new HashSet<>(); + private final Set areaPlayers = new HashSet<>(); public KillcheckerVisualizer(Region region) { this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL); @@ -67,13 +67,13 @@ public class KillcheckerVisualizer { xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ()); } - private REntityServer outline = new REntityServer(); - private REntityServer inner = new REntityServer(); + private final REntityServer outline = new REntityServer(); + private final REntityServer inner = new REntityServer(); - private Map killCount = new HashMap<>(); - private Set outlinePointsCache = new HashSet<>(); - private Map rEntities = new HashMap<>(); - private Map bossBars = new HashMap<>(); + private final Map killCount = new HashMap<>(); + private final Set outlinePointsCache = new HashSet<>(); + private final Map rEntities = new HashMap<>(); + private final Map bossBars = new HashMap<>(); private double percent = 0; private int kills = 0; @@ -272,7 +272,7 @@ public class KillcheckerVisualizer { if (killCount.get(point) == count && outlinePoints.contains(point) == outlinePointsCacheLast.contains(point)) return; rEntities.get(point).die(); } - RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]); + RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), MATERIALS[Math.min(count - 1, MATERIALS.length) - 1]); entity.setNoGravity(true); rEntities.put(point, entity); if (outlinePoints.contains(point)) outlinePointsCache.add(point); From 3e3415e9ca3053cb44f72c1eeaaf55e2ade714c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:56:25 +0100 Subject: [PATCH 045/174] Update some visuals, still needs to be multilingualed Signed-off-by: yoyosource --- .../bausystem/features/killchecker/KillcheckerVisualizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2edf614d..3b66aae6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -285,7 +285,7 @@ public class KillcheckerVisualizer { } private void updateBossBar(Player player, BossBar bossBar) { - bossBar.setTitle("§c§l" + kills + " §7(" + ((int) (percent * 1000) / 10.0) + "%) §e§l" + cannonCount + "§7 Kanonen"); + bossBar.setTitle("§e§l" + kills + " §7(§e" + ((int) (percent * 1000) / 10.0) + "%§7) §e§l" + cannonCount + "§7 Kanonen"); bossBar.setProgress(percent); if (percent >= 0.35) { bossBar.setColor(BarColor.RED); From e7d5cee75a47b816f562a3eab9a527b028a03046 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Mar 2023 21:20:52 +0100 Subject: [PATCH 046/174] Hotfix NPE Signed-off-by: yoyosource --- .../bausystem/features/killchecker/KillcheckerVisualizer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 3b66aae6..2d876ebe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -369,7 +369,9 @@ public class KillcheckerVisualizer { public boolean hide(Player player) { outline.removePlayer(player); - inner.removePlayer(player); + if (areaPlayers.contains(player)) { + inner.removePlayer(player); + } players.remove(player); areaPlayers.remove(player); bossBars.remove(player).removePlayer(player); From 519c832c9dcbd3066f42b5e6525561a8a2306147 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 17:04:22 +0100 Subject: [PATCH 047/174] Hotfix NMSWrapper19 --- .../src/de/steamwar/bausystem/utils/NMSWrapper19.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 24edeb9a..d6c7df29 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -28,6 +28,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.network.syncher.DataWatcher; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; @@ -44,7 +45,6 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.LongSupplier; public class NMSWrapper19 implements NMSWrapper { @@ -91,7 +91,9 @@ public class NMSWrapper19 implements NMSWrapper { if (entity instanceof TNTPrimed) { net.minecraft.world.entity.Entity serverEntity = ((CraftEntity) entity).getHandle(); - packets.add(new PacketPlayOutEntityMetadata(serverEntity.ah(), Objects.requireNonNull(serverEntity.al().c()))); + List> list = serverEntity.al().c(); + if(list != null) + packets.add(new PacketPlayOutEntityMetadata(serverEntity.ah(), list)); } }); } From 69b31483f49edac7246e41977f7221b32922a70a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 12 Mar 2023 21:04:56 +0100 Subject: [PATCH 048/174] Fix -builddestroyonly Trace option Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/region/TNTListener.java | 3 ++- .../bausystem/features/tracer/record/Recorder.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 6bb5b15b..958471e2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -35,6 +35,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent; @@ -83,7 +84,7 @@ public class TNTListener implements Listener { explode(event.blockList(), event.getBlock().getLocation(), null, null); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 2d74492d..fe941f5f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -32,6 +32,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; @@ -180,7 +181,7 @@ public class Recorder implements Listener { }); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed)) { @@ -188,7 +189,9 @@ public class Recorder implements Listener { } TraceRecorder traceRecorder = get((TNTPrimed) entity); Region region = tntTraceRecorderMap.get((TNTPrimed) entity); - traceRecorder.explode((TNTPrimed) entity, !event.blockList().isEmpty() && region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); + boolean inBuildRegion = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); + System.out.println(event.blockList() + " " + inBuildRegion); + traceRecorder.explode((TNTPrimed) entity, inBuildRegion); tntTraceRecorderMap.remove(entity); tick(); } From 8e133f08328eac647a96cb76297fc73390f80ffd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Mar 2023 20:58:53 +0100 Subject: [PATCH 049/174] Probable fix for SelfJoin Event Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/script/ScriptListener.java | 2 +- .../bausystem/features/script/custom/event/EventListener.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index fbdbf0f2..ef9abe06 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -47,7 +47,7 @@ public class ScriptListener implements Listener { new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { GLOBAL_CONTEXT.put(event.getPlayer(), new Context()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java index f8913e28..4ee1a97d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java @@ -30,6 +30,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; @@ -58,7 +59,7 @@ public class EventListener implements Listener { }, 2, 2); } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { manager.callEvent(EventType.SelfJoin, event.getPlayer(), event); } From ca338699faee167e78b94b249f641d1d3a6d0784 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Mar 2023 18:23:52 +0100 Subject: [PATCH 050/174] Hotfix If Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/script/command/If.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index e2a2ac44..47d92f25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -46,7 +46,7 @@ public class If implements SpecialCommand { BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_NO_BOOLEAN", scriptExecutor.getPlayer()); return false; } - if (v.asBoolean()) { + if (v.asBoolean() && command.length > 2) { jumpToIndex(scriptExecutor, command[2]); } else if (command.length > 3) { jumpToIndex(scriptExecutor, command[3]); From b75d7c278aee73c532a45eb6cb5012b8312f2c95 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:09:13 +0100 Subject: [PATCH 051/174] Finalize Killchecker and include BauSystem Bossbar API for better Bossbar usage Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../killchecker/KillcheckerCommand.java | 7 +- .../killchecker/KillcheckerVisualizer.java | 43 +++--- .../utils/bossbar/BauSystemBossbar.java | 51 ++++++ .../utils/bossbar/BossBarService.java | 90 +++++++++++ .../utils/bossbar/GlobalBossbar.java | 112 ++++++++++++++ .../utils/bossbar/RegionedBossbar.java | 146 ++++++++++++++++++ 8 files changed, 429 insertions(+), 22 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 8d03d0ca..4ad71e2f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -657,6 +657,7 @@ KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Disables Killcheck KILLCHECKER_INFO = §7Shows the overlaps of cannon kills in your build area. KILLCHECKER_ENABLE = §aKillchecker activated KILLCHECKER_DISABLE = §cKillchecker deactivated +KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index f49f1fc6..89c05696 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -630,6 +630,7 @@ KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Deaktiviert Killch KILLCHECKER_INFO = §7Zeigt Überlappungen der Kanonen Kills im Baubereich an. KILLCHECKER_ENABLE = §aKillchecker aktiviert KILLCHECKER_DISABLE = §cKillchecker deaktiviert +KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 6a0fe5b9..7148b0f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -21,8 +21,10 @@ package de.steamwar.bausystem.features.killchecker; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -42,6 +44,9 @@ public class KillcheckerCommand extends SWCommand implements Listener { private Map visualizers = new HashMap<>(); + @LinkedInstance + public BossBarService bossBarService; + public KillcheckerCommand() { super("killchecker"); addDefaultHelpMessage("KILLCHECKER_INFO"); @@ -50,7 +55,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") public void genericCommand(Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) { Region region = Region.getRegion(player.getLocation()); - KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, KillcheckerVisualizer::new); + KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, region1 -> new KillcheckerVisualizer(region1, bossBarService)); killcheckerVisualizer.recalc(); killcheckerVisualizer.show(player, onlyOutline); BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); 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 2d876ebe..161a44b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -19,11 +19,13 @@ package de.steamwar.bausystem.features.killchecker; -import de.steamwar.bausystem.features.killchecker.Cuboid; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; @@ -58,13 +60,19 @@ public class KillcheckerVisualizer { private final Set players = new HashSet<>(); private final Set areaPlayers = new HashSet<>(); - public KillcheckerVisualizer(Region region) { + private final Region region; + private final BossBarService bossBarService; + + public KillcheckerVisualizer(Region region, BossBarService bossBarService) { + this.region = region; this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL); this.maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL); yArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getZ() - minPoint.getZ()); zArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getY() - minPoint.getY()); xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ()); + + this.bossBarService = bossBarService; } private final REntityServer outline = new REntityServer(); @@ -73,7 +81,6 @@ public class KillcheckerVisualizer { private final Map killCount = new HashMap<>(); private final Set outlinePointsCache = new HashSet<>(); private final Map rEntities = new HashMap<>(); - private final Map bossBars = new HashMap<>(); private double percent = 0; private int kills = 0; @@ -253,9 +260,7 @@ public class KillcheckerVisualizer { double zPercent = xCount / (double) zArea; percent = (xPercent + yPercent + zPercent) / 3; kills = zKills + yKills + xKills; - for (Map.Entry entry : bossBars.entrySet()) { - updateBossBar(entry.getKey(), entry.getValue()); - } + players.forEach(this::updateBossBar); Set pointSet = new HashSet<>(killCount.keySet()); Set outlinePointsCacheLast = new HashSet<>(outlinePointsCache); @@ -284,17 +289,19 @@ public class KillcheckerVisualizer { return kills * (kills - 1) / 2; } - private void updateBossBar(Player player, BossBar bossBar) { - bossBar.setTitle("§e§l" + kills + " §7(§e" + ((int) (percent * 1000) / 10.0) + "%§7) §e§l" + cannonCount + "§7 Kanonen"); - bossBar.setProgress(percent); + private void updateBossBar(Player player) { + BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker"); + bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount)); + bossbar.setProgress(percent); + if (percent >= 0.35) { - bossBar.setColor(BarColor.RED); + bossbar.setColor(BarColor.RED); } else if (percent >= 0.25) { - bossBar.setColor(BarColor.PURPLE); + bossbar.setColor(BarColor.PURPLE); } else if (percent >= 0.15) { - bossBar.setColor(BarColor.YELLOW); + bossbar.setColor(BarColor.YELLOW); } else { - bossBar.setColor(BarColor.GREEN); + bossbar.setColor(BarColor.GREEN); } } @@ -357,13 +364,7 @@ public class KillcheckerVisualizer { inner.removePlayer(player); areaPlayers.remove(player); } - bossBars.computeIfAbsent(player, player1 -> { - BossBar bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SOLID); - updateBossBar(player1, bossBar); - bossBar.addPlayer(player1); - bossBar.setVisible(true); - return bossBar; - }); + updateBossBar(player); return players.add(player); } @@ -374,7 +375,7 @@ public class KillcheckerVisualizer { } players.remove(player); areaPlayers.remove(player); - bossBars.remove(player).removePlayer(player); + bossBarService.remove(player, region, "killchecker"); if (players.isEmpty()) { outline.close(); return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java new file mode 100644 index 00000000..e72e0b53 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java @@ -0,0 +1,51 @@ +/* + * 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.utils.bossbar; + +import de.steamwar.bausystem.region.Region; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; + +public interface BauSystemBossbar { + + String getTitle(); + void setTitle(String title); + + double getProgress(); + void setProgress(double progress); + + BarColor getColor(); + void setColor(BarColor color); + + BarStyle getStyle(); + void setStyle(BarStyle style); + + boolean hasFlag(BarFlag flag); + void addFlag(BarFlag flag); + void removeFlag(BarFlag flag); + + boolean isVisible(); + void setVisible(boolean visible); + + Region getRegion(); + + void cleanup(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java new file mode 100644 index 00000000..6c7d636d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java @@ -0,0 +1,90 @@ +/* + * 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.utils.bossbar; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class BossBarService implements Listener { + + private final Map>> playerBossBars = new HashMap<>(); + + public synchronized BauSystemBossbar get(Player player, Region region, String key) { + return playerBossBars.computeIfAbsent(player, p -> new HashMap<>()) + .computeIfAbsent(region, r -> new HashMap<>()) + .computeIfAbsent(key, k -> { + BossBar bossBar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID); + bossBar.addPlayer(player); + if (region.isGlobal()) { + return new GlobalBossbar(bossBar); + } else { + return new RegionedBossbar(bossBar, region, player); + } + }); + } + + public synchronized void removeAll(Player player, String key) { + Map> regionMap = playerBossBars.get(player); + if (regionMap == null) return; + for (Map bossBarMap : regionMap.values()) { + BauSystemBossbar bossBar = bossBarMap.remove(key); + if (bossBar == null) continue; + bossBar.cleanup(); + } + } + + public synchronized void removeAll(Player player) { + Map> regionMap = playerBossBars.remove(player); + if (regionMap == null) return; + for (Map bossBarMap : regionMap.values()) { + for (BauSystemBossbar bossBar : bossBarMap.values()) { + bossBar.cleanup(); + } + } + } + + public synchronized void remove(Player player, Region region, String key) { + Map> regionMap = playerBossBars.get(player); + if (regionMap == null) return; + Map bossBarMap = regionMap.get(region); + if (bossBarMap == null) return; + BauSystemBossbar bossBar = bossBarMap.remove(key); + if (bossBar == null) return; + bossBar.cleanup(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + removeAll(event.getPlayer()); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java new file mode 100644 index 00000000..a5aaf9fe --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java @@ -0,0 +1,112 @@ +/* + * 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.utils.bossbar; + +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; + +public class GlobalBossbar implements BauSystemBossbar { + + private BossBar bossBar; + + public GlobalBossbar(BossBar bossBar) { + this.bossBar = bossBar; + } + + @Override + public String getTitle() { + return bossBar.getTitle(); + } + + @Override + public void setTitle(String title) { + bossBar.setTitle(title); + } + + @Override + public double getProgress() { + return bossBar.getProgress(); + } + + @Override + public void setProgress(double progress) { + bossBar.setProgress(progress); + } + + @Override + public BarColor getColor() { + return bossBar.getColor(); + } + + @Override + public void setColor(BarColor color) { + bossBar.setColor(color); + } + + @Override + public BarStyle getStyle() { + return bossBar.getStyle(); + } + + @Override + public void setStyle(BarStyle style) { + bossBar.setStyle(style); + } + + @Override + public boolean hasFlag(BarFlag flag) { + return bossBar.hasFlag(flag); + } + + @Override + public void addFlag(BarFlag flag) { + bossBar.addFlag(flag); + } + + @Override + public void removeFlag(BarFlag flag) { + bossBar.removeFlag(flag); + } + + @Override + public boolean isVisible() { + return bossBar.isVisible(); + } + + @Override + public void setVisible(boolean visible) { + bossBar.setVisible(visible); + } + + @Override + public Region getRegion() { + return GlobalRegion.getInstance(); + } + + @Override + public void cleanup() { + bossBar.removeAll(); + bossBar = null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java new file mode 100644 index 00000000..4d922143 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java @@ -0,0 +1,146 @@ +/* + * 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.utils.bossbar; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class RegionedBossbar implements BauSystemBossbar, Listener { + + private BossBar bossBar; + private Region region; + private Player player; + + public RegionedBossbar(BossBar bossBar, Region region, Player player) { + this.bossBar = bossBar; + this.region = region; + this.player = player; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + @Override + public String getTitle() { + return bossBar.getTitle(); + } + + @Override + public void setTitle(String title) { + bossBar.setTitle(title); + } + + @Override + public double getProgress() { + return bossBar.getProgress(); + } + + @Override + public void setProgress(double progress) { + bossBar.setProgress(progress); + } + + @Override + public BarColor getColor() { + return bossBar.getColor(); + } + + @Override + public void setColor(BarColor color) { + bossBar.setColor(color); + } + + @Override + public BarStyle getStyle() { + return bossBar.getStyle(); + } + + @Override + public void setStyle(BarStyle style) { + bossBar.setStyle(style); + } + + @Override + public boolean hasFlag(BarFlag flag) { + return bossBar.hasFlag(flag); + } + + @Override + public void addFlag(BarFlag flag) { + bossBar.addFlag(flag); + } + + @Override + public void removeFlag(BarFlag flag) { + bossBar.removeFlag(flag); + } + + @Override + public boolean isVisible() { + return bossBar.isVisible(); + } + + @Override + public void setVisible(boolean visible) { + bossBar.setVisible(visible); + } + + @Override + public Region getRegion() { + return region; + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer() != player) return; + if (region.inRegion(event.getTo(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { + bossBar.addPlayer(player); + } else { + bossBar.removePlayer(player); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer() != player) return; + cleanup(); + } + + @Override + public void cleanup() { + bossBar.removeAll(); + bossBar = null; + region = null; + player = null; + + PlayerMoveEvent.getHandlerList().unregister(this); + PlayerQuitEvent.getHandlerList().unregister(this); + } +} From b902fffb7669aa0a47df11027eac1a2df4e0d41f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:36:36 +0100 Subject: [PATCH 052/174] Move visualization outside of build area Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerVisualizer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 161a44b2..d83f4b64 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -126,7 +126,7 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { yCount++; yKills += splitIntoDoubleKills(cuboidSet.size()); - Point p2 = new Point(x, maxPoint.getY(), z); + Point p2 = new Point(x, maxPoint.getY() + 1, z); yPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } @@ -147,10 +147,10 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { xCount++; xKills += splitIntoDoubleKills(cuboidSet.size()); - Point p1 = new Point(minPoint.getX(), y, z); + Point p1 = new Point(minPoint.getX() - 1, y, z); xPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); - Point p2 = new Point(maxPoint.getX(), y, z); + Point p2 = new Point(maxPoint.getX() + 1, y, z); xPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } @@ -171,10 +171,10 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { zCount++; zKills += splitIntoDoubleKills(cuboidSet.size()); - Point p1 = new Point(x, y, minPoint.getZ()); + Point p1 = new Point(x, y, minPoint.getZ() - 1); zPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); - Point p2 = new Point(x, y, maxPoint.getZ()); + Point p2 = new Point(x, y, maxPoint.getZ() + 1); zPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } From ca730f7b8fd411d3b4fff8d46df68bceb8562ad2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 20:59:34 +0100 Subject: [PATCH 053/174] Fix NPE of KillcheckerVisualizer.hide Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerCommand.java | 2 +- .../killchecker/KillcheckerVisualizer.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 7148b0f9..74fc72c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -78,7 +78,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { Player player = event.getPlayer(); Set regions = new HashSet<>(); visualizers.forEach((region, visualizer) -> { - if (visualizer.hide(player)) { + if (visualizer.disconnect(player)) { regions.add(region); } }); 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 d83f4b64..ff21d13b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -97,6 +97,7 @@ public class KillcheckerVisualizer { if (block.getType().isAir()) continue; String name = block.getType().name(); if (!name.endsWith("_WOOL") && !name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue; + if (name.equals("_GLAZED_TERRACOTTA")) continue; Cuboid cuboid = create(block.getType(), x, y, z); cuboids.add(cuboid); for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { @@ -378,6 +379,19 @@ public class KillcheckerVisualizer { bossBarService.remove(player, region, "killchecker"); if (players.isEmpty()) { outline.close(); + inner.close(); + return true; + } + return false; + } + + public boolean disconnect(Player player) { + players.remove(player); + areaPlayers.remove(player); + bossBarService.remove(player, region, "killchecker"); + if (players.isEmpty()) { + outline.close(); + inner.close(); return true; } return false; From 0061bf77073ff418665fdefc4f09ba058c713ae0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 21:05:33 +0100 Subject: [PATCH 054/174] Add another help message Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../bausystem/features/killchecker/KillcheckerCommand.java | 1 + 3 files changed, 3 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4ad71e2f..695fe723 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -655,6 +655,7 @@ INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Enables Killchecker / Recalculates kills KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Disables Killchecker KILLCHECKER_INFO = §7Shows the overlaps of cannon kills in your build area. +KILLCHECKER_INFO2 = §7Only colorable blocks like Wool, Terractotta, Stained Glass and Concrete are counted. KILLCHECKER_ENABLE = §aKillchecker activated KILLCHECKER_DISABLE = §cKillchecker deactivated KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 89c05696..6dd8044b 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -628,6 +628,7 @@ INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Aktiviert Killchecker / Berechnet kills neu KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Deaktiviert Killchecker KILLCHECKER_INFO = §7Zeigt Überlappungen der Kanonen Kills im Baubereich an. +KILLCHECKER_INFO2 = §7Nur farbige Blöcke wie Wolle, Terracotta, Stained Glass und Concrete wird gezählt. KILLCHECKER_ENABLE = §aKillchecker aktiviert KILLCHECKER_DISABLE = §cKillchecker deaktiviert KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 74fc72c3..1340f1c1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -50,6 +50,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { public KillcheckerCommand() { super("killchecker"); addDefaultHelpMessage("KILLCHECKER_INFO"); + addDefaultHelpMessage("KILLCHECKER_INFO2"); } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") From fa906f7f4f11b78779831b34b765d2e6adce5c7a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:11:09 +0100 Subject: [PATCH 055/174] Hotfix Xray Signed-off-by: yoyosource --- .../utils/PlayerMovementWrapper19.java | 32 +++++++++++++++++++ .../bausystem/features/xray/XrayCommand.java | 1 + .../utils/PlayerMovementWrapper.java | 2 ++ 3 files changed, 35 insertions(+) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index fd9a892e..a3531e5e 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -21,19 +21,51 @@ package de.steamwar.bausystem.utils; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; +import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + public class PlayerMovementWrapper19 implements PlayerMovementWrapper { + private static class Position { + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + } + + private Map playerLocationMap = new HashMap<>(); + @Override public void setPosition(Player player, Object object) { + Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> new Position()); PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object); EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); if (packetPlayInFlying.h) { entityPlayer.b(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c, packetPlayInFlying.d, packetPlayInFlying.e); + position.x = packetPlayInFlying.a; + position.y = packetPlayInFlying.b; + position.z = packetPlayInFlying.c; + position.yaw = packetPlayInFlying.d; + position.pitch = packetPlayInFlying.e; } else { entityPlayer.e(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c); + position.x = packetPlayInFlying.a; + position.y = packetPlayInFlying.b; + position.z = packetPlayInFlying.c; + } + } + + @Override + public void disable(Player player) { + Position position = playerLocationMap.remove(player.getUniqueId()); + if (position != null) { + player.teleport(new Location(player.getWorld(), position.x, position.y, position.z, position.yaw, position.pitch)); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 22c19b67..f1232760 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -97,6 +97,7 @@ public class XrayCommand extends SWCommand implements Listener { techHiderCommand.disable(region, player); if (hidden.get(region).contains(player)) { hidden.get(region).remove(player); + PlayerMovementWrapper.impl.disable(player); BauSystem.MESSAGE.sendPrefixless("XRAY_OFF", player, ChatMessageType.ACTION_BAR); } else { hidden.get(region).add(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java index f8aa209d..4a6a6447 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java @@ -27,4 +27,6 @@ public interface PlayerMovementWrapper { PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); void setPosition(Player player, Object object); + default void disable(Player player) { + } } From d6c9e8f827eb32569c95e4c606b199adf21294c4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:14:08 +0100 Subject: [PATCH 056/174] Hotfix Xray Signed-off-by: yoyosource --- .../bausystem/utils/PlayerMovementWrapper19.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index a3531e5e..afc51ded 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -43,7 +43,16 @@ public class PlayerMovementWrapper19 implements PlayerMovementWrapper { @Override public void setPosition(Player player, Object object) { - Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> new Position()); + Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> { + Position pos = new Position(); + Location location = player.getLocation(); + pos.x = location.getX(); + pos.y = location.getY(); + pos.z = location.getZ(); + pos.yaw = location.getYaw(); + pos.pitch = location.getPitch(); + return pos; + }); PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object); EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); if (packetPlayInFlying.h) { From e2a2344c890e538fd6c27aeee0c228c5bf0f8b2d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:19:28 +0100 Subject: [PATCH 057/174] Add DragonEggCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + BauSystem_Main/src/BauSystem_de.properties | 2 + .../features/util/DragonEggCommand.java | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 695fe723..892091c3 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -920,6 +920,8 @@ SKULL_GUI_ITEM_NAME = §ePlayer Heads ANVIL_INV_NAME=Player name # StructureVoid STRUCTURE_VOID_COMMAND_HELP=§8/§estructureVoid §8-§7 Receive a StructureVoid +# Dragon Egg +DRAGON_EGG_COMMAND_HELP=§8/§edragonegg §8-§7 Receive a Dragon Egg # NightVision NIGHT_VISION_HELP=§8/§enightvision §8-§7 Toggel nightvision. NIGHT_VISION_OFF=§eNightvision deactivated diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 6dd8044b..d08d7d41 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -891,6 +891,8 @@ SKULL_GUI_ITEM_NAME = §eSpieler Köpfe ANVIL_INV_NAME=Spieler name # StructureVoid STRUCTURE_VOID_COMMAND_HELP=§8/§estructureVoid §8-§7 Erhalte ein StructureVoid +# Dragon Egg +DRAGON_EGG_COMMAND_HELP=§8/§edragonegg §8-§7 Erhalte ein Drachenei # NightVision NIGHT_VISION_HELP=§8/§enightvision §8-§7 Schalte Nightvision an oder aus. NIGHT_VISION_OFF=§eNightvision deaktiviert diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java new file mode 100644 index 00000000..b9cc7442 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java @@ -0,0 +1,40 @@ +/* + * 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.util; + +import de.steamwar.bausystem.SWUtils; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +@Linked +public class DragonEggCommand extends SWCommand { + + public DragonEggCommand() { + super("dragonegg", "enderdragon", "dragon", "egg", "enderei", "ender"); + } + + @Register(description = "DRAGON_EGG_COMMAND_HELP") + public void genericCommand(Player p) { + SWUtils.giveItemToPlayer(p, new ItemStack(Material.DRAGON_EGG, 1)); + } +} From 66b601bbfd0172f43480d674419eb9809820a9b7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:22:43 +0100 Subject: [PATCH 058/174] Fix SIOOBE for Substring Signed-off-by: yoyosource --- .../bausystem/features/script/command/string/Substring.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java index 74202855..8624cae1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java @@ -80,7 +80,7 @@ public class Substring implements SpecialCommand { } else { result = new Value.StringValue(v1.asString().substring((int) v2.asLong())); } - } catch (ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException e) { result = new Value.StringValue(""); } scriptExecutor.getLocalVariables().putValue(resultName, result); From 36532ccd5dad67b1af3afe43e56d1d257658969b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:24:42 +0100 Subject: [PATCH 059/174] Fix divide by Zero Signed-off-by: yoyosource --- .../script/expression/operator/math/DivideOperator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java index 679c69de..a4ab1c8c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java @@ -41,6 +41,9 @@ public class DivideOperator implements Operator { if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR"); } + if (value2.asDouble() == 0) { + return new Value.DoubleValue(Double.NaN); + } return new Value.DoubleValue(value.asDouble() / value2.asDouble()); } } From 3f4f237d63e6ddd2f75d3c22ed34a75c01d3fe21 Mon Sep 17 00:00:00 2001 From: PsiRobot Date: Thu, 23 Mar 2023 22:27:51 +0000 Subject: [PATCH 060/174] Fixed Issue #110 Loader bugt bei Strings --- .../de/steamwar/bausystem/features/loader/Loader.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 8c12f2de..1a64a8af 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -38,6 +38,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.scheduler.BukkitTask; import java.util.*; @@ -201,8 +202,18 @@ public class Loader implements Listener { if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; + if (event.getClickedBlock().getType() == Material.OBSERVER) return; + + if (event.getHand() == EquipmentSlot.OFF_HAND) { + return; + } + + if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { + return; + } + LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); if (button != LoaderButton.INVALID) { actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this)); From b8a27294fce996108dccdf4364b4a281a0d1121c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 4 Apr 2023 18:33:36 +0200 Subject: [PATCH 061/174] Possibly fix ScriptExecutor Signed-off-by: yoyosource --- .../features/script/ScriptExecutor.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 785c042b..25b29147 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -191,30 +191,6 @@ public final class ScriptExecutor { private String[] replaceExpressions(String s) { s = s.replaceAll(" +", " "); - // TODO: Remove this code as the Expression System below will replace it! - Set variables = new HashSet<>(localVariables.allVariables()); - variables.addAll(Constants.allVariables()); - variables.addAll(globalVariables.allVariables()); - - for (int i = 0; i < 3; i++) { - for (String variable : variables) { - s = s.replace("<" + variable + ">", getValue(variable)); - s = s.replace("<" + variable + ".type>", getOrItselfValue(variable).type()); - } - for (String constVariable : Constants.allVariables()) { - s = s.replace("", getConstant(constVariable)); - s = s.replace("", Constants.getConstant(constVariable, player).type()); - } - for (String localVariable : localVariables.allVariables()) { - s = s.replace("", getLocal(localVariable)); - s = s.replace("", getLocalVariables().getValue(localVariable).type()); - } - for (String globalVariable : globalVariables.allVariables()) { - s = s.replace("", getGlobal(globalVariable)); - s = s.replace("", globalVariables.getValue(globalVariable).type()); - } - } - StringBuilder result = new StringBuilder(); int depth = 0; StringBuilder st = new StringBuilder(); From cfd625c6f097fedaef90fc9750eef07e9ae81a0a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 Apr 2023 19:52:56 +0200 Subject: [PATCH 062/174] Remove sout Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tracer/record/Recorder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index fe941f5f..8b3fcea0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -190,7 +190,6 @@ public class Recorder implements Listener { TraceRecorder traceRecorder = get((TNTPrimed) entity); Region region = tntTraceRecorderMap.get((TNTPrimed) entity); boolean inBuildRegion = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); - System.out.println(event.blockList() + " " + inBuildRegion); traceRecorder.explode((TNTPrimed) entity, inBuildRegion); tntTraceRecorderMap.remove(entity); tick(); From e60ae56b67e1c6522192816afdf51ec45d5fee1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 Apr 2023 18:43:59 +0200 Subject: [PATCH 063/174] Fix TPSLimit 0 Signed-off-by: yoyosource --- .../features/tpslimit/FreezeUtils.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index b9a24ad1..c3c12fa9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -20,13 +20,27 @@ package de.steamwar.bausystem.features.tpslimit; import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.ChatWrapper; import lombok.Getter; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import yapion.utils.ReflectionsUtils; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; @UtilityClass public class FreezeUtils { @@ -64,10 +78,84 @@ public class FreezeUtils { if (freezeEnabled) { try { field.set(getWorldHandle.invoke(world), state); + cacheEntityPackets(state); frozen = state; } catch (IllegalAccessException e) { // Ignored; } } } + + private List packets = new ArrayList<>(); + private Set entities = new HashSet<>(); + private BukkitTask task = null; + + private Class vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); + private Reflection.FieldAccessor zeroVec3d = (Reflection.FieldAccessor) Reflection.getField(vec3dClass, vec3dClass, 0); + private Object ZERO_VEC3D = zeroVec3d.get(null); + private Class velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); + private Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); + + private Class teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); + private Class entityClass = Reflection.getClass("{nms.world.entity}.Entity"); + private Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); + + private Class craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); + private Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); + + private Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); + private Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); + + private void cacheEntityPackets(boolean state) { + if (state) { + createPackets(); + + if (task == null) { + task = new BukkitRunnable() { + @Override + public void run() { + createPackets(); + + for (Player player : Bukkit.getOnlinePlayers()) { + for (Object packet : packets) { + TinyProtocol.instance.sendPacket(player, packet); + } + } + } + }.runTaskTimer(BauSystem.getInstance(), 1, 1); + } + } else { + packets.clear(); + entities.clear(); + + if (task != null) { + task.cancel(); + task = null; + } + } + } + + private void createPackets() { + List entities = Bukkit.getWorlds().get(0).getEntities().stream() + .filter(e -> !(e instanceof Player)) + .filter(e -> !FreezeUtils.entities.contains(e)) + .collect(Collectors.toList()); + + for (Entity entity : entities) { + packets.add(teleportPacketConstructor.invoke(getHandle.invoke(entity))); + } + for (Entity entity : entities) { + packets.add(velocityPacketConstructor.invoke(entity.getEntityId(), ZERO_VEC3D)); + } + for (Entity entity : entities) { + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), noGravityDataWatcher, true)); + } + for (Entity entity : entities) { + if (!(entity instanceof TNTPrimed)) continue; + TNTPrimed tnt = (TNTPrimed) entity; + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, tnt.getFuseTicks())); + } + + FreezeUtils.entities.addAll(entities); + } } From 3c1275393fd4644e532bb7efbf8faf3eb81af41a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 Apr 2023 18:45:00 +0200 Subject: [PATCH 064/174] Hotfix Memory Leak Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/FreezeUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index c3c12fa9..bdb00e1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -136,6 +136,10 @@ public class FreezeUtils { } private void createPackets() { + if (FreezeUtils.entities.stream().anyMatch(Entity::isDead)) { + entities.clear(); + packets.clear(); + } List entities = Bukkit.getWorlds().get(0).getEntities().stream() .filter(e -> !(e instanceof Player)) .filter(e -> !FreezeUtils.entities.contains(e)) From 3f5f4d7b80c26d71d19b2df3374fd3874b835505 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 11:26:09 +0200 Subject: [PATCH 065/174] Remove tnt flicker Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/FreezeUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index bdb00e1a..294cffd0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -157,7 +157,8 @@ public class FreezeUtils { for (Entity entity : entities) { if (!(entity instanceof TNTPrimed)) continue; TNTPrimed tnt = (TNTPrimed) entity; - packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, tnt.getFuseTicks())); + int fuse = tnt.getFuseTicks(); + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, fuse - (fuse % 5) + 1)); } FreezeUtils.entities.addAll(entities); From e9d7c8211f78d9898cb9bc04dee8ee6b3596aa91 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 12:11:43 +0200 Subject: [PATCH 066/174] Add ShieldPrinting Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 ++ BauSystem_Main/src/BauSystem_de.properties | 10 ++ .../shieldprinting/ShieldPrinting.java | 101 ++++++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 110 ++++++++++++++++++ .../shieldprinting/ShieldPrintingState.java | 27 +++++ 5 files changed, 258 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 892091c3..27f1c19d 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -509,6 +509,16 @@ SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server +# Shield Printing +SHIELD_PRINTING_NO_REGION = §cYou are not in a region. +SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. +SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. + +SHIELD_PRINTING_START = §aThe shield printing has been started. +SHIELD_PRINTING_COPY = §aThe shield has been copied. +SHIELD_PRINTING_APPLY = §aThe shield has been applied. +SHIELD_PRINTING_STOP = §aThe shield printing has been stopped. + # Unsign Book UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index d08d7d41..a1461a99 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -502,6 +502,16 @@ SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server +# Shield Printing +SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. +SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. +SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. + +SHIELD_PRINTING_START = §aShield printing wurde gestartet. +SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. +SHIELD_PRINTING_APPLY = §aSchilde wurden angewendet. +SHIELD_PRINTING_STOP = §aShield printing wurde gestoppt. + # Unsign Book UNSIGN_HELP=§8/§eunsign §8- §7Mache ein Buch beschreibbar diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java new file mode 100644 index 00000000..9cf829b5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -0,0 +1,101 @@ +/* + * 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.shieldprinting; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.util.Vector; + +import java.util.*; + +public class ShieldPrinting implements Listener { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + /** + * Vector of current position, Vector of origin + */ + private Map shieldMap = new HashMap<>(); + private Map shieldData = new HashMap<>(); + + private final Region region; + + public ShieldPrinting(Region region) { + this.region = region; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + public void copy() { + for (Map.Entry entry : shieldMap.entrySet()) { + shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData()); + } + } + + public void apply() { + for (Map.Entry entry : shieldData.entrySet()) { + entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue()); + } + } + + public void disable() { + BlockPistonExtendEvent.getHandlerList().unregister(this); + BlockPistonRetractEvent.getHandlerList().unregister(this); + shieldMap.clear(); + shieldData.clear(); + } + + @EventHandler + public void onBlockPistonExtend(BlockPistonExtendEvent event) { + update(event.getDirection(), event.getBlocks()); + } + + @EventHandler + public void onBlockPistonRetract(BlockPistonRetractEvent event) { + update(event.getDirection(), event.getBlocks()); + } + + private void update(BlockFace direction, List blockList) { + Set toRemove = new HashSet<>(); + Map temp = new HashMap<>(); + for (Block block : blockList) { + if (Region.getRegion(block.getLocation()) != region) continue; + Vector vector = block.getLocation().toVector(); + Vector origin = vector.clone(); + vector = vector.add(direction.getDirection()); + if (shieldMap.containsKey(origin)) { + toRemove.add(origin); + temp.put(vector, shieldMap.get(origin)); + } else { + temp.put(vector, origin); + } + } + shieldMap.keySet().removeAll(toRemove); + shieldMap.putAll(temp); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java new file mode 100644 index 00000000..a789c748 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -0,0 +1,110 @@ +/* + * 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.shieldprinting; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.Region; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class ShieldPrintingCommand extends SWCommand { + + public ShieldPrintingCommand() { + super("shieldprinting"); + } + + private Map shieldMap = new HashMap<>(); + + @Register + public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + // BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + return; + } + ShieldPrinting shieldPrinting; + switch (shieldPrintingState) { + case START: + shieldPrinting = shieldMap.put(region, new ShieldPrinting(region)); + if (shieldPrinting != null) { + shieldPrinting.disable(); + } + BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player); + break; + case COPY: + shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.copy(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player); + break; + case APPLY: + shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.apply(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_APPLY", player); + break; + } + } + + @Register("stop") + public void stopCommand(@Validator Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + return; + } + ShieldPrinting shieldPrinting = shieldMap.remove(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.disable(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_STOP", player); + } + + @ClassValidator(value = Player.class, local = true) + public TypeValidator validator() { + return (commandSender, player, messageSender) -> { + if (!Permission.hasPermission(player, Permission.WORLD)) { + messageSender.send("SHIELD_PRINTING_DISALLOWED", player); + return false; + } + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + messageSender.send("SHIELD_PRINTING_NO_REGION", player); + return false; + } + return true; + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java new file mode 100644 index 00000000..0f782f67 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java @@ -0,0 +1,27 @@ +/* + * 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.shieldprinting; + +public enum ShieldPrintingState { + + START, + COPY, + APPLY +} From 48b2a87c96edabf4ee721ba18087c8ea47adc4a8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:53:58 +0200 Subject: [PATCH 067/174] Fix ShieldPrinting Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + BauSystem_Main/src/BauSystem_de.properties | 2 + .../shieldprinting/ShieldPrinting.java | 46 ++++++++++++++++++- .../shieldprinting/ShieldPrintingCommand.java | 23 +++++++++- .../utils/bossbar/BossBarService.java | 6 +++ 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 27f1c19d..a3860e34 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -513,6 +513,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. +SHIELD_PRINTING_BOSSBAR = §fMovements: {0} +SHIELD_PRINTING_BOSSBAR_COPIED = §fMovements: {0} Copied: {1} SHIELD_PRINTING_START = §aThe shield printing has been started. SHIELD_PRINTING_COPY = §aThe shield has been copied. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a1461a99..9689be29 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -506,6 +506,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. +SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0} +SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1} SHIELD_PRINTING_START = §aShield printing wurde gestartet. SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 9cf829b5..3ddefdc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -21,15 +21,24 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; +import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; +import org.bukkit.boss.BarColor; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; import java.util.*; @@ -49,12 +58,14 @@ public class ShieldPrinting implements Listener { public ShieldPrinting(Region region) { this.region = region; Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + updateBossbars(); } public void copy() { for (Map.Entry entry : shieldMap.entrySet()) { shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData()); } + updateBossbars(); } public void apply() { @@ -64,10 +75,13 @@ public class ShieldPrinting implements Listener { } public void disable() { - BlockPistonExtendEvent.getHandlerList().unregister(this); - BlockPistonRetractEvent.getHandlerList().unregister(this); + HandlerList.unregisterAll(this); shieldMap.clear(); shieldData.clear(); + + for (Player player : Bukkit.getOnlinePlayers()) { + BossBarService.instance.remove(player, region, "shieldprinting"); + } } @EventHandler @@ -97,5 +111,33 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + updateBossbars(); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) return; + if (event.getItem() == null) return; + if (Region.getRegion(event.getClickedBlock().getLocation()) != region) return; + Vector vector = event.getClickedBlock().getLocation().toVector(); + if (!shieldMap.containsKey(vector)) return; + event.getClickedBlock().setType(Material.AIR); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + updateBossbar(event.getPlayer()); + } + + private void updateBossbars() { + for (Player player : Bukkit.getOnlinePlayers()) { + updateBossbar(player); + } + } + + private void updateBossbar(Player player) { + BauSystemBossbar bossbar = BossBarService.instance.get(player, region, "shieldprinting"); + bossbar.setColor(BarColor.YELLOW); + bossbar.setTitle(BauSystem.MESSAGE.parse(shieldData.isEmpty() ? "SHIELD_PRINTING_BOSSBAR" : "SHIELD_PRINTING_BOSSBAR_COPIED", player, shieldMap.size(), shieldData.size())); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index a789c748..b2f31dbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -26,12 +26,15 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; import java.util.HashMap; import java.util.Map; @Linked -public class ShieldPrintingCommand extends SWCommand { +public class ShieldPrintingCommand extends SWCommand implements Listener { public ShieldPrintingCommand() { super("shieldprinting"); @@ -43,7 +46,7 @@ public class ShieldPrintingCommand extends SWCommand { public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { - // BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } ShieldPrinting shieldPrinting; @@ -107,4 +110,20 @@ public class ShieldPrintingCommand extends SWCommand { return true; }; } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) { + return; + } + Region region = Region.getRegion(event.getClickedBlock().getLocation()); + if (region.isGlobal()) { + return; + } + ShieldPrinting shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + return; + } + shieldPrinting.onPlayerInteract(event); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java index 6c7d636d..e6ea2c16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java @@ -37,6 +37,12 @@ import java.util.Map; @Linked public class BossBarService implements Listener { + public static BossBarService instance; + + public BossBarService() { + instance = this; + } + private final Map>> playerBossBars = new HashMap<>(); public synchronized BauSystemBossbar get(Player player, Region region, String key) { From 61895377d1f1ed09016993e778be21c18ac18dac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:56:05 +0200 Subject: [PATCH 068/174] Hotfix RegionedBossbar Signed-off-by: yoyosource --- .../steamwar/bausystem/utils/bossbar/RegionedBossbar.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java index 4d922143..5fb1cc99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java @@ -135,8 +135,10 @@ public class RegionedBossbar implements BauSystemBossbar, Listener { @Override public void cleanup() { - bossBar.removeAll(); - bossBar = null; + if (bossBar != null) { + bossBar.removeAll(); + bossBar = null; + } region = null; player = null; From a15e5aaf50cdb67281c6fc6162f1d005e867db9c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:07:40 +0200 Subject: [PATCH 069/174] Remove some memory Signed-off-by: yoyosource --- .../features/shieldprinting/ShieldPrinting.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 3ddefdc2..0ad8d710 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -111,6 +111,15 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + + toRemove.clear(); + for (Map.Entry entry : shieldMap.entrySet()) { + if (entry.getKey().equals(entry.getValue())) { + toRemove.add(entry.getKey()); + } + } + shieldMap.keySet().removeAll(toRemove); + updateBossbars(); } From f9919925283b9da1dd9054e43fb69534f42dbc26 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:39:51 +0200 Subject: [PATCH 070/174] Fix stoplag for ShieldPrinting.apply Signed-off-by: yoyosource --- .../bausystem/features/shieldprinting/ShieldPrinting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 0ad8d710..e1585fbb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -70,7 +70,7 @@ public class ShieldPrinting implements Listener { public void apply() { for (Map.Entry entry : shieldData.entrySet()) { - entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue()); + entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue(), false); } } From ad4a054a6385bfefd05ed1cfcb0c540028b60fdb Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:46:58 +0200 Subject: [PATCH 071/174] Added new Buttons to Loader Detonator not nescessary since detection works differently --- .../steamwar/bausystem/features/loader/LoaderButton.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index e5e74171..6825a247 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -46,6 +46,9 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; + case CRIMSON_BUTTON: + case MANGROVE_BUTTON: + case WARPED_BUTTON: case ACACIA_BUTTON: case BIRCH_BUTTON: case DARK_OAK_BUTTON: @@ -53,8 +56,13 @@ public enum LoaderButton { case OAK_BUTTON: case SPRUCE_BUTTON: return LoaderButton.WOOD_BUTTON; + case POLISHED_BLACKSTONE_BUTTON: case STONE_BUTTON: return LoaderButton.STONE_BUTTON; + case CRIMSON_PRESSURE_PLATE: + case MANGROVE_PRESSURE_PLATE: + case WARPED_PRESSURE_PLATE: + // case POLISHED_BLACKSTONE_PRESSURE_PLATE: case ACACIA_PRESSURE_PLATE: case BIRCH_PRESSURE_PLATE: case DARK_OAK_PRESSURE_PLATE: From 377bcb92fb845a29f9ce9698064c86bdbd4e97b0 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:55:30 +0200 Subject: [PATCH 072/174] Generalized LoaderButton assignment --- .../features/loader/LoaderButton.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index 6825a247..4a1d5159 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -24,6 +24,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.block.Block; + @AllArgsConstructor @RequiredArgsConstructor @Getter @@ -46,42 +47,25 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; - case CRIMSON_BUTTON: - case MANGROVE_BUTTON: - case WARPED_BUTTON: - case ACACIA_BUTTON: - case BIRCH_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case OAK_BUTTON: - case SPRUCE_BUTTON: - return LoaderButton.WOOD_BUTTON; - case POLISHED_BLACKSTONE_BUTTON: - case STONE_BUTTON: - return LoaderButton.STONE_BUTTON; - case CRIMSON_PRESSURE_PLATE: - case MANGROVE_PRESSURE_PLATE: - case WARPED_PRESSURE_PLATE: - // case POLISHED_BLACKSTONE_PRESSURE_PLATE: - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case STONE_PRESSURE_PLATE: - return LoaderButton.PRESSURE_PLATE; - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - return LoaderButton.WEIGHTED_PRESSURE_PLATE; case TRIPWIRE: return LoaderButton.TRIPWIRE; case NOTE_BLOCK: return LoaderButton.NOTEBLOCK; case DAYLIGHT_DETECTOR: return LoaderButton.DAYLIGHTSENSOR; + case HEAVY_WEIGHTED_PRESSURE_PLATE: + case LIGHT_WEIGHTED_PRESSURE_PLATE: + return LoaderButton.WEIGHTED_PRESSURE_PLATE; default: - return LoaderButton.INVALID; + if (block.getType().name().contains("STONE_BUTTON")) { + return LoaderButton.STONE_BUTTON; + } else if (block.getType().name().contains("BUTTON")) { + return LoaderButton.WOOD_BUTTON; + } else if (block.getType().name().contains("PRESSURE_PLATE")) { + return LoaderButton.PRESSURE_PLATE; + } else { + return LoaderButton.INVALID; + } } } } From 3786f1e2bb7e5d03a09d3d97d171eaa7fc1c83dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 13:38:00 +0200 Subject: [PATCH 073/174] Add sand shield printing tracking Signed-off-by: yoyosource --- .../shieldprinting/ShieldPrinting.java | 43 +++++++++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 12 +++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index e1585fbb..ea3b0fbc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -25,18 +25,27 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.boss.BarColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.EntityBlockFormEvent; +import org.bukkit.event.entity.EntityAirChangeEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; @@ -47,6 +56,17 @@ public class ShieldPrinting implements Listener { private static final World WORLD = Bukkit.getWorlds().get(0); + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> { + shieldPrinting.fallingBlocks.replaceAll((entity, location) -> { + if (entity.isDead()) return null; + return location; + }); + }); + }, 1, 1); + } + /** * Vector of current position, Vector of origin */ @@ -123,6 +143,29 @@ public class ShieldPrinting implements Listener { updateBossbars(); } + private Map fallingBlocks = new HashMap<>(); + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent event) { + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getLocation()) != region) return; + fallingBlocks.put(event.getEntity(), event.getLocation().getBlock().getLocation()); + } + + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if (!event.getBlock().getType().isAir()) return; + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getBlock().getLocation()) != region) return; + Location origin = fallingBlocks.remove(event.getEntity()); + if (origin == null) return; + Location destination = event.getBlock().getLocation(); + Vector originOrigin = shieldMap.remove(origin.toVector()); + shieldMap.put(destination.toVector(), originOrigin != null ? originOrigin : origin.toVector()); + + updateBossbars(); + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index b2f31dbd..a72443f5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -40,7 +40,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { super("shieldprinting"); } - private Map shieldMap = new HashMap<>(); + static final Map SHIELD_PRINTING_MAP = new HashMap<>(); @Register public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { @@ -52,14 +52,14 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { ShieldPrinting shieldPrinting; switch (shieldPrintingState) { case START: - shieldPrinting = shieldMap.put(region, new ShieldPrinting(region)); + shieldPrinting = SHIELD_PRINTING_MAP.put(region, new ShieldPrinting(region)); if (shieldPrinting != null) { shieldPrinting.disable(); } BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player); break; case COPY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -68,7 +68,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player); break; case APPLY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -86,7 +86,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } - ShieldPrinting shieldPrinting = shieldMap.remove(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.remove(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -120,7 +120,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { if (region.isGlobal()) { return; } - ShieldPrinting shieldPrinting = shieldMap.get(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { return; } From 37b76eff30ae157924c4b03fa4b2c23795faaa3c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 18:08:36 +0200 Subject: [PATCH 074/174] Add ShowModeParameterType.TICKS_SINCE_START Signed-off-by: yoyosource --- .../bausystem/features/tracer/show/EntityShowMode.java | 2 ++ .../bausystem/features/tracer/show/ShowModeParameter.java | 5 +++++ .../features/tracer/show/ShowModeParameterType.java | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) 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 index bfcd15e5..6f61a08e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -202,6 +202,8 @@ public class EntityShowMode implements ShowMode { entity.setDisplayName(fuseTicks + ""); } else if (showModeParameter.isCount()) { entity.setDisplayName(new HashSet<>(records).size() + ""); + } else if (showModeParameter.isTicksSinceStart()) { + entity.setDisplayName((80 - fuseTicks) + tntPosition.getRecord().getOffset() + ""); } } 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 d8e3a75f..4babe506 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 @@ -31,6 +31,7 @@ public class ShowModeParameter { private boolean ticks = false; private boolean count = false; private boolean buildDestroyOnly = false; + private boolean ticksSinceStart = false; public void enableWater() { this.water = true; @@ -63,4 +64,8 @@ public class ShowModeParameter { public void enableBuildDestroyOnly() { this.buildDestroyOnly = true; } + + public void enableTicksSinceStart() { + this.ticksSinceStart = 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 3d28237d..a80a3633 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 @@ -38,9 +38,10 @@ public enum ShowModeParameterType { }, 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", "COUNT"), - COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "COUNT"), - BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"); + TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"), + COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), + BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), + TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"); @Getter private final Consumer showModeParameterConsumer; From 740d3cfb95468b5262a2a462b1ffaca3caee6a38 Mon Sep 17 00:00:00 2001 From: PsiRobot Date: Fri, 21 Apr 2023 16:45:24 +0000 Subject: [PATCH 075/174] Fix SkullCommand for Bedrock --- .../src/de/steamwar/bausystem/features/util/SkullCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java index b8cce749..9bb2331d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java @@ -57,7 +57,7 @@ public class SkullCommand extends SWCommand { return new TypeMapper() { @Override public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - if (s.endsWith("⍇")) return null; + if (s.startsWith(".")) return null; return s; } From b494f0bf3a6b69d189788a7be98f1860bb09e41a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 24 Apr 2023 16:24:31 +0200 Subject: [PATCH 076/174] Hotfix Tracer Signed-off-by: yoyosource --- .../steamwar/bausystem/features/tracer/TraceCommand.java | 8 ++------ .../features/tracer/record/AutoTraceRecorder.java | 3 +-- .../bausystem/features/tracer/record/Recorder.java | 6 +----- .../features/tracer/record/SimpleTraceRecorder.java | 3 +-- .../bausystem/features/tracer/record/TraceRecorder.java | 3 +-- 5 files changed, 6 insertions(+), 17 deletions(-) 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 b24ec012..b79d08f0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -209,11 +209,10 @@ public class TraceCommand extends SWCommand { @AllArgsConstructor private enum ShowModeType { - ENTITY((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, 10), new ShowModeParameterType[]{}), - RAW((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, -1), new ShowModeParameterType[]{}); + ENTITY((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, 10)), + RAW((player, showModeParameter) -> new EntityShowMode(player, showModeParameter, -1)); private BiFunction> showModeBiFunction; - private ShowModeParameterType[] removedTypes; } @ClassMapper(value = ShowModeParameterType.class, local = true) @@ -235,9 +234,6 @@ public class TraceCommand extends SWCommand { @Override public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set showModeParameterTypeSet = new HashSet<>(); - previousArguments.getAll(ShowModeType.class).forEach(showModeType -> { - showModeParameterTypeSet.addAll(Arrays.asList(showModeType.removedTypes)); - }); Arrays.stream(previousArguments.userArgs).map(showModeParameterTypesMap::get).forEach(showModeParameterTypeSet::add); showModeParameterTypeSet.remove(null); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java index 49253e08..2af4146b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/AutoTraceRecorder.java @@ -70,10 +70,9 @@ public abstract class AutoTraceRecorder implements TraceRecorder { } @Override - public Record postClear() { + public void postClear() { recordMap.clear(); record = recordSupplier.get(); - return record; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 8b3fcea0..5d580005 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -147,11 +147,7 @@ public class Recorder implements Listener { } public void postClear(Region region) { - TraceRecorder traceRecorder = get(region); - Record record = traceRecorder.postClear(); - if (record != null) { - StoredRecords.add(region, record); - } + get(region).postClear(); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java index a1d03f27..79e984aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/SimpleTraceRecorder.java @@ -46,9 +46,8 @@ public class SimpleTraceRecorder implements TraceRecorder, ActiveTracer { } @Override - public Record postClear() { + public void postClear() { recordMap.clear(); - return record; } private Record.TNTRecord getRecord(TNTPrimed tntPrimed) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java index 2c75bf07..bb2a1325 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceRecorder.java @@ -30,8 +30,7 @@ public interface TraceRecorder { String scoreboard(Player player); default void recordSupplier(Supplier recordSupplier) { } - default Record postClear() { - return null; + default void postClear() { } void spawn(TNTPrimed tntPrimed); void tick(TNTPrimed tntPrimed); From a767a942fb0da7be6a80fdeb210ad0ac7db33704 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 29 Apr 2023 11:49:27 +0200 Subject: [PATCH 077/174] Add DesignEndStone or DesignEndStoneCommand Add Line for BauScoreboard to show XRay and TechHider Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 ++ BauSystem_Main/src/BauSystem_de.properties | 4 + .../design/endstone/DesignEndStone.java | 105 ++++++++++++++++++ .../endstone/DesignEndStoneCommand.java | 50 +++++++++ .../features/techhider/TechHiderCommand.java | 10 ++ .../features/world/BauScoreboard.java | 8 ++ .../bausystem/features/xray/XrayCommand.java | 10 ++ 7 files changed, 194 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index a3860e34..b2c9e377 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -37,6 +37,9 @@ SCOREBOARD_TPS_FROZEN = §e Frozen SCOREBOARD_TRACE_TICKS = Ticks +SCOREBOARD_TECHHIDER = TechHider +SCOREBOARD_XRAY = XRay + # Flags FLAG_COLOR = Color FLAG_TNT = TNT @@ -159,6 +162,10 @@ COUNTINGWAND_MESSAGE_LCLICK = §7Second position at: §8[§7{0}§8, §7{1}§8, COUNTINGWAND_MESSAGE_VOLUME = §e{0} COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} +# Design Endstone +DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Show where Endstone is +DESIGN_ENDSTONE_REGION_ERROR = §cThis region has no build area + # Detonator DETONATOR_LOC_REMOVE = §e{0} removed DETONATOR_LOC_ADD = §e{0} added diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9689be29..b14640b1 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -157,6 +157,10 @@ COUNTINGWAND_MESSAGE_LCLICK = §7Zweite Position bei: §8[§7{0}§8, §7{1}§8, COUNTINGWAND_MESSAGE_VOLUME = §e{0} COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} +# Design Endstone +DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Zeige wo Endstone ist +DESIGN_ENDSTONE_REGION_ERROR = §cDiese Region hat keinen Baubereich + # Detonator DETONATOR_LOC_REMOVE = §e{0} entfernt DETONATOR_LOC_ADD = §e{0} hinzugefügt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java new file mode 100644 index 00000000..78f39609 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -0,0 +1,105 @@ +/* + * 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.design.endstone; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.entity.REntity; +import de.steamwar.entity.REntityServer; +import de.steamwar.entity.RFallingBlockEntity; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class DesignEndStone { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + private int minX, minY, minZ, maxX, maxY, maxZ; + private REntityServer entityServer = new REntityServer(); + private List entities = new ArrayList<>(); + private Set locations = new HashSet<>(); + private List players = new ArrayList<>(); + + public DesignEndStone(Region region) { + this.minX = region.getMinPointBuild().getX(); + this.minY = region.getMinPointBuild().getY(); + this.minZ = region.getMinPointBuild().getZ(); + this.maxX = region.getMaxPointBuild().getX(); + this.maxY = region.getMaxPointBuild().getY(); + this.maxZ = region.getMaxPointBuild().getZ(); + } + + private void calc() { + entities.forEach(REntity::die); + entities.clear(); + locations.clear(); + + calc(minX, minY, minZ, maxX, maxY, minZ, 0, 0, 1, maxZ - minZ); + calc(minX, minY, maxZ, maxX, maxY, maxZ, 0, 0, -1, maxZ - minZ); + calc(minX, minY, minZ, minX, maxY, maxZ, 1, 0, 0, maxX - minX); + calc(maxX, minY, minZ, maxX, maxY, maxZ, -1, 0, 0, maxX - minX); + // calc(minX, minY, minZ, maxX, minY, maxZ, 0, 1, 0, maxY - minY); + calc(minX, maxY, minZ, maxX, maxY, maxZ, 0, -1, 0, maxY - minY); + } + + private void calc(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int dirX, int dirY, int dirZ, int steps) { + for (int x = minX; x <= maxX; x++) { + for (int y = minY; y <= maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + for (int step = 0; step < steps; step++) { + int cx = x + step * dirX; + int cy = y + step * dirY; + int cz = z + step * dirZ; + Material material = WORLD.getBlockAt(cx, cy, cz).getType(); + if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) { + Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5); + if (locations.contains(location)) break; + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.END_STONE); + entity.setNoGravity(true); + entity.setGlowing(true); + entities.add(entity); + break; + } else if (!material.isAir()) { + break; + } + } + } + } + } + } + + public void toggle(Player player) { + if (players.contains(player)) { + players.remove(player); + entityServer.removePlayer(player); + } else { + players.add(player); + entityServer.addPlayer(player); + calc(); + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java new file mode 100644 index 00000000..56b2d419 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -0,0 +1,50 @@ +/* + * 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.design.endstone; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class DesignEndStoneCommand extends SWCommand { + + public DesignEndStoneCommand() { + super("designendstone"); + } + + private Map designEndStoneMap = new HashMap<>(); + + @Register(description = "DESIGN_ENDSTONE_COMMAND_HELP") + public void genericCommand(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (!region.hasType(RegionType.BUILD)) { + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_REGION_ERROR", player); + return; + } + designEndStoneMap.computeIfAbsent(region, DesignEndStone::new).toggle(player); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index 622632fd..e06724ba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -50,6 +50,16 @@ public class TechHiderCommand extends SWCommand implements Listener { private Map> techHiders = new HashMap<>(); private Map> hidden = new HashMap<>(); + private static TechHiderCommand INSTANCE; + + { + INSTANCE = this; + } + + public static boolean isHidden(Region region, Player player) { + return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); + } + @LinkedInstance public XrayCommand xrayCommand; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index ace614eb..2d170bda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -3,10 +3,12 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.bausystem.features.script.CustomScriptManager; +import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; @@ -15,6 +17,7 @@ import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; +import de.steamwar.techhider.TechHider; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -86,6 +89,11 @@ public class BauScoreboard implements Listener { } strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); } + if (TechHiderCommand.isHidden(region, p)) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); + } else if (XrayCommand.isHidden(region, p)) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); + } strings.add("§3"); String traceScore = recorder.get(region).scoreboard(p); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index f1232760..9418a7e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -57,6 +57,16 @@ public class XrayCommand extends SWCommand implements Listener { private Map> xrayedBlocks = new HashMap<>(); private Map> hidden = new HashMap<>(); + private static XrayCommand INSTANCE; + + { + INSTANCE = this; + } + + public static boolean isHidden(Region region, Player player) { + return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); + } + @LinkedInstance public TechHiderCommand techHiderCommand; From c3838138b4f34d5a494fa649de9070c3ca8b7f65 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 29 Apr 2023 14:19:05 +0200 Subject: [PATCH 078/174] Fix DesignEndStone Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ BauSystem_Main/src/BauSystem_de.properties | 2 ++ .../bausystem/features/design/endstone/DesignEndStone.java | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index b2c9e377..82d131d2 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -165,6 +165,8 @@ COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} # Design Endstone DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Show where Endstone is DESIGN_ENDSTONE_REGION_ERROR = §cThis region has no build area +DESIGN_ENDSTONE_ENABLE = §aEndstone is activated +DESIGN_ENDSTONE_DISABLE = §cEndstone is deactivated # Detonator DETONATOR_LOC_REMOVE = §e{0} removed diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index b14640b1..ed657b0d 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -160,6 +160,8 @@ COUNTINGWAND_MESSAGE_DIMENSION = §e{0}§8, §e{1}§8, §e{2} # Design Endstone DESIGN_ENDSTONE_COMMAND_HELP = §8/§edesign endstone §8- §7Zeige wo Endstone ist DESIGN_ENDSTONE_REGION_ERROR = §cDiese Region hat keinen Baubereich +DESIGN_ENDSTONE_ENABLE = §aEndstone ist aktiviert +DESIGN_ENDSTONE_DISABLE = §cEndstone ist deaktiviert # Detonator DETONATOR_LOC_REMOVE = §e{0} entfernt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java index 78f39609..b2c83c7e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -19,10 +19,12 @@ package de.steamwar.bausystem.features.design.endstone; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; +import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -78,7 +80,7 @@ public class DesignEndStone { if (material == Material.END_STONE || material == Material.END_STONE_BRICKS || material == Material.END_STONE_BRICK_SLAB || material == Material.END_STONE_BRICK_STAIRS || material == Material.END_STONE_BRICK_WALL) { Location location = new Location(WORLD, cx + 0.5, cy, cz + 0.5); if (locations.contains(location)) break; - RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.END_STONE); + RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, location, Material.RED_STAINED_GLASS); entity.setNoGravity(true); entity.setGlowing(true); entities.add(entity); @@ -96,10 +98,12 @@ public class DesignEndStone { if (players.contains(player)) { players.remove(player); entityServer.removePlayer(player); + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR); } else { players.add(player); entityServer.addPlayer(player); calc(); + BauSystem.MESSAGE.send("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR); } } } From 4dafaab5d9a7925dbb57b7dd22fba54e3e29819d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 30 Apr 2023 12:39:11 +0200 Subject: [PATCH 079/174] Update TNTSimulator.edit to better reflect interactability Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 f9513cd4..46d9779a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -167,7 +167,30 @@ public class TNTSimulator { if (elements.size() == 1) { TNTElementGUI.open(player, (TNTElement) elements.get(0), null); } else { - TNTSimulatorGui.open(player, null, null, () -> elements, null); + List tntGroups = tntElementList.stream().filter(TNTGroup.class::isInstance).map(TNTGroup.class::cast).collect(Collectors.toList()); + List newElementList = new ArrayList<>(); + for (TNTGroup tntGroup : tntGroups) { + if (new HashSet<>(elements).containsAll(tntGroup.getElements())) { + newElementList.add(tntGroup); + elements.removeAll(tntGroup.getElements()); + } + } + newElementList.addAll(elements); + if (newElementList.size() == 1) { + SimulatorElement element = newElementList.get(0); + if (element instanceof TNTGroup) { + TNTGroup tntGroup = (TNTGroup) element; + TNTSimulatorGui.open(player, null, tntGroup, () -> { + List elementList = new ArrayList<>(); + elementList.addAll(tntGroup.getElements()); + return elementList; + }, null); + } else { + TNTElementGUI.open(player, (TNTElement) elements.get(0), null); + } + } else { + TNTSimulatorGui.open(player, null, null, () -> newElementList, null); + } } return; } From f1925dc366ec73117bea4f032e0bd073ecc8d46a Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 30 Apr 2023 14:20:37 +0200 Subject: [PATCH 080/174] =?UTF-8?q?=E2=80=9EBauSystem=5FMain/src/de/steamw?= =?UTF-8?q?ar/bausystem/features/loader/Loader.java=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 1a64a8af..6cba6fe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -211,7 +211,7 @@ public class Loader implements Listener { } if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; + return; } LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); From 8bc2fda2bab424d3670f75767f368dadd87dfa99 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sun, 30 Apr 2023 14:22:59 +0200 Subject: [PATCH 081/174] =?UTF-8?q?=E2=80=9EBauSystem=5FMain/src/de/steamw?= =?UTF-8?q?ar/bausystem/features/loader/Loader.java=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/steamwar/bausystem/features/loader/Loader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 1a64a8af..6cba6fe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -211,7 +211,7 @@ public class Loader implements Listener { } if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; + return; } LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); From b4d63e1fe976dee36fafa66826a47e2e3fac07b3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 00:04:14 +0200 Subject: [PATCH 082/174] Add reworked Loader Signed-off-by: yoyosource --- .../features/loader/LoaderCommand.java | 2 +- .../bausystem/features/loadern/Loader.java | 130 ++++++++++++ .../features/loadern/LoaderCommand.java | 92 +++++++++ .../features/loadern/LoaderRecorder.java | 187 +++++++++++++++++ .../loadern/elements/ElementSettings.java | 31 +++ .../loadern/elements/LoaderElement.java | 29 +++ .../elements/LoaderInteractionElement.java | 116 +++++++++++ .../elements/impl/LoaderComparator.java | 135 +++++++++++++ .../elements/impl/LoaderDaylightDetector.java | 159 +++++++++++++++ .../loadern/elements/impl/LoaderLectern.java | 155 ++++++++++++++ .../loadern/elements/impl/LoaderLever.java | 132 ++++++++++++ .../elements/impl/LoaderNoteBlock.java | 115 +++++++++++ .../loadern/elements/impl/LoaderOpenable.java | 138 +++++++++++++ .../loadern/elements/impl/LoaderRepeater.java | 149 ++++++++++++++ .../loadern/elements/impl/LoaderTNT.java | 63 ++++++ .../loadern/elements/impl/LoaderTicks.java | 191 ++++++++++++++++++ .../loadern/elements/impl/LoaderWait.java | 88 ++++++++ 17 files changed, 1911 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index ffea7e4f..95fa92b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -26,7 +26,7 @@ import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; -@Linked +// @Linked public class LoaderCommand extends SWCommand { public LoaderCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java new file mode 100644 index 00000000..01d56d04 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -0,0 +1,130 @@ +/* + * 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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Loader implements Listener { + + private static final Map LOADER_MAP = new HashMap<>(); + + public static Loader getLoader(Player player) { + return LOADER_MAP.get(player); + } + + public static void newLoader(Player player) { + LOADER_MAP.put(player, new Loader(player)); + } + + private final Player p; + + private Stage stage = Stage.SETUP; + private LoaderRecorder recorder; + + private List elements = new ArrayList<>(); + private int currentElement = 0; + + public Loader(Player p) { + this.p = p; + this.recorder = new LoaderRecorder(p, elements); + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + private void next() { + currentElement++; + if (currentElement >= elements.size()) { + currentElement = 0; + } + if (stage == Stage.RUNNING) { + elements.get(currentElement).execute(this::next); + } + } + + public void start() { + if (stage == Stage.END) return; + if (stage == Stage.RUNNING) return; + stage = Stage.RUNNING; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + if (elements.isEmpty()) { + p.sendMessage("§cEs wurden keine Elemente aufgenommen!"); + stop(); + return; + } + elements.get(currentElement).execute(this::next); + } + + public void pause() { + if (stage == Stage.END) return; + if (stage == Stage.PAUSE) return; + stage = Stage.PAUSE; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + } + + public void stop() { + stage = Stage.END; + if (recorder != null) { + recorder.stop(); + recorder = null; + } + elements.clear(); + LOADER_MAP.remove(p); + } + + public void settings() { + List> list = new ArrayList<>(); + for (LoaderElement element : elements) { + list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); + } + new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { + entry.click(p, this::settings); + }).open(); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer() != p) return; + stop(); + } + + public enum Stage { + SETUP, + RUNNING, + PAUSE, + END + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java new file mode 100644 index 00000000..6539d16a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -0,0 +1,92 @@ +/* + * 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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class LoaderCommand extends SWCommand { + + public LoaderCommand() { + super("loader"); + } + + private boolean loaderNullCheck(Loader loader, Player p) { + if (loader == null) { + BauSystem.MESSAGE.send("LOADER_NO_LOADER", p); + return true; + } + return false; + } + + @Register(value = "setup", description = "LOADER_HELP_SETUP") + public void setupLoader(@Validator Player player) { + if (Loader.getLoader(player) != null) { + player.sendMessage("Please stop the current loader first!"); + return; + } + Loader.newLoader(player); + BauSystem.MESSAGE.send("LOADER_NEW", player); + BauSystem.MESSAGE.send("LOADER_HOW_TO_START", player); + } + + @Register(value = "start", description = "LOADER_HELP_START") + public void startLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.start(); + BauSystem.MESSAGE.send("LOADER_ACTIVE", player); + } + + @Register(value = "stop", description = "LOADER_HELP_STOP") + public void stopLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.stop(); + BauSystem.MESSAGE.send("LOADER_STOP", player); + } + + @Register(value = "pause", description = "LOADER_HELP_PAUSE") + public void pauseLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.pause(); + BauSystem.MESSAGE.send("LOADER_PAUSED", player); + } + + @Register(value = "settings", description = "LOADER_HELP_PAUSE") + public void settingsLoader(@Validator Player player) { + Loader loader = Loader.getLoader(player); + if (loaderNullCheck(loader, player)) return; + loader.settings(); + } + + @ClassValidator(value = Player.class, local = true) + public TypeValidator loaderValidator() { + return (commandSender, player, messageSender) -> { + return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "LOADER_PERMS"); + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java new file mode 100644 index 00000000..4bc9f071 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -0,0 +1,187 @@ +/* + * 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.loadern; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loadern.elements.impl.*; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.EquipmentSlot; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class LoaderRecorder implements Listener { + + private Player player; + private List loaderElementList; + private Set blockSet = new HashSet<>(); + private long lastInteraction = TPSUtils.currentTick.get(); + + public LoaderRecorder(Player player, List loaderElementList) { + this.player = player; + this.loaderElementList = loaderElementList; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + public void stop() { + addWaitTime(true); + HandlerList.unregisterAll(this); + player = null; + blockSet.clear(); + } + + private void addWaitTime(boolean last) { + if (loaderElementList.isEmpty()) { + lastInteraction = TPSUtils.currentTick.get(); + return; + } + if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) { + return; + } + long diff = TPSUtils.currentTick.get() - lastInteraction; + if (last && diff > 160) diff = 160; + lastInteraction = TPSUtils.currentTick.get(); + loaderElementList.add(new LoaderWait(diff)); + } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + if (event.getPlayer() != player) return; + if (event.getBlock().getType() != Material.TNT) return; + + addWaitTime(false); + loaderElementList.add(new LoaderTNT(event.getBlock().getLocation())); + } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEvent event) { + if (event.getPlayer() != player) return; + if (player.isSneaking()) return; + if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; + if (event.getClickedBlock().getType() == Material.OBSERVER) return; + if (event.getHand() == EquipmentSlot.OFF_HAND) return; + + addWaitTime(false); + Block block = event.getClickedBlock(); + Material type = block.getType(); + switch (type) { + case COMPARATOR: + loaderElementList.add(new LoaderComparator(block.getLocation())); + break; + case REPEATER: + loaderElementList.add(new LoaderRepeater(block.getLocation())); + break; + case NOTE_BLOCK: + loaderElementList.add(new LoaderNoteBlock(block.getLocation())); + break; + case LEVER: + loaderElementList.add(new LoaderLever(block.getLocation())); + break; + case DAYLIGHT_DETECTOR: + loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); + break; + case LECTERN: + loaderElementList.add(new LoaderLectern(block.getLocation())); + break; + case IRON_TRAPDOOR: + break; + default: + if (type.name().endsWith("_TRAPDOOR")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Trapdoor", type)); + } else if (type.name().endsWith("_DOOR")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Door", type)); + } else if (type.name().endsWith("FENCE_GATE")) { + loaderElementList.add(new LoaderOpenable(block.getLocation(), "Fencegate", type)); + } else if (type.name().endsWith("STONE_BUTTON")) { + loaderElementList.add(new LoaderTicks(block.getLocation(), "Stone Button", type, 20)); + } else if (type.name().endsWith("BUTTON")) { + loaderElementList.add(new LoaderTicks(block.getLocation(), "Wooden Button", type, 30)); + } + break; + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer() != player) return; + + Block fromBlock = event.getTo().getBlock(); + Block toBlock = event.getTo().getBlock(); + if (!blockSet.contains(toBlock.getLocation())) { + blockSet.remove(fromBlock.getLocation()); + blockSet.add(toBlock.getLocation()); + + addWaitTime(false); + Material type = toBlock.getType(); + switch (type) { + case TRIPWIRE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + break; + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + break; + default: + if (type.name().endsWith("PRESSURE_PLATE")) { + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + } + break; + } + } + + fromBlock = fromBlock.getRelative(0, 1, 0); + toBlock = toBlock.getRelative(0, 1, 0); + if (!blockSet.contains(toBlock.getLocation())) { + blockSet.remove(fromBlock.getLocation()); + blockSet.add(toBlock.getLocation()); + + addWaitTime(false); + Material type = toBlock.getType(); + switch (type) { + case TRIPWIRE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + break; + case LIGHT_WEIGHTED_PRESSURE_PLATE: + case HEAVY_WEIGHTED_PRESSURE_PLATE: + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + break; + default: + if (type.name().endsWith("PRESSURE_PLATE")) { + loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + } + break; + } + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java new file mode 100644 index 00000000..5142e8cf --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java @@ -0,0 +1,31 @@ +/* + * 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.loadern.elements; + +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +public interface ElementSettings { + SWItem menu(Player player); + void execute(Runnable nextAction); + void click(Player player, Runnable backAction, Runnable deleteAction); + + default void playerInteract() {} +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java new file mode 100644 index 00000000..4b1734bd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java @@ -0,0 +1,29 @@ +/* + * 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.loadern.elements; + +import de.steamwar.inventory.SWItem; +import org.bukkit.entity.Player; + +public interface LoaderElement { + SWItem menu(Player player); + void execute(Runnable nextAction); + void click(Player player, Runnable backAction); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java new file mode 100644 index 00000000..7785f07b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -0,0 +1,116 @@ +/* + * 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.loadern.elements; + +import de.steamwar.bausystem.features.loader.LoaderButton; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.FaceAttachable; +import org.bukkit.block.data.type.Switch; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public abstract class LoaderInteractionElement implements LoaderElement { + + protected final Location location; + protected int currentShot = 0; + protected List elements = new ArrayList<>(); + + protected LoaderInteractionElement(Location location) { + this.location = location; + + T element = createNewElement(); + element.playerInteract(); + elements.add(element); + } + + @Override + public void execute(Runnable nextAction) { + if (currentShot >= elements.size()) currentShot = 0; + elements.get(currentShot).execute(nextAction); + currentShot++; + if (currentShot >= elements.size()) currentShot = 0; + } + + @Override + public void click(Player player, Runnable backAction) { + List> entries = new ArrayList<>(); + for (T element : elements) { + entries.add(new SWListInv.SWListEntry<>(element.menu(player), element)); + } + + SWListInv listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> { + entry.click(player, () -> { + click(player, backAction); + }, () -> { + if (elements.size() == 1) return; + elements.remove(entry); + click(player, backAction); + }); + }); + listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { + backAction.run(); + })); + listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another", clickType -> { + T element = createNewElement(); + elements.add(element); + element.click(player, () -> click(player, backAction), () -> { + if (elements.size() == 1) return; + elements.remove(element); + click(player, backAction); + }); + })); + listInv.open(); + } + + protected void update(Block block) { + Material material = block.getType(); + if (block.getBlockData() instanceof Switch) { + Switch sw = (Switch) block.getBlockData(); + FaceAttachable.AttachedFace face = sw.getAttachedFace(); + if (face == FaceAttachable.AttachedFace.FLOOR) { + updateBlock(block.getRelative(BlockFace.DOWN)); + } else if (face == FaceAttachable.AttachedFace.CEILING) { + updateBlock(block.getRelative(BlockFace.UP)); + } else { + updateBlock(block.getRelative(sw.getFacing().getOppositeFace())); + } + } else if (material == Material.TRIPWIRE) { + updateBlock(block); + } else if (material.name().endsWith("_PLATE")) { + updateBlock(block.getRelative(BlockFace.DOWN)); + } + } + + protected void updateBlock(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER, true); + block.setBlockData(data, true); + } + + public abstract T createNewElement(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java new file mode 100644 index 00000000..d92ea4ad --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -0,0 +1,135 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Comparator; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderComparator extends LoaderInteractionElement { + + public LoaderComparator(Location location) { + super(location); + } + + public class ComparatorSettings implements ElementSettings { + + private boolean interact = false; + private Comparator.Mode mode = Comparator.Mode.COMPARE; + + @Override + public SWItem menu(Player player) { + return menu(player, interact, mode); + } + + private SWItem menu(Player player, boolean interact, Comparator.Mode mode) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.STICK, "§7Comparator§8: §eInteract"); + } else if (mode == null) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP"); + } else { + swItem = new SWItem(Material.COMPARATOR, "§7Comparator§8: §e" + mode.name()); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.COMPARATOR) return; + Comparator comparator = (Comparator) location.getBlock().getBlockData(); + if (interact) { + comparator.setMode(comparator.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE); + } else if (mode == null) { + return; + } else { + comparator.setMode(mode); + } + location.getBlock().setBlockData(comparator, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, null).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, null).getItemStack(), clickType -> { + interact = false; + mode = null; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> { + interact = false; + mode = Comparator.Mode.COMPARE; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, Comparator.Mode.SUBTRACT).getItemStack(), clickType -> { + interact = false; + mode = Comparator.Mode.SUBTRACT; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact, Comparator.Mode mode) { + SWItem swItem = menu(player, interact, mode); + if (swItem.getItemStack().equals(menu(player, this.interact, this.mode).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + @Override + public void playerInteract() { + interact = true; + mode = null; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.COMPARATOR, "§7Comparator"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public ComparatorSettings createNewElement() { + return new ComparatorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java new file mode 100644 index 00000000..cbdcc7dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -0,0 +1,159 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.DaylightDetector; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderDaylightDetector extends LoaderInteractionElement { + + public LoaderDaylightDetector(Location location) { + super(location); + } + + public class DaylightDetectorSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = false; + private boolean inverted = true; + private int power = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, inverted); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Daylight Detector§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7Daylight Detector§8: §eInteract"); + } else { + swItem = new SWItem(Material.DAYLIGHT_DETECTOR, "§7Daylight Detector§8: §e" + (powered ? "Powered" : "Unpowered")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return; + DaylightDetector daylightDetector = (DaylightDetector) location.getBlock().getBlockData(); + if (noop) { + return; + } else if (interact) { + daylightDetector.setInverted(!daylightDetector.isInverted()); + } else { + daylightDetector.setInverted(inverted); + } + daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power); + location.getBlock().setBlockData(daylightDetector); + update(location.getBlock().getRelative(0, -1, 0)); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 36, "Settings"); + for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(27, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + inverted = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + inverted = true; + click(player, backAction, deleteAction); + }); + + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean inverted) { + SWItem swItem = menu(player, noop, interact, inverted); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.inverted).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + + @Override + public void playerInteract() { + noop = false; + interact = true; + inverted = false; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.DAYLIGHT_DETECTOR, "§7Daylight Detector"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public DaylightDetectorSettings createNewElement() { + return new DaylightDetectorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java new file mode 100644 index 00000000..033d936a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -0,0 +1,155 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Lectern; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.BookMeta; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderLectern extends LoaderInteractionElement { + + + public LoaderLectern(Location location) { + super(location); + } + + public class LecternSettings implements ElementSettings { + + private boolean noop = true; + private LecternAction action = LecternAction.PAGE_NEXT; + private int page = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, action, page); + } + + private SWItem menu(Player player, boolean noop, LecternAction action, int page) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Lectern§8: §eNOOP"); + } else if (action == LecternAction.PAGE_PREV) { + swItem = new SWItem(Material.STICK, "§7Lectern§8: §ePage Prev"); + } else if (action == LecternAction.PAGE_NEXT) { + swItem = new SWItem(Material.STICK, "§7Lectern§8: §ePage Next"); + } else { + swItem = new SWItem(Material.LECTERN, "§7Lectern§8: §ePage " + page); + swItem.getItemStack().setAmount(page); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.LECTERN) return; + Lectern lectern = (Lectern) location.getBlock().getState(); + if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return; + int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size(); + if (noop) { + return; + } else if (action == LecternAction.PAGE_PREV) { + int page = lectern.getPage(); + if (page > 1) lectern.setPage(page - 1); + } else if (action == LecternAction.PAGE_NEXT) { + int page = lectern.getPage(); + if (page < pages) lectern.setPage(page + 1); + } else if (action == LecternAction.PAGE_SET) { + if (page <= pages) lectern.setPage(page); + } + lectern.update(false, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 36, "Settings"); + for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(27, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, LecternAction.PAGE_PREV, 0).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_PREV; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, LecternAction.PAGE_NEXT, 0).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_NEXT; + click(player, backAction, deleteAction); + }); + + for (int i = 0; i < 15; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + if (i >= 12) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, false, LecternAction.PAGE_SET, finalI + 1).getItemStack(), clickType -> { + noop = false; + action = LecternAction.PAGE_SET; + page = finalI + 1; + click(player, backAction, deleteAction); + }); + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, LecternAction action, int page) { + SWItem swItem = menu(player, noop, action, page); + if (swItem.getItemStack().equals(menu(player, this.noop, this.action, this.page).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + public enum LecternAction { + PAGE_NEXT, + PAGE_PREV, + PAGE_SET + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.LECTERN, "§7Lectern"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public LecternSettings createNewElement() { + return new LecternSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java new file mode 100644 index 00000000..8bd0d7b0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java @@ -0,0 +1,132 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Switch; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderLever extends LoaderInteractionElement { + + public LoaderLever(Location location) { + super(location); + } + + public class LeverSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = false; + private boolean power = false; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, power); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean power) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Lever§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7Lever§8: §eInteract"); + } else { + swItem = new SWItem(Material.LEVER, "§7Lever§8: §e" + (power ? "Active" : "Inactive")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.LEVER) return; + if (noop) return; + + Switch lever = (Switch) location.getBlock().getBlockData(); + if (interact) { + lever.setPowered(!lever.isPowered()); + } else { + lever.setPowered(power); + } + location.getBlock().setBlockData(lever); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + power = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + power = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean power) { + SWItem swItem = menu(player, noop, interact, power); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.power).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.LEVER, "§7Lever"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public LeverSettings createNewElement() { + return new LeverSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java new file mode 100644 index 00000000..5f062f87 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -0,0 +1,115 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Instrument; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.NoteBlock; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderNoteBlock extends LoaderInteractionElement { + + public LoaderNoteBlock(Location location) { + super(location); + } + + public class NoteBlockSettings implements ElementSettings { + + private boolean interact = true; + + @Override + public SWItem menu(Player player) { + return menu(player, interact); + } + + private SWItem menu(Player player, boolean interact) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.NOTE_BLOCK, "§7Note Block§8: §eInteract"); + } else { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Note Block§8: §eNOOP"); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.NOTE_BLOCK) return; + NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData(); + if (interact) { + if (noteBlock.getInstrument() == Instrument.BANJO) noteBlock.setInstrument(Instrument.BIT); + else noteBlock.setInstrument(Instrument.BANJO); + } else { + return; + } + location.getBlock().setBlockData(noteBlock); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, false).getItemStack(), clickType -> { + interact = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, true).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact) { + SWItem swItem = menu(player, interact); + if (swItem.getItemStack().equals(menu(player, this.interact).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.NOTE_BLOCK, "§7Note Block"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public NoteBlockSettings createNewElement() { + return new NoteBlockSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java new file mode 100644 index 00000000..1fc45d69 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -0,0 +1,138 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.Openable; +import org.bukkit.block.data.type.TrapDoor; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderOpenable extends LoaderInteractionElement { + + private String name; + private Material material; + + public LoaderOpenable(Location location, String name, Material material) { + super(location); + this.name = name; + this.material = material; + } + + public class TrapdoorSettings implements ElementSettings { + + private boolean noop = false; + private boolean interact = true; + private boolean open = false; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, interact, open); + } + + private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name +"§8: §eNOOP"); + } else if (interact) { + swItem = new SWItem(Material.STICK, "§7" + name + "§8: §eInteract"); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §e" + (powered ? "Open" : "Closed")); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != material) return; + Openable openable = (Openable) location.getBlock().getBlockData(); + if (noop) { + return; + } else if (interact) { + openable.setOpen(!openable.isOpen()); + } else { + openable.setOpen(open); + } + location.getBlock().setBlockData(openable); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> { + noop = false; + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> { + noop = false; + interact = false; + open = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> { + noop = false; + interact = false; + open = true; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean interact, boolean open) { + SWItem swItem = menu(player, noop, interact, open); + if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.open).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public TrapdoorSettings createNewElement() { + return new TrapdoorSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java new file mode 100644 index 00000000..a0e50e48 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -0,0 +1,149 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.type.Repeater; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderRepeater extends LoaderInteractionElement { + + public LoaderRepeater(Location location) { + super(location); + } + + public class RepeaterSettings implements ElementSettings { + + private boolean interact = false; + private int delay = 1; + + @Override + public SWItem menu(Player player) { + return menu(player, interact, delay); + } + + private SWItem menu(Player player, boolean interact, int delay) { + SWItem swItem; + if (interact) { + swItem = new SWItem(Material.STICK, "§7Repeater§8: §eInteract"); + } else if (delay == 0) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7Repeater§8: §eNOOP"); + } else { + swItem = new SWItem(Material.REPEATER, "§7Repeater§8: §e" + delay); + swItem.getItemStack().setAmount(delay); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + nextAction.run(); + if (location.getBlock().getType() != Material.REPEATER) return; + Repeater repeater = (Repeater) location.getBlock().getBlockData(); + if (interact) { + int delay = repeater.getDelay(); + delay++; + if (delay > 4) delay = 1; + repeater.setDelay(delay); + } else if (delay == 0) { + return; + } else { + repeater.setDelay(delay); + } + location.getBlock().setBlockData(repeater, true); + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(1, item(player, true, -1).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); + swInventory.setItem(2, item(player, false, 0).getItemStack(), clickType -> { + interact = false; + delay = 0; + click(player, backAction, deleteAction); + }); + swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> { + interact = false; + delay = 1; + click(player, backAction, deleteAction); + }); + swInventory.setItem(5, item(player, false, 2).getItemStack(), clickType -> { + interact = false; + delay = 2; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, 3).getItemStack(), clickType -> { + interact = false; + delay = 3; + click(player, backAction, deleteAction); + }); + swInventory.setItem(7, item(player, false, 4).getItemStack(), clickType -> { + interact = false; + delay = 4; + click(player, backAction, deleteAction); + }); + + swInventory.open(); + } + + private SWItem item(Player player, boolean interact, int delay) { + SWItem swItem = menu(player, interact, delay); + if (swItem.getItemStack().equals(menu(player, this.interact, this.delay).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + @Override + public void playerInteract() { + interact = true; + delay = 0; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.REPEATER, "§7Repeater"); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public RepeaterSettings createNewElement() { + return new RepeaterSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java new file mode 100644 index 00000000..92c2bd4e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java @@ -0,0 +1,63 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.Arrays; + +public class LoaderTNT implements LoaderElement { + + private Location location; + + public LoaderTNT(Location location) { + this.location = location; + } + + @Override + public SWItem menu(Player player) { + SWItem item = new SWItem(Material.TNT, "§cTNT"); + item.setLore(Arrays.asList("§7X§8: " + location.getBlockX(), "§7Y§8: " + location.getBlockY(), "§7Z§8: " + location.getBlockZ())); + return item; + } + + @Override + public void execute(Runnable nextAction) { + Block block = location.getBlock(); + if (block.getType() != Material.AIR && block.getType() != Material.WATER) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1); + return; + } + + block.setType(Material.TNT, true); + nextAction.run(); + } + + @Override + public void click(Player player, Runnable backAction) { + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java new file mode 100644 index 00000000..54e63d34 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -0,0 +1,191 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.AnaloguePowerable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderTicks extends LoaderInteractionElement { + + protected String name; + protected Material material; + protected boolean analogue; + protected int ticks; + + public LoaderTicks(Location location, String name, Material material, int ticks) { + super(location); + this.name = name; + this.material = material; + this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable; + this.ticks = ticks; + } + + public class StoneButtonSettings implements ElementSettings { + + private boolean noop = false; + private boolean waitFor = true; + private int power = 0; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, waitFor); + } + + private SWItem menu(Player player, boolean noop, boolean waitFor) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name + "§8: §eNOOP"); + } else if (waitFor) { + swItem = new SWItem(material, "§7" + name + "§8: §eWaitFor"); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §eNoWaitFor"); + swItem.setEnchanted(true); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (location.getBlock().getType() != material) { + nextAction.run(); + return; + } + if (noop) { + nextAction.run(); + return; + } + + BlockData blockData = location.getBlock().getBlockData(); + if (blockData instanceof AnaloguePowerable) { + AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData(); + analoguePowerable.setPower(power); + } else if (blockData instanceof Powerable) { + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + if (ticks < 0) { + powerable.setPowered(power > 0); + } else { + powerable.setPowered(true); + } + } + + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (ticks >= 0) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (blockData instanceof AnaloguePowerable) { + ((AnaloguePowerable) blockData).setPower(0); + } else { + ((Powerable) blockData).setPowered(false); + } + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (finalWaitFor) { + nextAction.run(); + } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); + } + } + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings"); + for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + if (ticks >= 0) { + swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> { + noop = false; + waitFor = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> { + noop = false; + waitFor = true; + click(player, backAction, deleteAction); + }); + } + + if (analogue) { + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean waitFor) { + SWItem swItem = menu(player, noop, waitFor); + if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public StoneButtonSettings createNewElement() { + return new StoneButtonSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java new file mode 100644 index 00000000..5b263af9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -0,0 +1,88 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import java.util.Arrays; + +public class LoaderWait implements LoaderElement, Listener { + + private long delay; + + public LoaderWait(long delay) { + this.delay = delay; + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(Material.CLOCK, "§7Wartezeit: §e" + delay + " Ticks"); + swItem.getItemStack().setAmount((int) Math.max(Math.min(delay, 64), 1)); + if (delay == 0) swItem.setEnchanted(true); + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (delay == 0) { + nextAction.run(); + return; + } + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay); + } + + @Override + public void click(Player player, Runnable backAction) { + SWInventory swInventory = new SWInventory(player, 9, "Wartezeit"); + swInventory.setItem(0, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + + swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + delay -= clickType.isShiftClick() ? 5 : 1; + if (delay < 0) delay = 0; + swInventory.setItem(4, menu(player)); + }); + swInventory.setItem(4, menu(player).getItemStack(), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "§7Wartezeit", delay + ""); + swAnvilInv.setCallback(s -> { + try { + delay = Long.parseLong(s); + } catch (NumberFormatException ignored) { + } + click(player, backAction); + }); + swAnvilInv.open(); + }); + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + delay += clickType.isShiftClick() ? 5 : 1; + swInventory.setItem(4, menu(player)); + }); + + swInventory.open(); + } +} From e997243887d38b929a0f0f2d002637f7a3e7bec8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 12:20:24 +0200 Subject: [PATCH 083/174] Update LoaderRecorder Signed-off-by: yoyosource --- .../features/loadern/LoaderRecorder.java | 56 ++--- .../loadern/elements/impl/LoaderMovement.java | 226 ++++++++++++++++++ .../loadern/elements/impl/LoaderTicks.java | 16 +- .../loadern/elements/impl/LoaderWait.java | 1 + 4 files changed, 261 insertions(+), 38 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 4bc9f071..329cfd55 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -37,15 +37,14 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.EquipmentSlot; -import java.util.HashSet; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; public class LoaderRecorder implements Listener { private Player player; private List loaderElementList; - private Set blockSet = new HashSet<>(); private long lastInteraction = TPSUtils.currentTick.get(); public LoaderRecorder(Player player, List loaderElementList) { @@ -132,56 +131,53 @@ public class LoaderRecorder implements Listener { } } + private Map blockSet = new HashMap<>(); + private Map movementSet = new HashMap<>(); + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if (event.getPlayer() != player) return; Block fromBlock = event.getTo().getBlock(); Block toBlock = event.getTo().getBlock(); - if (!blockSet.contains(toBlock.getLocation())) { - blockSet.remove(fromBlock.getLocation()); - blockSet.add(toBlock.getLocation()); - - addWaitTime(false); - Material type = toBlock.getType(); - switch (type) { - case TRIPWIRE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); - break; - case LIGHT_WEIGHTED_PRESSURE_PLATE: - case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); - break; - default: - if (type.name().endsWith("PRESSURE_PLATE")) { - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); - } - break; - } - } + calcMovementBlocks(fromBlock, toBlock); fromBlock = fromBlock.getRelative(0, 1, 0); toBlock = toBlock.getRelative(0, 1, 0); - if (!blockSet.contains(toBlock.getLocation())) { - blockSet.remove(fromBlock.getLocation()); - blockSet.add(toBlock.getLocation()); + calcMovementBlocks(fromBlock, toBlock); + } + + private void calcMovementBlocks(Block fromBlock, Block toBlock) { + if (!blockSet.containsKey(toBlock.getLocation())) { + Long startTime = blockSet.remove(fromBlock.getLocation()); + LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation()); + if (loaderMovement != null && startTime != null) { + loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime); + } + + blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get()); addWaitTime(false); + loaderMovement = null; Material type = toBlock.getType(); switch (type) { case TRIPWIRE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Tripwire", Material.STRING, 30)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Tripwire", Material.STRING); break; case LIGHT_WEIGHTED_PRESSURE_PLATE: case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Weighted Pressure Plate", type, 20)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Weighted Pressure Plate", type); break; default: if (type.name().endsWith("PRESSURE_PLATE")) { - loaderElementList.add(new LoaderTicks(toBlock.getLocation(), "Pressure Plate", type, 30)); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "Pressure Plate", type); } break; } + if (loaderMovement != null) { + movementSet.put(toBlock.getLocation(), loaderMovement); + loaderElementList.add(loaderMovement); + } } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java new file mode 100644 index 00000000..ee1f11ac --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -0,0 +1,226 @@ +/* + * 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.loadern.elements.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loadern.elements.ElementSettings; +import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.data.AnaloguePowerable; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.Collections; + +public class LoaderMovement extends LoaderInteractionElement { + + private String name; + private Material material; + private boolean analogue; + + public LoaderMovement(Location location, String name, Material material) { + super(location); + this.name = name; + this.material = material; + this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable; + } + + public void setInitialTicks(long ticks) { + elements.get(currentShot).ticks = ticks; + } + + public class MovementSettings implements ElementSettings { + + private boolean noop = false; + private boolean waitFor = true; + private int power = 0; + private long ticks = 1; + + @Override + public SWItem menu(Player player) { + return menu(player, noop, waitFor); + } + + private SWItem menu(Player player, boolean noop, boolean waitFor) { + SWItem swItem; + if (noop) { + swItem = new SWItem(Material.STRUCTURE_VOID, "§7" + name + "§8: §eNOOP"); + } else if (waitFor) { + swItem = new SWItem(material, "§7" + name + "§8: §eWaitFor"); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + } else { + swItem = new SWItem(material, "§7" + name + "§8: §eNoWaitFor"); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + swItem.setEnchanted(true); + } + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + + @Override + public void execute(Runnable nextAction) { + if (location.getBlock().getType() != material) { + nextAction.run(); + return; + } + if (noop) { + nextAction.run(); + return; + } + + BlockData blockData = location.getBlock().getBlockData(); + if (blockData instanceof AnaloguePowerable) { + AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData(); + analoguePowerable.setPower(power); + } else if (blockData instanceof Powerable) { + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + if (ticks < 0) { + powerable.setPowered(power > 0); + } else { + powerable.setPowered(true); + } + } + + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (ticks >= 0) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (blockData instanceof AnaloguePowerable) { + ((AnaloguePowerable) blockData).setPower(0); + } else { + ((Powerable) blockData).setPowered(false); + } + location.getBlock().setBlockData(blockData); + update(location.getBlock()); + if (finalWaitFor) { + nextAction.run(); + } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); + } + } + } + + @Override + public void click(Player player, Runnable backAction, Runnable deleteAction) { + SWInventory swInventory = new SWInventory(player, analogue ? 45 : 27, "Settings"); + for (int i = analogue ? 36 : 18; i < (analogue ? 44 : 26); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(analogue ? 36 : 18, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + + swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + noop = true; + click(player, backAction, deleteAction); + }); + if (ticks >= 0) { + swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> { + noop = false; + waitFor = false; + click(player, backAction, deleteAction); + }); + swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> { + noop = false; + waitFor = true; + click(player, backAction, deleteAction); + }); + } + + swInventory.setItem(12, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + ticks -= clickType.isShiftClick() ? 5 : 1; + if (ticks < 1) ticks = 1; + swInventory.setItem(13, item(player)); + }); + swInventory.setItem(13, item(player).getItemStack(), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Ticks", ticks + ""); + swAnvilInv.setCallback(s -> { + try { + ticks = Long.parseLong(s); + if (ticks < 1) ticks = 1; + } catch (NumberFormatException ignored) { + } + click(player, backAction, deleteAction); + }); + swAnvilInv.open(); + }); + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + ticks += clickType.isShiftClick() ? 5 : 1; + swInventory.setItem(13, item(player)); + }); + + if (analogue) { + for (int i = 0; i < 16; i++) { + int finalI = i; + int finalI2 = i; + if (i >= 9) finalI2++; + swInventory.setItem(finalI2 + 18, item(player, finalI).getItemStack(), clickType -> { + power = finalI; + click(player, backAction, deleteAction); + }); + } + } + + swInventory.open(); + } + + private SWItem item(Player player, boolean noop, boolean waitFor) { + SWItem swItem = menu(player, noop, waitFor); + if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) { + swItem.setEnchanted(true); + } + swItem.setLore(Collections.emptyList()); + return swItem; + } + + private SWItem item(Player player, int power) { + SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power); + swItem.getItemStack().setAmount(power == 0 ? 1 : power); + if (!this.noop && this.power == power) swItem.setEnchanted(true); + return swItem; + } + + private SWItem item(Player player) { + SWItem swItem = new SWItem(Material.CLOCK, "§7Ticks§8: §e" + ticks); + swItem.getItemStack().setAmount((int) Math.min(ticks, 64)); + swItem.setLore(Arrays.asList("§7Click to edit")); + return swItem; + } + } + + @Override + public SWItem menu(Player player) { + SWItem swItem = new SWItem(material, "§7" + name); + swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit")); + return swItem; + } + + @Override + public MovementSettings createNewElement() { + return new MovementSettings(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 54e63d34..8e203d7d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -35,12 +35,12 @@ import org.bukkit.entity.Player; import java.util.Arrays; import java.util.Collections; -public class LoaderTicks extends LoaderInteractionElement { +public class LoaderTicks extends LoaderInteractionElement { - protected String name; - protected Material material; - protected boolean analogue; - protected int ticks; + private String name; + private Material material; + private boolean analogue; + private int ticks; public LoaderTicks(Location location, String name, Material material, int ticks) { super(location); @@ -50,7 +50,7 @@ public class LoaderTicks extends LoaderInteractionElement { try { delay = Long.parseLong(s); + if (delay < 0) delay = 0; } catch (NumberFormatException ignored) { } click(player, backAction); From c320f92ea31017f0ffb9ae3f8ce3c427c7c7b336 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 12:34:22 +0200 Subject: [PATCH 084/174] Update BauScoreboard design Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 7 +++---- BauSystem_Main/src/BauSystem_de.properties | 6 ++++-- .../features/tracer/record/Recorder.java | 4 ++-- .../bausystem/features/world/BauScoreboard.java | 15 +++++++++++---- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 82d131d2..320cd623 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -37,8 +37,8 @@ SCOREBOARD_TPS_FROZEN = §e Frozen SCOREBOARD_TRACE_TICKS = Ticks -SCOREBOARD_TECHHIDER = TechHider -SCOREBOARD_XRAY = XRay +SCOREBOARD_TECHHIDER = TechHider§8: §aOn +SCOREBOARD_XRAY = XRay§8: §aOn # Flags FLAG_COLOR = Color @@ -731,7 +731,7 @@ TPSLIMIT_INVALID_FROZEN = §c and '0' # Trace TRACE_RECORD=§aon -TRACE_IDLE=§coff +TRACE_HAS_TRACES=§ehas Traces TRACE_IDLE_SINGLE=§esingle TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) @@ -787,7 +787,6 @@ TRACE_GUI_POSITION_SOURCE = §7Source§8: §e{0} TRACE_GUI_POSITION_EXPLODED = §7Exploded§8: §e{0} # Loader -LOADER_OFF = §coff LOADER_SETUP = §eSetup LOADER_RUNNING = §aRunning LOADER_SINGLE_SIDEBAR = §aSingle diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ed657b0d..a4eae658 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -37,6 +37,9 @@ SCOREBOARD_TPS_FROZEN = §e Eingefroren SCOREBOARD_TRACE_TICKS = Ticks +SCOREBOARD_TECHHIDER = TechHider§8: §aAn +SCOREBOARD_XRAY = XRay§8: §aAn + # Flags FLAG_COLOR = Color FLAG_TNT = TNT @@ -701,7 +704,7 @@ TPSLIMIT_INVALID_FROZEN = §c und '0' # Trace TRACE_RECORD=§aan -TRACE_IDLE=§caus +TRACE_HAS_TRACES=§ehat Traces TRACE_IDLE_SINGLE=§esingle TRACE_IDLE_AUTO_EXPLODE=§eauto §8(§7explode§8) TRACE_IDLE_AUTO_IGNITE=§eauto §8(§7ignite§8) @@ -757,7 +760,6 @@ TRACE_GUI_POSITION_SOURCE = §7Ursprung§8: §e{0} TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0} # Loader -LOADER_OFF = §caus LOADER_SETUP = §eEinrichtung LOADER_RUNNING = §aLaufend LOADER_SINGLE_SIDEBAR = §aEiner diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 5d580005..85d2ef2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -49,7 +49,7 @@ public class Recorder implements Listener { INSTANCE = this; } - private static class NoopTraceRecorder implements TraceRecorder { + public static class NoopTraceRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { return null; @@ -82,7 +82,7 @@ public class Recorder implements Listener { private static class DisabledTracerRecorder implements TraceRecorder { @Override public String scoreboard(Player player) { - return BauSystem.MESSAGE.parse("TRACE_IDLE", player); + return null; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 2d170bda..eaebc5ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -8,6 +8,7 @@ import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; @@ -17,7 +18,6 @@ import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; -import de.steamwar.techhider.TechHider; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -89,22 +89,29 @@ public class BauScoreboard implements Listener { } strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); } + strings.add("§3"); + if (TechHiderCommand.isHidden(region, p)) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); } else if (XrayCommand.isHidden(region, p)) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); } - strings.add("§3"); String traceScore = recorder.get(region).scoreboard(p); if (traceScore != null) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); + } else if (!(recorder.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p)); } Loader loader = Loader.getLoader(p); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); + if (loader != null) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p)); + } - strings.add("§5"); + if (!strings.get(strings.size() - 1).equals("§3")) { + strings.add("§5"); + } if (FreezeUtils.frozen()) { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); } else { From 043b3860a0a350066dcdc450289894876bc30a97 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 14:30:29 +0200 Subject: [PATCH 085/174] Add better Scoreboard building Signed-off-by: yoyosource --- .../types/ScoreboardElement_GENERIC.java | 40 +++++ .../loader/LoaderScoreboardElement.java | 47 ++++++ .../features/region/FireListener.java | 20 ++- .../features/region/FreezeListener.java | 20 ++- .../features/region/ProtectListener.java | 21 ++- .../region/RegionScoreboardElement.java | 47 ++++++ .../features/region/TNTListener.java | 20 ++- .../features/techhider/TechHiderCommand.java | 29 ++-- .../tpslimit/TPSScoreboardElement.java | 68 ++++++++ .../tracer/TraceScoreboardElement.java | 53 ++++++ .../features/world/BauScoreboard.java | 153 +++++------------- .../bausystem/features/xray/XrayCommand.java | 29 ++-- .../steamwar/bausystem/region/flags/Flag.java | 16 +- .../bausystem/utils/ScoreboardElement.java | 37 +++++ .../utils/TimeScoreboardElement.java | 47 ++++++ 15 files changed, 498 insertions(+), 149 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java new file mode 100644 index 00000000..01e29833 --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java @@ -0,0 +1,40 @@ +/* + * 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.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 ScoreboardElement_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard"); + methodBuilder.addLine("BauScoreboard.ELEMENTS.add(" + s + ");"); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java new file mode 100644 index 00000000..847ed59b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.loader; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class LoaderScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + Loader loader = Loader.getLoader(p); + if (loader == null) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 43aaf626..56fd3232 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -1,16 +1,19 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockSpreadEvent; @Linked -public class FireListener implements Listener { +public class FireListener implements Listener, ScoreboardElement { @EventHandler public void onFireDamage(BlockBurnEvent e) { @@ -22,4 +25,19 @@ public class FireListener implements Listener { if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.DENY) e.setCancelled(true); } + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index f8e811aa..17e7dd43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -4,6 +4,7 @@ import de.steamwar.bausystem.BauSystem; 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.utils.ScoreboardElement; import de.steamwar.core.Core; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; @@ -11,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.Switch; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,7 +23,7 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; @Linked -public class FreezeListener implements Listener { +public class FreezeListener implements Listener, ScoreboardElement { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { @@ -182,4 +184,20 @@ public class FreezeListener implements Listener { event.setCancelled(true); } } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java index e52d1ebb..9b173359 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java @@ -1,11 +1,14 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; @@ -14,7 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.List; @Linked -public class ProtectListener implements Listener { +public class ProtectListener implements Listener, ScoreboardElement { private void explode(List blockList, Location location) { Region region = Region.getRegion(location); @@ -36,4 +39,20 @@ public class ProtectListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation()); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.PROTECT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.PROTECT).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java new file mode 100644 index 00000000..246b9a01 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class RegionScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (GlobalRegion.getInstance() == region) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 958471e2..945858f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.script.CustomScriptManager; import de.steamwar.bausystem.features.script.custom.event.EventType; import de.steamwar.bausystem.region.Region; @@ -27,6 +28,7 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; @@ -44,7 +46,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @Linked -public class TNTListener implements Listener { +public class TNTListener implements Listener, ScoreboardElement { @LinkedInstance public CustomScriptManager customScriptManager; @@ -88,4 +90,20 @@ public class TNTListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index e06724ba..b6c6975e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.techhider; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -41,7 +42,7 @@ import java.util.*; import java.util.stream.Collectors; @Linked -public class TechHiderCommand extends SWCommand implements Listener { +public class TechHiderCommand extends SWCommand implements Listener, ScoreboardElement { public TechHiderCommand() { super("techhider", "hider", "obfuscate", "hide", "hide-tech"); @@ -50,16 +51,6 @@ public class TechHiderCommand extends SWCommand implements Listener { private Map> techHiders = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static TechHiderCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public XrayCommand xrayCommand; @@ -124,4 +115,20 @@ public class TechHiderCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java new file mode 100644 index 00000000..f22660dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java @@ -0,0 +1,68 @@ +/* + * 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.tpslimit; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.core.TPSWatcher; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TPSScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.FOOTER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (FreezeUtils.frozen()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p); + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); + } + } + + private String tpsColor() { + double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { + return "§a"; + } + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { + return "§e"; + } + return "§c"; + } + + private String tpsLimit() { + if (TPSLimitUtils.getCurrentTPSLimit() == 20) { + return ""; + } + return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java new file mode 100644 index 00000000..5e955824 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -0,0 +1,53 @@ +/* + * 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; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TraceScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); + if (traceScore != null) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; + } else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); + } + return null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index eaebc5ed..6efda09f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -1,21 +1,11 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.bausystem.features.techhider.TechHiderCommand; -import de.steamwar.bausystem.features.tpslimit.FreezeUtils; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.show.StoredRecords; -import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.core.TPSWatcher; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.entity.Player; @@ -23,128 +13,65 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.text.SimpleDateFormat; import java.util.*; @Linked public class BauScoreboard implements Listener { - private static final Random RANDOM = new Random(); - private static final String ALL = "0123456789abcdef"; - - private static String getRandomColorCode() { - StringBuilder st = new StringBuilder(); - for (int i = 0; i < 6; i++) { - st.append("§" + ALL.charAt(RANDOM.nextInt(ALL.length()))); - } - return st.toString(); - } - - @LinkedInstance - public Recorder recorder; - - @LinkedInstance - public CustomScriptManager customScriptManager; + public static final List ELEMENTS = new ArrayList<>(); @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + Map> map = new HashMap<>(); + for (ScoreboardElement element : ELEMENTS) { + map.computeIfAbsent(element.getGroup(), scoreboardGroup -> new ArrayList<>()).add(element); + } + map.forEach((scoreboardGroup, scoreboardElements) -> { + scoreboardElements.sort(Comparator.comparingInt(ScoreboardElement::order)); + }); + SWScoreboard.createScoreboard(player, new ScoreboardCallback() { @Override public HashMap getData() { - return sidebar(player); + Region region = Region.getRegion(player.getLocation()); + + List elements = new ArrayList<>(); + calcGroup(elements, "§0", region, ScoreboardElement.ScoreboardGroup.HEADER); + calcGroup(elements, "§1", region, ScoreboardElement.ScoreboardGroup.REGION); + calcGroup(elements, "§2", region, ScoreboardElement.ScoreboardGroup.OTHER); + calcGroup(elements, "§3", region, ScoreboardElement.ScoreboardGroup.FOOTER); + + int i = elements.size(); + HashMap result = new HashMap<>(); + for (String s : elements) { + result.put(s, i--); + } + return result; + } + + private void calcGroup(List elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) { + if (map.containsKey(group)) { + List groupElements = new ArrayList<>(); + for (ScoreboardElement element : map.get(group)) { + groupElements.add(element.get(region, player)); + } + groupElements.removeIf(Objects::isNull); + if (!groupElements.isEmpty()) { + elements.add(separator); + elements.addAll(groupElements); + } + } } @Override public String getTitle() { - // ■ Region region = Region.getRegion(player.getLocation()); - if (GlobalRegion.getInstance() == region) { - return "§eSteam§8War"; - } + if (GlobalRegion.getInstance() == region) return "§eSteam§8War"; String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), player).substring(0, 2); - return colorCode + "■ §eSteam§8War " + colorCode + "■"; + return colorCode + "■ §eSteam§8War " + colorCode + "■"; // ■ } }); } - - private HashMap sidebar(Player p) { - Region region = Region.getRegion(p.getLocation()); - - List strings = new ArrayList<>(); - if (!customScriptManager.callScoreboard(p, new HashMap<>(), strings::add)) { - // String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), p).substring(0, 2); - String colorCode = "§e"; - strings.add("§1"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime())); - if (GlobalRegion.getInstance() != region) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName()); - } - - strings.add("§2"); - for (Flag flag : Flag.getFlags()) { - if (!flag.getRegionPredicate().test(region)) { - continue; - } - strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); - } - strings.add("§3"); - - if (TechHiderCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); - } else if (XrayCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); - } - - String traceScore = recorder.get(region).scoreboard(p); - if (traceScore != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); - } else if (!(recorder.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p)); - } - - Loader loader = Loader.getLoader(p); - if (loader != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p)); - } - - if (!strings.get(strings.size() - 1).equals("§3")) { - strings.add("§5"); - } - if (FreezeUtils.frozen()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); - } else { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); - } - } - - int i = strings.size(); - HashMap result = new HashMap<>(); - for (String s : strings) { - if (s.isEmpty()) { - s = getRandomColorCode(); - } - result.put(s, i--); - } - return result; - } - - private String tpsColor() { - double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { - return "§a"; - } - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { - return "§e"; - } - return "§c"; - } - - private String tpsLimit() { - if (TPSLimitUtils.getCurrentTPSLimit() == 20) { - return ""; - } - return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 9418a7e1..1a9387c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -47,7 +48,7 @@ import java.util.*; import java.util.function.BiFunction; @Linked -public class XrayCommand extends SWCommand implements Listener { +public class XrayCommand extends SWCommand implements Listener, ScoreboardElement { public XrayCommand() { super("xray"); @@ -57,16 +58,6 @@ public class XrayCommand extends SWCommand implements Listener { private Map> xrayedBlocks = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static XrayCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public TechHiderCommand techHiderCommand; @@ -176,4 +167,20 @@ public class XrayCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 800c7a77..0c45d1ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -19,23 +19,21 @@ package de.steamwar.bausystem.region.flags; -import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; import java.util.EnumSet; import java.util.Set; -import java.util.function.Predicate; @Getter public enum Flag implements EnumDisplay { - COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, region -> false), - TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, region -> true), - FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true), - FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, region -> region.getFloorLevel() != 0); + COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW), + TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), + FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), + FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); @Getter private static final Set flags; @@ -48,14 +46,12 @@ public enum Flag implements EnumDisplay { private final Class> valueType; private final Flag.Value defaultValue; private final Value[] values; - private final Predicate regionPredicate; - & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue, Predicate regionPredicate) { + & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue) { this.chatValue = chatValue; this.valueType = valueType; this.defaultValue = defaultValue; this.values = defaultValue.getValues(); - this.regionPredicate = regionPredicate; } public Value getFlagValueOf(final String name) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java new file mode 100644 index 00000000..5f573322 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java @@ -0,0 +1,37 @@ +/* + * 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.utils; + +import de.steamwar.bausystem.region.Region; +import org.bukkit.entity.Player; + +public interface ScoreboardElement { + ScoreboardGroup getGroup(); + int order(); + + String get(Region region, Player p); + + enum ScoreboardGroup { + HEADER, + REGION, + OTHER, + FOOTER + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java new file mode 100644 index 00000000..d3ca0fea --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * 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.utils; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Linked +public class TimeScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime()); + } +} From d0ab735bbf9049bb6bec30bb165c973595ef2872 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 15:06:15 +0200 Subject: [PATCH 086/174] Hotfix stuff Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../src/de/steamwar/bausystem/features/region/FireListener.java | 1 - .../de/steamwar/bausystem/features/region/FreezeListener.java | 1 - .../src/de/steamwar/bausystem/features/region/TNTListener.java | 1 - 5 files changed, 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 320cd623..d71c6aaf 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -606,7 +606,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_6 = §7z§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator SIMULATOR_GUI_DELETE = §cDelete TNT -SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a4eae658..9ac07bd8 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -589,7 +589,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Elementanzahl§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Kanonensimulator SIMULATOR_GUI_DELETE = §cTNT löschen -SIMULATOR_GUI_START = §eStarten SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eAlle Verschieben diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 56fd3232..afe30aa1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -37,7 +37,6 @@ public class FireListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index 17e7dd43..d810ce61 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -197,7 +197,6 @@ public class FreezeListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 945858f6..08309eb6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -103,7 +103,6 @@ public class TNTListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); } } From 35f882c1239fbbd8d773b91f5046b6ce14441ec7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 16:39:00 +0200 Subject: [PATCH 087/174] Update Loader Signed-off-by: yoyosource --- .../bausystem/features/loadern/LoaderRecorder.java | 2 +- .../loadern/elements/impl/LoaderComparator.java | 10 +++++----- .../features/loadern/elements/impl/LoaderLectern.java | 2 +- .../features/loadern/elements/impl/LoaderMovement.java | 3 ++- .../loadern/elements/impl/LoaderNoteBlock.java | 4 ++-- .../features/loadern/elements/impl/LoaderRepeater.java | 10 +++++----- .../features/loadern/elements/impl/LoaderTicks.java | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 329cfd55..04eb1c11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -138,7 +138,7 @@ public class LoaderRecorder implements Listener { public void onPlayerMove(PlayerMoveEvent event) { if (event.getPlayer() != player) return; - Block fromBlock = event.getTo().getBlock(); + Block fromBlock = event.getFrom().getBlock(); Block toBlock = event.getTo().getBlock(); calcMovementBlocks(fromBlock, toBlock); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index d92ea4ad..1205e4bf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -82,15 +82,15 @@ public class LoaderComparator extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(2, item(player, true, null).getItemStack(), clickType -> { - interact = true; - click(player, backAction, deleteAction); - }); - swInventory.setItem(3, item(player, false, null).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> { interact = false; mode = null; click(player, backAction, deleteAction); }); + swInventory.setItem(3, item(player, true, null).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> { interact = false; mode = Comparator.Mode.COMPARE; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java index 033d936a..5df1594d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -94,7 +94,7 @@ public class LoaderLectern extends LoaderInteractionElement backAction.run()); swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index ee1f11ac..176ffd19 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -50,6 +50,7 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java index 5f062f87..53811035 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -79,11 +79,11 @@ public class LoaderNoteBlock extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, false).getItemStack(), clickType -> { interact = false; click(player, backAction, deleteAction); }); - swInventory.setItem(5, item(player, true).getItemStack(), clickType -> { + swInventory.setItem(3, item(player, true).getItemStack(), clickType -> { interact = true; click(player, backAction, deleteAction); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java index a0e50e48..102ee35c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -86,15 +86,15 @@ public class LoaderRepeater extends LoaderInteractionElement backAction.run()); swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(1, item(player, true, -1).getItemStack(), clickType -> { - interact = true; - click(player, backAction, deleteAction); - }); - swInventory.setItem(2, item(player, false, 0).getItemStack(), clickType -> { + swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> { interact = false; delay = 0; click(player, backAction, deleteAction); }); + swInventory.setItem(2, item(player, true, -1).getItemStack(), clickType -> { + interact = true; + click(player, backAction, deleteAction); + }); swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> { interact = false; delay = 1; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 8e203d7d..5b615f20 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -128,7 +128,7 @@ public class LoaderTicks extends LoaderInteractionElement backAction.run()); swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); - swInventory.setItem(3, item(player, true, false).getItemStack(), clickType -> { + swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; click(player, backAction, deleteAction); }); From 7e78c2890a0ce1cd91b04d79b74480dfec518a18 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 16:59:06 +0200 Subject: [PATCH 088/174] Update loader and remove old one Signed-off-by: yoyosource --- .../bausystem/features/loader/Loader.java | 244 ------------------ .../features/loader/LoaderBauGuiItem.java | 107 -------- .../features/loader/LoaderButton.java | 71 ----- .../features/loader/LoaderCommand.java | 160 ------------ .../activations/AbstractLoaderActivation.java | 36 --- .../BlockPlaceLoaderActivation.java | 57 ---- .../activations/InteractionActivation.java | 174 ------------- .../bausystem/features/loadern/Loader.java | 18 +- .../LoaderScoreboardElement.java | 2 +- .../loadern/elements/impl/LoaderWait.java | 5 +- 10 files changed, 17 insertions(+), 857 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java rename BauSystem_Main/src/de/steamwar/bausystem/features/{loader => loadern}/LoaderScoreboardElement.java (96%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java deleted file mode 100644 index 6cba6fe9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java +++ /dev/null @@ -1,244 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation; -import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation; -import de.steamwar.bausystem.features.loader.activations.InteractionActivation; -import de.steamwar.bausystem.shared.EnumDisplay; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.scheduler.BukkitTask; - -import java.util.*; - -@Getter -@Setter -public class Loader implements Listener { - - private static final Map LOADER_MAP = new HashMap<>(); - private final Player p; - private final List actions = new LinkedList<>(); - private int ticksBetweenShots = 80; - private int ticksBetweenBlocks = 1; - private Stage stage; - private int lastActivation = -1; - private int countdown = 0; - - @Getter(AccessLevel.PRIVATE) - private final BukkitTask task; - - @Getter(AccessLevel.PRIVATE) - @Setter(AccessLevel.PRIVATE) - private AbstractLoaderActivation current; - - @Getter(AccessLevel.PRIVATE) - @Setter(AccessLevel.PRIVATE) - private ListIterator iterator; - - private Loader(Player p) { - this.p = p; - stage = Stage.SETUP; - Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); - task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1); - } - - public static Loader getLoader(Player p) { - return LOADER_MAP.getOrDefault(p, null); - } - - public static Loader newLoader(Player p) { - return LOADER_MAP.put(p, new Loader(p)); - } - - public void start() { - if (stage != Stage.SETUP) return; - iterator = actions.listIterator(); - countdown = 0; - current = null; - stage = Stage.RUNNING; - } - - public void pause() { - if (stage == Stage.RUNNING) { - stage = Stage.PAUSE; - } - } - - public void resume() { - if (stage == Stage.PAUSE) { - stage = Stage.RUNNING; - } - } - - public void setup() { - stage = Stage.SETUP; - iterator = null; - current = null; - countdown = 0; - } - - public void stop() { - stage = Stage.END; - task.cancel(); - LOADER_MAP.remove(p, this); - } - - public void clear() { - if (stage == Stage.SETUP) { - actions.clear(); - BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR", p); - } else { - BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR_HELP", p); - } - } - - public void single() { - if (stage != Stage.PAUSE && stage != Stage.SETUP) return; - if (iterator == null || !iterator.hasNext()) { - iterator = actions.listIterator(); - countdown = 0; - current = null; - } - stage = Stage.SINGLE; - } - - public void run() { - if (stage == Stage.SETUP && lastActivation >= 0) - lastActivation++; - - if (stage != Stage.RUNNING && stage != Stage.SINGLE) { - return; - } - - if (countdown-- > 0) { - return; - } - - while (countdown <= 0) { - if (!iterator.hasNext()) { - countdown = getTicksBetweenShots(); - iterator = actions.listIterator(); - if (stage == Stage.SINGLE) stage = Stage.PAUSE; - return; - } - - current = iterator.next(); - - if (current.execute()) { - countdown = current.delay(this); - } else { - countdown = 1; - iterator.previous(); - } - } - } - - public void undo() { - if (actions.isEmpty() || stage != Stage.SETUP) { - return; - } - actions.remove(actions.size() - 1); - } - - @EventHandler - public void onBlockPlace(BlockPlaceEvent event) { - if (event.getPlayer() != p) { - return; - } - - if (stage != Stage.SETUP) { - return; - } - - if (event.getBlock().getType() != Material.TNT) { - return; - } - - actions.add(new BlockPlaceLoaderActivation(p, event.getBlock().getLocation(), Material.TNT)); - SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_TNT", p, actions.size())); - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent event) { - if (event.getPlayer() != p) { - return; - } - - if (stage != Stage.SETUP) { - return; - } - - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) - return; - - if (event.getClickedBlock().getType() == Material.OBSERVER) - return; - - if (event.getHand() == EquipmentSlot.OFF_HAND) { - return; - } - - if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) { - return; - } - - LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock()); - if (button != LoaderButton.INVALID) { - actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this)); - lastActivation = 0; - SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", p, BauSystem.MESSAGE.parse(button.getName(), p), actions.size())); - } - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - if (event.getPlayer() != p) { - return; - } - stop(); - } - - @AllArgsConstructor - public enum Stage implements EnumDisplay { - SETUP("LOADER_SETUP"), - RUNNING("LOADER_RUNNING"), - SINGLE("LOADER_SINGLE_SIDEBAR"), - PAUSE("LOADER_PAUSE"), - END("LOADER_END"); - - @Getter - private String chatValue; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java deleted file mode 100644 index 55370c3f..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderBauGuiItem.java +++ /dev/null @@ -1,107 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.linkage.specific.BauGuiItem; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -import java.util.Arrays; - -@Linked -public class LoaderBauGuiItem extends BauGuiItem { - - public LoaderBauGuiItem() { - super(9); - } - - @Override - public ItemStack getItem(Player player) { - return SWUtils.setCustomModelData(new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", player)), 1).getItemStack(); - } - - @Override - public boolean click(ClickType click, Player p) { - p.closeInventory(); - openLoaderGui(p); - return false; - } - - private void openLoaderGui(Player p) { - SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", p)); - if (Loader.getLoader(p) == null) { - inv.setItem(4, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("LOADER_GUI_NEW", p), clickType -> { - p.closeInventory(); - p.performCommand("loader setup"); - })); - } else { - Loader loader = Loader.getLoader(p); - if (loader.getStage() != Loader.Stage.RUNNING) { - inv.setItem(0, new SWItem(Material.GREEN_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_START", p), clickType -> { - p.closeInventory(); - p.performCommand("loader start"); - })); - } else { - inv.setItem(0, new SWItem(Material.RED_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_PAUSE", p), clickType -> { - p.closeInventory(); - p.performCommand("loader pause"); - })); - } - inv.setItem(2, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_UNDO", p), clickType -> { - p.closeInventory(); - p.performCommand("loader undo"); - })); - inv.setItem(4, new SWItem(Material.COMPASS, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_LORE", p, loader.getTicksBetweenShots())), false, clickType -> { - p.closeInventory(); - SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", p)); - anvilInv.setItem(Material.CLOCK); - anvilInv.setCallback(s -> p.performCommand("loader delay " + s)); - anvilInv.open(); - })); - inv.setItem(6, new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_LORE", p, loader.getTicksBetweenBlocks())), false, clickType -> { - p.closeInventory(); - SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_TITLE", p)); - anvilInv.setItem(Material.CLOCK); - anvilInv.setCallback(s -> p.performCommand("loader speed " + s)); - anvilInv.open(); - })); - inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_STOP", p), clickType -> { - p.closeInventory(); - p.performCommand("loader stop"); - })); - } - inv.open(); - } - - @Override - public Permission permission() { - return Permission.WORLD; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java deleted file mode 100644 index 4a1d5159..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ /dev/null @@ -1,71 +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.loader; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.bukkit.block.Block; - - -@AllArgsConstructor -@RequiredArgsConstructor -@Getter -public enum LoaderButton { - SWITCH(0, true, "LOADER_BUTTON_SWITCH"), - WOOD_BUTTON(30, "LOADER_BUTTON_WOOD_BUTTON"), - STONE_BUTTON(20, "LOADER_BUTTON_STONE_BUTTON"), - PRESSURE_PLATE(30, "LOADER_BUTTON_PRESSURE_PLATE"), - WEIGHTED_PRESSURE_PLATE(20, "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"), - TRIPWIRE(30, "LOADER_BUTTON_TRIPWIRE"), - NOTEBLOCK(1, "LOADER_BUTTON_NOTEBLOCK"), - DAYLIGHTSENSOR(0, true, "LOADER_BUTTON_DAYLIGHTSENSOR"), - INVALID(-1, "LOADER_BUTTON_INVALID"); - - private final int time; - private boolean toggle; - private final String name; - - public static LoaderButton fromBlock(Block block) { - switch (block.getType()) { - case LEVER: - return LoaderButton.SWITCH; - case TRIPWIRE: - return LoaderButton.TRIPWIRE; - case NOTE_BLOCK: - return LoaderButton.NOTEBLOCK; - case DAYLIGHT_DETECTOR: - return LoaderButton.DAYLIGHTSENSOR; - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - return LoaderButton.WEIGHTED_PRESSURE_PLATE; - default: - if (block.getType().name().contains("STONE_BUTTON")) { - return LoaderButton.STONE_BUTTON; - } else if (block.getType().name().contains("BUTTON")) { - return LoaderButton.WOOD_BUTTON; - } else if (block.getType().name().contains("PRESSURE_PLATE")) { - return LoaderButton.PRESSURE_PLATE; - } else { - return LoaderButton.INVALID; - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java deleted file mode 100644 index 95fa92b6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ /dev/null @@ -1,160 +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.loader; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeValidator; -import de.steamwar.linkage.Linked; -import org.bukkit.entity.Player; - -// @Linked -public class LoaderCommand extends SWCommand { - - public LoaderCommand() { - super("loader", "autoloader", "al"); - addDefaultHelpMessage("LOADER_HELP_OTHER"); - } - - private boolean loaderNullCheck(Loader loader, Player p) { - if (loader == null) { - BauSystem.MESSAGE.send("LOADER_NO_LOADER", p); - return true; - } - return false; - } - - @Register(value = "setup", description = "LOADER_HELP_SETUP") - public void setupLoader(@Validator Player p) { - if (Loader.getLoader(p) != null) { - Loader.getLoader(p).setup(); - BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p); - } else { - Loader.newLoader(p); - BauSystem.MESSAGE.send("LOADER_NEW", p); - BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p); - } - } - - @Register(value = "start", description = "LOADER_HELP_START") - public void startLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.start(); - BauSystem.MESSAGE.send("LOADER_ACTIVE", p); - } - - @Register(value = "stop", description = "LOADER_HELP_STOP") - public void stopLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.stop(); - BauSystem.MESSAGE.send("LOADER_STOP", p); - } - - @Register(value = "pause", description = "LOADER_HELP_PAUSE") - public void pauseLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.pause(); - BauSystem.MESSAGE.send("LOADER_PAUSED", p); - } - - @Register(value = "resume", description = "LOADER_HELP_RESUME") - public void resumeLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.resume(); - BauSystem.MESSAGE.send("LOADER_RESUME", p); - } - - @Register(value = "wait", description = "LOADER_HELP_WAIT") - public void shotDelayLoader(@Validator Player p, int delay) { - if (delay < 1) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots()); - loader.setTicksBetweenShots(delay); - } - - @Register(value = "speed", description = "LOADER_HELP_SPEED") - public void speedLoader(@Validator Player p, int delay) { - if (delay < 0) { - BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p); - return; - } - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks()); - loader.setTicksBetweenBlocks(delay); - } - - @Register(value = "undo", description = "LOADER_HELP_UNDO") - public void undoLast(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - BauSystem.MESSAGE.send("LOADER_UNDO", p); - loader.undo(); - } - - @Register(value = "clear", description = "LOADER_HELP_CLEAR") - public void clearLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.clear(); - } - - @Register(value = "single", description = "LOADER_HELP_SINGLE") - public void singleLoader(@Validator Player p) { - Loader loader = Loader.getLoader(p); - if (loaderNullCheck(loader, p)) { - return; - } - loader.single(); - BauSystem.MESSAGE.send("LOADER_SINGLE", p); - } - - @ClassValidator(value = Player.class, local = true) - public TypeValidator loaderValidator() { - return (commandSender, player, messageSender) -> { - return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "LOADER_PERMS"); - }; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java deleted file mode 100644 index 7c4d4768..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/AbstractLoaderActivation.java +++ /dev/null @@ -1,36 +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.loader.activations; - -import de.steamwar.bausystem.features.loader.Loader; -import org.bukkit.entity.Player; - -public abstract class AbstractLoaderActivation { - - Player p; - - public AbstractLoaderActivation(Player p) { - this.p = p; - } - - public abstract boolean execute(); - - public abstract int delay(Loader loader); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java deleted file mode 100644 index 910f2071..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/BlockPlaceLoaderActivation.java +++ /dev/null @@ -1,57 +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.loader.activations; - -import de.steamwar.bausystem.features.loader.Loader; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -public class BlockPlaceLoaderActivation extends AbstractLoaderActivation { - - private final Location location; - private final Material material; - - public BlockPlaceLoaderActivation(Player p, Location location, Material material) { - super(p); - this.location = location; - if (!material.isBlock()) { - throw new IllegalStateException("Only Blocks, " + material.name() + " is not a Block"); - } - this.material = material; - } - - @Override - public boolean execute() { - Block currBlock = location.getBlock(); - if (currBlock.getType() != Material.AIR && currBlock.getType() != Material.WATER) { - return false; - } - - currBlock.setType(material, true); - return true; - } - - @Override - public int delay(Loader loader) { - return loader.getTicksBetweenBlocks(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java deleted file mode 100644 index c7f27bd3..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/activations/InteractionActivation.java +++ /dev/null @@ -1,174 +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.loader.activations; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.loader.LoaderButton; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.data.*; -import org.bukkit.block.data.type.DaylightDetector; -import org.bukkit.block.data.type.Switch; -import org.bukkit.entity.Player; - -public abstract class InteractionActivation extends AbstractLoaderActivation { - - Location location; - LoaderButton button; - - InteractionActivation(Player p, Location location, LoaderButton button) { - super(p); - this.location = location; - this.button = button; - } - - public static InteractionActivation construct(Player p, Location location, Loader loader) { - LoaderButton button = LoaderButton.fromBlock(location.getBlock()); - if (button.isToggle()) { - return new ToggleActivation(p, location, button, loader.getLastActivation()); - } else { - return new TimedActivation(p, location, button); - } - } - - void updateButton() { - Block block = location.getBlock(); - if (block.getBlockData() instanceof Switch) { - Switch sw = (Switch) block.getBlockData(); - FaceAttachable.AttachedFace face = sw.getAttachedFace(); - if (face == FaceAttachable.AttachedFace.FLOOR) { - update(block.getRelative(BlockFace.DOWN)); - } else if (face == FaceAttachable.AttachedFace.CEILING) { - update(block.getRelative(BlockFace.UP)); - } else { - update(block.getRelative(sw.getFacing().getOppositeFace())); - } - } else if (button == LoaderButton.TRIPWIRE) { - update(block); - } else if (button == LoaderButton.PRESSURE_PLATE || button == LoaderButton.WEIGHTED_PRESSURE_PLATE) { - update(block.getRelative(BlockFace.DOWN)); - } - } - - void update(Block block) { - BlockData data = block.getBlockData(); - block.setType(Material.BARRIER, true); - block.setBlockData(data, true); - } - - boolean getBlockPower() { - Block block = location.getBlock(); - BlockData data = block.getBlockData(); - if (data instanceof Powerable) { - Powerable pow = (Powerable) data; - return pow.isPowered(); - } - if (data instanceof DaylightDetector) { - DaylightDetector detector = (DaylightDetector) data; - return detector.isInverted(); - } - if (data instanceof AnaloguePowerable) { - AnaloguePowerable powerable = (AnaloguePowerable) data; - return powerable.getPower() > 0; - } - return false; - } - - void setBlockPower(boolean state) { - Block block = location.getBlock(); - BlockData data = block.getBlockData(); - if (data instanceof Powerable) { - Powerable pow = (Powerable) data; - pow.setPowered(state); - } - if (data instanceof Openable) { - Openable openable = (Openable) data; - openable.setOpen(state); - } - if (data instanceof DaylightDetector) { - DaylightDetector detector = (DaylightDetector) data; - detector.setInverted(state); - } - if (data instanceof AnaloguePowerable) { - AnaloguePowerable powerable = (AnaloguePowerable) data; - if (block.getType() == Material.REDSTONE_WIRE) { - powerable.setPower(state ? 15 : 0); - } else { - powerable.setPower(state ? 1 : 0); - } - } - block.setBlockData(data); - } - - public static class ToggleActivation extends InteractionActivation { - - private final int delay; - - public ToggleActivation(Player p, Location location, LoaderButton button, int delay) { - super(p, location, button); - this.delay = Math.max(delay, 0); - } - - @Override - public boolean execute() { - if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) - return false; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(!getBlockPower()); - updateButton(); - }, delay); - return true; - } - - @Override - public int delay(Loader loader) { - return delay; - } - } - - public static class TimedActivation extends InteractionActivation { - - public TimedActivation(Player p, Location location, LoaderButton button) { - super(p, location, button); - } - - @Override - public boolean execute() { - if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID) - return false; - setBlockPower(true); - updateButton(); - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - setBlockPower(false); - updateButton(); - }, button.getTime()); - return true; - } - - @Override - public int delay(Loader loader) { - return button.getTime(); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 01d56d04..d1eef52d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -21,7 +21,10 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.inventory.SWListInv; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -47,6 +50,7 @@ public class Loader implements Listener { private final Player p; + @Getter private Stage stage = Stage.SETUP; private LoaderRecorder recorder; @@ -121,10 +125,14 @@ public class Loader implements Listener { stop(); } - public enum Stage { - SETUP, - RUNNING, - PAUSE, - END + @AllArgsConstructor + public enum Stage implements EnumDisplay { + SETUP("LOADER_SETUP"), + RUNNING("LOADER_RUNNING"), + PAUSE("LOADER_PAUSE"), + END("LOADER_END"); + + @Getter + private String chatValue; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index 847ed59b..d0b41cc0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loader; +package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index ad84fa21..67875b2b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -59,8 +59,9 @@ public class LoaderWait implements LoaderElement, Listener { @Override public void click(Player player, Runnable backAction) { - SWInventory swInventory = new SWInventory(player, 9, "Wartezeit"); - swInventory.setItem(0, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + SWInventory swInventory = new SWInventory(player, 18, "Wartezeit"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; From 792f16fadf0a4329250f6df6660e0eb36c0d5cec Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 17:13:15 +0200 Subject: [PATCH 089/174] Update Loader Signed-off-by: yoyosource --- .../bausystem/features/loadern/Loader.java | 41 ++++++++++++++++--- .../features/loadern/LoaderCommand.java | 2 +- .../elements/LoaderInteractionElement.java | 1 - .../features/script/variables/Constants.java | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index d1eef52d..40c3f750 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -21,11 +21,15 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; +import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; +import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.AllArgsConstructor; import lombok.Getter; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -109,14 +113,36 @@ public class Loader implements Listener { LOADER_MAP.remove(p); } - public void settings() { + public void settings(SettingsSorting settingsSorting) { List> list = new ArrayList<>(); for (LoaderElement element : elements) { + if (settingsSorting != null) { + if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) { + continue; + } + if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) { + continue; + } + } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { - entry.click(p, this::settings); - }).open(); + SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { + entry.click(p, () -> settings(settingsSorting)); + }); + + SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { + settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); + }); + if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); + swListInv.setItem(48, onlyWaitElements); + + SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> { + settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); + }); + if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); + swListInv.setItem(50, onlyInteractionsElements); + + swListInv.open(); } @EventHandler @@ -125,6 +151,11 @@ public class Loader implements Listener { stop(); } + public enum SettingsSorting { + WAIT, + INTERACTIONS, + } + @AllArgsConstructor public enum Stage implements EnumDisplay { SETUP("LOADER_SETUP"), @@ -133,6 +164,6 @@ public class Loader implements Listener { END("LOADER_END"); @Getter - private String chatValue; + private final String chatValue; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 6539d16a..b2d7a2b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -80,7 +80,7 @@ public class LoaderCommand extends SWCommand { public void settingsLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; - loader.settings(); + loader.settings(null); } @ClassValidator(value = Player.class, local = true) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 7785f07b..8397779a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.features.loadern.elements; -import de.steamwar.bausystem.features.loader.LoaderButton; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index e0ec0872..10d4a75d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.loadern.Loader; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; From b1dcd6d57bf7e2ddb7efb7e48addcac2caeb6876 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 18:00:54 +0200 Subject: [PATCH 090/174] Update Loader and fix many things Signed-off-by: yoyosource --- .../bausystem/features/loadern/Loader.java | 18 ++++- .../loadern/LoaderScoreboardElement.java | 6 +- .../elements/LoaderInteractionElement.java | 17 +++-- .../elements/impl/LoaderDaylightDetector.java | 2 +- .../loadern/elements/impl/LoaderLever.java | 2 +- .../loadern/elements/impl/LoaderMovement.java | 18 +++-- .../loadern/elements/impl/LoaderTicks.java | 74 ++++--------------- .../loadern/elements/impl/LoaderWait.java | 2 + 8 files changed, 62 insertions(+), 77 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 40c3f750..0560f1a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -60,6 +60,7 @@ public class Loader implements Listener { private List elements = new ArrayList<>(); private int currentElement = 0; + private long totalDelay = 0; public Loader(Player p) { this.p = p; @@ -71,9 +72,18 @@ public class Loader implements Listener { currentElement++; if (currentElement >= elements.size()) { currentElement = 0; + if (totalDelay == 0) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1); + return; + } + totalDelay = 0; } if (stage == Stage.RUNNING) { - elements.get(currentElement).execute(this::next); + LoaderElement element = elements.get(currentElement); + if (element instanceof LoaderWait) { + totalDelay += ((LoaderWait) element).getDelay(); + } + element.execute(this::next); } } @@ -136,7 +146,7 @@ public class Loader implements Listener { if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); - SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> { + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); }); if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); @@ -151,6 +161,10 @@ public class Loader implements Listener { stop(); } + public String getProgress() { + return "§7" + (currentElement + 1) + "§8/§7" + elements.size(); + } + public enum SettingsSorting { WAIT, INTERACTIONS, diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index d0b41cc0..dd0a59c5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -42,6 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement { public String get(Region region, Player p) { Loader loader = Loader.getLoader(p); if (loader == null) return null; - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)"; + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 8397779a..948a3e1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -86,10 +86,12 @@ public abstract class LoaderInteractionElement implem listInv.open(); } - protected void update(Block block) { - Material material = block.getType(); - if (block.getBlockData() instanceof Switch) { - Switch sw = (Switch) block.getBlockData(); + protected void update(BlockData blockData) { + Material material = blockData.getMaterial(); + Block block = location.getBlock(); + if (blockData instanceof Switch) { + Switch sw = (Switch) blockData; + updateBlock(block, sw); FaceAttachable.AttachedFace face = sw.getAttachedFace(); if (face == FaceAttachable.AttachedFace.FLOOR) { updateBlock(block.getRelative(BlockFace.DOWN)); @@ -99,14 +101,17 @@ public abstract class LoaderInteractionElement implem updateBlock(block.getRelative(sw.getFacing().getOppositeFace())); } } else if (material == Material.TRIPWIRE) { - updateBlock(block); + updateBlock(block, blockData); } else if (material.name().endsWith("_PLATE")) { updateBlock(block.getRelative(BlockFace.DOWN)); } } protected void updateBlock(Block block) { - BlockData data = block.getBlockData(); + updateBlock(block, block.getBlockData()); + } + + protected void updateBlock(Block block, BlockData data) { block.setType(Material.BARRIER, true); block.setBlockData(data, true); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index cbdcc7dc..d78e6319 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -76,7 +76,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement= 0) { boolean finalWaitFor = waitFor; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); + AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData; + analoguePowerable.setPower(0); + location.getBlock().setBlockData(analoguePowerable, true); } else { - ((Powerable) blockData).setPowered(false); + Powerable powerable = (Powerable) blockData; + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); if (finalWaitFor) { nextAction.run(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 5b615f20..0bdb5228 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -27,8 +27,6 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.block.data.AnaloguePowerable; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Powerable; import org.bukkit.entity.Player; @@ -39,22 +37,19 @@ public class LoaderTicks extends LoaderInteractionElement 0); - } else { - powerable.setPowered(true); - } - } + Powerable powerable = (Powerable) location.getBlock().getBlockData(); + powerable.setPowered(true); + location.getBlock().setBlockData(powerable, true); - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (ticks >= 0) { - boolean finalWaitFor = waitFor; - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - if (blockData instanceof AnaloguePowerable) { - ((AnaloguePowerable) blockData).setPower(0); - } else { - ((Powerable) blockData).setPowered(false); - } - location.getBlock().setBlockData(blockData); - update(location.getBlock()); - if (finalWaitFor) { - nextAction.run(); - } - }, ticks); - if (!finalWaitFor) { + boolean finalWaitFor = waitFor; + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + powerable.setPowered(false); + location.getBlock().setBlockData(powerable, true); + if (finalWaitFor) { nextAction.run(); } + }, ticks); + if (!finalWaitFor) { + nextAction.run(); } } @Override public void click(Player player, Runnable backAction, Runnable deleteAction) { - SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings"); - for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); - swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + SWInventory swInventory = new SWInventory(player, 18, "Settings"); + for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); + swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; @@ -145,18 +122,6 @@ public class LoaderTicks extends LoaderInteractionElement= 9) finalI2++; - swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> { - power = finalI; - click(player, backAction, deleteAction); - }); - } - } - swInventory.open(); } @@ -168,13 +133,6 @@ public class LoaderTicks extends LoaderInteractionElement Date: Mon, 1 May 2023 18:10:32 +0200 Subject: [PATCH 091/174] Fix LoaderMovement Signed-off-by: yoyosource --- .../features/loadern/elements/impl/LoaderMovement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index e931ea50..0ca03583 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -84,7 +84,7 @@ public class LoaderMovement extends LoaderInteractionElement Date: Mon, 1 May 2023 20:17:30 +0200 Subject: [PATCH 092/174] Update scoreboard Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/loadern/Loader.java | 7 +++---- .../features/loadern/LoaderScoreboardElement.java | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 0560f1a6..06dffc03 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -136,9 +136,8 @@ public class Loader implements Listener { } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, entry) -> { - entry.click(p, () -> settings(settingsSorting)); - }); + SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); + swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); @@ -162,7 +161,7 @@ public class Loader implements Listener { } public String getProgress() { - return "§7" + (currentElement + 1) + "§8/§7" + elements.size(); + return (currentElement + 1) + "§8/§7" + elements.size(); } public enum SettingsSorting { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java index dd0a59c5..e9fc9004 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java @@ -42,8 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement { public String get(Region region, Player p) { Loader loader = Loader.getLoader(p); if (loader == null) return null; - if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) { - return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)"; + if (loader.getStage() == Loader.Stage.RUNNING) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §a" + loader.getProgress(); + } else if (loader.getStage() == Loader.Stage.PAUSE) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §c" + loader.getProgress(); } else { return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); } From 6e82b57fbf8f9ef5a719a2faa3a5248370245a88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 16:51:14 +0200 Subject: [PATCH 093/174] Fix some stuff and add lores Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 32 ++++++----------- BauSystem_Main/src/BauSystem_de.properties | 32 ++++++----------- .../features/loadern/LoaderCommand.java | 2 +- .../features/loadern/LoaderRecorder.java | 36 ++++++++++++++----- .../loadern/elements/impl/LoaderMovement.java | 8 +++-- .../loadern/elements/impl/LoaderOpenable.java | 1 - .../loadern/elements/impl/LoaderTicks.java | 2 ++ .../loadern/elements/impl/LoaderWait.java | 4 +-- 8 files changed, 61 insertions(+), 56 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d71c6aaf..7d3618d3 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -788,47 +788,36 @@ TRACE_GUI_POSITION_EXPLODED = §7Exploded§8: §e{0} # Loader LOADER_SETUP = §eSetup LOADER_RUNNING = §aRunning -LOADER_SINGLE_SIDEBAR = §aSingle LOADER_PAUSE = §7Pause LOADER_END = §8Finished -LOADER_MESSAGE_CLEAR = §7Loader cleared -LOADER_MESSAGE_CLEAR_HELP = §cYou have to be in Setup-Mode to clear the Loader -LOADER_MESSAGE_TNT = §eTNT added {0} LOADER_MESSAGE_INTERACT = §e{0} added {1} +LOADER_BUTTON_TNT = TNT LOADER_BUTTON_SWITCH=Lever -LOADER_BUTTON_WOOD_BUTTON=Button -LOADER_BUTTON_STONE_BUTTON=Button +LOADER_BUTTON_WOOD_BUTTON=Wooden Button +LOADER_BUTTON_STONE_BUTTON=Stone Button LOADER_BUTTON_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_DAYLIGHTSENSOR=Daylightsensor -LOADER_BUTTON_INVALID=Invalid +LOADER_BUTTON_COMPARATOR=Comparator +LOADER_BUTTON_REPEATER=Repeater +LOADER_BUTTON_LECTERN=Lectern +LOADER_BUTTON_TRAPDOOR=Trapdoor +LOADER_BUTTON_DOOR=Door +LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions -LOADER_HELP_UNDO=§8/§7loader undo §8- §7Removes last recorded action LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action -LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Sets wait time between shots -LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Sets wait time between actions LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader -LOADER_HELP_RESUME=§8/§7loader resume §8- §7Resumes Loader +LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Shows Loader settings LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback -LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Clears recording -LOADER_HELP_SINGLE=§8/§eloader single §8- §7Starts a single shot -LOADER_HELP_OTHER=§7The loader works with §eIngame§8-§eTicks §7(20 ticks per Second) LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup -LOADER_BACK_SETUP=§7DYour Loader is in Setup again LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. LOADER_HOW_TO_START=§7Then, execute /§eloader start§7 to start the Loader LOADER_ACTIVE=§7The Loader is now active. LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. -LOADER_RESUME=§7The Loader is resuming. -LOADER_SINGLE=§7The Loader is shooting once. -LOADER_SMALL_TIME=§cThe wait time is too small -LOADER_NEW_TIME=§7The wait time is now: {0}, before {1} -LOADER_NEW_LOAD_TIME=§7The action wait time is now: {0}, before {1} -LOADER_UNDO=§7Undo succesful. LOADER_PERMS=§cYou are not allowed to use the Loader here LOADER_GUI_NAME=§eLoader LOADER_GUI_NEW=§eNew Loader @@ -842,6 +831,7 @@ LOADER_GUI_SPEED=§eSpeed LOADER_GUI_SPEED_LORE=§7Currently: §e{0} LOADER_GUI_SPEED_TITLE=§7Block placing speed LOADER_GUI_STOP=§eStop Loader + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 9ac07bd8..ce5c7c17 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -761,47 +761,36 @@ TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0} # Loader LOADER_SETUP = §eEinrichtung LOADER_RUNNING = §aLaufend -LOADER_SINGLE_SIDEBAR = §aEiner LOADER_PAUSE = §7Pausiert LOADER_END = §8Beendet -LOADER_MESSAGE_CLEAR = §7Loader gecleart -LOADER_MESSAGE_CLEAR_HELP = §cDu must im Setup-Modus sein um den Loader zu clearen -LOADER_MESSAGE_TNT = §eTNT hinzugefügt {0} LOADER_MESSAGE_INTERACT = §e{0} hinzugefügt {1} +LOADER_BUTTON_TNT = TNT LOADER_BUTTON_SWITCH=Hebel -LOADER_BUTTON_WOOD_BUTTON=Knopf -LOADER_BUTTON_STONE_BUTTON=Knopf +LOADER_BUTTON_WOOD_BUTTON=Holzknopf +LOADER_BUTTON_STONE_BUTTON=Steinknopf LOADER_BUTTON_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor -LOADER_BUTTON_INVALID=Invalider +LOADER_BUTTON_COMPARATOR=Comparator +LOADER_BUTTON_REPEATER=Repeater +LOADER_BUTTON_LECTERN=Lectern +LOADER_BUTTON_TRAPDOOR=Trapdoor +LOADER_BUTTON_DOOR=Door +LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen -LOADER_HELP_UNDO=§8/§7loader undo §8- §7Entfernt die zuletzt aufgenommene Aktion LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab -LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Schüssen -LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Aktionen LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen -LOADER_HELP_RESUME=§8/§7loader resume §8- §7Spielt den Loader weiter ab +LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Zeigt die Einstellungen an LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen -LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Cleart die Aufnahme -LOADER_HELP_SINGLE=§8/§eloader single §8- §7Spielt die Aufnahme einmal ab -LOADER_HELP_OTHER=§7Der Loader arbeitet mit §eIngame§8-§eTicks §7(20 Ticks pro Sekunde) LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup -LOADER_BACK_SETUP=§7Dein Loader ist nun wieder im Setup LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren. LOADER_HOW_TO_START=§7Führe dann /§eloader start§7 um den Loader zu starten LOADER_ACTIVE=§7Der Loader ist nun aktiviert. LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. -LOADER_RESUME=§7Der Loader läuft nun weiter. -LOADER_SINGLE=§7Der Loader schießt einmal. -LOADER_SMALL_TIME=§cDie Wartezeit ist zu klein -LOADER_NEW_TIME=§7Die Schusswartezeit ist nun: {0}, zuvor {1} -LOADER_NEW_LOAD_TIME=§7Die Setzwartezeit ist nun: {0}, zuvor {1} -LOADER_UNDO=§7Undo erfolgreich. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen LOADER_GUI_NAME=§eLoader LOADER_GUI_NEW=§eNeuer Loader @@ -815,6 +804,7 @@ LOADER_GUI_SPEED=§eGeschwindigkeit LOADER_GUI_SPEED_LORE=§7Aktuell: §e{0} LOADER_GUI_SPEED_TITLE=§7Block Platzier Geschwindigkeit LOADER_GUI_STOP=§eLoader Stoppen + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index b2d7a2b8..77168028 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -76,7 +76,7 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_PAUSED", player); } - @Register(value = "settings", description = "LOADER_HELP_PAUSE") + @Register(value = "settings", description = "LOADER_HELP_SETTINGS") public void settingsLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 04eb1c11..16a41002 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.loadern; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.loadern.elements.LoaderElement; import de.steamwar.bausystem.features.loadern.elements.impl.*; import de.steamwar.bausystem.features.tpslimit.TPSUtils; @@ -81,6 +82,7 @@ public class LoaderRecorder implements Listener { addWaitTime(false); loaderElementList.add(new LoaderTNT(event.getBlock().getLocation())); + message("LOADER_BUTTON_TNT"); } @EventHandler @@ -97,35 +99,46 @@ public class LoaderRecorder implements Listener { switch (type) { case COMPARATOR: loaderElementList.add(new LoaderComparator(block.getLocation())); + message("LOADER_BUTTON_COMPARATOR"); break; case REPEATER: loaderElementList.add(new LoaderRepeater(block.getLocation())); + message("LOADER_BUTTON_REPEATER"); break; case NOTE_BLOCK: loaderElementList.add(new LoaderNoteBlock(block.getLocation())); + message("LOADER_BUTTON_NOTEBLOCK"); break; case LEVER: loaderElementList.add(new LoaderLever(block.getLocation())); + message("LOADER_BUTTON_SWITCH"); break; case DAYLIGHT_DETECTOR: loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); + message("LOADER_BUTTON_DAYLIGHTSENSOR"); break; case LECTERN: loaderElementList.add(new LoaderLectern(block.getLocation())); + message("LOADER_BUTTON_LECTERN"); break; case IRON_TRAPDOOR: break; default: if (type.name().endsWith("_TRAPDOOR")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "Trapdoor", type)); + loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type)); + message("LOADER_BUTTON_TRAPDOOR"); } else if (type.name().endsWith("_DOOR")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "Door", type)); + loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type)); + message("LOADER_BUTTON_DOOR"); } else if (type.name().endsWith("FENCE_GATE")) { - loaderElementList.add(new LoaderOpenable(block.getLocation(), "Fencegate", type)); + loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type)); + message("LOADER_BUTTON_FENCEGATE"); } else if (type.name().endsWith("STONE_BUTTON")) { - loaderElementList.add(new LoaderTicks(block.getLocation(), "Stone Button", type, 20)); + loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20)); + message("LOADER_BUTTON_STONE_BUTTON"); } else if (type.name().endsWith("BUTTON")) { - loaderElementList.add(new LoaderTicks(block.getLocation(), "Wooden Button", type, 30)); + loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30)); + message("LOADER_BUTTON_WOOD_BUTTON"); } break; } @@ -162,15 +175,18 @@ public class LoaderRecorder implements Listener { Material type = toBlock.getType(); switch (type) { case TRIPWIRE: - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Tripwire", Material.STRING); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_TRIPWIRE", Material.STRING); + message("LOADER_BUTTON_TRIPWIRE"); break; case LIGHT_WEIGHTED_PRESSURE_PLATE: case HEAVY_WEIGHTED_PRESSURE_PLATE: - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Weighted Pressure Plate", type); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE", type); + message("LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"); break; default: if (type.name().endsWith("PRESSURE_PLATE")) { - loaderMovement = new LoaderMovement(toBlock.getLocation(), "Pressure Plate", type); + loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_PRESSURE_PLATE", type); + message("LOADER_BUTTON_PRESSURE_PLATE"); } break; } @@ -180,4 +196,8 @@ public class LoaderRecorder implements Listener { } } } + + private void message(String type) { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size())); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index 0ca03583..ec9b7f60 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -98,6 +98,7 @@ public class LoaderMovement extends LoaderInteractionElement= 0) { @@ -115,10 +117,12 @@ public class LoaderMovement extends LoaderInteractionElement { + swInventory.setItem(12, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { ticks -= clickType.isShiftClick() ? 5 : 1; if (ticks < 1) ticks = 1; swInventory.setItem(13, item(player)); @@ -171,7 +175,7 @@ public class LoaderMovement extends LoaderInteractionElement { + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { ticks += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(13, item(player)); }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java index 1fc45d69..876a51d4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -26,7 +26,6 @@ import de.steamwar.inventory.SWItem; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.data.Openable; -import org.bukkit.block.data.type.TrapDoor; import org.bukkit.entity.Player; import java.util.Arrays; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 0bdb5228..53c9e455 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -84,11 +84,13 @@ public class LoaderTicks extends LoaderInteractionElement { powerable.setPowered(false); location.getBlock().setBlockData(powerable, true); + update(powerable); if (finalWaitFor) { nextAction.run(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 3ea9dc28..08ba91c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -65,7 +65,7 @@ public class LoaderWait implements LoaderElement, Listener { for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); - swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { + swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; if (delay < 0) delay = 0; swInventory.setItem(4, menu(player)); @@ -82,7 +82,7 @@ public class LoaderWait implements LoaderElement, Listener { }); swAnvilInv.open(); }); - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1").getItemStack(), clickType -> { + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { delay += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(4, menu(player)); }); From ac2900c080aa59101c368bd0789ec245da043734 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 17:07:55 +0200 Subject: [PATCH 094/174] Add Loader setWaitBetween TNT and setGlobalWait Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/loadern/Loader.java | 60 ++++++++++++++++--- .../features/loadern/LoaderCommand.java | 6 +- .../loadern/elements/impl/LoaderWait.java | 2 + 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 7d3618d3..3b9bba5f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -810,7 +810,7 @@ LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader -LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Shows Loader settings +LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ce5c7c17..08371f51 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -783,7 +783,7 @@ LOADER_BUTTON_FENCEGATE=Fencegate LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen -LOADER_HELP_SETTINGS=§8/§7loader settings §8- §7Zeigt die Einstellungen an +LOADER_HELP_GUI=§8/§7loader settings §8- §7Zeigt die Einstellungen an LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index 06dffc03..d5b48efa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.loadern.elements.LoaderElement; import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import lombok.AllArgsConstructor; @@ -123,7 +124,7 @@ public class Loader implements Listener { LOADER_MAP.remove(p); } - public void settings(SettingsSorting settingsSorting) { + public void gui(SettingsSorting settingsSorting) { List> list = new ArrayList<>(); for (LoaderElement element : elements) { if (settingsSorting != null) { @@ -139,17 +140,62 @@ public class Loader implements Listener { SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { + gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); + }); + if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); + swListInv.setItem(47, onlyInteractionsElements); + SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { - settings(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); + gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); }); if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); - SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { - settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); - }); - if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); - swListInv.setItem(50, onlyInteractionsElements); + if (settingsSorting == SettingsSorting.WAIT) { + SWItem waitBetweenTNT = new SWItem(Material.TNT, "§7Wait Time zwischen TNT", clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + swAnvilInv.setCallback(s -> { + try { + long delay = Long.parseLong(s); + if (delay < 0) delay = 0; + for (int i = 1; i < elements.size() - 1; i++) { + if (!(elements.get(i - 1) instanceof LoaderTNT)) continue; + if (!(elements.get(i + 1) instanceof LoaderTNT)) continue; + if (!(elements.get(i) instanceof LoaderWait)) continue; + ((LoaderWait) elements.get(i)).setDelay(delay); + } + } catch (NumberFormatException ignored) { + } + gui(settingsSorting); + }); + swAnvilInv.open(); + }); + swListInv.setItem(50, waitBetweenTNT); + + SWItem waitTime = new SWItem(Material.PAPER, "§7Wait Time alle", clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + swAnvilInv.setCallback(s -> { + try { + long delay = Long.parseLong(s); + if (delay < 0) delay = 0; + long finalDelay = delay; + elements.stream() + .filter(LoaderWait.class::isInstance) + .map(LoaderWait.class::cast) + .forEach(loaderWait -> loaderWait.setDelay(finalDelay)); + } catch (NumberFormatException ignored) { + } + swListInv.open(); + }); + gui(settingsSorting); + }); + swListInv.setItem(51, waitTime); + } else { + SWItem empty = new SWItem(Material.STRUCTURE_VOID, "§7", clickType -> {}); + swListInv.setItem(50, empty); + swListInv.setItem(51, empty); + } swListInv.open(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 77168028..5799bc6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -76,11 +76,11 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_PAUSED", player); } - @Register(value = "settings", description = "LOADER_HELP_SETTINGS") - public void settingsLoader(@Validator Player player) { + @Register(value = "gui", description = "LOADER_HELP_GUI") + public void guiLoader(@Validator Player player) { Loader loader = Loader.getLoader(player); if (loaderNullCheck(loader, player)) return; - loader.settings(null); + loader.gui(null); } @ClassValidator(value = Player.class, local = true) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 08ba91c6..841969fe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -25,6 +25,7 @@ import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -35,6 +36,7 @@ import java.util.Arrays; public class LoaderWait implements LoaderElement, Listener { @Getter + @Setter private long delay; public LoaderWait(long delay) { From 55a720eb438e1b0474cc5ff3471c7a64418e11a7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 5 May 2023 17:15:10 +0200 Subject: [PATCH 095/174] Remove unused translations Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 12 ------------ BauSystem_Main/src/BauSystem_de.properties | 12 ------------ .../loadern/elements/LoaderInteractionElement.java | 2 +- 3 files changed, 1 insertion(+), 25 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3b9bba5f..9a9f24af 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -819,18 +819,6 @@ LOADER_ACTIVE=§7The Loader is now active. LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. LOADER_PERMS=§cYou are not allowed to use the Loader here -LOADER_GUI_NAME=§eLoader -LOADER_GUI_NEW=§eNew Loader -LOADER_GUI_START=§eStart Loader -LOADER_GUI_PAUSE=§7pause Loader -LOADER_GUI_UNDO=§7Undo last action -LOADER_GUI_WAIT=§7Shot delay -LOADER_GUI_WAIT_LORE=§7Currently: §e{0} -LOADER_GUI_WAIT_TITLE=§7Shot delay -LOADER_GUI_SPEED=§eSpeed -LOADER_GUI_SPEED_LORE=§7Currently: §e{0} -LOADER_GUI_SPEED_TITLE=§7Block placing speed -LOADER_GUI_STOP=§eStop Loader # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 08371f51..e0d12fa6 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -792,18 +792,6 @@ LOADER_ACTIVE=§7Der Loader ist nun aktiviert. LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen -LOADER_GUI_NAME=§eLoader -LOADER_GUI_NEW=§eNeuer Loader -LOADER_GUI_START=§eLoader starten -LOADER_GUI_PAUSE=§7Loader pausieren -LOADER_GUI_UNDO=§7Letzte Aktion Rückgängig machen -LOADER_GUI_WAIT=§7Schuss Delay -LOADER_GUI_WAIT_LORE=§7Aktuell: §e{0} -LOADER_GUI_WAIT_TITLE=§7Schuss Delay -LOADER_GUI_SPEED=§eGeschwindigkeit -LOADER_GUI_SPEED_LORE=§7Aktuell: §e{0} -LOADER_GUI_SPEED_TITLE=§7Block Platzier Geschwindigkeit -LOADER_GUI_STOP=§eLoader Stoppen # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 948a3e1d..0d38cd7a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -74,7 +74,7 @@ public abstract class LoaderInteractionElement implem listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> { backAction.run(); })); - listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another", clickType -> { + listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> { T element = createNewElement(); elements.add(element); element.click(player, () -> click(player, backAction), () -> { From bb654018d602792ac27f77b6a8ea322af8ff54e4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 01:43:28 +0200 Subject: [PATCH 096/174] Update some multilingual stuff for Loader and LoaderCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 ++++++++++ BauSystem_Main/src/BauSystem_de.properties | 10 ++++++++++ .../bausystem/features/loadern/Loader.java | 20 +++++++++---------- .../features/loadern/LoaderCommand.java | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9a9f24af..7a451354 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -807,7 +807,9 @@ LOADER_BUTTON_LECTERN=Lectern LOADER_BUTTON_TRAPDOOR=Trapdoor LOADER_BUTTON_DOOR=Door LOADER_BUTTON_FENCEGATE=Fencegate + LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions +LOADER_SETUP_STOP_FIRST=§cPlease stop the current loader first! LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui @@ -820,6 +822,14 @@ LOADER_STOP=§7The Loader has been stopped. LOADER_PAUSED=§7The Loader is now paused. LOADER_PERMS=§cYou are not allowed to use the Loader here +LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet! +LOADER_GUI_TITLE=Loader GUI +LOADER_GUI_SHOW_INTERACTIONS=§eShow only Interactions +LOADER_GUI_SHOW_WAITS=§eShow only Waits +LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT +LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all +LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index e0d12fa6..38a4e4cb 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -780,7 +780,9 @@ LOADER_BUTTON_LECTERN=Lectern LOADER_BUTTON_TRAPDOOR=Trapdoor LOADER_BUTTON_DOOR=Door LOADER_BUTTON_FENCEGATE=Fencegate + LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen +LOADER_SETUP_STOP_FIRST=§cBitte stoppe zuerst den Loader LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen LOADER_HELP_GUI=§8/§7loader settings §8- §7Zeigt die Einstellungen an @@ -793,6 +795,14 @@ LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen +LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen! +LOADER_GUI_TITLE=Loader Einstellungen +LOADER_GUI_SHOW_INTERACTIONS=§eZeige Interaktionen +LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten +LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT +LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle +LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index d5b48efa..a50ad0bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -97,7 +97,7 @@ public class Loader implements Listener { recorder = null; } if (elements.isEmpty()) { - p.sendMessage("§cEs wurden keine Elemente aufgenommen!"); + BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p); stop(); return; } @@ -137,24 +137,24 @@ public class Loader implements Listener { } list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); } - SWListInv swListInv = new SWListInv<>(p, "Loader Settings", false, list, (clickType, loaderElement) -> {}); + SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); - SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> { + SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> { gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); }); if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); swListInv.setItem(47, onlyInteractionsElements); - SWItem onlyWaitElements = new SWItem(Material.CLOCK, "§eNur Warten", clickType -> { + SWItem onlyWaitElements = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS", p), clickType -> { gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); }); if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); swListInv.setItem(48, onlyWaitElements); if (settingsSorting == SettingsSorting.WAIT) { - SWItem waitBetweenTNT = new SWItem(Material.TNT, "§7Wait Time zwischen TNT", clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + SWItem waitBetweenTNT = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT", p), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), ""); swAnvilInv.setCallback(s -> { try { long delay = Long.parseLong(s); @@ -173,8 +173,8 @@ public class Loader implements Listener { }); swListInv.setItem(50, waitBetweenTNT); - SWItem waitTime = new SWItem(Material.PAPER, "§7Wait Time alle", clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(p, "§7Wartezeit", ""); + SWItem waitTime = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> { + SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), ""); swAnvilInv.setCallback(s -> { try { long delay = Long.parseLong(s); @@ -186,9 +186,9 @@ public class Loader implements Listener { .forEach(loaderWait -> loaderWait.setDelay(finalDelay)); } catch (NumberFormatException ignored) { } - swListInv.open(); + gui(settingsSorting); }); - gui(settingsSorting); + swAnvilInv.open(); }); swListInv.setItem(51, waitTime); } else { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java index 5799bc6e..070b2e95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java @@ -44,7 +44,7 @@ public class LoaderCommand extends SWCommand { @Register(value = "setup", description = "LOADER_HELP_SETUP") public void setupLoader(@Validator Player player) { if (Loader.getLoader(player) != null) { - player.sendMessage("Please stop the current loader first!"); + BauSystem.MESSAGE.send("LOADER_SETUP_STOP_FIRST", player); return; } Loader.newLoader(player); From be33184cfede23c99bbb538bb536e397e2bf9490 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 01:50:56 +0200 Subject: [PATCH 097/174] Update some gui texts Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 5 +++++ BauSystem_Main/src/BauSystem_de.properties | 5 +++++ .../features/loadern/elements/impl/LoaderComparator.java | 7 ++++--- .../loadern/elements/impl/LoaderDaylightDetector.java | 7 ++++--- .../features/loadern/elements/impl/LoaderLectern.java | 7 ++++--- .../features/loadern/elements/impl/LoaderLever.java | 7 ++++--- .../features/loadern/elements/impl/LoaderMovement.java | 6 +++--- .../features/loadern/elements/impl/LoaderNoteBlock.java | 7 ++++--- .../features/loadern/elements/impl/LoaderOpenable.java | 7 ++++--- .../features/loadern/elements/impl/LoaderRepeater.java | 7 ++++--- .../features/loadern/elements/impl/LoaderTicks.java | 6 +++--- .../features/loadern/elements/impl/LoaderWait.java | 4 ++-- 12 files changed, 46 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 7a451354..cd378576 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -829,6 +829,11 @@ LOADER_GUI_SHOW_WAITS=§eShow only Waits LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time +LOADER_GUI_SETTINGS_TITLE=Settings +LOADER_GUI_SETTINGS_BACK=§8Back +LOADER_GUI_SETTINGS_DELETE=§cDelete +LOADER_GUI_WAIT_TITLE=Settings +LOADER_GUI_WAIT_BACK=§8Back # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 38a4e4cb..2515d945 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -802,6 +802,11 @@ LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit +LOADER_GUI_SETTINGS_TITLE=Einstellungen +LOADER_GUI_SETTINGS_BACK=§8Zurück +LOADER_GUI_SETTINGS_DELETE=§cLöschen +LOADER_GUI_WAIT_TITLE=Wartezeit +LOADER_GUI_WAIT_BACK=§8Zurück # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index 1205e4bf..52d51fe5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -77,10 +78,10 @@ public class LoaderComparator extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index d78e6319..cc1927b6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -81,10 +82,10 @@ public class LoaderDaylightDetector extends LoaderInteractionElement backAction.run()); - swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java index 5df1594d..c60e9f30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -89,10 +90,10 @@ public class LoaderLectern extends LoaderInteractionElement backAction.run()); - swInventory.setItem(35, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java index e83d5539..06105eaf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -78,10 +79,10 @@ public class LoaderLever extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java index ec9b7f60..6147d9c4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java @@ -136,10 +136,10 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); - swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(analogue ? 36 : 18, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java index 53811035..f36271b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -74,10 +75,10 @@ public class LoaderNoteBlock extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, false).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java index 876a51d4..599582ef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -83,10 +84,10 @@ public class LoaderOpenable extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java index 102ee35c..3e0354d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements.impl; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loadern.elements.ElementSettings; import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; @@ -81,10 +82,10 @@ public class LoaderRepeater extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> { interact = false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java index 53c9e455..1b6da9e4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java @@ -102,10 +102,10 @@ public class LoaderTicks extends LoaderInteractionElement backAction.run()); - swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run()); + swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run()); swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> { noop = true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java index 841969fe..75374abc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java @@ -63,9 +63,9 @@ public class LoaderWait implements LoaderElement, Listener { @Override public void click(Player player, Runnable backAction) { - SWInventory swInventory = new SWInventory(player, 18, "Wartezeit"); + SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", player)); for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7")); - swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); + swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).getItemStack(), clickType -> backAction.run()); swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; From a73372a406b58436f0e94f2598d03688115661db Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 7 May 2023 22:36:33 +0200 Subject: [PATCH 098/174] Update some more messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ BauSystem_Main/src/BauSystem_de.properties | 2 ++ .../features/loadern/elements/impl/LoaderComparator.java | 2 +- .../features/loadern/elements/impl/LoaderDaylightDetector.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderLectern.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderLever.java | 2 +- .../features/loadern/elements/impl/LoaderMovement.java | 2 +- .../features/loadern/elements/impl/LoaderNoteBlock.java | 2 +- .../features/loadern/elements/impl/LoaderOpenable.java | 2 +- .../features/loadern/elements/impl/LoaderRepeater.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderTicks.java | 2 +- .../bausystem/features/loadern/elements/impl/LoaderWait.java | 2 +- 12 files changed, 14 insertions(+), 10 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index cd378576..d6e9c273 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -835,6 +835,8 @@ LOADER_GUI_SETTINGS_DELETE=§cDelete LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back +LOADER_GUI_CLICK_TO_EDIT=§7Click to edit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 2515d945..692c5253 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -808,6 +808,8 @@ LOADER_GUI_SETTINGS_DELETE=§cLöschen LOADER_GUI_WAIT_TITLE=Wartezeit LOADER_GUI_WAIT_BACK=§8Zurück +LOADER_GUI_CLICK_TO_EDIT=§7Click to edit + # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java index 52d51fe5..25f874c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java @@ -57,7 +57,7 @@ public class LoaderComparator extends LoaderInteractionElement Date: Tue, 9 May 2023 11:25:47 +0200 Subject: [PATCH 099/174] Removing 1.15 only TPSWarp limiter... --- .../de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index fff2ebe6..482ff2ee 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.tpslimit; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.utils.NMSWrapper; -import de.steamwar.core.Core; import de.steamwar.core.TPSWatcher; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -42,9 +41,6 @@ public class TPSWarpUtils { public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); - if (Core.getVersion() != 15) { - return; - } if (nanoDOffset == 0) { if (bukkitTask == null) return; bukkitTask.cancel(); From 3c7168494f0d6ecde5e433d6fbe1921c9a2ddc35 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 9 May 2023 11:42:39 +0200 Subject: [PATCH 100/174] Fix TPS Warp inversion --- .../de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index 482ff2ee..b6f4fa9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -45,7 +45,7 @@ public class TPSWarpUtils { if (bukkitTask == null) return; bukkitTask.cancel(); bukkitTask = null; - } else if (bukkitTask != null) { + } else if (bukkitTask == null) { bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> nanoOffset += nanoDOffset, 1, 1); } } From 7785bb4c11cbc7f64371ee65d6c7a29fef12de05 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 16:44:21 +0200 Subject: [PATCH 101/174] Reenable item Signed-off-by: yoyosource --- .../features/world/OtherTNTListener.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java new file mode 100644 index 00000000..7cf94fc1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/OtherTNTListener.java @@ -0,0 +1,43 @@ +/* + * 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.world; + +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +@Linked +public class OtherTNTListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR) + public void onExplosion(EntityExplodeEvent e) { + e.blockList().removeIf(block -> { + if(block.getType() == Material.TNT) { + return false; + } else { + block.setType(Material.AIR); + return true; + } + }); + } +} From 7c9c27ae3e89c87d4f88b99b07f4a67f4b2d3548 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 17:19:27 +0200 Subject: [PATCH 102/174] Update LoaderDaylightDetector Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 +++++++++- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/loadern/LoaderRecorder.java | 2 +- .../features/loadern/elements/ElementSettings.java | 5 +++++ .../loadern/elements/LoaderInteractionElement.java | 5 +++++ .../elements/impl/LoaderDaylightDetector.java | 12 ++++++------ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d6e9c273..5dfba6ed 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -800,7 +800,7 @@ LOADER_BUTTON_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock -LOADER_BUTTON_DAYLIGHTSENSOR=Daylightsensor +LOADER_BUTTON_DAYLIGHT_DETECTOR=Daylight Detector LOADER_BUTTON_COMPARATOR=Comparator LOADER_BUTTON_REPEATER=Repeater LOADER_BUTTON_LECTERN=Lectern @@ -836,6 +836,14 @@ LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} +LOADER_SETTING_NAME=§7{0} +LOADER_SETTING_MODES=§7Modes§8: §e{0} +LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_INTERACTION_NOOP=NOOP +LOADER_INTERACTION_INTERACT=Interact +LOADER_INTERACTION_POWERED=Powered +LOADER_INTERACTION_UNPOWERED=Unpowered # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 692c5253..5495c3be 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -773,7 +773,7 @@ LOADER_BUTTON_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_NOTEBLOCK=Noteblock -LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor +LOADER_BUTTON_DAYLIGHT_DETECTOR=Tageslichtsensor LOADER_BUTTON_COMPARATOR=Comparator LOADER_BUTTON_REPEATER=Repeater LOADER_BUTTON_LECTERN=Lectern diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java index 16a41002..135cd7ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java @@ -115,7 +115,7 @@ public class LoaderRecorder implements Listener { break; case DAYLIGHT_DETECTOR: loaderElementList.add(new LoaderDaylightDetector(block.getLocation())); - message("LOADER_BUTTON_DAYLIGHTSENSOR"); + message("LOADER_BUTTON_DAYLIGHT_DETECTOR"); break; case LECTERN: loaderElementList.add(new LoaderLectern(block.getLocation())); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java index 5142e8cf..f2a63b69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements; +import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; @@ -28,4 +29,8 @@ public interface ElementSettings { void click(Player player, Runnable backAction, Runnable deleteAction); default void playerInteract() {} + + default String translateItemName(String name, String mode, Player player) { + return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player)); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java index 0d38cd7a..eabd054f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.loadern.elements; +import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import org.bukkit.Location; @@ -117,4 +118,8 @@ public abstract class LoaderInteractionElement implem } public abstract T createNewElement(); + + protected final String translateItemName(String name, Player player) { + return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player)); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index d5c0192e..f81236c7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -53,11 +53,11 @@ public class LoaderDaylightDetector extends LoaderInteractionElement Date: Tue, 9 May 2023 18:28:53 +0200 Subject: [PATCH 103/174] Add all translations Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 38 +++++++++++++++---- BauSystem_Main/src/BauSystem_de.properties | 30 +++++++++++++++ .../bausystem/features/loadern/Loader.java | 9 ++--- .../loadern/elements/ElementSettings.java | 4 +- .../elements/impl/LoaderDaylightDetector.java | 4 +- .../loadern/elements/impl/LoaderLectern.java | 12 +++--- .../loadern/elements/impl/LoaderLever.java | 10 ++--- .../loadern/elements/impl/LoaderMovement.java | 22 +++++------ .../elements/impl/LoaderNoteBlock.java | 8 ++-- .../loadern/elements/impl/LoaderOpenable.java | 10 ++--- .../loadern/elements/impl/LoaderRepeater.java | 10 ++--- .../loadern/elements/impl/LoaderTNT.java | 4 +- .../loadern/elements/impl/LoaderTicks.java | 10 ++--- .../loadern/elements/impl/LoaderWait.java | 8 ++-- 14 files changed, 107 insertions(+), 72 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5dfba6ed..9f4b2edb 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -791,8 +791,8 @@ LOADER_RUNNING = §aRunning LOADER_PAUSE = §7Pause LOADER_END = §8Finished -LOADER_MESSAGE_INTERACT = §e{0} added {1} -LOADER_BUTTON_TNT = TNT +LOADER_MESSAGE_INTERACT=§e{0} added {1} +LOADER_BUTTON_TNT=TNT LOADER_BUTTON_SWITCH=Lever LOADER_BUTTON_WOOD_BUTTON=Wooden Button LOADER_BUTTON_STONE_BUTTON=Stone Button @@ -835,15 +835,37 @@ LOADER_GUI_SETTINGS_DELETE=§cDelete LOADER_GUI_WAIT_TITLE=Settings LOADER_GUI_WAIT_BACK=§8Back -LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_CLICK_TO_EDIT=§7Klicke zum editieren LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} LOADER_SETTING_NAME=§7{0} -LOADER_SETTING_MODES=§7Modes§8: §e{0} -LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_SETTING_MODES=§7Modi§8: §e{0} +LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0} +LOADER_SETTING_TICKS=§7Ticks§8: §e{0} +LOADER_SETTING_REPEATER=§7Repeater§8: §e{0} +LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s) +LOADER_SETTING_WAIT_NAME=Wartezeit +LOADER_SETTING_TICKS_NAME=Ticks +LOADER_SETTING_TICKS_REMOVE_ONE=§c-1 +LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5 +LOADER_SETTING_TICKS_ADD_ONE=§a+1 +LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5 +LOADER_SETTING_TNT_NAME=§cTNT +LOADER_SETTING_TNT_X=§7X§8: §e{0} +LOADER_SETTING_TNT_Y=§7Y§8: §e{0} +LOADER_SETTING_TNT_Z=§7Z§8: §e{0} LOADER_INTERACTION_NOOP=NOOP -LOADER_INTERACTION_INTERACT=Interact -LOADER_INTERACTION_POWERED=Powered -LOADER_INTERACTION_UNPOWERED=Unpowered +LOADER_INTERACTION_INTERACT=Interagiere +LOADER_INTERACTION_POWERED=Aktiviert +LOADER_INTERACTION_UNPOWERED=Deaktiviert +LOADER_INTERACTION_PAGE_PREV=Vorherige Seite +LOADER_INTERACTION_PAGE_NEXT=Nächste Seite +LOADER_INTERACTION_PAGE=Seite {0} +LOADER_INTERACTION_ACTIVE=Aktiviert +LOADER_INTERACTION_INACTIVE=Deaktiviert +LOADER_INTERACTION_WAIT_FOR=Darauf warten +LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten +LOADER_INTERACTION_OPEN=Geöffnet +LOADER_INTERACTION_CLOSED=Geschlossen # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 5495c3be..97ba1f97 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -809,6 +809,36 @@ LOADER_GUI_WAIT_TITLE=Wartezeit LOADER_GUI_WAIT_BACK=§8Zurück LOADER_GUI_CLICK_TO_EDIT=§7Click to edit +LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1} +LOADER_SETTING_NAME=§7{0} +LOADER_SETTING_MODES=§7Modes§8: §e{0} +LOADER_SETTING_POWER=§7Power§8: §e{0} +LOADER_SETTING_TICKS=§7Ticks§8: §e{0} +LOADER_SETTING_REPEATER=§7Repeater§8: §e{0} +LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s) +LOADER_SETTING_WAIT_NAME=Wait +LOADER_SETTING_TICKS_NAME=Ticks +LOADER_SETTING_TICKS_REMOVE_ONE=§c-1 +LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5 +LOADER_SETTING_TICKS_ADD_ONE=§a+1 +LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5 +LOADER_SETTING_TNT_NAME=§cTNT +LOADER_SETTING_TNT_X=§7X§8: §e{0} +LOADER_SETTING_TNT_Y=§7Y§8: §e{0} +LOADER_SETTING_TNT_Z=§7Z§8: §e{0} +LOADER_INTERACTION_NOOP=NOOP +LOADER_INTERACTION_INTERACT=Interact +LOADER_INTERACTION_POWERED=Powered +LOADER_INTERACTION_UNPOWERED=Unpowered +LOADER_INTERACTION_PAGE_PREV=Previous Page +LOADER_INTERACTION_PAGE_NEXT=Next Page +LOADER_INTERACTION_PAGE=Page {0} +LOADER_INTERACTION_ACTIVE=Active +LOADER_INTERACTION_INACTIVE=Inactive +LOADER_INTERACTION_WAIT_FOR=Wait for +LOADER_INTERACTION_NO_WAIT_FOR=No wait for +LOADER_INTERACTION_OPEN=Open +LOADER_INTERACTION_CLOSED=Closed # Loadtimer LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java index a50ad0bc..612ebd28 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java @@ -36,10 +36,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class Loader implements Listener { @@ -135,7 +132,9 @@ public class Loader implements Listener { continue; } } - list.add(new SWListInv.SWListEntry<>(element.menu(p), element)); + SWItem item = element.menu(p); + item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, elements.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); + list.add(new SWListInv.SWListEntry<>(item, element)); } SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {}); swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java index f2a63b69..be62173c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java @@ -30,7 +30,7 @@ public interface ElementSettings { default void playerInteract() {} - default String translateItemName(String name, String mode, Player player) { - return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player)); + default String translateItemName(String name, String mode, Player player, Object... args) { + return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player, args)); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java index f81236c7..42d1909f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java @@ -148,9 +148,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement {}).getItemStack(), clickType -> { + swInventory.setItem(12, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { ticks -= clickType.isShiftClick() ? 5 : 1; if (ticks < 1) ticks = 1; swInventory.setItem(13, item(player)); }); swInventory.setItem(13, item(player).getItemStack(), clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Ticks", ticks + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_NAME", player), ticks + ""); swAnvilInv.setCallback(s -> { try { ticks = Long.parseLong(s); @@ -175,7 +175,7 @@ public class LoaderMovement extends LoaderInteractionElement {}).getItemStack(), clickType -> { + swInventory.setItem(14, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { ticks += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(13, item(player)); }); @@ -205,25 +205,23 @@ public class LoaderMovement extends LoaderInteractionElement backAction.run()); - swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1", Arrays.asList("§7Shift: §c-5"), false, clickType -> {}).getItemStack(), clickType -> { + swInventory.setItem(3, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay -= clickType.isShiftClick() ? 5 : 1; if (delay < 0) delay = 0; swInventory.setItem(4, menu(player)); }); swInventory.setItem(4, menu(player).getItemStack(), clickType -> { - SWAnvilInv swAnvilInv = new SWAnvilInv(player, "§7Wartezeit", delay + ""); + SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_WAIT_NAME", player), delay + ""); swAnvilInv.setCallback(s -> { try { delay = Long.parseLong(s); @@ -84,7 +84,7 @@ public class LoaderWait implements LoaderElement, Listener { }); swAnvilInv.open(); }); - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§a+1", Arrays.asList("§7Shift: §a+5"), false, clickType -> {}).getItemStack(), clickType -> { + swInventory.setItem(5, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> { delay += clickType.isShiftClick() ? 5 : 1; swInventory.setItem(4, menu(player)); }); From f6357c2a376b401411fb1b8b725f1d24e3db28ad Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 18:31:03 +0200 Subject: [PATCH 104/174] Fix package name Signed-off-by: yoyosource --- .../bausystem/features/{loadern => loader}/Loader.java | 8 ++++---- .../features/{loadern => loader}/LoaderCommand.java | 2 +- .../features/{loadern => loader}/LoaderRecorder.java | 6 +++--- .../{loadern => loader}/LoaderScoreboardElement.java | 2 +- .../{loadern => loader}/elements/ElementSettings.java | 2 +- .../{loadern => loader}/elements/LoaderElement.java | 2 +- .../elements/LoaderInteractionElement.java | 2 +- .../elements/impl/LoaderComparator.java | 6 +++--- .../elements/impl/LoaderDaylightDetector.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderLectern.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderLever.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderMovement.java | 6 +++--- .../elements/impl/LoaderNoteBlock.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderOpenable.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderRepeater.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderTNT.java | 4 ++-- .../{loadern => loader}/elements/impl/LoaderTicks.java | 6 +++--- .../{loadern => loader}/elements/impl/LoaderWait.java | 4 ++-- .../bausystem/features/script/variables/Constants.java | 2 +- 19 files changed, 44 insertions(+), 44 deletions(-) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/Loader.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderCommand.java (98%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderRecorder.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/LoaderScoreboardElement.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/ElementSettings.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/LoaderElement.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/LoaderInteractionElement.java (98%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderComparator.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderDaylightDetector.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderLectern.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderLever.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderMovement.java (97%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderNoteBlock.java (95%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderOpenable.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderRepeater.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderTNT.java (94%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderTicks.java (96%) rename BauSystem_Main/src/de/steamwar/bausystem/features/{loadern => loader}/elements/impl/LoaderWait.java (96%) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java index 612ebd28..6b61f14f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/Loader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/Loader.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; -import de.steamwar.bausystem.features.loadern.elements.impl.LoaderTNT; -import de.steamwar.bausystem.features.loadern.elements.impl.LoaderWait; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT; +import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait; import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java similarity index 98% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 070b2e95..ee03be16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java index 135cd7ac..f42ad0db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderRecorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderRecorder.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; -import de.steamwar.bausystem.features.loadern.elements.impl.*; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.impl.*; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java index e9fc9004..b3e2ba2f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/LoaderScoreboardElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern; +package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java index be62173c..7650878c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/ElementSettings.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/ElementSettings.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java index 4b1734bd..eb173dc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.inventory.SWItem; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java similarity index 98% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java index eabd054f..dad60ebf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/LoaderInteractionElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/LoaderInteractionElement.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements; +package de.steamwar.bausystem.features.loader.elements; import de.steamwar.bausystem.BauSystem; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java index 25f874c3..fef006f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderComparator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderComparator.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java index 42d1909f..10c2b74c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderDaylightDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderDaylightDetector.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java index 5ed7cfdf..b2cf3ff4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLectern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLectern.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java index 1e20094c..911daf57 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderLever.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderLever.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java similarity index 97% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java index 00d6855d..55c41fd7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderMovement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderMovement.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java similarity index 95% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java index 40a7a198..b8c04fe8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderNoteBlock.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderNoteBlock.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Instrument; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java index a63cbdb1..de4abe42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderOpenable.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderOpenable.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java index b73f3a56..26234c54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderRepeater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderRepeater.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java similarity index 94% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java index 929b14c2..6c95bf71 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTNT.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTNT.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java index 6f09ba4a..098d29ea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderTicks.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderTicks.java @@ -17,11 +17,11 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.ElementSettings; -import de.steamwar.bausystem.features.loadern.elements.LoaderInteractionElement; +import de.steamwar.bausystem.features.loader.elements.ElementSettings; +import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java similarity index 96% rename from BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java index 2dc8eb19..0c694a87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loadern/elements/impl/LoaderWait.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/elements/impl/LoaderWait.java @@ -17,10 +17,10 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.loadern.elements.impl; +package de.steamwar.bausystem.features.loader.elements.impl; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.elements.LoaderElement; +import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index 10d4a75d..e0ec0872 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -1,7 +1,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loadern.Loader; +import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; From 76631908f0898b370510e45f7e718769d036b666 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 19:45:27 +0200 Subject: [PATCH 105/174] Add Flag.ITEMS for 1.19 server and up Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 9 ++ BauSystem_Main/src/BauSystem_de.properties | 9 ++ .../features/region/ItemsCommand.java | 87 +++++++++++++++++++ .../features/region/ItemsListener.java | 68 +++++++++++++++ .../bausystem/region/FlagStorage.java | 2 +- .../steamwar/bausystem/region/flags/Flag.java | 4 +- .../region/flags/flagvalues/ItemMode.java | 60 +++++++++++++ 7 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9f4b2edb..fcc1f0e5 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -46,6 +46,7 @@ FLAG_TNT = TNT FLAG_FIRE = Fire FLAG_FREEZE = Freeze FLAG_PROTECT = Protect +FLAG_ITEMS = Items FLAG_FIRE_ALLOW = §con FLAG_FIRE_DENY = §aoff @@ -60,6 +61,9 @@ FLAG_TNT_ALLOW = §aon FLAG_TNT_DENY = §coff FLAG_TNT_ONLY_TB = §7no §ebuild area +FLAG_ITEMS_ACTIVE = §aon +FLAG_ITEMS_INACTIVE = §coff + FLAG_COLOR_WHITE = §fWhite FLAG_COLOR_ORANGE = §6Orange FLAG_COLOR_MAGENTA = §dMagenta @@ -1052,6 +1056,11 @@ REGION_FREEZE_HELP=§8/§efreeze §8- §7Toggle Freeze REGION_FREEZE_NO_PERMS=§cYou are not allowed to freeze this world REGION_FREEZE_ENABLED=§cRegion frozen REGION_FREEZE_DISABLED=§aRegion thawed +REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items +REGION_ITEMS_NO_PERMS=§cYou are not allowed to toggle items in this world +REGION_ITEMS_ENABLED=§cItems disabled in this region +REGION_ITEMS_ENABLED_GLOBAL=§cItems disabled in this world +REGION_ITEMS_DISABLED=§aItems enabled in this region REGION_PROTECT_HELP=§8/§eprotect §8- §7Protect the region REGION_PROTECT_DISABLE=§cProtection disabled REGION_PROTECT_ENABLE=§aProtection enabled diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 97ba1f97..b9e86e58 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -46,6 +46,7 @@ FLAG_TNT = TNT FLAG_FIRE = Fire FLAG_FREEZE = Freeze FLAG_PROTECT = Protect +FLAG_ITEMS = Items FLAG_FIRE_ALLOW = §can FLAG_FIRE_DENY = §aaus @@ -60,6 +61,9 @@ FLAG_TNT_ALLOW = §aan FLAG_TNT_DENY = §caus FLAG_TNT_ONLY_TB = §7Kein §eBaurahmen +FLAG_ITEMS_ACTIVE = §aan +FLAG_ITEMS_INACTIVE = §caus + FLAG_COLOR_WHITE = §fWeiß FLAG_COLOR_ORANGE = §6Orange FLAG_COLOR_MAGENTA = §dMagenta @@ -1021,6 +1025,11 @@ REGION_FREEZE_HELP=§8/§efreeze §8- §7Toggle Freeze REGION_FREEZE_NO_PERMS=§cDu darfst diese Welt nicht einfrieren REGION_FREEZE_ENABLED=§cRegion eingefroren REGION_FREEZE_DISABLED=§aRegion aufgetaut +REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items +REGION_ITEMS_NO_PERMS=§cDu darfst hier nicht Items (de-)aktivieren +REGION_ITEMS_ENABLED=§cItems deaktiviert in dieser Region +REGION_ITEMS_ENABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. +REGION_ITEMS_DISABLED=§aItems aktiviert in dieser Region REGION_PROTECT_HELP=§8/§eprotect §8- §7Schütze die Region REGION_PROTECT_DISABLE=§cBoden Schutz aufgehoben REGION_PROTECT_ENABLE=§aBoden geschützt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java new file mode 100644 index 00000000..8eb42c64 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -0,0 +1,87 @@ +/* + * 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.region; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ItemMode; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.entity.Player; + +@Linked +@MinVersion(19) +public class ItemsCommand extends SWCommand { + + public ItemsCommand() { + super("items"); + } + + @Register(description = "REGION_ITEMS_HELP") + public void toggleCommand(@Validator Player p) { + Region region = Region.getRegion(p.getLocation()); + if (region != GlobalRegion.getInstance() && GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class) == ItemMode.INACTIVE) { + RegionUtils.actionBar(region, "REGION_ITEMS_ENABLED_GLOBAL"); + return; + } + + if (toggle(region)) { + RegionUtils.actionBar(region, getEnableMessage()); + } else { + RegionUtils.actionBar(region, getDisableMessage()); + } + } + + private String getNoPermMessage() { + return "REGION_ITEMS_NO_PERMS"; + } + + private String getEnableMessage(){ + return "REGION_ITEMS_ENABLED"; + } + + private String getDisableMessage(){ + return "REGION_ITEMS_DISABLED"; + } + + private boolean toggle(Region region) { + switch (region.getPlain(Flag.ITEMS, ItemMode.class)) { + case ACTIVE: + region.set(Flag.ITEMS, ItemMode.INACTIVE); + return false; + default: + case INACTIVE: + region.set(Flag.ITEMS, ItemMode.ACTIVE); + return true; + } + } + + @ClassValidator(value = Player.class, local = true) + public TypeValidator validator() { + return (commandSender, player, messageSender) -> { + return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), getNoPermMessage()); + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java new file mode 100644 index 00000000..1becf08b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsListener.java @@ -0,0 +1,68 @@ +/* + * 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.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ItemMode; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import de.steamwar.linkage.MinVersion; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ItemSpawnEvent; + +@Linked +@MinVersion(19) +public class ItemsListener implements Listener, ScoreboardElement { + + private static ItemMode getMode(Region region) { + ItemMode itemMode = GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class); + if (itemMode == ItemMode.INACTIVE) return ItemMode.INACTIVE; + return region.getPlain(Flag.ITEMS, ItemMode.class); + } + + @EventHandler + public void onItemSpawn(ItemSpawnEvent event) { + if (getMode(Region.getRegion(event.getLocation())) == ItemMode.INACTIVE) { + event.setCancelled(true); + } + } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 3; + } + + @Override + public String get(Region region, Player p) { + ItemMode itemMode = getMode(region); + if (itemMode == ItemMode.ACTIVE) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.ITEMS.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(itemMode.getChatValue(), p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index b89f3df5..e0ee43a5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -84,7 +84,7 @@ public class FlagStorage { } public Flag.Value get(final Flag flagType) { - return flags.get(flagType); + return flags.getOrDefault(flagType, flagType.getDefaultValue()); } public boolean set(final Tag tag) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 0c45d1ce..86888666 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -33,7 +33,9 @@ public enum Flag implements EnumDisplay { TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE), + ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.ACTIVE), + ; @Getter private static final Set flags; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java new file mode 100644 index 00000000..c0cefa38 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/ItemMode.java @@ -0,0 +1,60 @@ +/* + * 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.region.flags.flagvalues; + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ItemMode implements Flag.Value { + + ACTIVE("FLAG_ITEMS_ACTIVE"), + INACTIVE("FLAG_ITEMS_INACTIVE"); + + private static ItemMode[] values; + private final String chatValue; + + @Override + public ItemMode[] getValues() { + if (ItemMode.values == null) { + ItemMode.values = ItemMode.values(); //NOSONAR + } + return ItemMode.values; + } + + @Override + public ItemMode getValue() { + return this; + } + + @Override + public ItemMode getValueOf(final String name) { + try { + return ItemMode.valueOf(name.toUpperCase()); + } catch (IllegalArgumentException e) { + if (name.equalsIgnoreCase("false")) { + return ItemMode.INACTIVE; + } + return ItemMode.ACTIVE; + } + } +} From d715a6a066fca112d88af81f393874fe46f03bf7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 19:56:41 +0200 Subject: [PATCH 106/174] Hotfix BauInfoBauGuiItem Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index fcc1f0e5..438728ee 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -144,6 +144,7 @@ BAU_INFO_ITEM_LORE_DAMAGE= BAU_INFO_ITEM_LORE_FIRE = §7Fire§8: §e{0} BAU_INFO_ITEM_LORE_COLOR = §7Color§8: §e{0} BAU_INFO_ITEM_LORE_PROTECT = §7Protect§8: §e{0} +BAU_INFO_ITEM_LORE_ITEMS = §7Items§8: §e{0} BAU_INFO_COMMAND_HELP = §8/§ebauinfo §8- §7Information regarding this build server BAU_INFO_COMMAND_OWNER = §7Owner: §e{0} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java index 7f3c27b9..d8ba9171 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/BauInfoBauGuiItem.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.core.Core; import de.steamwar.inventory.SWItem; import de.steamwar.linkage.Linked; import de.steamwar.sql.SteamwarUser; @@ -58,6 +59,9 @@ public class BauInfoBauGuiItem extends BauGuiItem { if (flag == Flag.PROTECT && region.getFloorLevel() == 0) { continue; } + if (flag == Flag.ITEMS && Core.getVersion() < 19) { + continue; + } Flag.Value value = region.get(flag); if (value != null) { stringList.add(BauSystem.MESSAGE.parse("BAU_INFO_ITEM_LORE_" + flag.name(), player, BauSystem.MESSAGE.parse(value.getChatValue(), player))); From 911f91a5706d3e8e3cd4d5de15c4549ec09d54e8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 9 May 2023 21:10:52 +0200 Subject: [PATCH 107/174] Fix messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 6 +++--- BauSystem_Main/src/BauSystem_de.properties | 6 +++--- .../de/steamwar/bausystem/features/region/ItemsCommand.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 438728ee..448fd952 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1059,9 +1059,9 @@ REGION_FREEZE_ENABLED=§cRegion frozen REGION_FREEZE_DISABLED=§aRegion thawed REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items REGION_ITEMS_NO_PERMS=§cYou are not allowed to toggle items in this world -REGION_ITEMS_ENABLED=§cItems disabled in this region -REGION_ITEMS_ENABLED_GLOBAL=§cItems disabled in this world -REGION_ITEMS_DISABLED=§aItems enabled in this region +REGION_ITEMS_ENABLED=§aItems enabled in this region +REGION_ITEMS_DISABLED_GLOBAL=§cItems disabled in this world +REGION_ITEMS_DISABLED=§cItems disabled in this region REGION_PROTECT_HELP=§8/§eprotect §8- §7Protect the region REGION_PROTECT_DISABLE=§cProtection disabled REGION_PROTECT_ENABLE=§aProtection enabled diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index b9e86e58..804afa46 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1027,9 +1027,9 @@ REGION_FREEZE_ENABLED=§cRegion eingefroren REGION_FREEZE_DISABLED=§aRegion aufgetaut REGION_ITEMS_HELP=§8/§eitems §8- §7Toggle Items REGION_ITEMS_NO_PERMS=§cDu darfst hier nicht Items (de-)aktivieren -REGION_ITEMS_ENABLED=§cItems deaktiviert in dieser Region -REGION_ITEMS_ENABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. -REGION_ITEMS_DISABLED=§aItems aktiviert in dieser Region +REGION_ITEMS_ENABLED=§aItems aktiviert in dieser Region +REGION_ITEMS_DISABLED=§cItems deaktiviert in dieser Region +REGION_ITEMS_DISABLED_GLOBAL=§cItems sind auf dem Server deaktiviert. REGION_PROTECT_HELP=§8/§eprotect §8- §7Schütze die Region REGION_PROTECT_DISABLE=§cBoden Schutz aufgehoben REGION_PROTECT_ENABLE=§aBoden geschützt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java index 8eb42c64..3b99382d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -43,7 +43,7 @@ public class ItemsCommand extends SWCommand { public void toggleCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); if (region != GlobalRegion.getInstance() && GlobalRegion.getInstance().getPlain(Flag.ITEMS, ItemMode.class) == ItemMode.INACTIVE) { - RegionUtils.actionBar(region, "REGION_ITEMS_ENABLED_GLOBAL"); + RegionUtils.actionBar(region, "REGION_ITEMS_DISABLED_GLOBAL"); return; } From d2473ee72f91608653e8701f57532de52554ff83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 May 2023 20:59:42 +0200 Subject: [PATCH 108/174] Add global ItemsCommand Signed-off-by: yoyosource --- .../bausystem/features/region/ItemsCommand.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java index 3b99382d..157f16ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -54,6 +54,16 @@ public class ItemsCommand extends SWCommand { } } + @Register(value = "global", description = "REGION_ITEMS_HELP") + public void globalToggleCommand(@Validator Player p) { + Region region = GlobalRegion.getInstance(); + if (toggle(region)) { + RegionUtils.actionBar(region, getEnableMessage()); + } else { + RegionUtils.actionBar(region, getDisableMessage()); + } + } + private String getNoPermMessage() { return "REGION_ITEMS_NO_PERMS"; } From 6b395bde172f395567d55a711dbebd9a9d317c19 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 10 May 2023 21:03:28 +0200 Subject: [PATCH 109/174] Remove help Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/region/ItemsCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java index 157f16ae..cbde76cf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ItemsCommand.java @@ -54,7 +54,7 @@ public class ItemsCommand extends SWCommand { } } - @Register(value = "global", description = "REGION_ITEMS_HELP") + @Register(value = "global") public void globalToggleCommand(@Validator Player p) { Region region = GlobalRegion.getInstance(); if (toggle(region)) { From 072833f503b2dd1d3e8e5a6eae24a131c829cfb9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 13 May 2023 11:09:28 +0200 Subject: [PATCH 110/174] Fix TPSLimit Freeze Signed-off-by: yoyosource --- .../bausystem/features/script/variables/Constants.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java index e0ec0872..b14310b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.script.variables; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tracer.record.ActiveTracer; @@ -275,7 +276,10 @@ public class Constants { }); CONSTANTS.put("tps", player -> { - return new ConstantDoubleValue(TPSWatcher::getTPS); + return new ConstantDoubleValue(() -> { + if (FreezeUtils.isFrozen()) return 0.0; + return TPSWatcher.getTPS(); + }); }); CONSTANTS.put("tps_limit", player -> { return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit); From 16a6d10472fac763b225fedbb9eaa7db87897953 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 19:29:38 +0200 Subject: [PATCH 111/174] Script System Lua Todo: * /script and global script storage * Code Cleanup --- .../linkage/types/LuaLib_GENERIC.java | 21 ++ .../linkage/types/Operator_GENERIC.java | 40 -- .../linkage/types/SpecialCommand_GENERIC.java | 40 -- BauSystem_Main/build.gradle | 2 + .../features/region/TNTListener.java | 19 +- .../features/script/CustomScriptManager.java | 342 ------------------ .../features/script/ScriptCommand.java | 153 -------- .../features/script/ScriptExecutor.java | 304 ---------------- .../features/script/ScriptListener.java | 30 +- .../features/script/ScriptRunner.java | 75 ++++ .../features/script/ScriptSyntaxSender.java | 105 ------ .../features/script/SpecialCommand.java | 86 ----- .../features/script/command/Call.java | 49 --- .../features/script/command/Exit.java | 41 --- .../bausystem/features/script/command/If.java | 68 ---- .../features/script/command/Jump.java | 49 --- .../features/script/command/Return.java | 43 --- .../features/script/command/Sleep.java | 58 --- .../script/command/arithmetic/other/Ceil.java | 107 ------ .../command/arithmetic/other/Floor.java | 107 ------ .../command/arithmetic/other/Round.java | 107 ------ .../features/script/command/io/Echo.java | 62 ---- .../script/command/io/Echoactionbar.java | 62 ---- .../features/script/command/io/Input.java | 79 ---- .../script/command/string/Insert.java | 98 ----- .../script/command/string/Remove.java | 89 ----- .../script/command/string/Replace.java | 98 ----- .../script/command/string/Substring.java | 99 ----- .../script/command/variable/Const.java | 87 ----- .../script/command/variable/Convert.java | 74 ---- .../script/command/variable/Global.java | 67 ---- .../script/command/variable/Unglobal.java | 49 --- .../script/command/variable/Unvar.java | 49 --- .../features/script/command/variable/Var.java | 67 ---- .../script/command/world/GetMaterial.java | 89 ----- .../script/command/world/SetMaterial.java | 92 ----- .../features/script/custom/MenuScript.java | 29 -- .../features/script/custom/Script.java | 23 -- .../custom/command/CommandListener.java | 45 --- .../script/custom/command/CustomCommand.java | 87 ----- .../custom/command/InventoryCommand.java | 51 --- .../script/custom/command/MenuCommand.java | 99 ----- .../script/custom/event/CustomEvent.java | 34 -- .../script/custom/event/EventType.java | 133 ------- .../script/custom/event/InventoryEvent.java | 47 --- .../script/custom/event/MenuEvent.java | 76 ---- .../features/script/custom/hotkey/Hotkey.java | 29 -- .../script/custom/hotkey/HotkeyListener.java | 57 --- .../script/custom/hotkey/Hotkeys.java | 135 ------- .../script/custom/hotkey/InventoryHotkey.java | 51 --- .../script/custom/hotkey/MenuHotkey.java | 80 ---- .../script/event/CommandListener.java | 22 ++ .../{custom => }/event/EventListener.java | 85 +++-- .../script/expression/Expression.java | 242 ------------- .../features/script/expression/Operator.java | 37 -- .../expression/UnknownOperatorException.java | 27 -- .../expression/VarNotFoundException.java | 27 -- .../operator/comparison/EqualOperator.java | 61 ---- .../operator/comparison/GreaterOperator.java | 50 --- .../comparison/GreaterOrEqualOperator.java | 50 --- .../operator/comparison/LessOperator.java | 50 --- .../comparison/LessOrEqualOperator.java | 50 --- .../operator/comparison/NotEqualOperator.java | 61 ---- .../operator/logic/AndOperator.java | 47 --- .../operator/logic/BitwiseAndOperator.java | 55 --- .../operator/logic/BitwiseOrOperator.java | 55 --- .../operator/logic/BitwiseXorOperator.java | 55 --- .../expression/operator/logic/OrOperator.java | 47 --- .../operator/math/BitwiseLeftOperator.java | 46 --- .../math/BitwiseLogicRightOperator.java | 46 --- .../operator/math/BitwiseRightOperator.java | 46 --- .../operator/math/DivideOperator.java | 49 --- .../operator/math/MinusOperator.java | 50 --- .../operator/math/ModuloOperator.java | 46 --- .../operator/math/MultiplyOperator.java | 57 --- .../operator/math/PlusOperator.java | 53 --- .../operator/math/PowerOperator.java | 46 --- .../script/items/ScriptMenuBauGuiItem.java | 55 --- .../features/script/lua/CommandRegister.java | 15 + .../script/lua/SteamWarGlobalLuaPlugin.java | 74 ++++ .../script/lua/SteamWarLuaPlugin.java | 144 ++++++++ .../features/script/lua/SteamWarPlatform.java | 40 ++ .../features/script/lua/libs/LuaLib.java | 88 +++++ .../features/script/lua/libs/PlayerLib.java | 66 ++++ .../features/script/lua/libs/RegionLib.java | 58 +++ .../features/script/lua/libs/ServerLib.java | 65 ++++ .../features/script/variables/Constants.java | 315 ---------------- .../features/script/variables/Context.java | 42 --- .../features/script/variables/Value.java | 188 ---------- SCRIPT.md | 183 ++++++++++ 90 files changed, 919 insertions(+), 5857 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java delete mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java delete mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java rename BauSystem_Main/src/de/steamwar/bausystem/features/script/{custom => }/event/EventListener.java (52%) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java create mode 100644 SCRIPT.md diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java new file mode 100644 index 00000000..79c02770 --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java @@ -0,0 +1,21 @@ +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 LuaLib_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + buildPlan.addImport("de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin"); + methodBuilder.addLine("SteamWarLuaPlugin.add(" + s + ");"); + } +} diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_GENERIC.java deleted file mode 100644 index 8a1916a8..00000000 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/Operator_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 Operator_GENERIC implements LinkageType { - - @Override - public String method() { - return "linkScriptCommands"; - } - - @Override - public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { - buildPlan.addImport("de.steamwar.bausystem.features.script.expression.Expression"); - methodBuilder.addLine("Expression.registerOperator(" + s + ");"); - } -} diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_GENERIC.java deleted file mode 100644 index 97c63276..00000000 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/SpecialCommand_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 SpecialCommand_GENERIC implements LinkageType { - - @Override - public String method() { - return "linkScriptCommands"; - } - - @Override - public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { - buildPlan.addImport("de.steamwar.bausystem.features.script.ScriptExecutor"); - methodBuilder.addLine("ScriptExecutor.SPECIAL_COMMANDS.add(" + s + ");"); - } -} diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index 1052e30a..2e9a8d6c 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -64,4 +64,6 @@ dependencies { annotationProcessor swdep('SpigotCore') compileOnly swdep('FastAsyncWorldEdit-1.18') + + implementation 'org.luaj:luaj-jse:3.0.1' } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 08309eb6..d65a8750 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -20,8 +20,6 @@ package de.steamwar.bausystem.features.region; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.bausystem.features.script.custom.event.EventType; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; @@ -48,10 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean; @Linked public class TNTListener implements Listener, ScoreboardElement { - @LinkedInstance - public CustomScriptManager customScriptManager; - - private void explode(List blockList, Location location, EventType eventType, Event event) { + private void explode(List blockList) { AtomicBoolean inBuild = new AtomicBoolean(); blockList.removeIf(block -> { Region region = Region.getRegion(block.getLocation()); @@ -71,24 +66,16 @@ public class TNTListener implements Listener, ScoreboardElement { } return value == TNTMode.DENY; }); - if (inBuild.get()) { - Region region = Region.getRegion(location); - for (Player player : Bukkit.getOnlinePlayers()) { - if (region.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - customScriptManager.callEvent(eventType, player, event); - } - } - } } @EventHandler public void onBlockExplode(BlockExplodeEvent event) { - explode(event.blockList(), event.getBlock().getLocation(), null, null); + explode(event.blockList()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onExplode(EntityExplodeEvent event) { - explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); + explode(event.blockList()); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java deleted file mode 100644 index 0c4e50af..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/CustomScriptManager.java +++ /dev/null @@ -1,342 +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.script; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.custom.command.CustomCommand; -import de.steamwar.bausystem.features.script.custom.command.InventoryCommand; -import de.steamwar.bausystem.features.script.custom.command.MenuCommand; -import de.steamwar.bausystem.features.script.custom.event.CustomEvent; -import de.steamwar.bausystem.features.script.custom.event.EventType; -import de.steamwar.bausystem.features.script.custom.event.InventoryEvent; -import de.steamwar.bausystem.features.script.custom.event.MenuEvent; -import de.steamwar.bausystem.features.script.custom.hotkey.Hotkey; -import de.steamwar.bausystem.features.script.custom.hotkey.Hotkeys; -import de.steamwar.bausystem.features.script.custom.hotkey.InventoryHotkey; -import de.steamwar.bausystem.features.script.custom.hotkey.MenuHotkey; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.bausystem.utils.FlatteningWrapper; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import de.steamwar.linkage.Linked; -import de.steamwar.sql.UserConfig; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.output.LengthOutput; -import yapion.hierarchy.output.StringOutput; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; -import yapion.hierarchy.types.YAPIONObject; -import yapion.hierarchy.types.YAPIONValue; -import yapion.parser.YAPIONParser; - -import java.util.*; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -@Linked -public class CustomScriptManager implements Listener { - - public final Map> playerMap = Collections.synchronizedMap(new HashMap<>()); // new ConcurrentHashMap<>(); - - private void updateInventory(Player p) { - playerMap.computeIfPresent(p, (player, customCommands) -> { - customCommands.removeIf(script -> !(script instanceof MenuScript)); - return customCommands; - }); - for (ItemStack item : p.getInventory().getContents()) { - if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { - continue; - } - - BookMeta bookMeta = ((BookMeta) item.getItemMeta()); - if (bookMeta.getPageCount() == 0) { - continue; - } - if (bookMeta.getPage(1).isEmpty()) { - continue; - } - String s = bookMeta.getPage(1).split("\n")[0]; - if (s.startsWith("#!CMD /")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryCommand(bookMeta, s.substring(6).split(" "))); - } else if (s.startsWith("#!EVENT ")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryEvent(bookMeta, s.substring(8).split(" "))); - } else if (s.startsWith("#!HOTKEY ")) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new InventoryHotkey(bookMeta, s.substring(9).split(" "))); - } - } - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - load(e.getPlayer()); - } - - private synchronized void load(Player p) { - updateInventory(p); - - String s = UserConfig.getConfig(p.getUniqueId(), "bausystem-scripts"); - if (s == null) { - s = UserConfig.getConfig(p.getUniqueId(), "bausystem-commands"); - UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-commands"); - } - YAPIONObject yapionObject; - if (s == null) { - yapionObject = new YAPIONObject(); - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui")); - } else { - yapionObject = YAPIONParser.parse(s); - if (yapionObject.containsKey("")) { - yapionObject.add("commands", yapionObject.getMap("")); - yapionObject.remove(""); - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).add("FF", new YAPIONArray().add("#!EVENT FF /gui Script\ngui")); - } - } - - yapionObject.getYAPIONMapOrSetDefault("commands", new YAPIONMap()).forEach((key, value) -> { - String[] command = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuCommand(pages, command)); - }); - - yapionObject.getYAPIONMapOrSetDefault("events", new YAPIONMap()).forEach((key, value) -> { - String[] event = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuEvent(pages, event)); - }); - - yapionObject.getYAPIONMapOrSetDefault("hotkeys", new YAPIONMap()).forEach((key, value) -> { - String[] hotkey = ((YAPIONValue) key).get().split(" "); - List pages = ((YAPIONArray) value).stream().map(YAPIONValue.class::cast).map(YAPIONValue::get).map(String.class::cast).collect(Collectors.toList()); - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(new MenuHotkey(pages, hotkey)); - }); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent e) { - save(e.getPlayer()); - playerMap.remove(e.getPlayer()); - } - - private YAPIONObject output(Player p) { - if (!playerMap.containsKey(p)) return new YAPIONObject(); - YAPIONObject yapionObject = new YAPIONObject(); - - YAPIONMap commandsMap = new YAPIONMap(); - yapionObject.add("commands", commandsMap); - playerMap.get(p).stream().filter(MenuCommand.class::isInstance).map(MenuCommand.class::cast).forEach(menuCommand -> { - menuCommand.save(commandsMap); - }); - - YAPIONMap eventsMap = new YAPIONMap(); - yapionObject.add("events", eventsMap); - playerMap.get(p).stream().filter(MenuEvent.class::isInstance).map(MenuEvent.class::cast).forEach(menuCommand -> { - menuCommand.save(eventsMap); - }); - - YAPIONMap hotkeysMap = new YAPIONMap(); - yapionObject.add("hotkeys", hotkeysMap); - playerMap.get(p).stream().filter(MenuHotkey.class::isInstance).map(MenuHotkey.class::cast).forEach(menuCommand -> { - menuCommand.save(hotkeysMap); - }); - return yapionObject; - } - - private boolean save(Player p) { - if (!playerMap.containsKey(p)) { - UserConfig.removePlayerConfig(p.getUniqueId(), "bausystem-scripts"); - return true; - } - YAPIONObject yapionObject = output(p); - if (yapionObject.toYAPION(new LengthOutput()).getLength() > 64 * 1024) { - return false; - } - UserConfig.updatePlayerConfig(p.getUniqueId(), "bausystem-scripts", yapionObject.toYAPION(new StringOutput()).getResult()); - return true; - } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent e) { - if (e.getPlayer() instanceof Player) { - updateInventory((Player) e.getPlayer()); - } - } - - public void openCommandsMenu(Player p) { - List> menuCommands = new ArrayList<>(); - playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(MenuScript.class::isInstance).map(MenuScript.class::cast).forEach(menuItem -> { - SWItem swItem = menuItem.toItem(p); - ItemStack itemStack = swItem.getItemStack(); - if (menuItem instanceof MenuHotkey) { - itemStack.setType(Material.CHAIN_COMMAND_BLOCK); - } else if (menuItem instanceof MenuEvent) { - itemStack.setType(Material.REPEATING_COMMAND_BLOCK); - } else { - itemStack.setType(Material.COMMAND_BLOCK); - } - swItem.setItemStack(itemStack); - swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", p), BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", p))); - - menuCommands.add(new SWListInv.SWListEntry<>(swItem, menuItem)); - }); - - int length = (int) output(p).toYAPION(new LengthOutput()).getLength(); - double percentage = ((int) ((length / 655336.0) * 1000)) / 10.0; - String menuName = BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_NAME", p, percentage > 99 ? "§c" : (percentage >= 75 ? "§6" : "§a"), percentage); - - SWListInv menuCommandSWListInv = new SWListInv<>(p, menuName, false, menuCommands, (clickType, menuCommand) -> { - if (!clickType.isShiftClick()) { - playerMap.get(p).removeIf(customCommand -> customCommand == menuCommand); - } - SWUtils.giveItemToPlayer(p, menuCommand.toItem(p).getItemStack()); - p.closeInventory(); - save(p); - }); - menuCommandSWListInv.setItem(49, new SWItem(Material.HOPPER, BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_ADD_LORE", p)), false, clickType -> { - ItemStack item = p.getItemOnCursor(); - if (item.getType().isAir()) { - return; - } - if (FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { - return; - } - - BookMeta bookMeta = ((BookMeta) item.getItemMeta()); - if (bookMeta.getPageCount() == 0) { - return; - } - if (bookMeta.getPage(1).isEmpty()) { - return; - } - String s = bookMeta.getPage(1).split("\n")[0]; - if (s.startsWith("#!CMD /")) { - MenuCommand menuCommand = new MenuCommand(bookMeta.getPages(), s.substring(6).split(" ")); - for (Script script : playerMap.computeIfAbsent(p, player -> new ArrayList<>())) { - if (!(script instanceof MenuCommand)) { - continue; - } - if (((MenuCommand) script).equals(menuCommand)) { - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_DUPLICATE_COMMAND", p, String.join(" ", menuCommand.command())); - return; - } - } - scriptBookLimit(p, menuCommand); - } else if (s.startsWith("#!EVENT ")) { - MenuEvent menuEvent = new MenuEvent(bookMeta.getPages(), s.substring(8).split(" ")); - try { - EventType.valueOf(menuEvent.eventName()); - } catch (Exception e) { - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_UNKNOWN_EVENT", p, menuEvent.eventName()); - return; - } - scriptBookLimit(p, menuEvent); - } else if (s.startsWith("#!HOTKEY ")) { - scriptBookLimit(p, new MenuHotkey(bookMeta.getPages(), s.substring(9).split(" "))); - } - })); - menuCommandSWListInv.open(); - } - - private void scriptBookLimit(Player p, Script menuScript) { - playerMap.computeIfAbsent(p, player -> new ArrayList<>()).add(menuScript); - if (!save(p)) { - playerMap.get(p).removeIf(script -> script == menuScript); - p.closeInventory(); - SWUtils.giveItemToPlayer(p, p.getItemOnCursor()); - save(p); - BauSystem.MESSAGE.sendPrefixless("SCRIPT_MENU_GUI_LIMIT", p); - return; - } - p.setItemOnCursor(null); - openCommandsMenu(p); - } - - public boolean callCommand(Player p, PlayerCommandPreprocessEvent e, String message) { - List customCommands = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomCommand.class::isInstance).map(CustomCommand.class::cast).collect(Collectors.toList()); - String[] command = message.split(" "); - for (CustomCommand customCommand : customCommands) { - if (customCommand.execute(command, e)) { - return true; - } - } - return false; - } - - public boolean callScoreboard(Player p, Map variables, Consumer echoConsumer) { - Map valueMap = new HashMap<>(); - for (Map.Entry entry : variables.entrySet()) { - valueMap.put(entry.getKey(), new Value.StringValue(entry.getValue())); - } - List customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList()); - boolean hasScript = false; - for (CustomEvent customEvent : customEvents) { - if (customEvent.eventName().equals(EventType.Scoreboard.name())) { - customEvent.execute(p, valueMap, echoConsumer); - hasScript = true; - } - } - return hasScript; - } - - public void callEvent(EventType eventType, Player p, Event e) { - if (eventType == null) return; - if (!eventType.getEventType().equals(e.getClass())) return; - - List customEvents = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(CustomEvent.class::isInstance).map(CustomEvent.class::cast).collect(Collectors.toList()); - for (CustomEvent customEvent : customEvents) { - if (customEvent.eventName().equals(eventType.name())) { - Map variables = eventType.getEventValues().apply(e); - if (variables == null) { - variables = new HashMap<>(); - } - if (e instanceof Cancellable) { - variables.put("cancel", new Value.BooleanValue(((Cancellable) e).isCancelled())); - } - customEvent.execute(p, variables, null); - if (variables.containsKey("cancel")) { - Value value = variables.get("cancel"); - ((Cancellable) e).setCancelled(value.asBoolean()); - } - } - } - } - - public void callHotkey(int modifiers, char pressedHotkey, Player p, boolean pressed) { - List hotkeys = playerMap.getOrDefault(p, new ArrayList<>()).stream().filter(Hotkey.class::isInstance).map(Hotkey.class::cast).collect(Collectors.toList()); - for (Hotkey hotkey : hotkeys) { - if (Hotkeys.isSame(modifiers, pressedHotkey, hotkey.hotkey())) { - hotkey.execute(p, pressed); - } - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java index d9bed371..6952d796 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -1,163 +1,10 @@ package de.steamwar.bausystem.features.script; -import de.steamwar.bausystem.BauSystem; import de.steamwar.command.SWCommand; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; - -import static de.steamwar.bausystem.features.script.ScriptExecutor.SPECIAL_COMMANDS; - -@Linked public class ScriptCommand extends SWCommand { public ScriptCommand() { super("script"); } - - @LinkedInstance - public CustomScriptManager customScriptManager = null; - - private List loreBuilder(Player p, String... strings) { - List result = new ArrayList<>(); - for (String s : strings) { - result.addAll(split(BauSystem.MESSAGE.parse(s, p))); - } - return result; - } - - @Register(description = "SCRIPT_COMMAND_HELP") - public void menuCommand(Player p) { - List> swItems = new ArrayList<>(); - addEmptyItems(swItems, 2); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_HOTKEYS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4", "SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5")), null)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_COMMANDS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1", "SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2")), null)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_EVENTS", loreBuilder(p, "SCRIPT_GUI_CUSTOM_EVENTS_LORE_1", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_2", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_3", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_4", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_5", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_6", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_7", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_8", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_9", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_10", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_11", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_12", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_13", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_14", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_15", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_16", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_17", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_18", "SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1")), null)); - addEmptyItems(swItems, 1); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_OTHER", loreBuilder(p, "SCRIPT_GUI_OTHER_LORE_1", "SCRIPT_GUI_OTHER_LORE_2", "SCRIPT_GUI_OTHER_LORE_3", "SCRIPT_GUI_OTHER_LORE_4", "SCRIPT_GUI_OTHER_LORE_5", "SCRIPT_GUI_OTHER_LORE_6", "SCRIPT_GUI_OTHER_LORE_7", "SCRIPT_GUI_OTHER_LORE_8", "SCRIPT_GUI_OTHER_LORE_9", "SCRIPT_GUI_OTHER_LORE_10", "SCRIPT_GUI_OTHER_LORE_11", "SCRIPT_GUI_OTHER_LORE_12", "SCRIPT_GUI_OTHER_LORE_13", "SCRIPT_GUI_OTHER_LORE_14", "SCRIPT_GUI_OTHER_LORE_15", "SCRIPT_GUI_OTHER_LORE_16", "SCRIPT_GUI_OTHER_LORE_17", "SCRIPT_GUI_OTHER_LORE_18")), null)); - addEmptyItems(swItems, 2); - addCustomScriptsItems(swItems, p); - addEmptyItems(swItems, 45 - swItems.size() % 45); - addEmptyItems(swItems, 4); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, Material.BOOK, "SCRIPT_GUI_CUSTOM_VARIABLES", new ArrayList<>()), null)); - addEmptyItems(swItems, 4); - addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TIME_NAME", "SCRIPT_GUI_CONSTANT_TIME_LORE"); - addConstantItem(swItems, p, Material.CLOCK, "SCRIPT_GUI_CONSTANT_TICKS_NAME", "SCRIPT_GUI_CONSTANT_TICKS_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_NAME", "SCRIPT_GUI_CONSTANT_TRACE_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME", "SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME", "SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE"); - addConstantItem(swItems, p, Material.TNT_MINECART, "SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME", "SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE"); - addConstantItem(swItems, p, Material.HOPPER, "SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME", "SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE"); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_TNT_NAME", "SCRIPT_GUI_CONSTANT_TNT_LORE"); - addConstantItem(swItems, p, Material.TNT, "SCRIPT_GUI_CONSTANT_ONLY_TB_NAME", "SCRIPT_GUI_CONSTANT_ONLY_TB_LORE"); - addConstantItem(swItems, p, Material.GUNPOWDER, "SCRIPT_GUI_CONSTANT_FREEZE_NAME", "SCRIPT_GUI_CONSTANT_FREEZE_LORE"); - addConstantItem(swItems, p, Material.FIRE_CHARGE, "SCRIPT_GUI_CONSTANT_FIRE_NAME", "SCRIPT_GUI_CONSTANT_FIRE_LORE"); - addConstantItem(swItems, p, Material.OBSIDIAN, "SCRIPT_GUI_CONSTANT_PROTECT_NAME", "SCRIPT_GUI_CONSTANT_PROTECT_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_X_NAME", "SCRIPT_GUI_CONSTANT_X_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Y_NAME", "SCRIPT_GUI_CONSTANT_Y_LORE"); - addConstantItem(swItems, p, Material.PLAYER_HEAD, "SCRIPT_GUI_CONSTANT_Z_NAME", "SCRIPT_GUI_CONSTANT_Z_LORE"); - addConstantItem(swItems, p, Material.NAME_TAG, "SCRIPT_GUI_CONSTANT_NAME_NAME", "SCRIPT_GUI_CONSTANT_NAME_LORE"); - addConstantItem(swItems, p, Material.IRON_BOOTS, "SCRIPT_GUI_CONSTANT_SNEAK_NAME", "SCRIPT_GUI_CONSTANT_SNEAK_LORE"); - addConstantItem(swItems, p, Material.DIAMOND_BOOTS, "SCRIPT_GUI_CONSTANT_SPRINTING_NAME", "SCRIPT_GUI_CONSTANT_SPRINTING_LORE"); - addConstantItem(swItems, p, Material.ARROW, "SCRIPT_GUI_CONSTANT_SLOT_NAME", "SCRIPT_GUI_CONSTANT_SLOT_LORE"); - addConstantItem(swItems, p, Material.GRASS_BLOCK, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE"); - addConstantItem(swItems, p, Material.IRON_BLOCK, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE"); - addConstantItem(swItems, p, Material.BIRCH_SIGN, "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE"); - addConstantItem(swItems, p, Material.ACACIA_SIGN, "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME", "SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE"); - addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME", "SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE"); - addConstantItem(swItems, p, Material.MAP, "SCRIPT_GUI_CONSTANT_REGION_NAME_NAME", "SCRIPT_GUI_CONSTANT_REGION_NAME_LORE"); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_NAME", "SCRIPT_GUI_CONSTANT_TPS_LORE"); - addConstantItem(swItems, p, Material.COMPASS, "SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME", "SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE"); - addEmptyItems(swItems, 45 - swItems.size() % 45); - - SWListInv swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("SCRIPT_GUI_NAME", p), swItems, (clickType, o) -> { - if (o != null) { - BauSystem.MESSAGE.send("SCRIPT_GUI_COMMAND_CHAT", p, o.command()); - for (String s : o.description()) { - if (s.isEmpty()) { - BauSystem.MESSAGE.sendPrefixless("PREFIX", p); - } else { - BauSystem.MESSAGE.send(s, p); - } - } - p.closeInventory(); - } - }); - swListInv.open(); - } - - private void addEmptyItems(List> swItems, int count) { - for (int i = 0; i < count; i++) { - swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> { - }), null)); - } - } - - private SWItem createItem(Player p, Material material, String name, List lore) { - return new SWItem(material, BauSystem.MESSAGE.parse(name, p), lore, false, clickType -> { - }); - } - - private void addConstantItem(List> swItems, Player p, Material material, String name, String lore) { - List itemLore = new ArrayList<>(); - itemLore.add(BauSystem.MESSAGE.parse(lore, p)); - swItems.add(new SWListInv.SWListEntry<>(createItem(p, material, name, itemLore), null)); - } - - private void addCustomScriptsItems(List> swItems, Player p) { - List specialCommands = new ArrayList<>(SPECIAL_COMMANDS); - specialCommands.sort(Comparator.comparing(specialCommand -> specialCommand.getClass().getTypeName())); - specialCommands.forEach(specialCommand -> { - List strings = new ArrayList<>(); - boolean b = false; - for (String s : specialCommand.description()) { - if (s.isEmpty()) { - b = true; - strings.add(""); - continue; - } - s = BauSystem.MESSAGE.parse(s, p); - if (b) { - strings.addAll(split(s)); - } else { - strings.add(s); - } - } - - SWItem swItem = new SWItem(specialCommand.material(), BauSystem.MESSAGE.parse("SCRIPT_GUI_COMMAND_NAME", p, specialCommand.command()), strings, false, clickType -> { - }); - swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand)); - }); - } - - private List split(String s) { - List strings = new ArrayList<>(); - while (s.length() > 60) { - int index = s.indexOf(' ', 60); - if (index == -1) { - strings.add("§7" + s); - s = null; - break; - } else { - strings.add("§7" + s.substring(0, index)); - s = s.substring(index + 1); - } - } - if (s != null) { - strings.add("§7" + s); - } - return strings; - } - - @Register(value = "menu", description = "SCRIPT_COMMAND_HELP_MENU") - public void menuGUICommand(Player p) { - customScriptManager.openCommandsMenu(p); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java deleted file mode 100644 index 25b29147..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ /dev/null @@ -1,304 +0,0 @@ -package de.steamwar.bausystem.features.script; - -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.event.platform.CommandEvent; -import com.sk89q.worldedit.extension.platform.Actor; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.expression.Expression; -import de.steamwar.bausystem.features.script.expression.UnknownOperatorException; -import de.steamwar.bausystem.features.script.expression.VarNotFoundException; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Context; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.bausystem.features.world.WorldEditListener; -import de.steamwar.bausystem.linkage.LinkageUtils; -import de.steamwar.bausystem.utils.WorldEditUtils; -import lombok.Getter; -import lombok.Setter; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.*; -import java.util.function.Consumer; -import java.util.logging.Level; - -public final class ScriptExecutor { - - public static final Set SPECIAL_COMMANDS = new HashSet<>(); - - static { - LinkageUtils.linkScriptCommands(); - } - - private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null; - - private String specialCommand = null; - - @Getter - private final Player player; - - @Getter - private final Context localVariables = new Context(); - - @Getter - private final Context globalVariables; - - private final List commands = new ArrayList<>(); - - @Getter - public final Map jumpPoints = new HashMap<>(); - - @Getter - private final LinkedList returnStack = new LinkedList<>(); - - @Getter - @Setter - private int index = 0; - - @Getter - private final Consumer echoConsumer; - - public ScriptExecutor(BookMeta bookMeta, Player player, Consumer echoConsumer) { - this(bookMeta, player, new HashMap<>(), echoConsumer); - } - - public ScriptExecutor(List pages, Player player, Consumer echoConsumer) { - this(pages, player, new HashMap<>(), echoConsumer); - } - - public ScriptExecutor(BookMeta bookMeta, Player player, Map localVariables, Consumer echoConsumer) { - this.player = player; - globalVariables = ScriptListener.getGlobalContext(player); - - parseMeta(bookMeta); - this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); - }; - if (commands.isEmpty()) return; - localVariables.forEach(this.localVariables::putValue); - resume(); - } - - public ScriptExecutor(List pages, Player player, Map localVariables, Consumer echoConsumer) { - this.player = player; - globalVariables = ScriptListener.getGlobalContext(player); - - parseList(pages); - this.echoConsumer = echoConsumer != null ? echoConsumer : s -> { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", player, s); - }; - if (commands.isEmpty()) return; - localVariables.forEach(this.localVariables::putValue); - resume(); - } - - private void parseMeta(BookMeta bookMeta) { - boolean initial = true; - for (String page : bookMeta.getPages()) { - initial = parsePage(page, initial); - } - } - - private void parseList(List pages) { - boolean initial = true; - for (String page : pages) { - initial = parsePage(page, initial); - } - } - - private boolean parsePage(String page, boolean initial) { - for (String command : page.split("\n")) { - command = command.replaceAll(" +", " "); - if (command.startsWith("#") || command.trim().isEmpty()) { - if (initial && command.startsWith("#!CMD /")) { - specialCommand = command.substring(7).split(" ")[0]; - } - initial = false; - continue; - } - initial = false; - if (command.startsWith(".")) { - jumpPoints.put(command.substring(1), commands.size()); - continue; - } - commands.add(command); - } - return initial; - } - - public void resume() { - if (!player.isOnline()) { - return; - } - - int executionPoints = 0; - - while (index < commands.size()) { - String command = commands.get(index).trim(); - index++; - if (executionPoints++ > 200) { - BauSystem.MESSAGE.send("SCRIPT_SLEEP_ERROR", player); - return; - } - - String[] strings = replaceExpressions(command); - if (strings.length == 0) { - return; - } - boolean found = false; - for (SpecialCommand specialCommand : SPECIAL_COMMANDS) { - if (specialCommand.command().equalsIgnoreCase(strings[0])) { - found = true; - if (!specialCommand.execute(strings, this)) { - return; - } - } - } - if (found) { - continue; - } - - if (strings[0].contains(":")) { - continue; - } - - // Variable Replaces in commands. - command = String.join(" ", strings); - - PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + (specialCommand != null && command.startsWith(specialCommand) ? "script:" : "") + command); - Bukkit.getServer().getPluginManager().callEvent(preprocessEvent); - if (preprocessEvent.isCancelled()) { - continue; - } - - Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); - if (!strings[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + strings[0])) { - EditSession editSession = WorldEditUtils.getEditSession(player); - Actor actor = BukkitAdapter.adapt(player); - WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, command, editSession)); - editSession.flushSession(); - WorldEditUtils.addToPlayer(player, editSession); - } else { - Bukkit.getServer().dispatchCommand(player, command); - } - } - } - - private String[] replaceExpressions(String s) { - s = s.replaceAll(" +", " "); - StringBuilder result = new StringBuilder(); - int depth = 0; - StringBuilder st = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '{') { - st.append(c); - depth++; - } else if (c == '}') { - st.append(c); - depth--; - if (depth == 0) { - try { - Expression expression = new Expression(player, st.toString(), this); - result.append(expression.eval().asString()); - st = new StringBuilder(); - } catch (IllegalArgumentException e) { - BauSystem.MESSAGE.send(e.getMessage(), player); - return new String[0]; - } catch (VarNotFoundException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_VAR", player, e.getMessage()); - return new String[0]; - } catch (IndexOutOfBoundsException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_EXPRESSION", player, st.toString()); - return new String[0]; - } catch (UnknownOperatorException e) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION", player, e.getMessage()); - return new String[0]; - } - } - } else if (st.length() > 0) { - st.append(c); - } else { - result.append(c); - } - } - return result.toString().split(" "); - } - - public Value getOrItselfValue(String variable) { - if (!isVariable(variable)) { - return Value.parse(variable); - } - - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable); - } - return Constants.getConstant(variable, player); - } - - public Value getValueOrNull(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable); - } - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player); - } - return null; - } - - public String getOrItself(String variable) { - if (isVariable(variable)) { - return getValue(variable); - } - return variable; - } - - public boolean isVariable(String variable) { - return Constants.isConstant(variable) || globalVariables.hasValue(variable) || localVariables.hasValue(variable); - } - - public String getValue(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable).asString(); - } - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable).asString(); - } - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player).asString(); - } - return ""; - } - - public String getConstant(String variable) { - if (Constants.isConstant(variable)) { - return Constants.getConstant(variable, player).asString(); - } - return "0"; - } - - public String getGlobal(String variable) { - if (globalVariables.hasValue(variable)) { - return globalVariables.getValue(variable).asString(); - } - return "0"; - } - - public String getLocal(String variable) { - if (localVariables.hasValue(variable)) { - return localVariables.getValue(variable).asString(); - } - return "0"; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index ef9abe06..f2b5852c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -1,6 +1,5 @@ package de.steamwar.bausystem.features.script; -import de.steamwar.bausystem.features.script.variables.Context; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -9,22 +8,19 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BookMeta; -import java.util.HashMap; +import java.util.Collections; import java.util.HashSet; -import java.util.Map; import java.util.Set; @Linked public class ScriptListener implements Listener { - private static final Map GLOBAL_CONTEXT = new HashMap<>(); - - private Set playerSet = new HashSet<>(); + private final Set playerSet = new HashSet<>(); @EventHandler(priority = EventPriority.HIGH) public void onLeftClick(PlayerInteractEvent event) { @@ -44,20 +40,22 @@ public class ScriptListener implements Listener { } event.setCancelled(true); - new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerJoin(PlayerJoinEvent event) { - GLOBAL_CONTEXT.put(event.getPlayer(), new Context()); + ScriptRunner.runScript(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null), event.getPlayer()); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - GLOBAL_CONTEXT.remove(event.getPlayer()); + ScriptRunner.remove(event.getPlayer()); } - public static Context getGlobalContext(Player player) { - return GLOBAL_CONTEXT.computeIfAbsent(player, ignore -> new Context()); + @EventHandler + public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { + ItemStack item = event.getOffHandItem(); + if (item == null || FlatteningWrapper.impl.isNoBook(item) || item.getItemMeta() == null) { + return; + } + + event.setCancelled(true); + ScriptRunner.createGlobalScript(Collections.singletonList(((BookMeta) item.getItemMeta()).getPages().stream().reduce((s, s2) -> s + "\n" + s2).orElse(null)), event.getPlayer()); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java new file mode 100644 index 00000000..8c4ce348 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -0,0 +1,75 @@ +package de.steamwar.bausystem.features.script; + +import de.steamwar.bausystem.features.script.lua.CommandRegister; +import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; +import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import org.bukkit.entity.Player; +import org.luaj.vm2.Globals; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaValue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ScriptRunner { + + // Script Table + // User + // Key -> bau-script- + // Value -> + + private static final Map>> EVENT_MAP = new HashMap<>(); + private static final Map> COMMAND_MAP = new HashMap<>(); + + public static void runScript(String script, Player player) { + Globals globals = SteamWarPlatform.createClickGlobals(player); + + try { + globals.load(script).call(); + } catch (Exception e) { + player.sendMessage("§cFehler beim Ausführen des Scripts: " + e.getMessage()); + } + } + + public static void createGlobalScript(List scripts, Player player) { + EVENT_MAP.remove(player); + Globals globals = SteamWarPlatform.createGlobalGlobals(player, + (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister)); + + for (String script : scripts) { + globals.load(script).call(); + } + } + + public static void remove(Player player) { + EVENT_MAP.remove(player); + } + + public static void callEvent(Player player, SteamWarGlobalLuaPlugin.EventType event, LuaValue eventValue) { + Map> stringListMap = EVENT_MAP.get(player); + if (stringListMap == null) { + return; + } + + List luaFunctions = stringListMap.get(event); + if (luaFunctions == null) { + return; + } + + for (LuaFunction luaFunction : luaFunctions) { + luaFunction.call(eventValue); + } + } + + public static void callCommand(Player player, String command, LuaValue args) { + CommandRegister commandRegister = COMMAND_MAP.get(player).get(command.toLowerCase()); + if (commandRegister == null) { + return; + } + + commandRegister.getFunction().call(args); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java deleted file mode 100644 index 8c9763c3..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptSyntaxSender.java +++ /dev/null @@ -1,105 +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.script; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.custom.event.EventType; -import de.steamwar.bausystem.features.script.expression.Expression; -import de.steamwar.linkage.Linked; -import lombok.SneakyThrows; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; -import yapion.hierarchy.output.StringOutput; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONObject; - -import java.util.Arrays; - -@Linked -public class ScriptSyntaxSender implements Listener { - - private byte[] syntax; - - { - Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(BauSystem.getInstance(), "sw:script_syntax"); - - // Whole Syntax object - YAPIONObject yapionObject = new YAPIONObject(); - - ScriptExecutor.SPECIAL_COMMANDS.toString(); - - // Operators - YAPIONArray operators = new YAPIONArray(); - yapionObject.add("@operators", operators); - Expression.OPERATORS.forEach((s, operator) -> { - operators.add(s); - }); - - // Headers - YAPIONArray headers = new YAPIONArray(); - yapionObject.add("@headers", headers); - headers.add("CMD /.*"); - headers.add("EVENT " + Arrays.stream(EventType.values()).map(Enum::name).reduce((s, s2) -> s + "|" + s2).map(s -> "(" + s + ")").orElse("") + "( .+)?"); - headers.add("HOTKEY .+"); - - // Variable prefixes - YAPIONArray prefixes = new YAPIONArray(); - yapionObject.add("@prefixes", prefixes); - prefixes.add("global"); - prefixes.add("const"); - prefixes.add("local"); - - // Variable suffixes - YAPIONArray suffixes = new YAPIONArray(); - yapionObject.add("@suffixes", suffixes); - suffixes.add("isset"); - suffixes.add("type"); - suffixes.add("length"); - - // Commands - ScriptExecutor.SPECIAL_COMMANDS.forEach(specialCommand -> { - YAPIONArray yapionArray = new YAPIONArray(); - yapionObject.add(specialCommand.command(), yapionArray); - if (specialCommand.repeating()) { - yapionArray.add(true); - } else { - yapionArray.add(false); - } - for (SpecialCommand.TokenType[] types : specialCommand.getSyntax()) { - YAPIONArray syntax = new YAPIONArray(); - yapionArray.add(syntax); - for (SpecialCommand.TokenType type : types) { - syntax.add(type.ordinal()); - } - } - }); - syntax = yapionObject.toJSONLossy(new StringOutput()).getResult().getBytes(); - } - - @EventHandler - @SneakyThrows - public void onPlayerJoin(PlayerJoinEvent event) { - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - event.getPlayer().sendPluginMessage(BauSystem.getInstance(), "sw:script_syntax", syntax); - }, 5); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java deleted file mode 100644 index 3cb32f9b..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.steamwar.bausystem.features.script; - -import org.bukkit.Material; - -public interface SpecialCommand { - - default String[] description() { - return new String[0]; - } - - default Material material() { - return Material.PAPER; - } - - String command(); - - boolean execute(String[] command, ScriptExecutor scriptExecutor); - - default boolean repeating() { - return false; - } - - TokenType[][] getSyntax(); - - default long asLong(String value) { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return 0; - } - } - - default boolean asBoolean(String value) { - return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"); - } - - default String asString(String value) { - return value; - } - - default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) { - scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> { - scriptExecutor.setIndex(integer); - return integer; - }); - } - - default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null); - if (jp == null) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.setIndex(jp); - } - - default void jumpToIndexWithMessageAndReturnStack(ScriptExecutor scriptExecutor, String jumpPoint, String message) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null); - if (jp == null) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.getReturnStack().add(scriptExecutor.getIndex()); - scriptExecutor.setIndex(jp); - } - - default void returnFromStackWithMessage(ScriptExecutor scriptExecutor, String message) { - if (scriptExecutor.getReturnStack().isEmpty()) { - scriptExecutor.getPlayer().sendMessage(message); - return; - } - scriptExecutor.setIndex(scriptExecutor.getReturnStack().pop()); - } - - enum TokenType { - any, // This does not include jump_point and variable - expression, - jump_point, - variable, - - text_type, - number_type, - floating_number_type, - boolean_type, - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java deleted file mode 100644 index 4cb22c65..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Call.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Call implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_CALL_HELP_1", - "", - "SCRIPT_COMMAND_CALL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.LEATHER_BOOTS; - } - - @Override - public String command() { - return "call"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - jumpToIndexWithMessageAndReturnStack(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_CALL_ERROR", scriptExecutor.getPlayer(), command[1])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.jump_point }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java deleted file mode 100644 index c274d252..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Exit implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_EXIT_HELP_1", - "", - "SCRIPT_COMMAND_EXIT_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BARRIER; - } - - @Override - public String command() { - return "exit"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - return false; - } - - private TokenType[][] syntax = {}; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java deleted file mode 100644 index 47d92f25..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class If implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IF_HELP_1", - "SCRIPT_COMMAND_IF_HELP_2", - "", - "SCRIPT_COMMAND_IF_HELP_3" - }; - } - - @Override - public Material material() { - return Material.OBSERVER; - } - - @Override - public String command() { - return "if"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length < 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length < 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - - Value v = scriptExecutor.getOrItselfValue(command[1]); - if (!(v instanceof Value.BooleanValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_NO_BOOLEAN", scriptExecutor.getPlayer()); - return false; - } - if (v.asBoolean() && command.length > 2) { - jumpToIndex(scriptExecutor, command[2]); - } else if (command.length > 3) { - jumpToIndex(scriptExecutor, command[3]); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.boolean_type, TokenType.jump_point }, - { TokenType.boolean_type, TokenType.jump_point, TokenType.jump_point }, - { TokenType.expression, TokenType.jump_point }, - { TokenType.expression, TokenType.jump_point, TokenType.jump_point } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java deleted file mode 100644 index 10ff4ab1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Jump implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_JUMP_HELP_1", - "", - "SCRIPT_COMMAND_JUMP_HELP_2" - }; - } - - @Override - public Material material() { - return Material.LEATHER_BOOTS; - } - - @Override - public String command() { - return "jump"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT", scriptExecutor.getPlayer()); - return true; - } - jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_JUMP_ERROR", scriptExecutor.getPlayer(), command[1])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.jump_point } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java deleted file mode 100644 index 0d9e6492..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Return.java +++ /dev/null @@ -1,43 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Return implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_RETURN_HELP_1", - "", - "SCRIPT_COMMAND_RETURN_HELP_2" - }; - } - - @Override - public Material material() { - return Material.DIAMOND_BOOTS; - } - - @Override - public String command() { - return "return"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - returnFromStackWithMessage(scriptExecutor, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_RETURN_ERROR", scriptExecutor.getPlayer())); - return true; - } - - private TokenType[][] syntax = {}; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java deleted file mode 100644 index 3cb0f025..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.steamwar.bausystem.features.script.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; - -@Linked -public class Sleep implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_SLEEP_HELP_1", - "", - "SCRIPT_COMMAND_SLEEP_HELP_2" - }; - } - - @Override - public Material material() { - return Material.CLOCK; - } - - @Override - public String command() { - return "sleep"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER", scriptExecutor.getPlayer()); - return true; - } - long sleepTime = asLong(command[1]); - if (sleepTime < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_SLEEP_ERROR", scriptExecutor.getPlayer()); - return true; - } - if (sleepTime == 0) { - return true; - } - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), scriptExecutor::resume, sleepTime); - return false; - } - - private TokenType[][] syntax = { - { TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java deleted file mode 100644 index da87c9f9..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Ceil.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Ceil implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "ceil"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.ceil(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.ceil(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java deleted file mode 100644 index ce5d0730..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Floor.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Floor implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "floor"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue((long) Math.floor(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.floor(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java deleted file mode 100644 index 2af5d261..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/other/Round.java +++ /dev/null @@ -1,107 +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.script.command.arithmetic.other; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Round implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2", - "", - "SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3" - }; - } - - @Override - public Material material() { - return Material.REDSTONE_TORCH; - } - - @Override - public String command() { - return "round"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - Value v1; - Value v2; - if (command.length == 3) { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - v2 = new Value.LongValue(0); - } else { - v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - } - if (!(v1 instanceof Value.DoubleValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - if (v2.asLong() < 0) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2", scriptExecutor.getPlayer()); - return true; - } - - if (v2.asLong() == 0) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(Math.round(v1.asDouble()))); - } else { - double pow = Math.pow(10, v2.asLong()); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.DoubleValue(Math.round(v1.asDouble() * pow) / pow)); - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.floating_number_type, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.floating_number_type, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java deleted file mode 100644 index da83635c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echo.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Material; - -@Linked -public class Echo implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_ECHO_HELP_1", - "", - "SCRIPT_COMMAND_IO_ECHO_HELP_2" - }; - } - - @Override - public Material material() { - return Material.OAK_SIGN; - } - - @Override - public String command() { - return "echo"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - scriptExecutor.getEchoConsumer().accept(""); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 1; i < command.length; i++) { - if (i != 1) { - st.append(" "); - } - st.append(command[i]); - } - scriptExecutor.getEchoConsumer().accept(ChatColor.translateAlternateColorCodes('&', st.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java deleted file mode 100644 index c5c99240..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Echoactionbar.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.SWUtils; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatColor; -import org.bukkit.Material; - -@Linked -public class Echoactionbar implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1", - "", - "SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BIRCH_SIGN; - } - - @Override - public String command() { - return "echoactionbar"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ""); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 1; i < command.length; i++) { - if (i != 1) { - st.append(" "); - } - st.append(command[i]); - } - SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java deleted file mode 100644 index 4ecb4237..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java +++ /dev/null @@ -1,79 +0,0 @@ -package de.steamwar.bausystem.features.script.command.io; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.linkage.Linked; -import org.bukkit.ChatColor; -import org.bukkit.Material; - -@Linked -public class Input implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_IO_INPUT_HELP_1", - "", - "SCRIPT_COMMAND_IO_INPUT_HELP_2" - }; - } - - @Override - public Material material() { - return Material.ANVIL; - } - - @Override - public String command() { - return "input"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - StringBuilder st = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (i != 2) { - st.append(" "); - } - st.append(command[i]); - } - SWAnvilInv swAnvilInv = new SWAnvilInv(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); - swAnvilInv.setCallback(s -> { - try { - long value = Long.parseLong(s); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(value)); - } catch (NumberFormatException e) { - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(s.equalsIgnoreCase("true"))); - } else { - scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(s)); - } - } - scriptExecutor.resume(); - }); - swAnvilInv.addCloseCallback(scriptExecutor::resume); - swAnvilInv.open(); - return false; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java deleted file mode 100644 index 00dbf597..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Insert.java +++ /dev/null @@ -1,98 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Insert implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_INSERT_HELP_1", - "SCRIPT_COMMAND_STRING_INSERT_HELP_2", - "", - "SCRIPT_COMMAND_STRING_INSERT_HELP_3" - }; - } - - @Override - public Material material() { - return Material.HOPPER; - } - - @Override - public String command() { - return "insert"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v3 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(new StringBuilder(v1.asString()).insert((int) v3.asLong(), v2.asString()).toString())); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.variable, TokenType.number_type }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java deleted file mode 100644 index 002fd3c5..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Remove.java +++ /dev/null @@ -1,89 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Remove implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_REMOVE_HELP_1", - "SCRIPT_COMMAND_STRING_REMOVE_HELP_2", - "", - "SCRIPT_COMMAND_STRING_REMOVE_HELP_3" - }; - } - - @Override - public Material material() { - return Material.SHEARS; - } - - @Override - public String command() { - return "remove"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), ""))); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.variable, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java deleted file mode 100644 index a7a5716f..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Replace.java +++ /dev/null @@ -1,98 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Replace implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_REPLACE_HELP_1", - "SCRIPT_COMMAND_STRING_REPLACE_HELP_2", - "", - "SCRIPT_COMMAND_STRING_REPLACE_HELP_3" - }; - } - - @Override - public Material material() { - return Material.WOODEN_AXE; - } - - @Override - public String command() { - return "replace"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 3]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v3 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v3 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), v3.asString()))); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.variable, TokenType.variable }, - { TokenType.variable, TokenType.variable, TokenType.variable, TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java deleted file mode 100644 index 8624cae1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java +++ /dev/null @@ -1,99 +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.script.command.string; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Substring implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1", - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2", - "", - "SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3" - }; - } - - @Override - public Material material() { - return Material.STICKY_PISTON; - } - - @Override - public String command() { - return "substring"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - String resultName = command[1]; - Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); - Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); - - if (!(v1 instanceof Value.StringValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - if (!(v2 instanceof Value.LongValue)) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer()); - return true; - } - - Value result; - try { - if (v2.asLong() < 0) { - result = new Value.StringValue(v1.asString().substring(v1.asString().length() - 1 - (int) v2.asLong())); - } else { - result = new Value.StringValue(v1.asString().substring((int) v2.asLong())); - } - } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException e) { - result = new Value.StringValue(""); - } - scriptExecutor.getLocalVariables().putValue(resultName, result); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type }, - { TokenType.variable, TokenType.variable, TokenType.number_type }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java deleted file mode 100644 index 850a6642..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Const.java +++ /dev/null @@ -1,87 +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.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Const implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_CONST_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_CONST_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_BLOCK; - } - - @Override - public String command() { - return "const"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - Constants.getConstant(varName, scriptExecutor.getPlayer()).fromValue(Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java deleted file mode 100644 index a99c0bb6..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Convert.java +++ /dev/null @@ -1,74 +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.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Convert implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2", - }; - } - - @Override - public Material material() { - return Material.ENDER_CHEST; - } - - @Override - public String command() { - return "convert"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - - scriptExecutor.getLocalVariables().putValue(command[1], Value.parse(command[2])); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java deleted file mode 100644 index ae3f33a7..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Global implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.MAP; - } - - @Override - public String command() { - return "global"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - scriptExecutor.getGlobalVariables().putValue(varName, Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java deleted file mode 100644 index 06e9e7b1..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Unglobal implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.BEACON; - } - - @Override - public String command() { - return "unglobal"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - scriptExecutor.getGlobalVariables().removeValue(command[1]); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java deleted file mode 100644 index 76230f87..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Unvar implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_VOID; - } - - @Override - public String command() { - return "unvar"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - scriptExecutor.getLocalVariables().removeValue(command[1]); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java deleted file mode 100644 index 6cda1236..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.steamwar.bausystem.features.script.command.variable; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; - -@Linked -public class Var implements SpecialCommand { - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_VARIABLE_VAR_HELP_1", - "", - "SCRIPT_COMMAND_VARIABLE_VAR_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STRUCTURE_BLOCK; - } - - @Override - public String command() { - return "var"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - String varName = command[1]; - StringBuilder varValue = new StringBuilder(); - for (int i = 2; i < command.length; i++) { - if (varValue.length() != 0) { - varValue.append(" "); - } - varValue.append(command[i]); - } - scriptExecutor.getLocalVariables().putValue(varName, Value.parse(varValue.toString())); - return true; - } - - @Override - public boolean repeating() { - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.any }, - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java deleted file mode 100644 index e5511e98..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/GetMaterial.java +++ /dev/null @@ -1,89 +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.script.command.world; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; - -@Linked -public class GetMaterial implements SpecialCommand { - - private final World world = Bukkit.getWorlds().get(0); - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1", - "", - "SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.STICKY_PISTON; - } - - @Override - public String command() { - return "getmaterial"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 4) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - - int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong(); - int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong(); - int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong(); - scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(world.getBlockAt(x, y, z).getType().name())); - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java deleted file mode 100644 index 1411c708..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/world/SetMaterial.java +++ /dev/null @@ -1,92 +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.script.command.world; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.SpecialCommand; -import de.steamwar.linkage.Linked; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; - -@Linked -public class SetMaterial implements SpecialCommand { - - private final World world = Bukkit.getWorlds().get(0); - - @Override - public String[] description() { - return new String[]{ - "SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1", - "", - "SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2" - }; - } - - @Override - public Material material() { - return Material.PISTON; - } - - @Override - public String command() { - return "setmaterial"; - } - - @Override - public boolean execute(String[] command, ScriptExecutor scriptExecutor) { - if (command.length <= 1) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 2) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 3) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - if (command.length <= 4) { - BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE", scriptExecutor.getPlayer()); - return true; - } - - int x = (int) scriptExecutor.getOrItselfValue(command[2]).asLong(); - int y = (int) scriptExecutor.getOrItselfValue(command[3]).asLong(); - int z = (int) scriptExecutor.getOrItselfValue(command[4]).asLong(); - try { - world.getBlockAt(x, y, z).setType(Material.valueOf(scriptExecutor.getOrItself(command[1]))); - } catch (Exception e) { - // Ignored - } - return true; - } - - private TokenType[][] syntax = { - { TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type } - }; - - @Override - public TokenType[][] getSyntax() { - return syntax; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java deleted file mode 100644 index 49befa41..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/MenuScript.java +++ /dev/null @@ -1,29 +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.script.custom; - -import de.steamwar.inventory.SWItem; -import org.bukkit.entity.Player; -import yapion.hierarchy.types.YAPIONMap; - -public interface MenuScript { - void save(YAPIONMap yapionMap); - SWItem toItem(Player p); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java deleted file mode 100644 index 17693f8a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/Script.java +++ /dev/null @@ -1,23 +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.script.custom; - -public interface Script { -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java deleted file mode 100644 index 4c2e7ddf..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CommandListener.java +++ /dev/null @@ -1,45 +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.script.custom.command; - -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - - -@Linked -public class CommandListener implements Listener { - - @LinkedInstance - public CustomScriptManager manager; - - @EventHandler - public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) { - if (e.getMessage().startsWith("/script:")) { - e.setMessage("/" + e.getMessage().substring(8)); - return; - } - - manager.callCommand(e.getPlayer(), e, e.getMessage()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java deleted file mode 100644 index b0a7d386..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/CustomCommand.java +++ /dev/null @@ -1,87 +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.script.custom.command; - -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; - -import java.util.HashMap; -import java.util.Map; - -public interface CustomCommand extends Script { - String[] command(); - - default Map check(String[] args, String[] command) { - if (args.length < command.length) { - return null; - } - - if (!args[0].equals(command[0])) { - return null; - } - - Map arguments = new HashMap<>(); - if (!check(arguments, args, command, 0, 0)) { - return null; - } - return arguments; - } - - default boolean check(Map arguments, String[] args, String[] command, int argsIndex, int commandIndex) { - if (command.length <= commandIndex) { - for (int i = argsIndex; i < args.length; i++) { - if (!(args[i].startsWith("(") && args[i].endsWith(")"))) { - return false; - } - } - return true; - } - if (args.length <= argsIndex) return true; - - String currentArg = args[argsIndex]; - String currentCommand = command[commandIndex]; - - if (currentArg.startsWith("<") && currentArg.endsWith(">")) { - arguments.put(trim(currentArg, 1), new Value.StringValue(currentCommand)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } else if (currentArg.startsWith("(<") && currentArg.endsWith(">)")) { - arguments.put(trim(currentArg, 2), new Value.StringValue(currentCommand)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } else if (currentArg.startsWith("(") && currentArg.endsWith(")")) { - if (!trim(currentArg, 1).equals(currentCommand)) { - arguments.put(trim(currentArg, 1), new Value.BooleanValue(false)); - return check(arguments, args, command, argsIndex + 1, commandIndex); - } else { - arguments.put(trim(currentArg, 1), new Value.BooleanValue(true)); - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } - } else { - if (!currentArg.equals(currentCommand)) return false; - return check(arguments, args, command, argsIndex + 1, commandIndex + 1); - } - } - - default String trim(String s, int count) { - return s.substring(count, s.length() - count); - } - - boolean execute(String[] command, PlayerCommandPreprocessEvent e); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.java deleted file mode 100644 index 34cfc738..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/InventoryCommand.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.script.custom.command; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.Map; - -@RequiredArgsConstructor -public -class InventoryCommand implements CustomCommand { - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String[] command() { - return args; - } - - public boolean execute(String[] command, PlayerCommandPreprocessEvent e) { - Map arguments = check(args, command); - if (arguments == null) { - return false; - } - - e.setCancelled(true); - new ScriptExecutor(bookMeta, e.getPlayer(), arguments, null); - return true; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java deleted file mode 100644 index 5583f360..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/command/MenuCommand.java +++ /dev/null @@ -1,99 +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.script.custom.command; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.List; -import java.util.Map; - -@RequiredArgsConstructor -public -class MenuCommand implements CustomCommand, MenuScript { - public final List pages; - public final String[] args; - - @Override - public String[] command() { - return args; - } - - public boolean execute(String[] command, PlayerCommandPreprocessEvent e) { - Map arguments = check(args, command); - if (arguments == null) { - return false; - } - - e.setCancelled(true); - new ScriptExecutor(pages, e.getPlayer(), arguments, null); - return true; - } - - public boolean equals(MenuCommand menuCommand) { - if (menuCommand.args.length != args.length) { - return false; - } - if (!args[0].equals(menuCommand.args[0])) { - return false; - } - for (int i = 0; i < args.length; i++) { - if (i == 0) continue; - String s1 = args[i]; - String s2 = menuCommand.args[i]; - if (!s1.equals(s2)) { - return false; - } - if (!(s1.startsWith("<") && s1.endsWith(">") && s2.startsWith("<") && s2.endsWith(">"))) { - return false; - } - if (!(s1.startsWith("(<") && s1.endsWith(">)") && s2.startsWith("(<") && s2.endsWith(">)"))) { - return false; - } - } - return true; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", p, String.join(" ", args))); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java deleted file mode 100644 index ec4bebd7..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/CustomEvent.java +++ /dev/null @@ -1,34 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.custom.Script; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.entity.Player; - -import java.util.Map; -import java.util.function.Consumer; - -public interface CustomEvent extends Script { - - String eventName(); - boolean execute(Player p, Map variables, Consumer echoConsumer); - -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java deleted file mode 100644 index 3a6d471d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventType.java +++ /dev/null @@ -1,133 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.Getter; -import org.bukkit.Location; -import org.bukkit.event.Event; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.player.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -@Getter -public enum EventType { - FF(PlayerSwapHandItemsEvent.class, event -> null), - PlaceBlock(BlockPlaceEvent.class, event -> { - Map valueMap = new HashMap<>(); - addBlockXYZ(valueMap, event.getBlockPlaced().getLocation()); - valueMap.put("blockType", new Value.StringValue(event.getBlockPlaced().getType().name())); - return valueMap; - }), - BreakBlock(BlockBreakEvent.class, event -> { - Map valueMap = new HashMap<>(); - addBlockXYZ(valueMap, event.getBlock().getLocation()); - valueMap.put("blockType", new Value.StringValue(event.getBlock().getType().name())); - return valueMap; - }), - RightClick(PlayerInteractEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand())); - valueMap.put("action", new Value.StringValue(event.getAction().name())); - valueMap.put("handType", new Value.StringValue(event.getMaterial().name())); - valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock())); - if (event.hasBlock()) { - addBlockXYZ(valueMap, event.getClickedBlock().getLocation()); - valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name())); - } - return valueMap; - }), - LeftClick(PlayerInteractEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("blockInHand", new Value.BooleanValue(event.isBlockInHand())); - valueMap.put("action", new Value.StringValue(event.getAction().name())); - valueMap.put("handType", new Value.StringValue(event.getMaterial().name())); - valueMap.put("hasBlock", new Value.BooleanValue(event.hasBlock())); - if (event.hasBlock()) { - addBlockXYZ(valueMap, event.getClickedBlock().getLocation()); - valueMap.put("blockFace", new Value.StringValue(event.getBlockFace().name())); - } - return valueMap; - }), - TNTSpawn(EntitySpawnEvent.class, event -> null), - TNTExplode(EntityExplodeEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getLocation()); - return valueMap; - }), - TNTExplodeInBuild(EntityExplodeEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getLocation()); - return valueMap; - }), - SelfJoin(PlayerJoinEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getPlayer().getLocation()); - return valueMap; - }), - SelfLeave(PlayerQuitEvent.class, event -> { - Map valueMap = new HashMap<>(); - addXYZ(valueMap, event.getPlayer().getLocation()); - return valueMap; - }), - DropItem(PlayerDropItemEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("material", new Value.StringValue(event.getItemDrop().getItemStack().getType().name())); - addXYZ(valueMap, event.getItemDrop().getLocation()); - return valueMap; - }), - EntityDeath(EntityDeathEvent.class, event -> { - Map valueMap = new HashMap<>(); - valueMap.put("entityType", new Value.StringValue(event.getEntityType().name())); - addXYZ(valueMap, event.getEntity().getLocation()); - return valueMap; - }), - Scoreboard(Event.class, event -> { - return new HashMap<>(); - }), - ; - - private static void addXYZ(Map valueMap, Location location) { - valueMap.put("x", new Value.DoubleValue(location.getX())); - valueMap.put("y", new Value.DoubleValue(location.getY())); - valueMap.put("z", new Value.DoubleValue(location.getZ())); - } - - private static void addBlockXYZ(Map valueMap, Location location) { - valueMap.put("blockX", new Value.LongValue(location.getBlockX())); - valueMap.put("blockY", new Value.LongValue(location.getBlockY())); - valueMap.put("blockZ", new Value.LongValue(location.getBlockZ())); - } - - private Class eventType; - private Function> eventValues; - - EventType(Class eventType, Function> eventValues) { - this.eventType = eventType; - this.eventValues = event -> eventValues.apply((T) event); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java deleted file mode 100644 index d323dbc8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/InventoryEvent.java +++ /dev/null @@ -1,47 +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.script.custom.event; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.Map; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public -class InventoryEvent implements CustomEvent { - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String eventName() { - return args[0]; - } - - @Override - public boolean execute(Player p, Map variables, Consumer echoConsumer) { - new ScriptExecutor(bookMeta, p, variables, echoConsumer); - return true; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java deleted file mode 100644 index 96a7d6d2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/MenuEvent.java +++ /dev/null @@ -1,76 +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.script.custom.event; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -@RequiredArgsConstructor -public -class MenuEvent implements CustomEvent, MenuScript { - public final List pages; - public final String[] args; - - @Override - public String eventName() { - return args[0]; - } - - @Override - public boolean execute(Player p, Map variables, Consumer echoConsumer) { - new ScriptExecutor(pages, p, variables, echoConsumer); - return false; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - StringBuilder st = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i != 1) st.append(" "); - st.append(args[i]); - } - - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", p, args[0], st.toString())); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java deleted file mode 100644 index 2c9bd6c8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkey.java +++ /dev/null @@ -1,29 +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.script.custom.hotkey; - -import de.steamwar.bausystem.features.script.custom.Script; -import org.bukkit.entity.Player; - -public interface Hotkey extends Script { - - String hotkey(); - boolean execute(Player p, boolean pressed); -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.java deleted file mode 100644 index 5f8adadd..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/HotkeyListener.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.script.custom.hotkey; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.messaging.PluginMessageListener; - -@Linked -public class HotkeyListener implements PluginMessageListener { - - { - Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this); - } - - @LinkedInstance - public CustomScriptManager manager; - - @Override - public void onPluginMessageReceived(String channel, Player player, byte[] message) { - if (!channel.equals("sw:hotkeys")) return; - if (message.length < 5) return; - int action = message[4] & 0xFF; - if (action == 2) return; - int key = (message[0] & 0xFF) << 24 | (message[1] & 0xFF) << 16 | (message[2] & 0xFF) << 8 | (message[3] & 0xFF); - if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return; - if (message.length >= 9) { - int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF); - // player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); - manager.callHotkey(mods, ((char) key), player, action == 1); - } else { - // player.sendMessage("Hotkey: " + (char) key + " " + action); - manager.callHotkey(0, ((char) key), player, action == 1); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java deleted file mode 100644 index 056afaea..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/Hotkeys.java +++ /dev/null @@ -1,135 +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.script.custom.hotkey; - -import java.util.HashSet; -import java.util.Set; - -public interface Hotkeys { - - public static boolean isSame(int mods, char key, String checkAgainst) { - Set modifiers = Modifier.get(mods); - Key k = Key.fromString(key + ""); - if (k == null) { - return false; - } - - try { - String[] split = checkAgainst.split("\\+"); - Set checkModifiers = new HashSet<>(); - Key checkKey = null; - for (String s : split) { - Modifier m = Modifier.fromString(s); - if (m != null) { - checkModifiers.add(m); - } else { - checkKey = Key.fromString(s); - } - } - return checkKey == k && checkModifiers.equals(modifiers); - } catch (Exception e) { - return false; - } - } - - enum Modifier { - SHIFT, - CTRL, - ALT, - META, - ; - - public static Set get(int mods) { - Set modifiers = new HashSet<>(); - for (Modifier modifier : values()) { - if ((mods & (1 << modifier.ordinal())) != 0) { - modifiers.add(modifier); - } - } - return modifiers; - } - - public static Modifier fromString(String string) { - try { - return valueOf(string.toUpperCase()); - } catch (IllegalArgumentException e) { - return null; - } - } - } - - enum Key { - // A-Z - A, - B, - C, - D, - E, - F, - G, - H, - I, - J, - K, - L, - M, - N, - O, - P, - Q, - R, - S, - T, - U, - V, - W, - X, - Y, - Z, - - // 0-9 - NUM_0, - NUM_1, - NUM_2, - NUM_3, - NUM_4, - NUM_5, - NUM_6, - NUM_7, - NUM_8, - NUM_9, - ; - - public static Key fromString(String key) { - key = key.toUpperCase(); - try { - return Key.valueOf(key); - } catch (IllegalArgumentException e) { - // ignore - } - try { - return Key.valueOf("NUM_" + key); - } catch (IllegalArgumentException e) { - // ignore - } - return null; - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.java deleted file mode 100644 index f467e460..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/InventoryHotkey.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.script.custom.hotkey; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Value; -import lombok.RequiredArgsConstructor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; - -import java.util.HashMap; -import java.util.Map; - -@RequiredArgsConstructor -public -class InventoryHotkey implements Hotkey { - - public final BookMeta bookMeta; - public final String[] args; - - @Override - public String hotkey() { - return args[0]; - } - - @Override - public boolean execute(Player p, boolean pressed) { - Map variables = new HashMap<>(); - variables.put("pressed", new Value.BooleanValue(pressed)); - variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(bookMeta, p, variables, null); - return false; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java deleted file mode 100644 index 0407f621..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/hotkey/MenuHotkey.java +++ /dev/null @@ -1,80 +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.script.custom.hotkey; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.custom.MenuScript; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.inventory.SWItem; -import lombok.RequiredArgsConstructor; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.BookMeta; -import yapion.hierarchy.types.YAPIONArray; -import yapion.hierarchy.types.YAPIONMap; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@RequiredArgsConstructor -public -class MenuHotkey implements Hotkey, MenuScript { - - public final List pages; - public final String[] args; - - @Override - public String hotkey() { - return args[0]; - } - - @Override - public boolean execute(Player p, boolean pressed) { - Map variables = new HashMap<>(); - variables.put("pressed", new Value.BooleanValue(pressed)); - variables.put("released", new Value.BooleanValue(!pressed)); - new ScriptExecutor(pages, p, variables, null); - return false; - } - - @Override - public void save(YAPIONMap yapionMap) { - YAPIONArray yapionArray = new YAPIONArray(); - pages.forEach(yapionArray::add); - yapionMap.put(String.join(" ", args), yapionArray); - } - - @Override - public SWItem toItem(Player p) { - StringBuilder st = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - if (i != 1) st.append(" "); - st.append(args[i]); - } - - SWItem swItem = new SWItem(Material.WRITABLE_BOOK, BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", p, args[0], st.toString())); - BookMeta bookMeta = (BookMeta) swItem.getItemMeta(); - bookMeta.setPages(pages.toArray(new String[0])); - swItem.setItemMeta(bookMeta); - return swItem; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java new file mode 100644 index 00000000..e0602616 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java @@ -0,0 +1,22 @@ +package de.steamwar.bausystem.features.script.event; + +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.linkage.Linked; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.luaj.vm2.LuaValue; + +@Linked +public class CommandListener implements Listener { + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { + String[] split = event.getMessage().split(" "); + LuaValue[] values = new LuaValue[split.length - 1]; + for (int i = 1; i < split.length; i++) { + values[i - 1] = LuaValue.valueOf(split[i]); + } + ScriptRunner.callCommand(event.getPlayer(), split[0].substring(1), LuaValue.listOf(values)); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java similarity index 52% rename from BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java rename to BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 4ee1a97d..3a43a83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -1,31 +1,12 @@ -/* - * 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.script.custom.event; +package de.steamwar.bausystem.features.script.event; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.script.CustomScriptManager; +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -39,6 +20,8 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.*; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; import java.util.HashMap; import java.util.HashSet; @@ -48,9 +31,6 @@ import java.util.Set; @Linked public class EventListener implements Listener { - @LinkedInstance - public CustomScriptManager manager; - private static final Map LAST_FS = new HashMap<>(); { @@ -61,18 +41,18 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { - manager.callEvent(EventType.SelfJoin, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfJoin, LuaValue.NIL); } @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - manager.callEvent(EventType.SelfLeave, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL); } @EventHandler public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) { if (LAST_FS.containsKey(event.getPlayer())) { - manager.callEvent(EventType.FF, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.FF, LuaValue.NIL); } else { LAST_FS.put(event.getPlayer(), System.currentTimeMillis()); } @@ -80,12 +60,22 @@ public class EventListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - manager.callEvent(EventType.PlaceBlock, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("x", event.getBlock().getX()); + table.set("y", event.getBlock().getY()); + table.set("z", event.getBlock().getZ()); + table.set("type", event.getBlock().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.PlaceBlock, table); } @EventHandler public void onBlockBreak(BlockBreakEvent event) { - manager.callEvent(EventType.BreakBlock, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("x", event.getBlock().getX()); + table.set("y", event.getBlock().getY()); + table.set("z", event.getBlock().getZ()); + table.set("type", event.getBlock().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.BreakBlock, table); } private Set ignore = new HashSet<>(); @@ -95,11 +85,25 @@ public class EventListener implements Listener { if (ignore.remove(event.getPlayer())) { return; } + LuaTable table = new LuaTable(); + table.set("action", event.getAction().name()); + table.set("hand", event.getHand().name()); + table.set("block", event.getItem().getType().name()); + if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { + table.set("hasBlock", LuaValue.valueOf(true)); + table.set("blockX", event.getClickedBlock().getX()); + table.set("blockY", event.getClickedBlock().getY()); + table.set("blockZ", event.getClickedBlock().getZ()); + table.set("blockFace", event.getBlockFace().name()); + } else { + table.set("hasBlock", LuaValue.valueOf(false)); + } + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { - manager.callEvent(EventType.RightClick, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.RightClick, table); } if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { - manager.callEvent(EventType.LeftClick, event.getPlayer(), event); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.LeftClick, table); } } @@ -112,7 +116,7 @@ public class EventListener implements Listener { for (Player player : Bukkit.getOnlinePlayers()) { if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - manager.callEvent(EventType.TNTSpawn, player, event); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTSpawn, LuaValue.NIL); } } } @@ -124,9 +128,14 @@ public class EventListener implements Listener { } Region tntRegion = Region.getRegion(event.getLocation()); + LuaTable table = new LuaTable(); + table.set("x", event.getLocation().getX()); + table.set("y", event.getLocation().getY()); + table.set("z", event.getLocation().getZ()); + for (Player player : Bukkit.getOnlinePlayers()) { if (tntRegion.inRegion(player.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { - manager.callEvent(EventType.TNTExplode, player, event); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.TNTExplode, table); } } } @@ -134,13 +143,17 @@ public class EventListener implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { ignore.add(event.getPlayer()); - manager.callEvent(EventType.DropItem, event.getPlayer(), event); + LuaTable table = new LuaTable(); + table.set("type", event.getItemDrop().getItemStack().getType().name()); + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.DropItem, table); } @EventHandler public void onEntityDeath(EntityDeathEvent event) { for (Player player : Bukkit.getOnlinePlayers()) { - manager.callEvent(EventType.EntityDeath, player, event); + LuaTable table = new LuaTable(); + table.set("type", event.getEntityType().name()); + ScriptRunner.callEvent(player, SteamWarGlobalLuaPlugin.EventType.EntityDeath, table); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java deleted file mode 100644 index 9bf807fb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Expression.java +++ /dev/null @@ -1,242 +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.script.expression; - -import de.steamwar.bausystem.features.script.ScriptExecutor; -import de.steamwar.bausystem.features.script.variables.Constants; -import de.steamwar.bausystem.features.script.variables.Value; -import org.bukkit.entity.Player; - -import java.util.*; - -public class Expression { - - private static int highestPrecedence = 1; - - public static final Map OPERATORS = new HashMap<>(); - - public static void registerOperator(Operator operator) { - highestPrecedence = Math.max(highestPrecedence, operator.getPriority()) + 1; - OPERATORS.put(operator.getOperator(), operator); - } - - private Player p; - private ScriptExecutor scriptExecutor; - - private String s; - - public Expression(Player p, String s, ScriptExecutor scriptExecutor) { - s = s.substring(1, s.length() - 1); - this.p = p; - this.s = s; - this.scriptExecutor = scriptExecutor; - } - - public Value eval() { - List tokens = new ArrayList<>(tokenize(s)); - List priorities = priorities(tokens); - - while (true) { - int toCalc = getToCalc(priorities); - if (priorities.get(toCalc) == 0) break; - if (priorities.get(toCalc) == highestPrecedence) { - String s = (String) tokens.get(toCalc); - if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { - tokens.set(toCalc, new Value.BooleanValue(Boolean.parseBoolean(s))); - priorities.set(toCalc, 0); - continue; - } - String[] strings = s.split("\\."); - if (strings.length == 1) { - Value value = scriptExecutor.getValueOrNull(strings[0]); - if (value == null) { - throw new VarNotFoundException(strings[0]); - } - tokens.set(toCalc, value); - priorities.set(toCalc, 0); - } else { - boolean searchGlobal = false; - boolean searchConst = false; - boolean searchLocal = false; - if (strings[0].equals("global")) { - searchGlobal = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } else if (strings[0].equals("const")) { - searchConst = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } else if (strings[0].equals("local")) { - searchLocal = true; - strings = Arrays.copyOfRange(strings, 1, strings.length); - } - String varName = strings[0]; - Value value; - if (searchGlobal) { - value = scriptExecutor.getGlobalVariables().getValue(varName); - } else if (searchConst) { - value = Constants.getConstant(varName, p); - } else if (searchLocal) { - value = scriptExecutor.getLocalVariables().getValue(varName); - } else { - value = scriptExecutor.getValueOrNull(varName); - } - for (int i = 1; i < strings.length; i++) { - switch (strings[i]) { - case "isset": - value = new Value.BooleanValue(value != null); - break; - case "type": - value = new Value.StringValue(value == null ? "" : value.type()); - break; - case "length": - value = new Value.LongValue(value == null ? 0 : value.asString().length()); - break; - } - } - if (value == null) { - throw new VarNotFoundException(strings[0]); - } - tokens.set(toCalc, value); - priorities.set(toCalc, 0); - } - } else { - Value first = parse(tokens.get(toCalc - 1)); - Value second = parse(tokens.get(toCalc + 1)); - String op = (String) tokens.get(toCalc); - Operator operation = OPERATORS.get(op); - if (operation == null) { - throw new UnknownOperatorException(op); - } - Value result = operation.operate(first, second); - tokens.set(toCalc - 1, result); - tokens.remove(toCalc); - tokens.remove(toCalc); - priorities.remove(toCalc); - priorities.remove(toCalc); - priorities.set(toCalc - 1, 0); - } - } - - return parse(tokens.get(0)); - } - - private Value parse(Object token) { - if (token instanceof Value) { - return (Value) token; - } else if (token instanceof String) { - String s = (String) token; - if (s.startsWith("{") && s.endsWith("}")) { - return new Expression(p, s, scriptExecutor).eval(); - } else { - return Value.parse(s); - } - } else { - throw new IllegalArgumentException("Unknown token: " + token); - } - } - - private String getExpressionString(String s, int index) { - StringBuilder result = new StringBuilder(); - int depth = 0; - for (int i = index; i < s.length(); i++) { - char c = s.charAt(i); - if (c == '{') { - depth++; - } else if (c == '}') { - result.append(c); - depth--; - if (depth == 0) { - return result.toString(); - } - } - if (depth > 0) { - result.append(c); - } - } - return result.toString(); - } - - private List tokenize(String s) { - List tokens = new ArrayList<>(); - StringBuilder token = new StringBuilder(); - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c == ' ') continue; - if (c == '{') { - String subExpression = getExpressionString(s, i); - tokens.add(subExpression); - i += subExpression.length() - 1; - continue; - } - StringBuilder op = new StringBuilder(); - for (int j = i; j < s.length(); j++) { - char k = s.charAt(j); - if (k == '+' || k == '-' || k == '*' || k == '/' || k == '%' || k == '^' || k == '&' || k == '|' || k == '>' || k == '<' || k == '=' || k == '!') { - op.append(k); - } else { - break; - } - } - if (op.length() > 0) { - if (token.length() > 0) { - tokens.add(token.toString()); - token = new StringBuilder(); - } - tokens.add(op.toString()); - i += op.length() - 1; - continue; - } - token.append(c); - } - if (token.length() > 0) { - tokens.add(token.toString()); - } - return tokens; - } - - private List priorities(List tokens) { - List priorities = new ArrayList<>(); - for (Object obj : tokens) { - String token = (String) obj; - Operator operator = OPERATORS.get(token); - if (token.startsWith("{") && token.endsWith("}")) { - priorities.add(0); - } else if (!token.matches("[0-9]+([.,][0-9]+)?") && operator == null) { - priorities.add(highestPrecedence); - } else if (operator != null) { - priorities.add(operator.getPriority()); - } else { - priorities.add(0); - } - } - return priorities; - } - - private int getToCalc(List priorities) { - int max = 0; - int index = 0; - for (int i = 0; i < priorities.size(); i++) { - if (priorities.get(i) > max) { - max = priorities.get(i); - index = i; - } - } - return index; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java deleted file mode 100644 index 6fa67838..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/Operator.java +++ /dev/null @@ -1,37 +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.script.expression; - -import de.steamwar.bausystem.features.script.variables.Value; - -public interface Operator { - String getOperator(); - int getPriority(); - Value operate(Value value, Value value2); - - default boolean is(Value value, Class... classes) { - for (Class clazz : classes) { - if (clazz.isInstance(value)) { - return true; - } - } - return false; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java deleted file mode 100644 index 163970c2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/UnknownOperatorException.java +++ /dev/null @@ -1,27 +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.script.expression; - -public class UnknownOperatorException extends RuntimeException{ - - public UnknownOperatorException(String message) { - super(message); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java deleted file mode 100644 index a007601d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/VarNotFoundException.java +++ /dev/null @@ -1,27 +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.script.expression; - -public class VarNotFoundException extends RuntimeException{ - - public VarNotFoundException(String message) { - super(message); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.java deleted file mode 100644 index 09ab767c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/EqualOperator.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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class EqualOperator implements Operator { - - @Override - public String getOperator() { - return "=="; - } - - @Override - public int getPriority() { - return 6; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (!value.type().equals(value2.type())) { - return new Value.BooleanValue(false); - } - if (value instanceof Value.StringValue) { - return new Value.BooleanValue(value.asString().equals(value2.asString())); - } - if (value instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() == value2.asDouble()); - } - if (value instanceof Value.LongValue) { - return new Value.BooleanValue(value.asLong() == value2.asLong()); - } - return new Value.BooleanValue(value.asBoolean() == value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java deleted file mode 100644 index 6234e2fb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class GreaterOperator implements Operator { - - @Override - public String getOperator() { - return ">"; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() > value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() > value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java deleted file mode 100644 index 6320c8a2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/GreaterOrEqualOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class GreaterOrEqualOperator implements Operator { - - @Override - public String getOperator() { - return ">="; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() >= value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() >= value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java deleted file mode 100644 index 93cd46ed..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class LessOperator implements Operator { - - @Override - public String getOperator() { - return "<"; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() < value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() < value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java deleted file mode 100644 index 5accf5cb..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/LessOrEqualOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class LessOrEqualOperator implements Operator { - - @Override - public String getOperator() { - return "<="; - } - - @Override - public int getPriority() { - return 7; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_NUMBER_COMPARE"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() <= value2.asDouble()); - } else { - return new Value.BooleanValue(value.asLong() <= value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.java deleted file mode 100644 index b41eea55..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/comparison/NotEqualOperator.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.script.expression.operator.comparison; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class NotEqualOperator implements Operator { - - @Override - public String getOperator() { - return "!="; - } - - @Override - public int getPriority() { - return 6; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.DoubleValue && value2 instanceof Value.LongValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (value instanceof Value.LongValue && value2 instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (!value.type().equals(value2.type())) { - return new Value.BooleanValue(false); - } - if (value instanceof Value.StringValue) { - return new Value.BooleanValue(!value.asString().equals(value2.asString())); - } - if (value instanceof Value.DoubleValue) { - return new Value.BooleanValue(value.asDouble() != value2.asDouble()); - } - if (value instanceof Value.LongValue) { - return new Value.BooleanValue(value.asLong() != value2.asLong()); - } - return new Value.BooleanValue(value.asBoolean() != value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java deleted file mode 100644 index ec6b219e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/AndOperator.java +++ /dev/null @@ -1,47 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class AndOperator implements Operator { - - @Override - public String getOperator() { - return "&&"; - } - - @Override - public int getPriority() { - return 2; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE"); - } - return new Value.BooleanValue(value.asBoolean() && value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.java deleted file mode 100644 index e269c7fc..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseAndOperator.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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseAndOperator implements Operator { - - @Override - public String getOperator() { - return "&"; - } - - @Override - public int getPriority() { - return 5; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() && value2.asBoolean()); - } - return new Value.LongValue(value.asLong() & value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.java deleted file mode 100644 index 21966f44..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseOrOperator.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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseOrOperator implements Operator { - - @Override - public String getOperator() { - return "|"; - } - - @Override - public int getPriority() { - return 4; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() || value2.asBoolean()); - } - return new Value.LongValue(value.asLong() | value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.java deleted file mode 100644 index f5e02568..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/BitwiseXorOperator.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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseXorOperator implements Operator { - - @Override - public String getOperator() { - return "^"; - } - - @Override - public int getPriority() { - return 3; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value.getClass() != value2.getClass()) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR"); - } - if (value instanceof Value.BooleanValue && value2 instanceof Value.BooleanValue) { - return new Value.BooleanValue(value.asBoolean() ^ value2.asBoolean()); - } - return new Value.LongValue(value.asLong() ^ value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java deleted file mode 100644 index 81b63190..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/logic/OrOperator.java +++ /dev/null @@ -1,47 +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.script.expression.operator.logic; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class OrOperator implements Operator { - - @Override - public String getOperator() { - return "||"; - } - - @Override - public int getPriority() { - return 1; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class) || is(value2, Value.StringValue.class, Value.DoubleValue.class, Value.LongValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE"); - } - return new Value.BooleanValue(value.asBoolean() || value2.asBoolean()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java deleted file mode 100644 index 172fc2ed..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLeftOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseLeftOperator implements Operator { - - @Override - public String getOperator() { - return "<<"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR"); - } - return new Value.LongValue(value.asLong() << value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java deleted file mode 100644 index cd0952a8..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseLogicRightOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseLogicRightOperator implements Operator { - - @Override - public String getOperator() { - return ">>>"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR"); - } - return new Value.LongValue(value.asLong() >>> value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java deleted file mode 100644 index f260489e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/BitwiseRightOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class BitwiseRightOperator implements Operator { - - @Override - public String getOperator() { - return ">>"; - } - - @Override - public int getPriority() { - return 8; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class, Value.DoubleValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR"); - } - return new Value.LongValue(value.asLong() >> value2.asLong()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java deleted file mode 100644 index a4ab1c8c..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class DivideOperator implements Operator { - - @Override - public String getOperator() { - return "/"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR"); - } - if (value2.asDouble() == 0) { - return new Value.DoubleValue(Double.NaN); - } - return new Value.DoubleValue(value.asDouble() / value2.asDouble()); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java deleted file mode 100644 index 877ce2af..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MinusOperator.java +++ /dev/null @@ -1,50 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class MinusOperator implements Operator { - - @Override - public String getOperator() { - return "-"; - } - - @Override - public int getPriority() { - return 9; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR"); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() - value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() - value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java deleted file mode 100644 index af241af4..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/ModuloOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class ModuloOperator implements Operator { - - @Override - public String getOperator() { - return "%"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.LongValue && value2 instanceof Value.LongValue) { - return new Value.LongValue(value.asLong() % value2.asLong()); - } - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR"); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.java deleted file mode 100644 index 34a99c5a..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/MultiplyOperator.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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class MultiplyOperator implements Operator { - - @Override - public String getOperator() { - return "*"; - } - - @Override - public int getPriority() { - return 10; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR"); - } - if (value instanceof Value.StringValue) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < value2.asLong(); i++) { - sb.append(value.asString()); - } - return new Value.StringValue(sb.toString()); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() * value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() * value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.java deleted file mode 100644 index 6b92dd84..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PlusOperator.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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class PlusOperator implements Operator { - - @Override - public String getOperator() { - return "+"; - } - - @Override - public int getPriority() { - return 9; - } - - @Override - public Value operate(Value value, Value value2) { - if (value instanceof Value.BooleanValue || value2 instanceof Value.BooleanValue) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR"); - } - if (value instanceof Value.StringValue || value2 instanceof Value.StringValue) { - return new Value.StringValue(value.asString() + value2.asString()); - } - if (value instanceof Value.DoubleValue || value2 instanceof Value.DoubleValue) { - return new Value.DoubleValue(value.asDouble() + value2.asDouble()); - } else { - return new Value.LongValue(value.asLong() + value2.asLong()); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java deleted file mode 100644 index f756a796..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/PowerOperator.java +++ /dev/null @@ -1,46 +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.script.expression.operator.math; - -import de.steamwar.bausystem.features.script.expression.Operator; -import de.steamwar.bausystem.features.script.variables.Value; -import de.steamwar.linkage.Linked; - -@Linked -public class PowerOperator implements Operator { - - @Override - public String getOperator() { - return "**"; - } - - @Override - public int getPriority() { - return 11; - } - - @Override - public Value operate(Value value, Value value2) { - if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { - throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_POW_ERROR"); - } - return new Value.DoubleValue(Math.pow(value.asDouble(), value2.asDouble())); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java deleted file mode 100644 index 437b4760..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/items/ScriptMenuBauGuiItem.java +++ /dev/null @@ -1,55 +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.script.items; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.linkage.specific.BauGuiItem; -import de.steamwar.inventory.SWItem; -import de.steamwar.linkage.Linked; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; - -@Linked -public class ScriptMenuBauGuiItem extends BauGuiItem { - - public ScriptMenuBauGuiItem() { - super(15); - } - - @Override - public ItemStack getItem(Player player) { - return new SWItem(Material.WRITTEN_BOOK, BauSystem.MESSAGE.parse("SCRIPT_GUI_ITEM_NAME", player)).getItemStack(); - } - - @Override - public boolean click(ClickType click, Player p) { - p.closeInventory(); - p.performCommand("script"); - return false; - } - - @Override - public Permission permission() { - return Permission.MEMBER; - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java new file mode 100644 index 00000000..2e6d9c46 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java @@ -0,0 +1,15 @@ +package de.steamwar.bausystem.features.script.lua; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.luaj.vm2.LuaFunction; + +import java.util.List; + +@AllArgsConstructor +@Getter +public class CommandRegister { + + private final String name; + private final LuaFunction function; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java new file mode 100644 index 00000000..544b8af9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -0,0 +1,74 @@ +package de.steamwar.bausystem.features.script.lua; + +import lombok.AllArgsConstructor; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.TwoArgFunction; +import org.luaj.vm2.lib.VarArgFunction; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +@AllArgsConstructor +public class SteamWarGlobalLuaPlugin extends TwoArgFunction { + private final BiConsumer eventConsumer; + private final Consumer commandRegisterConsumer; + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + LuaValue types = tableOf(); + for (EventType value : EventType.values()) { + types.set(value.name(), value.ordinal()); + } + env.set("type", types); + + + env.set("event", new On()); + env.set("command", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaString command = arg1.checkstring(); + LuaFunction function = arg2.checkfunction(); + + commandRegisterConsumer.accept(new CommandRegister(command.tojstring().toLowerCase(), function)); + + return NIL; + } + }); + return NIL; + } + + class On extends TwoArgFunction { + @Override + public LuaValue call(LuaValue eventName, LuaValue function) { + int ord = eventName.checkint(); + LuaFunction luaFunction = function.checkfunction(); + + int nArgs = luaFunction.narg(); + if (nArgs != 1) { + return LuaValue.valueOf("Expected 1 argument, got " + nArgs); + } + + eventConsumer.accept(EventType.values()[ord], luaFunction); + + return LuaValue.NIL; + } + } + + public enum EventType { + FF, + PlaceBlock, + BreakBlock, + RightClick, + LeftClick, + TNTSpawn, + TNTExplode, + TNTExplodeInBuild, + SelfJoin, + SelfLeave, + DropItem, + EntityDeath; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java new file mode 100644 index 00000000..21b24e5e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -0,0 +1,144 @@ +package de.steamwar.bausystem.features.script.lua; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.script.lua.libs.LuaLib; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.features.tracer.record.ActiveTracer; +import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.record.TraceRecorder; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.core.TPSWatcher; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWItem; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.luaj.vm2.*; +import org.luaj.vm2.lib.*; + +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.function.Supplier; + +public class SteamWarLuaPlugin extends TwoArgFunction { + + public static final Map, List> LUA_LIBS = new HashMap<>(); + + public static void add(LuaLib luaLib) { + LUA_LIBS.computeIfAbsent(luaLib.parent(), l -> new ArrayList<>()).add(luaLib); + } + + private final Player player; + + public SteamWarLuaPlugin(Player player) { + this.player = player; + } + + @Override + public LuaValue call(LuaValue modname, LuaValue env) { + LuaValue materialLib = tableOf(); + for (Material mat : Material.values()) { + materialLib.set(mat.name().toLowerCase(), valueOf(mat.name())); + } + + initialize(env, null); + + env.set("print", new Print()); + env.set("input", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + String message = arg1.tojstring(); + LuaFunction callback = arg2.checkfunction(); + + SWAnvilInv inv = new SWAnvilInv(player, message); + inv.setCallback(s -> callback.call(valueOf(s))); + inv.open(); + + return LuaValue.NIL; + } + }); + env.set("timeout", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + long time = arg1.checklong(); + LuaFunction callback = arg2.checkfunction(); + + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> callback.call(), time); + return LuaValue.NIL; + } + }); + env.set("pos", new ThreeArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3) { + double x = arg1.checkdouble(); + double y = arg2.checkdouble(); + double z = arg3.checkdouble(); + + Location loc = new Location(player.getWorld(), x, y, z); + + return tableOf(new LuaValue[] { + valueOf("x"), valueOf(loc.getBlockX()), + valueOf("y"), valueOf(loc.getBlockY()), + valueOf("z"), valueOf(loc.getBlockZ()) + }); + } + }); + env.set("exec", new VarArgFunction() { + @Override + public Varargs invoke(Varargs args) { + player.performCommand(varArgsToString(args)); + + return LuaValue.NIL; + } + }); + + env.set("collectgarbage", NIL); + env.set("dofile", NIL); + env.set("load", NIL); + env.set("loadfile", NIL); + env.set("pcall", NIL); + env.set("rawequal", NIL); + env.set("rawget", NIL); + env.set("rawlen", NIL); + env.set("rawset", NIL); + env.set("setmetatable", NIL); + env.set("xpcall", NIL); + return null; + } + + public static String varArgsToString(Varargs args) { + StringBuilder builder = new StringBuilder(); + for (int i = 1; i <= args.narg(); i++) { + LuaValue arg = args.arg(i); + builder.append(arg.tojstring()); + builder.append(" "); + } + return builder.toString(); + } + + private void initialize(LuaValue parent, Class clazz) { + LUA_LIBS.get(clazz).forEach(luaLib -> { + LuaTable luaTable = luaLib.get(player); + parent.set(luaLib.name(), luaTable); + initialize(luaTable, luaLib.getClass()); + }); + } + + class Print extends VarArgFunction { + @Override + public Varargs invoke(Varargs args) { + player.sendMessage(varArgsToString(args)); + return LuaValue.NIL; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java new file mode 100644 index 00000000..e30f70f8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -0,0 +1,40 @@ +package de.steamwar.bausystem.features.script.lua; + +import org.bukkit.entity.Player; +import org.luaj.vm2.Globals; +import org.luaj.vm2.LoadState; +import org.luaj.vm2.LuaFunction; +import org.luaj.vm2.compiler.LuaC; +import org.luaj.vm2.lib.Bit32Lib; +import org.luaj.vm2.lib.PackageLib; +import org.luaj.vm2.lib.StringLib; +import org.luaj.vm2.lib.TableLib; +import org.luaj.vm2.lib.jse.JseBaseLib; +import org.luaj.vm2.lib.jse.JseMathLib; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public class SteamWarPlatform { + + public static Globals createClickGlobals(Player player) { + Globals globals = new Globals(); + globals.load(new JseBaseLib()); + globals.load(new PackageLib()); + globals.load(new JseMathLib()); + globals.load(new TableLib()); + globals.load(new Bit32Lib()); + globals.load(new StringLib()); + globals.load(new SteamWarLuaPlugin(player)); + + LoadState.install(globals); + LuaC.install(globals); + return globals; + } + + public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, Consumer commandConsumer) { + Globals globals = createClickGlobals(player); + globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, commandConsumer)); + return globals; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java new file mode 100644 index 00000000..2e369f5f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -0,0 +1,88 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import lombok.AllArgsConstructor; +import org.bukkit.entity.Player; +import org.luaj.vm2.*; +import org.luaj.vm2.lib.VarArgFunction; +import org.luaj.vm2.lib.ZeroArgFunction; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface LuaLib { + + static LuaValue runGetter(Supplier supplier) { + T value = supplier.get(); + if (value == null) { + return LuaValue.NIL; + } + Class clazz = value.getClass(); + if (clazz == Integer.class || clazz == Long.class) { + return LuaValue.valueOf((int) value); + } else if (clazz == Double.class || clazz == Float.class) { + return LuaValue.valueOf((double) value); + } else if (clazz == String.class) { + return LuaValue.valueOf((String) value); + } else if (clazz == Boolean.class) { + return LuaValue.valueOf((boolean) value); + } + return LuaValue.NIL; + } + + default LuaFunction getter(Supplier supplier) { + return new ZeroArgFunction() { + @Override + public LuaValue call() { + return runGetter(supplier); + } + }; + } + + default LuaFunction getterAndSetter(Supplier supplier, Consumer consumer) { + return new GetterAndSetter<>(supplier, consumer); + } + + default String varArgsToString(Varargs varargs) { + return de.steamwar.bausystem.features.script.lua.SteamWarLuaPlugin.varArgsToString(varargs); + } + + default Class parent() { + return null; + } + String name(); + LuaTable get(Player player); + + @AllArgsConstructor + class GetterAndSetter extends VarArgFunction { + + private Supplier supplier; + private Consumer consumer; + + @Override + public Varargs invoke(Varargs args) { + if (args.narg() == 0) { + return runGetter(supplier); + } else { + if (args.narg() == 1) { + LuaValue luaValue = args.arg(0); + try { + if (luaValue instanceof LuaBoolean) { + consumer.accept(luaValue.toboolean()); + } else if (luaValue instanceof LuaInteger) { + consumer.accept(luaValue.toint()); + } else if (luaValue instanceof LuaDouble) { + consumer.accept(luaValue.todouble()); + } else if (luaValue instanceof LuaString) { + consumer.accept(luaValue.toString()); + } else { + throw new LuaError("Invalid lua type: " + luaValue.typename()); + } + } catch (Throwable throwable) { + throw new LuaError("Error in '" + checkfunction().name() + "' " + throwable.getMessage()); + } + } + return NIL; + } + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java new file mode 100644 index 00000000..9c6cfab1 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -0,0 +1,66 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import de.steamwar.linkage.Linked; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.Varargs; +import org.luaj.vm2.lib.VarArgFunction; + +@Linked +public class PlayerLib implements LuaLib { + + public String name() { + return "player"; + } + + public LuaTable get(Player player) { + LuaTable table = new LuaTable(); + table.set("name", getter(player::getName)); + table.set("message", new Print(player)); + table.set("actionbar", new SendActionbar(player)); + + table.set("x", getterAndSetter(player.getLocation()::getX, player.getLocation()::setX)); + table.set("y", getterAndSetter(player.getLocation()::getY, player.getLocation()::setY)); + table.set("z", getterAndSetter(player.getLocation()::getZ, player.getLocation()::setZ)); + table.set("yaw", getterAndSetter(player.getLocation()::getYaw, player.getLocation()::setYaw)); + table.set("pitch", getterAndSetter(player.getLocation()::getPitch, player.getLocation()::setPitch)); + + table.set("sneaking", getter(player::isSneaking)); + table.set("sprinting", getter(player::isSprinting)); + table.set("slot", getterAndSetter(player.getInventory()::getHeldItemSlot, player.getInventory()::setHeldItemSlot)); + table.set("item", getter(player.getInventory().getItemInMainHand().getType()::name)); + table.set("offHandItem", getter(player.getInventory().getItemInOffHand().getType()::name)); + return table; + } + + private class Print extends VarArgFunction { + private final Player player; + + public Print(Player player) { + this.player = player; + } + + @Override + public Varargs invoke(Varargs args) { + player.sendMessage(varArgsToString(args)); + return LuaValue.NIL; + } + } + + private class SendActionbar extends VarArgFunction { + private final Player player; + + public SendActionbar(Player player) { + this.player = player; + } + + @Override + public Varargs invoke(Varargs args) { + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(varArgsToString(args))); + return LuaValue.NIL; + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java new file mode 100644 index 00000000..b85a6c3f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -0,0 +1,58 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.tracer.record.ActiveTracer; +import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; + +@Linked +public class RegionLib implements LuaLib { + + + @Override + public String name() { + return "region"; + } + + @Override + public LuaTable get(Player player) { + LuaTable table = LuaValue.tableOf(); + + table.set("name", getter(() -> Region.getRegion(player.getLocation()).getName())); + table.set("type", getter(() -> Region.getRegion(player.getLocation()).getPrototype().getName())); + + LuaValue tntLib = LuaValue.tableOf(); + tntLib.set("mode", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class).name())); + tntLib.set("enabled", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY)); + tntLib.set("onlyTb", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB)); + + table.set("tnt", tntLib); + + table.set("fire", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW)); + table.set("freeze", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE)); + table.set("protect", getter(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE)); + + LuaValue traceLib = LuaValue.tableOf(); + traceLib.set("active", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof ActiveTracer)); + traceLib.set("auto", getter(() -> !Region.getRegion(player.getLocation()).isGlobal() && Recorder.INSTANCE.get(Region.getRegion(player.getLocation())) instanceof AutoTraceRecorder)); + traceLib.set("status", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptState())); + traceLib.set("time", getter(() -> Recorder.INSTANCE.get(Region.getRegion(player.getLocation())).scriptTime())); + + table.set("trace", traceLib); + + Loader loader = Loader.getLoader(player); + table.set("loader", getter(() -> loader == null ? "OFF" : loader.getStage().name())); + + return table; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java new file mode 100644 index 00000000..5c0ae63d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -0,0 +1,65 @@ +package de.steamwar.bausystem.features.script.lua.libs; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.core.TPSWatcher; +import de.steamwar.inventory.SWItem; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.luaj.vm2.LuaString; +import org.luaj.vm2.LuaTable; +import org.luaj.vm2.LuaValue; +import org.luaj.vm2.lib.OneArgFunction; +import org.luaj.vm2.lib.TwoArgFunction; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Linked +public class ServerLib implements LuaLib { + @Override + public String name() { + return "server"; + } + + @Override + public LuaTable get(Player player) { + LuaTable serverLib = LuaValue.tableOf(); + serverLib.set("time", getter(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime()))); + serverLib.set("ticks", getter(TPSUtils.currentTick)); + serverLib.set("getBlockAt", new OneArgFunction() { + @Override + public LuaValue call(LuaValue arg1) { + LuaTable pos = arg1.checktable(); + return valueOf(player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).getType().name()); + } + }); + serverLib.set("setBlockAt", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaTable pos = arg1.checktable(); + LuaString material = arg2.checkstring(); + Material mat = SWItem.getMaterial(material.tojstring()); + if (mat == null) { + return NIL; + } + player.getWorld().getBlockAt(pos.get("x").checkint(), pos.get("y").checkint(), pos.get("z").checkint()).setType(mat); + return NIL; + } + }); + + LuaValue tpsLib = LuaValue.tableOf(); + tpsLib.set("oneSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_SECOND))); + tpsLib.set("tenSecond", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_SECONDS))); + tpsLib.set("oneMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.ONE_MINUTE))); + tpsLib.set("fiveMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.FIVE_MINUTES))); + tpsLib.set("tenMinute", getter(() -> TPSWatcher.getTPS(TPSWatcher.TPSType.TEN_MINUTES))); + tpsLib.set("current", getter(TPSWatcher::getTPS)); + tpsLib.set("limit", getter(TPSLimitUtils::getCurrentTPSLimit)); + + serverLib.set("tps", tpsLib); + return serverLib; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java deleted file mode 100644 index b14310b2..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Constants.java +++ /dev/null @@ -1,315 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.tpslimit.FreezeUtils; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.bausystem.features.tpslimit.TPSUtils; -import de.steamwar.bausystem.features.tracer.record.ActiveTracer; -import de.steamwar.bausystem.features.tracer.record.AutoTraceRecorder; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.record.TraceRecorder; -import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.bausystem.region.flags.flagvalues.FireMode; -import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; -import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; -import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; -import de.steamwar.core.TPSWatcher; -import de.steamwar.sql.SteamwarUser; -import lombok.experimental.UtilityClass; -import org.bukkit.entity.Player; -import org.bukkit.inventory.meta.ItemMeta; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.function.Supplier; - -@UtilityClass -public class Constants { - - private final Map> CONSTANTS = new HashMap<>(); - - private static class ConstantDoubleValue extends Value.DoubleValue { - - private Supplier doubleSupplier; - - public ConstantDoubleValue(Supplier doubleSupplier) { - super(doubleSupplier.get()); - this.doubleSupplier = doubleSupplier; - } - - @Override - public long asLong() { - value = doubleSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = doubleSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = doubleSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = doubleSupplier.get(); - return super.asString(); - } - } - - private static class ConstantLongValue extends Value.LongValue { - - private Supplier longSupplier; - - public ConstantLongValue(Supplier longSupplier) { - super(longSupplier.get()); - this.longSupplier = longSupplier; - } - - @Override - public long asLong() { - value = longSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = longSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = longSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = longSupplier.get(); - return super.asString(); - } - } - - private static class ConstantBooleanValue extends Value.BooleanValue { - - private Supplier booleanSupplier; - - public ConstantBooleanValue(Supplier booleanSupplier) { - super(booleanSupplier.get()); - this.booleanSupplier = booleanSupplier; - } - - @Override - public long asLong() { - value = booleanSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = booleanSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = booleanSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = booleanSupplier.get(); - return super.asString(); - } - } - - private static class ConstantStringValue extends Value.StringValue { - - private Supplier stringSupplier; - - public ConstantStringValue(Supplier stringSupplier) { - super(stringSupplier.get()); - this.stringSupplier = stringSupplier; - } - - @Override - public long asLong() { - value = stringSupplier.get(); - return super.asLong(); - } - - @Override - public double asDouble() { - value = stringSupplier.get(); - return super.asDouble(); - } - - @Override - public boolean asBoolean() { - value = stringSupplier.get(); - return super.asBoolean(); - } - - @Override - public String asString() { - value = stringSupplier.get(); - return super.asString(); - } - } - - static { - CONSTANTS.put("trace", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantBooleanValue(() -> false); - } - return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof ActiveTracer); - }); - CONSTANTS.put("autotrace", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantBooleanValue(() -> false); - } - return new ConstantBooleanValue(() -> Recorder.INSTANCE.get(region) instanceof AutoTraceRecorder); - }); - CONSTANTS.put("trace_status", player -> { - TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); - return new ConstantStringValue(recorder::scriptState); - }); - CONSTANTS.put("trace_time", player -> { - TraceRecorder recorder = Recorder.INSTANCE.get(Region.getRegion(player.getLocation())); - return new ConstantLongValue(recorder::scriptTime); - }); - - CONSTANTS.put("tnt", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) != TNTMode.DENY); - }); - CONSTANTS.put("tnt_onlytb", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class) == TNTMode.ONLY_TB); - }); - - CONSTANTS.put("fire", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW); - }); - - CONSTANTS.put("freeze", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE); - }); - - CONSTANTS.put("protect", player -> { - return new ConstantBooleanValue(() -> Region.getRegion(player.getLocation()).getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE); - }); - - CONSTANTS.put("x", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getX()); - }); - CONSTANTS.put("y", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getY()); - }); - CONSTANTS.put("z", player -> { - return new ConstantDoubleValue(() -> player.getLocation().getZ()); - }); - CONSTANTS.put("name", player -> { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - return new ConstantStringValue(user::getUserName); - }); - CONSTANTS.put("sneaking", player -> { - return new ConstantBooleanValue(player::isSneaking); - }); - CONSTANTS.put("sprinting", player -> { - return new ConstantBooleanValue(player::isSprinting); - }); - CONSTANTS.put("slot", player -> { - return new ConstantLongValue(() -> (long) player.getInventory().getHeldItemSlot()); - }); - CONSTANTS.put("slotmaterial", player -> { - return new ConstantStringValue(() -> player.getInventory().getItemInMainHand().getType().name()); - }); - CONSTANTS.put("offhandmaterial", player -> { - return new ConstantStringValue(() -> player.getInventory().getItemInOffHand().getType().name()); - }); - CONSTANTS.put("materialname", player -> { - return new ConstantStringValue(() -> { - ItemMeta itemMeta = player.getInventory().getItemInMainHand().getItemMeta(); - if (itemMeta == null) { - return ""; - } - return itemMeta.getDisplayName(); - }); - }); - CONSTANTS.put("offmaterialname", player -> { - return new ConstantStringValue(() -> { - ItemMeta itemMeta = player.getInventory().getItemInOffHand().getItemMeta(); - if (itemMeta == null) { - return ""; - } - return itemMeta.getDisplayName(); - }); - }); - - CONSTANTS.put("region_type", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantStringValue(() -> "global"); - } - return new ConstantStringValue(() -> region.getPrototype().getDisplayName().replace(' ', '_').toLowerCase()); - }); - CONSTANTS.put("region_name", player -> { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return new ConstantStringValue(() -> "Global"); - } - return new ConstantStringValue(() -> region.getPrototype().getDisplayName()); - }); - - CONSTANTS.put("tps", player -> { - return new ConstantDoubleValue(() -> { - if (FreezeUtils.isFrozen()) return 0.0; - return TPSWatcher.getTPS(); - }); - }); - CONSTANTS.put("tps_limit", player -> { - return new ConstantDoubleValue(TPSLimitUtils::getCurrentTPSLimit); - }); - - CONSTANTS.put("ticks", player -> { - return new ConstantLongValue(TPSUtils.currentTick); - }); - CONSTANTS.put("time", player -> { - return new ConstantStringValue(() -> new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", player)).format(Calendar.getInstance().getTime())); - }); - - CONSTANTS.put("loader_status", player -> { - Loader loader = Loader.getLoader(player); - if (loader == null) { - return new ConstantStringValue(() -> "OFF"); - } - return new ConstantStringValue(() -> loader.getStage().name()); - }); - } - - public Set allVariables() { - return CONSTANTS.keySet(); - } - - public boolean isConstant(String variableName) { - return CONSTANTS.containsKey(variableName); - } - - public Value getConstant(String variableName, Player player) { - return CONSTANTS.get(variableName).apply(player); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java deleted file mode 100644 index e1662028..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class Context { - - private Map variables = new HashMap<>(); - - public void putValue(String variableName, Value value) { - if (variables.containsKey(variableName)) { - if (variables.get(variableName).type().equals(value.type())) { - variables.get(variableName).fromValue(value); - } else { - variables.put(variableName, value); - } - } else { - variables.put(variableName, value); - } - } - - public void removeValue(String variableName) { - variables.remove(variableName); - } - - public boolean hasValue(String variableName) { - return variables.containsKey(variableName); - } - - public Value getValue(String variableName) { - return variables.get(variableName); - } - - public Set allVariables() { - return variables.keySet(); - } - - public Set> entrySet() { - return variables.entrySet(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java deleted file mode 100644 index 5373ff5d..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Value.java +++ /dev/null @@ -1,188 +0,0 @@ -package de.steamwar.bausystem.features.script.variables; - -import lombok.AllArgsConstructor; -import lombok.ToString; - -public interface Value { - - static Value parse(String varValue) { - try { - return new Value.LongValue(Long.parseLong(varValue)); - } catch (NumberFormatException ne) { - try { - return new Value.DoubleValue(Double.parseDouble(varValue)); - } catch (NumberFormatException e) { - if (varValue.equalsIgnoreCase("true") || varValue.equalsIgnoreCase("false")) { - return new Value.BooleanValue(varValue.equalsIgnoreCase("true")); - } else { - return new Value.StringValue(varValue); - } - } - } - } - - String type(); - long asLong(); - double asDouble(); - boolean asBoolean(); - String asString(); - - void fromValue(Value value); - - @AllArgsConstructor - @ToString - class DoubleValue implements Value { - - protected double value; - - @Override - public String type() { - return "floating_number"; - } - - @Override - public long asLong() { - return Math.round(value); - } - - @Override - public double asDouble() { - return value; - } - - @Override - public boolean asBoolean() { - return value != 0; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asDouble(); - } - } - - @AllArgsConstructor - @ToString - class LongValue implements Value { - - protected long value; - - @Override - public String type() { - return "number"; - } - - @Override - public long asLong() { - return value; - } - - @Override - public double asDouble() { - return value; - } - - @Override - public boolean asBoolean() { - return value != 0; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asLong(); - } - } - - @AllArgsConstructor - @ToString - class BooleanValue implements Value { - - protected boolean value; - - @Override - public String type() { - return "boolean"; - } - - @Override - public long asLong() { - return value ? 1 : 0; - } - - @Override - public double asDouble() { - return value ? 1 : 0; - } - - @Override - public boolean asBoolean() { - return value; - } - - @Override - public String asString() { - return value + ""; - } - - @Override - public void fromValue(Value value) { - this.value = value.asBoolean(); - } - } - - @AllArgsConstructor - @ToString - class StringValue implements Value { - - protected String value; - - @Override - public String type() { - return "text"; - } - - @Override - public long asLong() { - try { - return Long.parseLong(value); - } catch (NumberFormatException e) { - return 0; - } - } - - @Override - public double asDouble() { - try { - return Double.parseDouble(value); - } catch (NumberFormatException e) { - return 0; - } - } - - @Override - public boolean asBoolean() { - return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"); - } - - @Override - public String asString() { - return value; - } - - @Override - public void fromValue(Value value) { - this.value = value.asString(); - } - } - -} diff --git a/SCRIPT.md b/SCRIPT.md new file mode 100644 index 00000000..f93a5f16 --- /dev/null +++ b/SCRIPT.md @@ -0,0 +1,183 @@ +# SteamWar.de - Script System + +--- + +* [SteamWar.de - Script System](#steamwarde---script-system) + * [Einleitung](#einleitung) +* [Basis-Apis](#basis-apis) +* [SteamWar.de-Api](#steamwarde-api) + * [global](#global) + * [player](#player) + * [region](#region) + * [tnt](#tnt) + * [server](#server) +* [SteamWar.de-Global-Api](#steamwarde-global-api) + * [Event Type](#event-type) + * [BlockEvent](#blockevent) + * [InteractEvent](#interactevent) + * [Position](#position) +* [Beispiele](#beispiele) + * [Hello, World!](#hello-world) + * [Code](#code) + * [Ausgabe](#ausgabe) + + + +## Einleitung +Das Script System auf SteamWar.de basiert auf [Lua](https://www.lua.org/docs.html). Der Code wird einfach in ein Minecraft Buch geschrieben und kann mit einem Links-Klick ausgeführt werden. + +# Basis-Apis +Es werden folgende Standard-Apis zur Verfügung gestellt: +- [`math`](https://www.lua.org/manual/5.4/manual.html#6.7) +- [`string`](https://www.lua.org/manual/5.4/manual.html#6.4) +- [`table`](https://www.lua.org/manual/5.4/manual.html#6.6) +- `bit32` + +# SteamWar.de-Api +In den Scripten gibt es dazu noch folgende globale Variablen: +- [`player`](#player) +- [`region`](#region) +- [`server`](#server) + +### global +Die `global`-Api stellt Funktionen zur Verfügung, QOL sind. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|-----------|----------------------------------|----------------------------------------------------------------------------------------------------| +| `print` | print(String...) | @see message(String...) | +| `input` | input(String, Function\) | Fragt den User nach einer Eingabe mit der Nachricht und called die zugehörige Funktion nach dieser | +| `timeout` | timeout(Number, Function\) | Wartet die angegebene Anzahl an Ticks und führt danach die zugehörige Funktion aus | +| `pos` | pos(Number, Number, Number) | Erstellt aus drei Zahlen eine Position-Table | +| `exec` | exec(String...) | Führt den angegebenen Befehl als Spieler aus | + +### player +Die `player`-Api stellt Funktionen zur Verfügung, die den Spieler betreffen. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|---------------|--------------------------------|-------------------------------------------------------------| +| `name` | name(): String | Gibt den `displayName` des Spielers zurück | +| `message` | message(String...) | Sendet den Text in den Chat des Spielers | +| `actionbar` | actionbar(String...) | Sendet den Text in die ActionBar des Spielers | +| `x` | x(Number), x(): Number | Setzt oder gibt die X-Koordinate des Spielers | +| `y` | y(Number), y(): Number | Setzt oder gibt die Y-Koordinate des Spielers | +| `z` | z(Number), z(): Number | Setzt oder gibt die Z-Koordinate des Spielers | +| `yaw` | yaw(Number), yaw(): Number | Setzt oder gibt den Yaw des Spielers | +| `pitch` | pitch(Number), pitch(): Number | Setzt oder gibt den Pitch des Spielers | +| `sneaking` | sneaking(): Boolean | Wahr, wenn der Spieler am Sneaken ist | +| `sprinting` | sprinting(): Boolean | Wahr, wenn der Spieler am Sprinten ist | +| `slot` | slot(Number), slot(): Number | Setzt oder gibt den Slot des gehaltenden Items des Spielers | +| `item` | item(): String | Gibt den Item Type der Main-Hand zurück | +| `offHandItem` | offHandItem(): String | Gibt den Item Type der Off-Hand zurück | + + +### region +Die `region`-Api stellt Funktion zur Verfügung, die die Region des Spielers betreffen. +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|--------|----------------|--------------------------------------------| +| `name` | name(): String | Gibt den Namen der Region zurück | +| `type` | type(): String | Gibt den Namen des Typen der Region zurück | + +Es gibt folgende Variablen: + +| Name | Beschreibung | +|--------|--------------| +| `tnt` | [tnt](#tnt) | + +#### tnt + + +## server + +# SteamWar.de-Global-Api +Mit `/script` kann man Script-Bücher global abspeichern. Diese haben dann zugrif auf die `global`-Api. +Die `global`-Api stellt Funktionen zur Verfügung um auf Events, Commands und Hotkeys mit einem Script zu reagieren. + +Es gibt folgende Funktionen: + +| Name | Signature | Beschreibung | +|-----------|---------------------------------|---------------------------------| +| `event` | event(EventType, Function(Any)) | Registriere einen Event Handler | +| `command` | cmd(String, Function(Any)) | Registriere einen Command | + +Es gibt folgende Variablen: + +| Name | Beschreibung | +|--------|----------------------------------| +| `type` | Siehe: [Event Type](#event-type) | + +## Event Type +Es gibt folgende Event-Typen: + +| Name | Wenn | Parameter | +|---------------------|-----------------------------------------------------|---------------------------------| +| `FF` | Beim Doppelten Drücken der Swap-Hands taste | NIL | +| `PlaceBlock` | Beim Platzieren von Blöcken | [BlockEvent](#blockevent) | +| `BreakBlock` | Beim Zerstören von Blöcken | [BlockEvent](#blockevent) | +| `RightClick` | Beim Rechts klicken | [InteractEvent](#interactevent) | +| `LeftClick` | Beim Links Klicken | [InteractEvent](#interactevent) | +| `TNTSpawn` | Wenn ein TNT in der aktuellen Region spawnt | NIL | +| `TNTExplode` | Wenn ein TNT in der aktuellen Region explodiert | [Position](#position) | +| `TNTExplodeInBuild` | Wenn ein TNT in der aktuellen Bau Region explodiert | [Position](#position) | +| `SelfJoin` | Wenn man selbst den Server betritt | NIL | +| `SelfLeave` | Wenn man den Server verlässt | NIL | +| `DropItem` | Wenn man ein item Droppt | (type: Material) | +| `EntityDeath` | Wenn ein Entity Stirbt | (type: Entity Type) | + +### BlockEvent +Das übergebene Objekt an den Handler hat folgende Variablen: + +| Name | Beschreibung | +|--------|-----------------------------| +| `x` | Die X-Koordinate des Blocks | +| `y` | Die Y-Koordinate des Blocks | +| `z` | Die Z-Koordinate des Blocks | +| `type` | Das Material des Blocks | + +### InteractEvent +Das übergebene Objekt an den Handler hat folgende Variablen: + +| Name | Beschreibung | +|------------|-------------------------------------------------------------------------------------------------------------------------------| +| `action` | Die Action die ausgeführt wurde, Mögliche Werte: `RIGHT_CLICK_BLOCK`, `RIGHT_CLICK_AIR`, `LEFT_CLICK_BLOCK`, `LEFT_CLICK_AIR` | +| `hand` | Die Hand die zum ausführen genutzt wird, Mögliche Werte: `HAND`, `OFF_HAND` | +| `block` | Der Typ des Items mit dem geklickt wurde | +| `hasBlock` | Wahr, wenn auf einen Block geklickt wurde | + +Wenn `hasBlock` wahr ist, gibt es folgende Variablen: + +| Name | Beschreibung | +|-------------|-----------------------------------------| +| `blockX` | Die X-Koordinate des Blocks | +| `blockY` | Die Y-Koordinate des Blocks | +| `blockZ` | Die Z-Koordinate des Blocks | +| `blockFace` | Die Seite des Blocks die geklickt wurde | + + +### Position +Die Position ist ein Objekt mit folgenden Variablen: + +| Name | Beschreibung | +|------|------------------| +| `x` | Die X-Koordinate | +| `y` | Die Y-Koordinate | +| `z` | Die Z-Koordinate | + + +# Beispiele + +## Hello, World! +Ein einfaches Hello, World!-Script. + +#### Code +```lua +print("Hello, World!") +``` + +#### Ausgabe +``` +Hello, World! +``` From 95f0625031ac6d3ffe50823600cb96b8a555a24c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 19:34:45 +0200 Subject: [PATCH 112/174] Add Copyright --- .../linkage/types/LuaLib_GENERIC.java | 19 +++++++++++++++ .../features/script/ScriptCommand.java | 19 +++++++++++++++ .../features/script/ScriptListener.java | 19 +++++++++++++++ .../features/script/ScriptRunner.java | 19 +++++++++++++++ .../features/script/UnsignCommand.java | 24 +++++++++---------- .../script/event/CommandListener.java | 19 +++++++++++++++ .../features/script/event/EventListener.java | 19 +++++++++++++++ .../features/script/lua/CommandRegister.java | 19 +++++++++++++++ .../script/lua/SteamWarGlobalLuaPlugin.java | 19 +++++++++++++++ .../script/lua/SteamWarLuaPlugin.java | 19 +++++++++++++++ .../features/script/lua/SteamWarPlatform.java | 19 +++++++++++++++ .../features/script/lua/libs/LuaLib.java | 19 +++++++++++++++ .../features/script/lua/libs/PlayerLib.java | 19 +++++++++++++++ .../features/script/lua/libs/RegionLib.java | 19 +++++++++++++++ .../features/script/lua/libs/ServerLib.java | 19 +++++++++++++++ 15 files changed, 278 insertions(+), 12 deletions(-) diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java index 79c02770..570f6a33 100644 --- a/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/LuaLib_GENERIC.java @@ -1,3 +1,22 @@ +/* + * 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.linkage.types; import de.steamwar.linkage.LinkageType; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java index 6952d796..782e6238 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -1,3 +1,22 @@ +/* + * 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.script; import de.steamwar.command.SWCommand; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index f2b5852c..20f0e595 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -1,3 +1,22 @@ +/* + * 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.script; import de.steamwar.bausystem.utils.FlatteningWrapper; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index 8c4ce348..7c3bac7f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -1,3 +1,22 @@ +/* + * 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.script; import de.steamwar.bausystem.features.script.lua.CommandRegister; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java index 5c4ebb6d..37dda16d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/UnsignCommand.java @@ -1,20 +1,20 @@ /* - * This file is a part of the SteamWar software. + * This file is a part of the SteamWar software. * - * Copyright (C) 2021 SteamWar.de-Serverteam + * 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 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. + * 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 . + * 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.script; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java index e0602616..8e0da5ef 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/CommandListener.java @@ -1,3 +1,22 @@ +/* + * 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.script.event; import de.steamwar.bausystem.features.script.ScriptRunner; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 3a43a83d..e3c09df6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -1,3 +1,22 @@ +/* + * 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.script.event; import de.steamwar.bausystem.BauSystem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java index 2e6d9c46..df4fd3bc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/CommandRegister.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua; import lombok.AllArgsConstructor; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java index 544b8af9..3e5dc4a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua; import lombok.AllArgsConstructor; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java index 21b24e5e..f2280f4a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarLuaPlugin.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua; import de.steamwar.bausystem.BauSystem; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java index e30f70f8..2cd2e023 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua; import org.bukkit.entity.Player; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java index 2e369f5f..4167c4cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/LuaLib.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua.libs; import lombok.AllArgsConstructor; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java index 9c6cfab1..e4f2f12b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/PlayerLib.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua.libs; import de.steamwar.linkage.Linked; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java index b85a6c3f..293bdad1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/RegionLib.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua.libs; import de.steamwar.bausystem.features.loader.Loader; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java index 5c0ae63d..54754471 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/libs/ServerLib.java @@ -1,3 +1,22 @@ +/* + * 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.script.lua.libs; import de.steamwar.bausystem.BauSystem; From edd44c172cfc13e2eea45289f95df490db18a59d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 19 May 2023 20:12:52 +0200 Subject: [PATCH 113/174] Add Hotkeys --- .../bausystem/features/script/Hotkey.java | 77 +++++++++++++++++++ .../features/script/ScriptRunner.java | 14 ++-- .../features/script/event/HotkeyListener.java | 54 +++++++++++++ .../script/lua/SteamWarGlobalLuaPlugin.java | 14 +++- .../features/script/lua/SteamWarPlatform.java | 4 +- 5 files changed, 154 insertions(+), 9 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java new file mode 100644 index 00000000..d149eedd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/Hotkey.java @@ -0,0 +1,77 @@ +/* + * 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.script; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; + +@AllArgsConstructor +@Builder +@EqualsAndHashCode +public class Hotkey { + + private final int charcode; + + private final boolean ctrl; + private final boolean shift; + private final boolean alt; + private final boolean meta; + + public static Hotkey fromString(String string) { + String[] parts = string.split("\\+"); + HotkeyBuilder builder = Hotkey.builder(); + + for (String part : parts) { + switch (part.toLowerCase()) { + case "ctrl": + builder.ctrl(true); + break; + case "shift": + builder.shift(true); + break; + case "alt": + builder.alt(true); + break; + case "meta": + builder.meta(true); + break; + default: + if (part.length() == 1) { + builder.charcode(Character.toLowerCase(part.charAt(0))); + } else { + throw new IllegalArgumentException("Invalid hotkey: " + string); + } + } + } + + return builder.build(); + } + + public static Hotkey fromChar(int c, int mods) { + return Hotkey.builder() + .charcode(Character.toLowerCase(c)) + .shift((mods & 1) != 0) + .ctrl((mods & 2) != 0) + .alt((mods & 4) != 0) + .meta((mods & 8) != 0) + .build(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java index 7c3bac7f..ab4feb4a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptRunner.java @@ -27,10 +27,7 @@ import org.luaj.vm2.Globals; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaValue; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class ScriptRunner { @@ -40,6 +37,7 @@ public class ScriptRunner { // Value -> private static final Map>> EVENT_MAP = new HashMap<>(); + private static final Map>> HOTKEY_MAP = new HashMap<>(); private static final Map> COMMAND_MAP = new HashMap<>(); public static void runScript(String script, Player player) { @@ -55,7 +53,8 @@ public class ScriptRunner { public static void createGlobalScript(List scripts, Player player) { EVENT_MAP.remove(player); Globals globals = SteamWarPlatform.createGlobalGlobals(player, - (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + (s, luaFunction) -> EVENT_MAP.computeIfAbsent(player, player1 -> new EnumMap<>(SteamWarGlobalLuaPlugin.EventType.class)).computeIfAbsent(s, s1 -> new ArrayList<>()).add(luaFunction), + (s, luaFunction) -> HOTKEY_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).computeIfAbsent(Hotkey.fromString(s), s1 -> new ArrayList<>()).add(luaFunction), commandRegister -> COMMAND_MAP.computeIfAbsent(player, player1 -> new HashMap<>()).put(commandRegister.getName(), commandRegister)); for (String script : scripts) { @@ -91,4 +90,9 @@ public class ScriptRunner { commandRegister.getFunction().call(args); } + + public static void callHotkey(int mods, int key, Player player, boolean pressed) { + Hotkey hotkey = Hotkey.fromChar(key, mods); + HOTKEY_MAP.get(player).getOrDefault(hotkey, Collections.emptyList()).forEach(luaFunction -> luaFunction.call(LuaValue.valueOf(pressed))); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java new file mode 100644 index 00000000..d6280b50 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/HotkeyListener.java @@ -0,0 +1,54 @@ +/* + * 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.script.event; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.ScriptRunner; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; + +@Linked +public class HotkeyListener implements PluginMessageListener { + + { + Bukkit.getServer().getMessenger().registerIncomingPluginChannel(BauSystem.getInstance(), "sw:hotkeys", this); + } + + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (!channel.equals("sw:hotkeys")) return; + if (message.length < 5) return; + int action = message[4] & 0xFF; + if (action == 2) return; + int key = (message[0] & 0xFF) << 24 | (message[1] & 0xFF) << 16 | (message[2] & 0xFF) << 8 | (message[3] & 0xFF); + if (!(key >= 'A' && key <= 'Z' || key >= '0' && key <= '9')) return; + if (message.length >= 9) { + int mods = (message[5] & 0xFF) << 24 | (message[6] & 0xFF) << 16 | (message[7] & 0xFF) << 8 | (message[8] & 0xFF); + // player.sendMessage("Hotkey: " + (char) key + " " + action + " " + Long.toBinaryString(mods)); + ScriptRunner.callHotkey(mods, key, player, action == 1); + } else { + // player.sendMessage("Hotkey: " + (char) key + " " + action); + ScriptRunner.callHotkey(0, key, player, action == 1); + } + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java index 3e5dc4a0..f45d4549 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarGlobalLuaPlugin.java @@ -23,9 +23,7 @@ import lombok.AllArgsConstructor; import org.luaj.vm2.LuaFunction; import org.luaj.vm2.LuaString; import org.luaj.vm2.LuaValue; -import org.luaj.vm2.Varargs; import org.luaj.vm2.lib.TwoArgFunction; -import org.luaj.vm2.lib.VarArgFunction; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -33,6 +31,7 @@ import java.util.function.Consumer; @AllArgsConstructor public class SteamWarGlobalLuaPlugin extends TwoArgFunction { private final BiConsumer eventConsumer; + private final BiConsumer hotkeyConsumer; private final Consumer commandRegisterConsumer; @Override @@ -56,6 +55,17 @@ public class SteamWarGlobalLuaPlugin extends TwoArgFunction { return NIL; } }); + env.set("hotkey", new TwoArgFunction() { + @Override + public LuaValue call(LuaValue arg1, LuaValue arg2) { + LuaString key = arg1.checkstring(); + LuaFunction function = arg2.checkfunction(); + + hotkeyConsumer.accept(key.tojstring().toLowerCase(), function); + + return null; + } + }); return NIL; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java index 2cd2e023..a20fa190 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/lua/SteamWarPlatform.java @@ -51,9 +51,9 @@ public class SteamWarPlatform { return globals; } - public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, Consumer commandConsumer) { + public static Globals createGlobalGlobals(Player player, BiConsumer eventConsumer, BiConsumer hotkeyConsumer, Consumer commandConsumer) { Globals globals = createClickGlobals(player); - globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, commandConsumer)); + globals.load(new SteamWarGlobalLuaPlugin(eventConsumer, hotkeyConsumer, commandConsumer)); return globals; } } From 2d8056883c1d6be65b1233c1cb64b153ddca0dd6 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 21 May 2023 11:27:36 +0200 Subject: [PATCH 114/174] Update Docs and Add Global GUI Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 288 +----------------- BauSystem_Main/src/BauSystem_de.properties | 281 +---------------- .../features/script/ScriptCommand.java | 8 + .../bausystem/features/script/ScriptGUI.java | 121 ++++++++ .../features/script/ScriptHelper.java | 55 ++++ .../features/script/ScriptListener.java | 13 +- .../features/script/ScriptRunner.java | 32 +- .../script/event/CommandListener.java | 2 +- .../features/script/event/EventListener.java | 3 +- .../features/script/lua/CommandRegister.java | 2 - .../script/lua/SteamWarGlobalLuaPlugin.java | 4 +- .../script/lua/SteamWarLuaPlugin.java | 31 +- .../features/script/lua/SteamWarPlatform.java | 8 + .../src/de/steamwar/sql/Script.java | 99 ++++++ SCRIPT.md | 134 +++++++- 15 files changed, 473 insertions(+), 608 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptHelper.java create mode 100644 BauSystem_Main/src/de/steamwar/sql/Script.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 448fd952..47fedf61 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -230,299 +230,31 @@ GUI_EDITOR_TITLE_MORE=Select item # Script ## Errors -SCRIPT_SLEEP_ERROR = §cInsert a sleep into your script -SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnknown variable {0} -SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression error with: {0} -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cThe first argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cThe first argument is missing and should be a number -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cThe first argument is missing and should be a variable or a number -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cThe first argument is missing and should be a jump-point -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cThe second argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cThe econd argument is missing and should be a value -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cThe second argument is missing and should be a jump-point -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cThe third argument is missing and should be a variable -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cThe third argument is missing and should be a value -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cThe third argument is missing and should be a variable or a number -SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cThe fourth argument is missing and should be a value - -SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cOnly booleans can be compared -SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cOnly numbers can be compared -SCRIPT_COMMAND_ERROR_NO_BOOLEAN = §cThe value is not a boolean - -SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cOnly strings are allowed -SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cOnly numbers are allowed - -SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnknown operation: {0} - -## Commands -SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cOnly numbers or strings can be added -SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cOnly numbers can be divided -SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cOnly numbers can be multiplied -SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cOnly numbers can be subtracted -SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cOnly numbers can be raised to a power -SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cOnly whole numbers can be used for modulo -SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cOnly whole numbers and booleans can be used for and -SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cOnly whole numbers and booleans can be used for or -SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cOnly whole numbers and booleans can be used for xor -SCRIPT_COMMAND_ARITHMETIC_BIT_LEFT_ERROR = §cOnly whole numbers can be used for left shift value -SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_ERROR = §cOnly whole numbers can be used for right shift value -SCRIPT_COMMAND_ARITHMETIC_BIT_RIGHT_LOGIC_ERROR = §cOnly whole numbers can be used for logic right shift value - -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Ceils the second number and writes it in the first or ceils the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cOnly floating point numbers can be ceiled -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Floors the second number and writes it in the first or floors the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cOnly floating point numbers can be floored -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7variable§8> §8<§7variable§8|§7value§8> §8<§7variable§8|§7value§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Round the second number and writes it in the first or rounds the second number with the precision from the third number and writes it in the first -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cOnly floating point numbers can be rounded -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cThe precision needs to be a whole number - -SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7value§8> -SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Send a message to the player. If the value is empty, the message will be empty as well -SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0} - -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7value§8> -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Send a message to the player to the action bar. If the value is empty, the message will be empty as well - -SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7variable§8> §8<§7text§8> -SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Request an input from the player, which will be written in the variable. The text is optional - -SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7variable§8> §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Insert something into a String at a given index. The number is the index and the variable is the string. Optionally the result can be written in another or a new variable - -SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7variable§8> §8<§7from variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Removes all occurrences of a string from another string. - -SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7variable§8> §8<§7variable§8> §8<§7from variable§8> §8<§7to variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Replaces all occurrences of a string from another string with a given string - -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7variable§8> §8<§7variable§8> §8<§7number§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Shortens a string either from the start or the end, depending on whether the given index is positive (start) or negative (end) - -SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Writes a value in a constant, which can be a number, a boolean or a string - -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7variable§8> §8<§7value§8> -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Converts a value to 'number' if it's a number, or to 'boolean' if it's either 'true' or 'false'. Otherwise it remains of type 'text'. - -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string - -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7variable§8> -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Deletes a global variable. - -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7variable§8> -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Deletes a local variable. - -SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7variable§8> §8[§7value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Writes a value in a variable, which can be a number, a boolean or a string - -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8> -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Writes the material of a block in the world in the variable - -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7variable§8> §8<§7number§8> §8<§7number§8> §8<§7number§8> -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Sets a block in the world with the given material, given in the variable - -SCRIPT_COMMAND_EXIT_HELP_1 = §eexit -SCRIPT_COMMAND_EXIT_HELP_2 = Exits the script - -SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_3 = §7Jump to the first jump-point if the given value is true or the second jump-point otherwise. - -SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7jump-point§8> -SCRIPT_COMMAND_JUMP_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before. -SCRIPT_COMMAND_JUMP_ERROR = §cUnknown jump-point: {0} - -SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7jump-point§8> -SCRIPT_COMMAND_CALL_HELP_2 = §7Jump to a jump-point. A jump-point is a line with §8'§7.§8'§7 before. Building a return stack alongside. Use 'return' to jump back. -SCRIPT_COMMAND_CALL_ERROR = §cUnknown jump-point: {0} - -SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn -SCRIPT_COMMAND_RETURN_HELP_2 = §7Jump back to the last 'call' command -SCRIPT_COMMAND_RETURN_ERROR = §cNo 'call' command executed before - -SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7time§8> -SCRIPT_COMMAND_SLEEP_HELP_2 = Pauses the execution by the given number of game ticks. -SCRIPT_COMMAND_SLEEP_ERROR = §cThe given number needs to be greater than zero. +SCRIPT_ERROR_GUI=§cError in parsing script: Line {0} +SCRIPT_ERROR_GLOBAL=§cError in global script: Line {0} +SCRIPT_ERROR_CLICK=§cError in script: Line {0} ## GUI SCRIPT_GUI_ITEM_NAME = §eScript Help ## CustomScript -SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1} -SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1} -SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0} +SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} +SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} +SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0} ## Script Menu GUI SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Click to retrieve SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift-Click to copy -SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7% +SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Right-Click to edit +SCRIPT_MENU_GUI_NAME = §eScript-Menu SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eInsert SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Click with a book to insert -SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' already defined +SCRIPT_MENU_GUI_DUPLICATE_SCRIPT = §cScript '{0}' already defined +SCRIPT_MENU_GUI_ENTER_NAME = §eEnter a name SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' cannot be defined SCRIPT_MENU_GUI_LIMIT = §cScript-Book limit reached -## ScriptCommand -SCRIPT_COMMAND_HELP = §8/§escript §8- §7Opens the ScriptGUI -SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Opens the ScriptGUI for custom commands shares across baus - -## Script GUI -SCRIPT_GUI_NAME = Script Elements -SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0} - -SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Write§8: §e#!HOTKEY 'Char' -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom hotkey. The 'Char' can be any char between '§eA§7' and '§eZ§7' as well as '§e0§7' and '§e9§7'. While executing two variables are available: §epressed§7, §ereleased§7. -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7You can add modifiers like "SHIFT", "CTRL", "ALT" or "META" to the hotkey. §7Example: §e#!HOTKEY SHIFT+A -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cThis can only be used in conjunction with the Fabric-Mod: §eAdvancedScripts §7found on §ehttps://steamwar.de/downloads - -SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Write§8: §e#!CMD 'COMMAND' -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7at the beginning of a Script Book to use a custom command. The command always starts with §e/§7 and can be structured as you wish. Everything in pointy Brackets '§e<>§7' will be counted as a Parameter and therefore as a variable. Parameters in round brackets '§e()§7' are optional. Simple texts as parameters get a variable with the same name with the values true/false, depending on whether the value was given or not - -SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events -SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Write§8: §e#!EVENT 'EventName' -SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7at the beginning of a Script Book to use a custom event. Every event can ve canceled by using 'var cancel true'. After the event name are the variables which are usable in a Script Book. -SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Usable Events are: -SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF -SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn -SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_18 = §eScoreboard -SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Everything in brackets is only set if the variable before is set on §etrue§7. - -SCRIPT_GUI_OTHER = §eOther -SCRIPT_GUI_OTHER_LORE_1 = §7Comments start with §e#§7. -SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points start with §e.§7. -SCRIPT_GUI_OTHER_LORE_3 = §7A variable name enclosed in '§e{}§7' is replaced by its value. A variable can be prefixed with '§econst.§7' or '§elocal.§7' or '§eglobal.§7'. -SCRIPT_GUI_OTHER_LORE_4 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_5 = §7- Local variables are only available in the script book. -SCRIPT_GUI_OTHER_LORE_6 = §7- Global variables are available in every script book. -SCRIPT_GUI_OTHER_LORE_7 = §7- Constant variables are variables from the server (e.g. player name, TPS, etc.) -SCRIPT_GUI_OTHER_LORE_8 = §7A variable can be appended with '§e.length§7' or '§e.type§7' or '§e.isset§7'. -SCRIPT_GUI_OTHER_LORE_9 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_10 = §7- Length returns the length of the variable as a number. -SCRIPT_GUI_OTHER_LORE_11 = §7- Type returns the type (number, floating_number, text or boolean) as text. -SCRIPT_GUI_OTHER_LORE_12 = §7- Isset returns as a boolean whether the variable exists. -SCRIPT_GUI_OTHER_LORE_13 = §7Mathematical as well as logical operations can be specified in '§e{}§7'. -SCRIPT_GUI_OTHER_LORE_14 = §7The following applies: -SCRIPT_GUI_OTHER_LORE_15 = §7- arithmetic operators: §e+ * - /§7 as well as §e%§7 for modulo -SCRIPT_GUI_OTHER_LORE_16 = §7- Logical operators: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (this is the character for or) -SCRIPT_GUI_OTHER_LORE_17 = §7- Bitwise operators: §e&§7; §e|§7; §e^ -SCRIPT_GUI_OTHER_LORE_18 = §7- Shift operators: §e<<§7; §e>>§7; §e>>>§7 - -SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} - -SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables - -SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime -SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formatted time variable. - -SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks -SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks since server start. - -SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace -SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 if the trace is activated. - -SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace -SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 if the auto trace is activated. - -SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status -SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7One of: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE - -SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time -SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 if the trace is not active, otherwise the time in ticks since the trace was started. - -SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status -SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7One of: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND - -SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt -SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 if tnt is not deactivated. - -SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb -SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 if tnt no build is activated. - -SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze -SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 if freeze is not deactivated. - -SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire -SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 if fire is not deactivated. - -SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect -SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 if protect is activated. - -SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex -SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 position of the player. - -SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey -SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 position of the player. - -SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez -SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 position of the player. - -SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename -SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 name of the player. - -SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking -SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 if the player is sneaking. - -SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting -SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 is the player is sprinting. - -SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot -SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 for the selected slot. - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 of the item in the current slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 of the item in the off hand - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the current slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 of the item in the off hand - -SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type -SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region - -SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name -SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eregion name§7 of the current region - -SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps -SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server - -SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit -SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server - # Shield Printing SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 804afa46..50f587a4 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -226,295 +226,26 @@ GUI_EDITOR_ITEM_CLOSE=§eSchließen GUI_EDITOR_TITLE_MORE=Item auswählen # Script -## Errors -SCRIPT_SLEEP_ERROR = §cFüge ein sleep in dein Script ein -SCRIPT_COMMAND_ERROR_UNKNOWN_VAR = §cUnbekannte Variable {0} -SCRIPT_COMMAND_ERROR_EXPRESSION = §cExpression fehler in: {0} -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR = §cDas erste Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NONUMER = §cDas erste Argument fehlt und sollte eine Zahl sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOVAR_OR_VALUE = §cDas erste Argument fehlt und sollte eine Variable oder ein Wert sein -SCRIPT_COMMAND_ERROR_FIRST_ARG_NOJUMPPOINT = §cDas erste Argument fehlt und sollte ein Jump-Point sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVAR = §cDas zweite Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOVALUE = §cDas zweite Argument fehlt und sollte ein Wert sein -SCRIPT_COMMAND_ERROR_SECOND_ARG_NOJUMPPOINT = §cDas dritte Argument fehlt und sollte ein Jump-Point sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR = §cDas dritte Argument fehlt und sollte eine Variable sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVALUE = §cDas dritte Argument fehlt und sollte ein Wert sein -SCRIPT_COMMAND_ERROR_THIRD_ARG_NOVAR_OR_NUMBER = §cDas dritte Argument fehlt und sollte eine Variable/Zahl sein -SCRIPT_COMMAND_ERROR_FOURTH_ARG_NOVALUE = §cDas vierte Argument fehlt und sollte ein Wert sein - -SCRIPT_COMMAND_ERROR_BOOLEAN_COMPARE = §cNur Booleans können verglichen werden -SCRIPT_COMMAND_ERROR_NUMBER_COMPARE = §cNur Zahlen können verglichen werden - -SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED = §cNur Strings können verwendet werden -SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED = §cNur Zahlen können verwendet werden - -SCRIPT_COMMAND_ERROR_UNKNOWN_OPERATION = §cUnbekannte Operation: {0} - -## Commands -SCRIPT_COMMAND_ARITHMETIC_ADD_ERROR = §cNur Zahlen können addiert werden -SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR = §cNur Zahlen können dividiert werden -SCRIPT_COMMAND_ARITHMETIC_MUL_ERROR = §cNur Zahlen können multipliziert werden -SCRIPT_COMMAND_ARITHMETIC_SUB_ERROR = §cNur Zahlen können subtrahiert werden -SCRIPT_COMMAND_ARITHMETIC_POW_ERROR = §cNur Zahlen können potenziert werden -SCRIPT_COMMAND_ARITHMETIC_MOD_ERROR = §cNur ganze Zahlen können für modulo verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_AND_ERROR = §cNur ganze Zahlen und booleans können für und verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_OR_ERROR = §cNur ganze Zahlen und booleans können für oder verwendet werden -SCRIPT_COMMAND_ARITHMETIC_BIT_XOR_ERROR = §cNur ganze Zahlen und booleans können für xor verwendet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_1 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_2 = §eceil §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_HELP_3 = Aufrunden der zweiten Zahl und schreibt es in die erste oder aufrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_1 = §cNur Fließ-Komma-Zahlen können aufgerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_CEIL_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_1 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_2 = §efloor §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_HELP_3 = Abrunden der zweiten Zahl und schreibt es in die erste oder abrunden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_1 = §cNur Fließ-Komma-Zahlen können abgerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_FLOOR_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_1 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_2 = §eround §8<§7Variable§8> §8<§7Variable§8|§7Wert§8> §8<§7Variable§8|§7Wert§8> -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_HELP_3 = Runden der zweiten Zahl und schreibt es in die erste oder runden der zweiten Zahl auf die Nachkommastellenanzahl aus der dritten Zahl und schreibt es in die erste. -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_1 = §cNur Fließ-Komma-Zahlen können gerundet werden -SCRIPT_COMMAND_ARITHMETIC_OTHER_ROUND_ERROR_2 = §cEs kann nur auf ganze Nachkommastellen gerundet werden - -SCRIPT_COMMAND_IO_ECHO_HELP_1 = §eecho §8<§7Wert§8> -SCRIPT_COMMAND_IO_ECHO_HELP_2 = §7Schreibe etwas dem Spieler. Wenn kein Wert angegeben wurde ist die Nachricht leer. -SCRIPT_COMMAND_IO_ECHO_MESSAGE = §f{0} - -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_1 = §eechoactionbar §8<§7Wert§8> -SCRIPT_COMMAND_IO_ECHOACTIONBAR_HELP_2 = §7Schreibe etwas dem Spieler in der ActionBar. Wenn kein Wert angegeben wurde ist die Nachricht leer. - -SCRIPT_COMMAND_IO_INPUT_HELP_1 = §einput §8<§7Variable§8> §8<§7Text§8> -SCRIPT_COMMAND_IO_INPUT_HELP_2 = §7Fordere eine Eingabe von dem Spieler, welche in die Variable geschrieben wird. Der Text ist optional. - -SCRIPT_COMMAND_STRING_INSERT_HELP_1 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_2 = §einsert §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_INSERT_HELP_3 = Füge etwas in einen String an einer Stelle ein. Die Zahl ist für die Position und die Variable davor für was. Schreibe optional dies in eine neue oder andere Variable. - -SCRIPT_COMMAND_STRING_REMOVE_HELP_1 = §eremove §8<§7Variable§8> §8<§7Von Variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_2 = §eremove §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> -SCRIPT_COMMAND_STRING_REMOVE_HELP_3 = Lösche eine Zeichenkette aus dem Ursprung. Dies ersetzt nicht nur die erste Stelle sondern alle. - -SCRIPT_COMMAND_STRING_REPLACE_HELP_1 = §ereplace §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_2 = §ereplace §8<§7Variable§8> §8<§7Variable§8> §8<§7Von Variable§8> §8<§7Zu Variable§8> -SCRIPT_COMMAND_STRING_REPLACE_HELP_3 = Ersetzte eine Zeichenkette aus dem Ursprung mit einer neuen Zeichenkette. Dies ersetzt nicht nur die erste Stelle sondern alle. - -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_1 = §esubstring §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_2 = §esubstring §8<§7Variable§8> §8<§7Variable§8> §8<§7Zahl§8> -SCRIPT_COMMAND_STRING_SUBSTRING_HELP_3 = Kürze einen String entweder vorne oder hinter, je nachdem ob die Zahl positiv (vorne) oder negativ (hinten) ist. - -SCRIPT_COMMAND_VARIABLE_CONST_HELP_1 = §econst §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_CONST_HELP_2 = Schreibt in eine Konstante einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_1 = §econvert §8<§7Variable§8> §8<§7Value§8> -SCRIPT_COMMAND_VARIABLE_CONVERT_HELP_2 = Konvertiere den Value zu 'number' wenn es eine Zahl ist, oder zu 'boolean' bei 'true' oder 'false' und behalte 'text' bei wenn nichts zutrifft. - -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_1 = §eglobal §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_GLOBAL_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_1 = §eunglobal §8<§7Variable§8> -SCRIPT_COMMAND_VARIABLE_UNGLOBAL_HELP_2 = Lösche eine Globale variable. - -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_1 = §eunvar §8<§7Variable§8> -SCRIPT_COMMAND_VARIABLE_UNVAR_HELP_2 = Lösche eine Locale variable. - -SCRIPT_COMMAND_VARIABLE_VAR_HELP_1 = §evar §8<§7Variable§8> §8[§7Value§8(§7s§8)§8] -SCRIPT_COMMAND_VARIABLE_VAR_HELP_2 = Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text. - -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_1 = §egetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8> -SCRIPT_COMMAND_WORLD_GETMATERIAL_HELP_2 = Schreibt das material von einem Block in der Welt in die Variable. - -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_1 = §esetmaterial §8<§7Variable§8> §8<§7Zahl§8> §8<§7Zahl§8> §8<§7Zahl§8> -SCRIPT_COMMAND_WORLD_SETMATERIAL_HELP_2 = Setzt an einem Block in der Welt das Material der ersten Variable. - -SCRIPT_COMMAND_EXIT_HELP_1 = §eexit -SCRIPT_COMMAND_EXIT_HELP_2 = Beendet das ausführen des Scripts. - -SCRIPT_COMMAND_IF_HELP_1 = §eif §8<§7true/false§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_2 = §eif §8<§7true/false§8> §8<§7jump-point§8> §8<§7jump-point§8> -SCRIPT_COMMAND_IF_HELP_3 = §7Springe zu ersten Stelle, wenn der Wert true ist. Oder zu dem zweiten, wenn dies nicht der fall ist. - -SCRIPT_COMMAND_JUMP_HELP_1 = §ejump §8<§7Jump-Point§8> -SCRIPT_COMMAND_JUMP_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor. -SCRIPT_COMMAND_JUMP_ERROR = §cDer Jump-Point ({0}) ist nicht definiert. - -SCRIPT_COMMAND_CALL_HELP_1 = §ecall §8<§7Jump-Point§8> -SCRIPT_COMMAND_CALL_HELP_2 = §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor. Hierbei wird auf den ReturnStack die jetzige Zeile geschrieben, dahin kann man wieder mit 'return' zurück springen. -SCRIPT_COMMAND_CALL_ERROR = §cDer Jump-Point ({0}) ist nicht definiert. - -SCRIPT_COMMAND_RETURN_HELP_1 = §ereturn -SCRIPT_COMMAND_RETURN_HELP_2 = §7Springe zum letzten 'call' Befehl. -SCRIPT_COMMAND_RETURN_ERROR = §cEs wurde kein 'call' Befehl ausgeführt - -SCRIPT_COMMAND_SLEEP_HELP_1 = §esleep §8<§7Time§8> -SCRIPT_COMMAND_SLEEP_HELP_2 = Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks. -SCRIPT_COMMAND_SLEEP_ERROR = §cDie Zeit muss eine Zahl großer 0 sein. - ## GUI SCRIPT_GUI_ITEM_NAME = §eScript Hilfe ## CustomScript -SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} §8-§7 {1} -SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} §8-§7 {1} -SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e{0} +SCRIPT_HOTKEY_ITEM_NAME = §7Hotkey§8: §e{0} +SCRIPT_EVENT_ITEM_NAME = §7Event§8: §e{0} +SCRIPT_COMMAND_ITEM_NAME = §7Command§8: §e/{0} ## Script Menu GUI SCRIPT_MENU_GUI_ITEM_LORE_1 = §7Klicke zum rausnehmen SCRIPT_MENU_GUI_ITEM_LORE_2 = §7Shift Klicke zum kopieren -SCRIPT_MENU_GUI_NAME = §eScript Commands {0}{1}§7% +SCRIPT_MENU_GUI_ITEM_LORE_3 = §7Rechts Klicke zum editieren +SCRIPT_MENU_GUI_NAME = §eScript-Menü SCRIPT_MENU_GUI_ITEM_ADD_NAME = §eHinzufügen SCRIPT_MENU_GUI_ITEM_ADD_LORE = §7Klicke mit einem Buch zum hinzufügen -SCRIPT_MENU_GUI_DUPLICATE_COMMAND = §cCommand '{0}' bereits definiert +SCRIPT_MENU_GUI_DUPLICATE_SCRIPT = §cCommand '{0}' bereits definiert SCRIPT_MENU_GUI_UNKNOWN_EVENT = §cEvent '{0}' ist nicht definierbar SCRIPT_MENU_GUI_LIMIT = §cScript-Buch Limit erreicht -## ScriptCommand -SCRIPT_COMMAND_HELP = §8/§escript §8- §7Öffnet die ScriptGUI -SCRIPT_COMMAND_HELP_MENU = §8/§escript menu §8- §7Öffnet die ScriptMenuGUI für Custom Command bauübergreifend - -## Script GUI -SCRIPT_GUI_NAME = Script Elements -SCRIPT_GUI_COMMAND_CHAT = §eScript Command§8: §e{0} - -SCRIPT_GUI_CUSTOM_HOTKEYS = §eCustom Hotkeys -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_1 = §7Schreibe§8: §e#!HOTKEY 'Char' -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_2 = §7am Anfang eines Skript Buches, um einen benutzerdefinierten Hotkey zu verwenden. Das 'Char' kann ein beliebiges Zeichen zwischen '§eA§7' und '§eZ§7' sowie '§e0§7' und '§e9§7' sein. Während der Ausführung sind zwei Variablen verfügbar: §epressed§7, §ereleased§7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_3 = §7Sie können dem Hotkey Modifikatoren wie "SHIFT", "CTRL", "ALT" oder "META" hinzufügen. §7Beispiel: §e#!HOTKEY SHIFT+A -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_4 = §7 -SCRIPT_GUI_CUSTOM_HOTKEYS_COMMANDS_LORE_5 = §cDies kann nur in Verbindung mit den Fabric-Mod: §eAdvancedScripts §7runterladbar unter §ehttps://steamwar.de/downloads §cverwendet werden. - -SCRIPT_GUI_CUSTOM_COMMANDS = §eCustom Commands -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_1 = §7Schreibe§8: §e#!CMD 'COMMAND' -SCRIPT_GUI_CUSTOM_COMMANDS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Command zu nutzen. Der Befehl startet immer mit §e/§7 und kann dann so aufgebaut sein wie du willst. Alles was in Spitzen Klammern steht '§e<>§7' wird als Parameter und somit als Variable gewertet. Parameter, welche in runden Klammern stehen sind Optional. Einfache Texte als Parameter bekommen eine gleichnamige Variable mit true/false als Wert je nachdem ob dieser angegeben wurde oder nicht - -SCRIPT_GUI_CUSTOM_EVENTS = §eCustom Events -SCRIPT_GUI_CUSTOM_EVENTS_LORE_1 = §7Schreibe§8: §e#!EVENT 'EventName' -SCRIPT_GUI_CUSTOM_EVENTS_LORE_2 = §7an den Anfang eines Script Buches um ein Custom Event zu nutzen. Jedes Event kann durch 'var cancel true' gecancelt werden. Hinter dem Event Namen stehen die Variablen, welche im Script durch das Event nutztbar sind. -SCRIPT_GUI_CUSTOM_EVENTS_LORE_3 = §7Nutzbare Events sind: -SCRIPT_GUI_CUSTOM_EVENTS_LORE_4 = §eFF -SCRIPT_GUI_CUSTOM_EVENTS_LORE_5 = §ePlaceBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_6 = §eBreakBlock §8-§7 blockX, blockY, blockZ, blockType -SCRIPT_GUI_CUSTOM_EVENTS_LORE_7 = §eRightClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_8 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_9 = §eLeftClick §8-§7 blockInHand, action, handType, -SCRIPT_GUI_CUSTOM_EVENTS_LORE_10 = §7 hasBlock §8[§7blockX, blockY, blockZ, blockFace§8]§e* -SCRIPT_GUI_CUSTOM_EVENTS_LORE_11 = §eTNTSpawn -SCRIPT_GUI_CUSTOM_EVENTS_LORE_12 = §eTNTExplode §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_13 = §eTNTExplodeInBuild §8-§7 x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_14 = §eSelfJoin §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_15 = §eSelfLeave §8-§7 x, y, z, playerName -SCRIPT_GUI_CUSTOM_EVENTS_LORE_16 = §eDropItem §8-§7 material, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_17 = §eEntityDeath §8-§7 entityType, x, y, z -SCRIPT_GUI_CUSTOM_EVENTS_LORE_STAR_1 = §e* §8-§7 Alles in den Klammern ist nur gesetzt, wenn die Variable davor auf §etrue§7 gesetzt ist. - -SCRIPT_GUI_OTHER = §eOther -SCRIPT_GUI_OTHER_LORE_1 = §7Kommentare fangen mit §e#§7 an. -SCRIPT_GUI_OTHER_LORE_2 = §7Jump_Points fangen mit §e.§7 an. -SCRIPT_GUI_OTHER_LORE_3 = §7Einen Variablennamen, der in '§e{}§7' eingeschlossen ist wird durch seinen Wert ersetzt. Eine Variable kann mit den Präfixen '§econst.§7' oder '§elocal.§7' oder '§eglobal.§7' versehen werden. -SCRIPT_GUI_OTHER_LORE_4 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_5 = §7- Lokalevariablen sind nur in dem Script-Buch verfügbar. -SCRIPT_GUI_OTHER_LORE_6 = §7- Gloablevariablen sind in jedem Script-Buch verfügbar. -SCRIPT_GUI_OTHER_LORE_7 = §7- Konstantevariablen sind Variablen vom Server (z.B. Spielername, TPS usw.) -SCRIPT_GUI_OTHER_LORE_8 = §7Eine Variable kann mit den Appendixen '§e.length§7' oder '§e.type§7' oder '§e.isset§7' versehen werden. -SCRIPT_GUI_OTHER_LORE_9 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_10 = §7- Length gibt die Länge der variable als Zahl zurück. -SCRIPT_GUI_OTHER_LORE_11 = §7- Type gibt den typen (number, floating number, text oder boolean) als Text zurück. -SCRIPT_GUI_OTHER_LORE_12 = §7- Isset gibt als boolean zurück, ob die Variable existiert. -SCRIPT_GUI_OTHER_LORE_13 = §7Mathematische sowie logische Operationsvorgänge können in '§e{}§7' angegeben werden. -SCRIPT_GUI_OTHER_LORE_14 = §7Dabei gilt: -SCRIPT_GUI_OTHER_LORE_15 = §7- Rechenoperatoren: §e+ * - /§7 sowie §e%§7 für Modulo -SCRIPT_GUI_OTHER_LORE_16 = §7- Logische Operatoren: §e==§7; §e!=§7; §e<=§7; §e>=§7; §e<§7; §e>§7; §e&&§7; §e||§7 (Dies ist das Zeichen für oder) -SCRIPT_GUI_OTHER_LORE_17 = §7- Bitweise Operatoren: §e&§7; §e|§7; §e^ -SCRIPT_GUI_OTHER_LORE_18 = §7- Shift Operatoren: §e<<§7; §e>>§7; §e>>>§7 - -SCRIPT_GUI_COMMAND_NAME = §7Command: §e{0} - -SCRIPT_GUI_CUSTOM_VARIABLES = §eCustom Variables - -SCRIPT_GUI_CONSTANT_TIME_NAME = §7Constant §etime -SCRIPT_GUI_CONSTANT_TIME_LORE = §7Formattierte Uhrzeit - -SCRIPT_GUI_CONSTANT_TICKS_NAME = §7Constant §eticks -SCRIPT_GUI_CONSTANT_TICKS_LORE = §7Ticks seit dem Serverstart - -SCRIPT_GUI_CONSTANT_TRACE_NAME = §7Constant §etrace -SCRIPT_GUI_CONSTANT_TRACE_LORE = §etrue§7 wenn gerade der Tracer an ist. - -SCRIPT_GUI_CONSTANT_AUTO_TRACE_NAME = §7Constant §eautotrace -SCRIPT_GUI_CONSTANT_AUTO_TRACE_LORE = §etrue§7 wenn gerade der AutoTracer an ist. - -SCRIPT_GUI_CONSTANT_TRACE_STATUS_NAME = §7Constant §etrace_status -SCRIPT_GUI_CONSTANT_TRACE_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eIDLE§8, §eIDLE_AUTO_EXPLODE§8, §eIDLE_AUTO_IGNITE§8, §eIDLE_SINGLE - -SCRIPT_GUI_CONSTANT_TRACE_TIME_NAME = §7Constant §etrace_time -SCRIPT_GUI_CONSTANT_TRACE_TIME_LORE = §e0§7 wenn gerade kein TNT getraced wird, ansonsten die Zeit in Ticks seit dem Start des Tracers. - -SCRIPT_GUI_CONSTANT_LOADER_STATUS_NAME = §7Constant §eloader_status -SCRIPT_GUI_CONSTANT_LOADER_STATUS_LORE = §7Ein Wert von: §eOFF§8, §eSETUP§8, §eRUNNING§8, §eSINGLE§8, §ePAUSE§8, §eEND - -SCRIPT_GUI_CONSTANT_TNT_NAME = §7Constant §etnt -SCRIPT_GUI_CONSTANT_TNT_LORE = §etrue§7 wenn TNT nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_ONLY_TB_NAME = §7Constant §etnt_onlytb -SCRIPT_GUI_CONSTANT_ONLY_TB_LORE = §etrue§7 wenn TNT Nur Testblock an ist. - -SCRIPT_GUI_CONSTANT_FREEZE_NAME = §7Constant §efreeze -SCRIPT_GUI_CONSTANT_FREEZE_LORE = §etrue§7 wenn Freeze nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_FIRE_NAME = §7Constant §efire -SCRIPT_GUI_CONSTANT_FIRE_LORE = §etrue§7 wenn Fire nicht ausgeschaltet ist. - -SCRIPT_GUI_CONSTANT_PROTECT_NAME = §7Constant §eprotect -SCRIPT_GUI_CONSTANT_PROTECT_LORE = §etrue§7 wenn Protect angeschaltet ist. - -SCRIPT_GUI_CONSTANT_X_NAME = §7Constant §ex -SCRIPT_GUI_CONSTANT_X_LORE = §ex§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_Y_NAME = §7Constant §ey -SCRIPT_GUI_CONSTANT_Y_LORE = §ey§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_Z_NAME = §7Constant §ez -SCRIPT_GUI_CONSTANT_Z_LORE = §ez§7 Position des Spielers. - -SCRIPT_GUI_CONSTANT_NAME_NAME = §7Constant §ename -SCRIPT_GUI_CONSTANT_NAME_LORE = §eDisplay§7 Name des Spielers. - -SCRIPT_GUI_CONSTANT_SNEAK_NAME = §7Constant §esneaking -SCRIPT_GUI_CONSTANT_SNEAK_LORE = §etrue§7 wenn der Spieler gerade sneakt. - -SCRIPT_GUI_CONSTANT_SPRINTING_NAME = §7Constant §esprinting -SCRIPT_GUI_CONSTANT_SPRINTING_LORE = §etrue§7 wenn der Spieler gerade rennt. - -SCRIPT_GUI_CONSTANT_SLOT_NAME = §7Constant §eslot -SCRIPT_GUI_CONSTANT_SLOT_LORE = §e0-8§7 für den ausgewählten slot. - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_NAME = §7Constant §eslotmaterial -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_LORE = §eMaterial§7 des Items im Slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_NAME = §7Constant §eoffhandmaterial -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_LORE = §eMaterial§7 des Items in der Off Hand - -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_NAME = §7Constant §ematerialname -SCRIPT_GUI_CONSTANT_SLOT_MATERIAL_DISPLAY_LORE = §eName§7 des Items im Slot - -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_NAME = §7Constant §eoffmaterialname -SCRIPT_GUI_CONSTANT_OFF_HAND_MATERIAL_DISPLAY_LORE = §eName§7 des Items in der Off Hand - -SCRIPT_GUI_CONSTANT_REGION_TYPE_NAME = §7Constant §eregion_type -SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eRegionstype§7 der jetztigen Region - -SCRIPT_GUI_CONSTANT_REGION_NAME_NAME = §7Constant §eregion_name -SCRIPT_GUI_CONSTANT_REGION_NAME_LORE = §eRegionsname§7 der jetztigen Region - -SCRIPT_GUI_CONSTANT_TPS_NAME = §7Constant §etps -SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server - -SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit -SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server - # Shield Printing SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java index 782e6238..9d640d52 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptCommand.java @@ -20,10 +20,18 @@ package de.steamwar.bausystem.features.script; import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; +@Linked public class ScriptCommand extends SWCommand { public ScriptCommand() { super("script"); } + + @Register + public void genericCommand(Player player) { + ScriptGUI.open(player); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java new file mode 100644 index 00000000..720feb78 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptGUI.java @@ -0,0 +1,121 @@ +/* + * 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.script; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.lua.SteamWarPlatform; +import de.steamwar.inventory.SWAnvilInv; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.linkage.Linked; +import de.steamwar.sql.Script; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BookMeta; +import org.luaj.vm2.Globals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Linked +public class ScriptGUI implements Listener { + public static void open(Player player) { + open(player, null); + } + + private static void open(Player player, ItemStack setCursor) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + List> entries = new ArrayList<>(); + List lore = new ArrayList<>(); + Globals globals = SteamWarPlatform.createGlobalParser( + (eventType, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_EVENT_ITEM_NAME", player, eventType.name())), + (s, luaFunction) -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_HOTKEY_ITEM_NAME", player, s)), + commandRegister -> lore.add(BauSystem.MESSAGE.parse("SCRIPT_COMMAND_ITEM_NAME", player, commandRegister.getName())) + ); + + Script.list(user).forEach(script -> { + try { + globals.load(script.getScript()).call(); + } catch (Exception e) { + String[] sp = e.getMessage().split(":"); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_ERROR_GUI", player, String.join(":", Arrays.copyOfRange(sp, 1, sp.length)))); + } + + if(!lore.isEmpty()) { + lore.add(""); + } + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_1", player)); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_2", player)); + lore.add(BauSystem.MESSAGE.parse("SCRIPT_MENU_GUI_ITEM_LORE_3", player)); + + entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.ENCHANTED_BOOK, script.getName(), new ArrayList<>(lore), false, clickType -> {}), script)); + lore.clear(); + }); + + SWListInv