forked from SteamWar/SteamWar
Merge pull request 'Update WorldEdit CUI to RBlockDisplay' (#34) from WorldEditCUI into main
Reviewed-on: SteamWar/SteamWar#34 Reviewed-by: D4rkr34lm <dark@steamwar.de>
This commit is contained in:
@@ -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 = Own Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD = Own Clipboard
|
||||
WORLDEDIT_CUI_SELECTION_OTHER = Other Selection
|
||||
WORLDEDIT_CUI_CLIPBOARD_OTHER = Other Clipboard
|
||||
|
||||
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 = 1/ 8 Block
|
||||
WORLDEDIT_CUI_WIDTH_LARGE = 1/16 Block
|
||||
WORLDEDIT_CUI_WIDTH_MEDIUM = 1/32 Block
|
||||
WORLDEDIT_CUI_WIDTH_SLIM = 1/64 Block
|
||||
@@ -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.
|
||||
UNNOSCHEMSUBMITTING=§e{0} §7darf nun wieder §e§lSchematis§7 einsenden§8.
|
||||
|
||||
WORLDEDIT_CUI_SELECTION = Eigene Auswahl
|
||||
WORLDEDIT_CUI_CLIPBOARD = Eigene 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
|
||||
@@ -23,7 +23,10 @@ import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.command.*;
|
||||
import de.steamwar.core.authlib.AuthlibInjector;
|
||||
import de.steamwar.core.events.*;
|
||||
import de.steamwar.core.events.AntiNocom;
|
||||
import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.steamwar.core.events.WorldLoadEvent;
|
||||
import de.steamwar.message.Message;
|
||||
import de.steamwar.network.NetworkReceiver;
|
||||
import de.steamwar.network.handlers.ServerDataHandler;
|
||||
@@ -41,7 +44,7 @@ import java.io.InputStreamReader;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Core extends JavaPlugin{
|
||||
public class Core extends JavaPlugin {
|
||||
|
||||
public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader());
|
||||
|
||||
@@ -67,6 +70,8 @@ public class Core extends JavaPlugin{
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new PlayerVersion();
|
||||
|
||||
errorHandler = new ErrorHandler();
|
||||
crashDetector = new CrashDetector();
|
||||
|
||||
@@ -102,7 +107,7 @@ public class Core extends JavaPlugin{
|
||||
if(Core.getVersion() >= 19)
|
||||
new ServerDataHandler();
|
||||
|
||||
if(Core.getVersion() > 8 && Bukkit.getPluginManager().getPlugin("WorldEdit") != null)
|
||||
if(Bukkit.getPluginManager().getPlugin("WorldEdit") != null)
|
||||
new WorldEditRenderer();
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.network.packets.PacketHandler;
|
||||
import de.steamwar.network.packets.server.ClientVersionPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerVersion extends PacketHandler implements Listener {
|
||||
|
||||
private static final Map<UUID, Integer> playerVersions = new HashMap<>();
|
||||
|
||||
public static int getVersion(Player player) {
|
||||
return playerVersions.getOrDefault(player.getUniqueId(), -1);
|
||||
}
|
||||
|
||||
public static boolean isBedrock(Player player) {
|
||||
return player.getName().startsWith(".");
|
||||
}
|
||||
|
||||
public PlayerVersion() {
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
register();
|
||||
}
|
||||
|
||||
@Handler
|
||||
public void handlePacket(ClientVersionPacket clientVersionPacket) {
|
||||
playerVersions.put(clientVersionPacket.getPlayer(), clientVersionPacket.getVersion());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
playerVersions.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,16 @@ public class VersionDependent {
|
||||
}
|
||||
|
||||
public static <T> T getVersionImpl(Plugin plugin, String className){
|
||||
return getVersionImpl(plugin, Core.getVersion(), className);
|
||||
}
|
||||
|
||||
public static <T> T getVersionImpl(Plugin plugin, int fromVersion){
|
||||
return getVersionImpl(plugin, fromVersion, (new Exception()).getStackTrace()[1].getClassName());
|
||||
}
|
||||
|
||||
public static <T> T getVersionImpl(Plugin plugin, int fromVersion, String className){
|
||||
ClassLoader loader = plugin.getClass().getClassLoader();
|
||||
for(int version = Core.getVersion(); version >= 8; version--) {
|
||||
for(int version = fromVersion; version >= 8; version--) {
|
||||
try {
|
||||
return ((Class<? extends T>) Class.forName(className + version, true, loader)).getDeclaredConstructor().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
|
||||
@@ -29,20 +29,15 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
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.player.*;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WorldEditRenderer {
|
||||
|
||||
private static final int VIEW_DISTANCE = 64;
|
||||
private static final int SQ_VIEW_DISTANCE = VIEW_DISTANCE * VIEW_DISTANCE;
|
||||
|
||||
private static final double STEP_SIZE = 0.5;
|
||||
|
||||
private static final Vector ONES = new Vector(1, 1, 1);
|
||||
public class WorldEditRenderer implements Listener {
|
||||
|
||||
private static final Material WAND = FlatteningWrapper.impl.getMaterial("WOOD_AXE");
|
||||
|
||||
@@ -50,77 +45,116 @@ public class WorldEditRenderer {
|
||||
|
||||
public WorldEditRenderer() {
|
||||
we = WorldEditWrapper.getWorldEditPlugin();
|
||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), this::render, 20, 20);
|
||||
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
renderPlayer(player, true);
|
||||
}
|
||||
}, 20, 20);
|
||||
}
|
||||
|
||||
private void render() {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
//noinspection deprecation
|
||||
if(player.getItemInHand().getType() != WAND)
|
||||
continue;
|
||||
private void renderPlayer(Player player, boolean scheduled) {
|
||||
LocalSession session = we.getSession(player);
|
||||
renderClipboard(player, session, scheduled);
|
||||
renderRegion(player, session, scheduled);
|
||||
}
|
||||
|
||||
LocalSession session = we.getSession(player);
|
||||
private void renderClipboard(Player player, LocalSession session, boolean scheduled) {
|
||||
try {
|
||||
Clipboard clipboard = session.getClipboard().getClipboard();
|
||||
Vector pos = player.getLocation().toVector();
|
||||
Region region = clipboard.getRegion();
|
||||
Transform transform = session.getClipboard().getTransform();
|
||||
Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
|
||||
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());
|
||||
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), scheduled, true, player);
|
||||
} catch (EmptyClipboardException e) {
|
||||
WorldEditRendererWrapper.impl.hide(player, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderRegion(Player player, LocalSession session, boolean scheduled) {
|
||||
World world = session.getSelectionWorld();
|
||||
if(world != null) {
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
try {
|
||||
Clipboard clipboard = session.getClipboard().getClipboard();
|
||||
Vector pos = player.getLocation().toVector();
|
||||
Region region = clipboard.getRegion();
|
||||
Transform transform = session.getClipboard().getTransform();
|
||||
Vector a = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMinimum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
|
||||
Vector b = WorldEditWrapper.impl.applyTransform(WorldEditWrapper.impl.getMaximum(region).subtract(WorldEditWrapper.impl.getOrigin(clipboard)), transform).add(pos);
|
||||
drawCuboid(Vector.getMinimum(a, b), Vector.getMaximum(a, b), TrickyParticleWrapper.impl.getVillagerHappy(), player);
|
||||
} catch (EmptyClipboardException e) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
World world = session.getSelectionWorld();
|
||||
if(world != null) {
|
||||
RegionSelector regionSelector = session.getRegionSelector(world);
|
||||
try {
|
||||
Region region = regionSelector.getRegion();
|
||||
drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), Particle.DRAGON_BREATH, player);
|
||||
} catch (IncompleteRegionException e) {
|
||||
//ignore
|
||||
}
|
||||
Region region = regionSelector.getRegion();
|
||||
drawCuboid(WorldEditWrapper.impl.getMinimum(region), WorldEditWrapper.impl.getMaximum(region), scheduled, false, player);
|
||||
} catch (IncompleteRegionException e) {
|
||||
WorldEditRendererWrapper.impl.hide(player, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawCuboid(Vector min, Vector max, Particle particle, Player owner) {
|
||||
max.add(ONES);
|
||||
|
||||
for(double x = min.getBlockX(); x <= max.getBlockX(); x += STEP_SIZE) {
|
||||
draw(x, min.getBlockY(), min.getBlockZ(), particle, owner);
|
||||
draw(x, min.getBlockY(), max.getBlockZ(), particle, owner);
|
||||
draw(x, max.getBlockY(), min.getBlockZ(), particle, owner);
|
||||
draw(x, max.getBlockY(), max.getBlockZ(), particle, owner);
|
||||
}
|
||||
|
||||
for(double y = min.getBlockY() + STEP_SIZE; y <= max.getBlockY() - STEP_SIZE; y += STEP_SIZE) {
|
||||
draw(min.getBlockX(), y, min.getBlockZ(), particle, owner);
|
||||
draw(min.getBlockX(), y, max.getBlockZ(), particle, owner);
|
||||
draw(max.getBlockX(), y, min.getBlockZ(), particle, owner);
|
||||
draw(max.getBlockX(), y, max.getBlockZ(), particle, owner);
|
||||
}
|
||||
|
||||
for(double z = min.getBlockZ() + STEP_SIZE; z <= max.getBlockZ() - STEP_SIZE; z += STEP_SIZE) {
|
||||
draw(min.getBlockX(), min.getBlockY(), z, particle, owner);
|
||||
draw(min.getBlockX(), max.getBlockY(), z, particle, owner);
|
||||
draw(max.getBlockX(), min.getBlockY(), z, particle, owner);
|
||||
draw(max.getBlockX(), max.getBlockY(), z, particle, owner);
|
||||
private void drawCuboid(Vector min, Vector max, boolean scheduled, boolean clipboard, Player owner) {
|
||||
//noinspection deprecation
|
||||
if(owner.getItemInHand().getType() != WAND) {
|
||||
WorldEditRendererWrapper.impl.hide(owner, true, true);
|
||||
WorldEditRendererWrapper.impl.hide(owner, false, true);
|
||||
} else {
|
||||
WorldEditRendererWrapper.impl.hide(owner, true, false);
|
||||
WorldEditRendererWrapper.impl.hide(owner, false, false);
|
||||
WorldEditRendererWrapper.safeDraw(owner, scheduled, clipboard, min, max);
|
||||
}
|
||||
}
|
||||
|
||||
private void draw(double x, double y, double z, Particle particle, Player owner) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
Location location = player.getLocation();
|
||||
double dx = x - location.getX();
|
||||
double dy = y - location.getY();
|
||||
double dz = z - location.getZ();
|
||||
if(dx*dx + dy*dy + dz*dz > SQ_VIEW_DISTANCE)
|
||||
continue;
|
||||
|
||||
player.spawnParticle(player == owner ? particle : Particle.TOWN_AURA, x, y, z, 1, 0.0, 0.0, 0.0, 0.0);
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(event.getPlayer().getItemInHand().getType() == WAND) {
|
||||
WorldEditRendererWrapper.impl.tick(event.getPlayer());
|
||||
}
|
||||
renderClipboard(event.getPlayer(), we.getSession(event.getPlayer()), false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
renderRegion(event.getPlayer(), we.getSession(event.getPlayer()), false);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
renderRegion(event.getPlayer(), we.getSession(event.getPlayer()), false);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if (event.getMessage().startsWith("//")) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
LocalSession session = we.getSession(event.getPlayer());
|
||||
renderRegion(event.getPlayer(), session, false);
|
||||
renderClipboard(event.getPlayer(), session, false);
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
renderPlayer(event.getPlayer(), false);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
renderPlayer(event.getPlayer(), false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
renderPlayer(event.getPlayer(), false);
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
WorldEditRendererWrapper.impl.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
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.MEDIUM),
|
||||
CLIPBOARD("cui_clipboard_material", "cui_clipboard_width", Material.LIME_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() {
|
||||
if (Core.getVersion() >= 20) {
|
||||
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, 3, "WORLDEDIT_CUI_SELECTION", Type.SELECTION);
|
||||
setElement(inv, player, 5, "WORLDEDIT_CUI_CLIPBOARD", Type.CLIPBOARD);
|
||||
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<String> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public interface WorldEditRendererWrapper {
|
||||
WorldEditRendererWrapper fallback = VersionDependent.getVersionImpl(Core.getInstance(), 9);
|
||||
WorldEditRendererWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||
|
||||
static void safeDraw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2) {
|
||||
if (PlayerVersion.isBedrock(player) || PlayerVersion.getVersion(player) < 20) {
|
||||
fallback.draw(player, scheduled, clipboard, pos1, pos2);
|
||||
} else {
|
||||
impl.draw(player, scheduled, clipboard, pos1, pos2);
|
||||
}
|
||||
}
|
||||
|
||||
void draw(Player player, boolean scheduled, boolean clipboard, Vector pos1, Vector pos2);
|
||||
|
||||
void tick(Player player);
|
||||
|
||||
void hide(Player player, boolean clipboard, boolean hide);
|
||||
|
||||
void remove(Player player);
|
||||
}
|
||||
Reference in New Issue
Block a user