From 80a156754d6d947676e5377e7fa3dc4ff59aab41 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 16 Apr 2025 12:54:07 +0200 Subject: [PATCH] Finalize WorldEditCUI --- .../src/de/steamwar/bausystem/BauSystem.java | 3 + .../de/steamwar/fightsystem/ArenaMode.java | 1 + .../de/steamwar/fightsystem/FightSystem.java | 4 +- .../core/WorldEditRendererWrapper20.java | 20 +-- .../SpigotCore_Main/src/SpigotCore.properties | 19 +++ .../src/SpigotCore_de.properties | 13 +- .../steamwar/WorldEditRendererCUIEditor.java | 157 ++++++++++++++++++ .../de/steamwar/core/WorldEditRenderer.java | 7 +- 8 files changed, 204 insertions(+), 20 deletions(-) create mode 100644 SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 0d5fa43c..8256a83d 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.bausystem.config.BauServer; import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.ConfigConverter; @@ -206,6 +207,8 @@ public class BauSystem extends JavaPlugin { TraceManager.instance.init(); TraceRecorder.instance.init(); + + new WorldEditRendererCUIEditor(); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index e96e0204..eb0a637a 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -53,4 +53,5 @@ public enum ArenaMode { public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); public static final Set SeriousFight = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, REPLAY))); + public static final Set CheckOrTest = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index ce47ee34..9a99789c 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; import de.steamwar.fightsystem.countdown.*; @@ -28,8 +29,8 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightWorld; import de.steamwar.fightsystem.fight.HotbarKit; -import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; +import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.record.FileSource; import de.steamwar.fightsystem.record.GlobalRecorder; @@ -106,6 +107,7 @@ public class FightSystem extends JavaPlugin { new HotbarKit.HotbarKitListener(); new JoinRequestListener(); new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); + new OneShotStateDependent(ArenaMode.CheckOrTest, FightState.All, WorldEditRendererCUIEditor::new); new EnterHandler(); techHider = new TechHiderWrapper(); diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java index 5bffe84f..9e2dd784 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/WorldEditRendererWrapper20.java @@ -19,10 +19,9 @@ package de.steamwar.core; +import de.steamwar.WorldEditRendererCUIEditor; import de.steamwar.entity.CAABox; -import de.steamwar.entity.CAALine; import de.steamwar.entity.REntityServer; -import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -74,21 +73,14 @@ public class WorldEditRendererWrapper20 implements WorldEditRendererWrapper { return entityServer; }); - float width = CAALine.DEFAULT_WIDTH; - if (player != owner) { - width = 1 / 64f; - } - - BlockData block; + WorldEditRendererCUIEditor.Type type; if (player == owner) { - if (clipboard) { - block = Material.LIME_CONCRETE.createBlockData(); - } else { - block = Material.PURPLE_CONCRETE.createBlockData(); - } + type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD : WorldEditRendererCUIEditor.Type.SELECTION; } else { - block = Material.GRAY_CONCRETE.createBlockData(); + type = clipboard ? WorldEditRendererCUIEditor.Type.CLIPBOARD_OTHER : WorldEditRendererCUIEditor.Type.SELECTION_OTHER; } + float width = type.getWidth(player).value; + BlockData block = type.getMaterial(player).createBlockData(); BoxPair boxPair = boxes.computeIfAbsent(player, __ -> new HashMap<>()).computeIfAbsent(owner, __ -> new BoxPair()); CAABox box = boxPair.get(clipboard); diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties index 10c64603..b4cae687 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore.properties @@ -105,3 +105,22 @@ NOSCHEMSUBMITTING_PERMA=§7You are §epermanently§7 excluded from submitting § NOSCHEMSUBMITTING_UNTIL=§7You are excluded from submitting §e§lschematics §euntil {0}§8: §e{1} UNNOSCHEMSUBMITTING_ERROR=§cThe player is not excluded from submitting schematics. UNNOSCHEMSUBMITTING=§e{0} §7may now submit §e§lschematics§7 again§8. + +WORLDEDIT_CUI_TITLE = WorldEdit CUI +WORLDEDIT_CUI_TITLE_SUBMENU = WorldEdit CUI - {0} +WORLDEDIT_CUI_SELECTION = Selection +WORLDEDIT_CUI_CLIPBOARD = Clipboard +WORLDEDIT_CUI_SELECTION_OTHER = Selection Other +WORLDEDIT_CUI_CLIPBOARD_OTHER = Clipboard Other + +WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0} +WORLDEDIT_CUI_MATERIAL_CLICK = §7Click to edit + +WORLDEDIT_CUI_WIDTH_NAME = §eWidth {0} +WORLDEDIT_CUI_WIDTH_LORE = §8> §7{0} +WORLDEDIT_CUI_WIDTH_LORE_SELECTED = §8> §e{0} +WORLDEDIT_CUI_WIDTH_CLICK = §7Click to change +WORLDEDIT_CUI_WIDTH_HUGE = 2/16 Block +WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block +WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block +WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties index 83fa39f5..cc5158ea 100644 --- a/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties +++ b/SpigotCore/SpigotCore_Main/src/SpigotCore_de.properties @@ -99,4 +99,15 @@ NOSCHEMSUBMITTING_TEAM={0} §e{1} §7wurde von §e{2} {3} §7vom §e§lSchematic NOSCHEMSUBMITTING_PERMA=§7Du bist §epermanent §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8: §e{0} NOSCHEMSUBMITTING_UNTIL=§7Du bist §ebis zum {0} §7vom §e§lEinsenden von Schematics§7 ausgeschlossen§8: §e{1} UNNOSCHEMSUBMITTING_ERROR=§cDer Spieler ist nicht vom Einsenden von Schematics ausgeschlossen. -UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8. \ No newline at end of file +UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8. + +WORLDEDIT_CUI_SELECTION = Auswahl +WORLDEDIT_CUI_CLIPBOARD = Kopie +WORLDEDIT_CUI_SELECTION_OTHER = Auswahl Anderer +WORLDEDIT_CUI_CLIPBOARD_OTHER = Kopie Anderer + +WORLDEDIT_CUI_MATERIAL_NAME = §eWorldEdit {0} +WORLDEDIT_CUI_MATERIAL_CLICK = §7Klicke zum Editieren + +WORLDEDIT_CUI_WIDTH_NAME = §eDicke - {0} +WORLDEDIT_CUI_WIDTH_CLICK = §7Klicke zum ändern \ No newline at end of file diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java new file mode 100644 index 00000000..6bd0f60a --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/WorldEditRendererCUIEditor.java @@ -0,0 +1,157 @@ +/* + * 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; + +import de.steamwar.command.SWCommand; +import de.steamwar.core.Core; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.sql.UserConfig; +import lombok.AllArgsConstructor; +import org.bukkit.Material; +import org.bukkit.block.data.type.Light; +import org.bukkit.entity.Player; +import org.bukkit.inventory.meta.BlockDataMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class WorldEditRendererCUIEditor { + + @AllArgsConstructor + public enum Type { + SELECTION("cui_selection_material", "cui_selection_width", Material.PURPLE_CONCRETE, Width.LARGE), + CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_CONCRETE, Width.LARGE), + SELECTION_OTHER("cui_selection_other_material", "cui_selection_other_width", Material.GRAY_CONCRETE, Width.SLIM), + CLIPBOARD_OTHER("cui_clipboard_other_material", "cui_clipboard_other_width", Material.GRAY_CONCRETE, Width.SLIM); + + private final String configMaterial; + private final String configWidth; + private final Material defaultMaterial; + private final Width defaultWidth; + + public Material getMaterial(Player player) { + String material = UserConfig.getConfig(player.getUniqueId(), configMaterial); + if (material == null) { + return defaultMaterial; + } else { + return Material.valueOf(material); + } + } + + public void setMaterial(Player player, Material material) { + UserConfig.updatePlayerConfig(player.getUniqueId(), configMaterial, material.name()); + } + + public Width getWidth(Player player) { + String width = UserConfig.getConfig(player.getUniqueId(), configWidth); + if (width == null) { + return defaultWidth; + } else { + return Width.valueOf(width); + } + } + + public void setWidth(Player player, Width width) { + UserConfig.updatePlayerConfig(player.getUniqueId(), configWidth, width.name()); + } + } + + @AllArgsConstructor + public enum Width { + HUGE(15, "WORLDEDIT_CUI_WIDTH_HUGE", 2/16f), + LARGE(8, "WORLDEDIT_CUI_WIDTH_LARGE", 1/16f), + MEDIUM(4, "WORLDEDIT_CUI_WIDTH_MEDIUM", 1/32f), + SLIM(0, "WORLDEDIT_CUI_WIDTH_SLIM", 1/64f); + + public final int lightLevel; + public final String name; + public final float value; + } + + public WorldEditRendererCUIEditor() { + new Command(); + } + + private static class Command extends SWCommand { + + public Command() { + super("cui"); + } + + @Register + public void cuiEditor(Player player) { + SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE", player)); + setElement(inv, player, 1, "WORLDEDIT_CUI_SELECTION", Type.SELECTION); + setElement(inv, player, 3, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD); + setElement(inv, player, 5, "WORLDEDIT_CUI_SELECTION_OTHER", Type.SELECTION_OTHER); + setElement(inv, player, 7, "WORLDEDIT_CUI_CLIPBOARD_OTHER", Type.CLIPBOARD_OTHER); + inv.open(); + } + + private void setElement(SWInventory inv, Player player, int index, String uiName, Type type) { + Material material = type.getMaterial(player); + Width width = type.getWidth(player); + + inv.setItem(index, new SWItem(material, Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_NAME", player, Core.MESSAGE.parse(uiName, player)), Arrays.asList(Core.MESSAGE.parse("WORLDEDIT_CUI_MATERIAL_CLICK", player)), false, click -> { + cuiMaterial(player, uiName, type, material); + })); + + List lore = new ArrayList<>(); + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_CLICK", player)); + lore.add(""); + for (Width value : Width.values()) { + if (value == width) { + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE_SELECTED", player, Core.MESSAGE.parse(value.name, player))); + } else { + lore.add(Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_LORE", player, Core.MESSAGE.parse(value.name, player))); + } + } + SWItem lightItem = new SWItem(Material.LIGHT, Core.MESSAGE.parse("WORLDEDIT_CUI_WIDTH_NAME", player, Core.MESSAGE.parse(uiName, player)), lore, false, click -> { + type.setWidth(player, Width.values()[(width.ordinal() + 1) % Width.values().length]); + setElement(inv, player, index, uiName, type); + }); + ItemMeta itemMeta = lightItem.getItemMeta(); + Light light = (Light) Material.LIGHT.createBlockData(); + light.setLevel(width.lightLevel); + ((BlockDataMeta) itemMeta).setBlockData(light); + lightItem.setItemMeta(itemMeta); + inv.setItem(index + 9, lightItem); + } + + private final Material[] materials = {Material.WHITE_CONCRETE, Material.LIGHT_GRAY_CONCRETE, Material.GRAY_CONCRETE, Material.BLACK_CONCRETE, Material.BROWN_CONCRETE, Material.RED_CONCRETE, Material.ORANGE_CONCRETE, Material.YELLOW_CONCRETE, Material.LIME_CONCRETE, Material.GREEN_CONCRETE, Material.CYAN_CONCRETE, Material.LIGHT_BLUE_CONCRETE, Material.BLUE_CONCRETE, Material.PURPLE_CONCRETE, Material.MAGENTA_CONCRETE, Material.PINK_CONCRETE, null, Material.BARRIER}; + + private void cuiMaterial(Player player, String subMenu, Type type, Material currentSelection) { + SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("WORLDEDIT_CUI_TITLE_SUBMENU", player, Core.MESSAGE.parse(subMenu, player))); + for (int i = 0; i < materials.length; i++) { + Material material = materials[i]; + if (material == null) continue; + inv.setItem(i, new SWItem(material, "", Collections.emptyList(), material == currentSelection, click -> { + type.setMaterial(player, material); + cuiEditor(player); + })); + } + inv.open(); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java index 7bf68c99..faed64e3 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditRenderer.java @@ -72,7 +72,6 @@ public class WorldEditRenderer implements Listener { Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos); a = new Vector(a.getBlockX(), a.getBlockY(), a.getBlockZ()); b = new Vector(b.getBlockX(), b.getBlockY(), b.getBlockZ()); - WorldEditRendererWrapper.impl.hide(player, player, true, false); drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), true, player); } catch (EmptyClipboardException e) { WorldEditRendererWrapper.impl.hide(player, player, true, true); @@ -85,7 +84,6 @@ public class WorldEditRenderer implements Listener { RegionSelector regionSelector = session.getRegionSelector(world); try { Region region = regionSelector.getRegion(); - WorldEditRendererWrapper.impl.hide(player, player, false, false); drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), false, player); } catch (IncompleteRegionException e) { WorldEditRendererWrapper.impl.hide(player, player, false, true); @@ -114,8 +112,9 @@ public class WorldEditRenderer implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - WorldEditRendererWrapper.impl.tick(event.getPlayer()); - + if(event.getPlayer().getItemInHand().getType() == WAND) { + WorldEditRendererWrapper.impl.tick(event.getPlayer()); + } renderClipboard(event.getPlayer(), we.getSession(event.getPlayer())); }