From 1b3da6004cc0e2994de645fd1c8c2bcfe0136ed5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 24 Aug 2021 14:36:57 +0200 Subject: [PATCH 1/7] Warp Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 13 +- .../bausystem/features/warp/Moon.java | 59 ++++++ .../bausystem/features/warp/Warp.java | 155 +++++++++++++++ .../bausystem/features/warp/WarpCommand.java | 178 ++++++++++++++++++ .../bausystem/features/warp/WarpGui.java | 96 ++++++++++ .../bausystem/worlddata/WorldData.java | 7 +- 6 files changed, 504 insertions(+), 4 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/warp/Moon.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index fcf18e04..302865d8 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -499,12 +499,19 @@ REGION_TNT_BUILD=§cEine Explosion hätte Blöcke im Baubereich zerstört # Unsign Book UNSIGN_HELP_1=§8/§eunsign §8- §7Mache ein Buch beschreibbar - # Team LOCK_SCHEM_NO_USER=§7Dieser Spieler existiert nicht! LOCK_SCHEM_NO_SCHEM=§7Dieser Spieler besitzt keine Schematic mit diesem Namen! LOCK_SCHEM_LOCKED=§e{0} §7von §e{1} §7wurde von §e{2} §7auf §eNORMAL §7zurück gesetz. §f§lGrund: §f{3} LOCK_SCHEM_HELP=§8/§eschemlock §8[§7Owner§8] [§7Schematic§8] [§7Grund§8] - §7Sperre eine Schematic - AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. -AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt \ No newline at end of file +AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt +WARP_EXISTS=§7Der Warp mit dem namen §e{0} §7existiert bereits +WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen +WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt +WARP_DELETED=§e{0} §7wurde gelöcht +WARP_GUI_NO=§cHier giebt es noch keine Warps +WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke +WARP_INFO_NAME=§7Name: §e{0} +WARP_INFO_CREATOR=§7Ersteller: §e{0} +WARP_INFO_CREATED=§7Erstellt am: §e{0} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Moon.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Moon.java new file mode 100644 index 00000000..02ed15e0 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Moon.java @@ -0,0 +1,59 @@ +/* + * 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.BauSystem; +import de.steamwar.inventory.SWItem; +import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; + +import java.util.concurrent.atomic.AtomicInteger; + +@UtilityClass +public class Moon { + + public static void startMoon(Player player) { + player.getInventory().setHelmet(new SWItem(Material.GLASS, "§3Atemkugel").getItemStack()); + AtomicInteger countDown = new AtomicInteger(5); + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> { + if (countDown.get() == 0) { + AtomicInteger iter = new AtomicInteger(1000); + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask1 -> { + if (player.getLocation().getY() > 300 || iter.getAndDecrement() <= 0) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 60 * 5 * 20, 1, false, false)); + bukkitTask1.cancel(); + } else { + player.setVelocity(player.getVelocity().add(new Vector(0, 0.2, 0))); + player.getWorld().spawnParticle(Particle.FLAME, player.getLocation(), 5); + } + }, 0, 1); + bukkitTask.cancel(); + } else { + player.sendMessage("§7Noch §e§l" + countDown.getAndDecrement() + " §7Sekunden!"); + } + }, 0, 20); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java new file mode 100644 index 00000000..0458670d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java @@ -0,0 +1,155 @@ +/* + * 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.worlddata.WorldData; +import lombok.Getter; +import org.bukkit.*; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; + +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +@Getter +public class Warp { + + private final Instant created; + private final YAPIONObject object; + private String name; + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + private Material mat; + private String creator; + + private Warp(YAPIONObject object) { + this.object = object; + name = object.getPlainValue("name"); + x = object.getPlainValue("x"); + y = object.getPlainValue("y"); + z = object.getPlainValue("z"); + yaw = object.getPlainValue("yaw"); + pitch = object.getPlainValue("pitch"); + mat = Material.getMaterial(object.getPlainValue("material")); + creator = object.getPlainValue("owner"); + created = Instant.ofEpochSecond(object.getPlainValue("time")); + } + + private Warp() { + object = new YAPIONObject(); + object.add("time", Instant.now().getEpochSecond()); + created = Instant.ofEpochSecond(object.getPlainValue("time")); + } + + public static List getWarps() { + List warpList = new ArrayList<>(); + YAPIONArray warpsObject = WorldData.getWarpData(); + warpsObject.forEach(yapionAnyType -> warpList.add(new Warp((YAPIONObject) yapionAnyType))); + return warpList; + } + + public static Optional getWarp(String name) { + YAPIONArray warpsObject = WorldData.getWarpData(); + return warpsObject.stream().filter(yapionAnyType -> name.equals(((YAPIONObject) yapionAnyType).getPlainValueOrDefault("name", null))).map(yapionAnyType -> new Warp((YAPIONObject) yapionAnyType)).findAny(); + } + + public static Warp createWarp(String name, double x, double y, double z, float yaw, float pitch, Material mat, String creator) { + Warp warp = new Warp(); + warp.setName(name); + warp.setX(x); + warp.setY(y); + warp.setZ(z); + warp.setYaw(yaw); + warp.setPitch(pitch); + warp.setMat(mat); + warp.setCreator(creator); + YAPIONArray warpsObject = WorldData.getWarpData(); + warpsObject.add(warp.object); + + return warp; + } + + public static Warp createWarp(String name, Player player, Material mat) { + Location loc = player.getLocation(); + return createWarp(name, loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), mat, player.getName()); + } + + public void setName(String name) { + this.name = name; + object.add("name", name); + } + + public void setX(double x) { + this.x = x; + object.add("x", x); + } + + public void setY(double y) { + this.y = y; + object.add("y", y); + } + + public void setZ(double z) { + this.z = z; + object.add("z", z); + } + + public void setYaw(float yaw) { + this.yaw = yaw; + object.add("yaw", yaw); + } + + public void setPitch(float pitch) { + this.pitch = pitch; + object.add("pitch", pitch); + } + + public void setMat(Material mat) { + this.mat = mat; + object.add("material", mat.name()); + } + + public void setCreator(String creator) { + this.creator = creator; + object.add("owner", creator); + } + + public void delete() { + YAPIONArray warpsObject = WorldData.getWarpData(); + warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name)); + } + + public Location toLocation() { + return new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); + } + + public void teleport(Player player) { + Location loc = toLocation(); + player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); + player.playSound(loc, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java new file mode 100644 index 00000000..7de20794 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -0,0 +1,178 @@ +/* + * 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.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.sql.Timestamp; +import java.util.List; +import java.util.stream.Collectors; + +@Linked(LinkageType.COMMAND) +public class WarpCommand extends SWCommand { + + private static final String[] FORBIDDEN_NAMES = new String[]{ + "add", "create", "delete", "list", "info", "gui" + }; + + protected WarpCommand() { + super("warp"); + } + + @ClassMapper(Warp.class) + public static TypeMapper getWarpMapper() { + return SWCommandUtils.createMapper(s -> Warp.getWarp(s).orElse(null), (commandSender, s) -> { + return Warp.getWarps().stream().map(Warp::getName).collect(Collectors.toList()); + }); + } + + @Register(help = true) + public void genericHelp(Player player, String... args) { + if (args.length > 0 && args[0].equals("moon")) { + Moon.startMoon(player); + return; + } + BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "Warp"); + } + + @Register("add") + @Register("create") + public void addWarp(Player player, String name) { + if (!permissionCheck(player)) return; + for (String forbiddenName : FORBIDDEN_NAMES) { + if (name.equalsIgnoreCase(forbiddenName)) { + BauSystem.MESSAGE.send("WARP_NAME_RESERVED", player, name); + return; + } + } + if (Warp.getWarp(name).isPresent()) { + BauSystem.MESSAGE.send("WARP_EXISTS", player, name); + return; + } + Warp.createWarp(name, player, Material.BEACON); + BauSystem.MESSAGE.send("WARP_CREATED", player, name); + } + + @Register + public void tpWarp(Player player, Warp warp) { + warp.teleport(player); + } + + @Register("delete") + public void deleteWarp(Player player, Warp warp) { + if (permissionCheck(player)) return; + warp.delete(); + BauSystem.MESSAGE.send("WARP_DELETED", player, warp.getName()); + } + + @Register("gui") + public void gui(Player player) { + WarpGui.openGui(player); + } + + @Register("list") + public void listWarps(Player player) { + listWarps(player, 0); + } + + @Register("list") + public void listWarps(Player player, int page) { + List warps = Warp.getWarps(); + int pageCount = (int) Math.ceil(warps.size() / 18d); + for (int i = page * 18; i < warps.size() && i < (page + 1) * 18; i++) { + Warp warp = warps.get(i); + TextComponent component = new TextComponent(); + component.setText(warp.getName()); + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName())); + component.setColor(ChatColor.YELLOW); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zu §e" + warp.getName() + " §7teleportieren"))); + player.spigot().sendMessage(component); + } + + TextComponent beforePage = new TextComponent("««"); + if (page > 0) { + beforePage.setColor(ChatColor.YELLOW); + beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create())); + beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page - 1))); + } else { + beforePage.setColor(ChatColor.RED); + } + + TextComponent nextPage = new TextComponent(" Seite (" + (page + 1) + "/" + Math.max(pageCount, 1) + ") »»"); + if (page < pageCount - 1) { + nextPage.setColor(ChatColor.YELLOW); + nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create())); + nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page + 1))); + } else { + nextPage.setColor(ChatColor.RED); + } + + beforePage.addExtra(nextPage); + player.spigot().sendMessage(beforePage); + } + + @Register("info") + public void warpInfo(Player player, Warp warp) { + BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); + BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); + BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATOR", player, warp.getCreator()); + BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATED", player, Timestamp.from(warp.getCreated()).toLocalDateTime()); + player.sendMessage("§7X: §e" + warp.getX()); + player.sendMessage("§7Y: §e" + warp.getY()); + player.sendMessage("§7Z: §e" + warp.getZ()); + BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.toLocation().distance(player.getLocation())); + } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + private boolean permissionCheck(Player player) { + if (!Permission.hasPermission(player, Permission.WORLD)) { + player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Du darfst hier nicht den Warp verändern"); + return false; + } + return true; + } + + @Linked(LinkageType.COMMAND) + public static class WarpsLink extends SWCommand { + + protected WarpsLink() { + super("warps"); + } + + @Register(help = true) + public void genericCommand(Player player, String... args) { + player.performCommand("warp list " + String.join(" ", args)); + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java new file mode 100644 index 00000000..b1c7fc47 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java @@ -0,0 +1,96 @@ +/* + * 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.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class WarpGui { + + public static void openGui(Player player) { + List> entries = new ArrayList<>(); + Warp.getWarps().forEach(warp -> entries.add(new SWListInv.SWListEntry<>(new SWItem( + warp.getMat(), + "§e" + warp.getName(), + Arrays.asList("§7X: §e" + (int) warp.getX(), + "§7Y: §e" + (int) warp.getY(), + "§7Z: §e" + (int) warp.getZ(), + BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.toLocation().distance(player.getLocation()))), + false, + clickType -> { + } + ), warp))); + + SWListInv inv = new SWListInv<>(player, "Warps", false, entries, (clickType, warp) -> { + if (clickType.isRightClick() && Permission.hasPermission(player, Permission.WORLD)) { + openWarpGui(player, warp); + } else { + warp.teleport(player); + } + }); + + if (entries.isEmpty()) { + inv.setItem(22, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("WARP_GUI_NO", player), clickType -> { + })); + } + + inv.open(); + } + + public static void openWarpGui(Player player, Warp warp) { + SWInventory inv = new SWInventory(player, 9, warp.getName()); + inv.setItem(0, new SWItem(Material.ENDER_PEARL, "§7Zu §e" + warp.getName() + " §7teleportieren", clickType -> { + player.closeInventory(); + warp.teleport(player); + })); + + inv.setItem(2, new SWItem(warp.getMat(), "§e" + warp.getMat().name(), clickType -> changeMaterial(player, warp))); + + inv.setItem(8, new SWItem(Material.BARRIER, "§e" + warp.getName() + " §7löschen", clickType -> { + player.closeInventory(); + warp.delete(); + })); + + inv.open(); + } + + public static void changeMaterial(Player player, Warp warp) { + List> materials = new ArrayList<>(); + for (Material value : Material.values()) { + if (value.isLegacy() || value.isAir()) continue; + materials.add(new SWListInv.SWListEntry<>(new SWItem(value, "§e" + value.name()), value)); + } + + SWListInv inv = new SWListInv<>(player, "Material auswählen", materials, (clickType, material) -> { + player.closeInventory(); + warp.setMat(material); + }); + inv.open(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java index f5eab71f..62f54e8f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.worlddata; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import yapion.hierarchy.output.FileOutput; +import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.parser.YAPIONParser; @@ -33,7 +34,7 @@ import java.io.IOException; @UtilityClass public class WorldData { - private File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); + private final File optionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "options.yapion"); private YAPIONObject worldData; public YAPIONObject getWorldData() { @@ -47,6 +48,10 @@ public class WorldData { return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject()); } + public YAPIONArray getWarpData() { + return getWorldData().getYAPIONArrayOrSetDefault("warps", new YAPIONArray()); + } + private void read() { worldData = new YAPIONObject(); if (optionsFile.length() != 0) { From e1bf93ab3a7491361192e2244791bd1905c6d7ed Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 24 Aug 2021 17:28:51 +0200 Subject: [PATCH 2/7] Add Help Signed-off-by: Chaoscaot --- BauSystem_Main/src/BauSystem.properties | 10 ++++++++-- .../steamwar/bausystem/features/warp/WarpCommand.java | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 302865d8..31feca0d 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -496,7 +496,6 @@ REGION_TNT_ON=§aTNT-Schaden aktiviert REGION_TNT_OFF=§cTNT-Schaden deaktiviert REGION_TNT_TB=§aTNT-Schaden außerhalb Baurahmen aktiviert REGION_TNT_BUILD=§cEine Explosion hätte Blöcke im Baubereich zerstört - # Unsign Book UNSIGN_HELP_1=§8/§eunsign §8- §7Mache ein Buch beschreibbar # Team @@ -506,6 +505,7 @@ LOCK_SCHEM_LOCKED=§e{0} §7von §e{1} §7wurde von §e{2} §7auf §eNORMAL §7z LOCK_SCHEM_HELP=§8/§eschemlock §8[§7Owner§8] [§7Schematic§8] [§7Grund§8] - §7Sperre eine Schematic AFK_KICK_MESSAGE=§cAuf diesem Server ist seit 5 Minuten nichts passiert. AFK_WARNING_MESSAGE=§cDieser Server wird bei weiterer Inaktivität in einer Minute gestoppt +# Warp WARP_EXISTS=§7Der Warp mit dem namen §e{0} §7existiert bereits WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt @@ -514,4 +514,10 @@ WARP_GUI_NO=§cHier giebt es noch keine Warps WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke WARP_INFO_NAME=§7Name: §e{0} WARP_INFO_CREATOR=§7Ersteller: §e{0} -WARP_INFO_CREATED=§7Erstellt am: §e{0} \ No newline at end of file +WARP_INFO_CREATED=§7Erstellt am: §e{0} +WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt +WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt +WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt +WARP_HELP_4=§8/§ewarp delete §8[§7Name§8] - §7Lösche einen Warp +WARP_HELP_5=§8/§ewarp gui - §7Öffne die Warp-GUI +WARP_HELP_6=§8/§ewarp list - §7Liste alle Warp-Punkt auf 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 7de20794..8f6aa0d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -64,6 +64,12 @@ public class WarpCommand extends SWCommand { return; } BauSystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "Warp"); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_1", player); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_2", player); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_3", player); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_4", player); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_5", player); + BauSystem.MESSAGE.sendPrefixless("WARP_HELP_6", player); } @Register("add") From 8b3b2f9ddba53569a0976b01c7d37f891ae22feb Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 11 Nov 2021 22:01:08 +0100 Subject: [PATCH 3/7] Update Warp --- .../bausystem/features/warp/Warp.java | 98 ++++++++++--------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java index 0458670d..9b5bb818 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java @@ -31,6 +31,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.UUID; @Getter public class Warp { @@ -38,22 +39,19 @@ public class Warp { private final Instant created; private final YAPIONObject object; private String name; - private double x; - private double y; - private double z; - private float yaw; - private float pitch; + private Location location; private Material mat; private String creator; private Warp(YAPIONObject object) { this.object = object; name = object.getPlainValue("name"); - x = object.getPlainValue("x"); - y = object.getPlainValue("y"); - z = object.getPlainValue("z"); - yaw = object.getPlainValue("yaw"); - pitch = object.getPlainValue("pitch"); + double x = object.getPlainValue("x"); + double y = object.getPlainValue("y"); + double z = object.getPlainValue("z"); + float yaw = object.getPlainValue("yaw"); + float pitch = object.getPlainValue("pitch"); + location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); mat = Material.getMaterial(object.getPlainValue("material")); creator = object.getPlainValue("owner"); created = Instant.ofEpochSecond(object.getPlainValue("time")); @@ -80,11 +78,7 @@ public class Warp { public static Warp createWarp(String name, double x, double y, double z, float yaw, float pitch, Material mat, String creator) { Warp warp = new Warp(); warp.setName(name); - warp.setX(x); - warp.setY(y); - warp.setZ(z); - warp.setYaw(yaw); - warp.setPitch(pitch); + warp.setLocation(new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch)); warp.setMat(mat); warp.setCreator(creator); YAPIONArray warpsObject = WorldData.getWarpData(); @@ -103,31 +97,6 @@ public class Warp { object.add("name", name); } - public void setX(double x) { - this.x = x; - object.add("x", x); - } - - public void setY(double y) { - this.y = y; - object.add("y", y); - } - - public void setZ(double z) { - this.z = z; - object.add("z", z); - } - - public void setYaw(float yaw) { - this.yaw = yaw; - object.add("yaw", yaw); - } - - public void setPitch(float pitch) { - this.pitch = pitch; - object.add("pitch", pitch); - } - public void setMat(Material mat) { this.mat = mat; object.add("material", mat.name()); @@ -138,18 +107,55 @@ public class Warp { object.add("owner", creator); } + public void setLocation(Location location) { + this.location = location; + } + public void delete() { YAPIONArray warpsObject = WorldData.getWarpData(); warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name)); } - public Location toLocation() { - return new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); + public void teleport(Player player) { + player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); + player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); } - public void teleport(Player player) { - Location loc = toLocation(); - player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); - player.playSound(loc, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); + public void normalize(String str) { + /* + x > x + y > y + z > z + w > yaw + p > pitch + */ + if(str.contains("x")) { + location.setX(0.5 + location.getBlockX()); + } + if(str.contains("y")) { + location.setY(location.getBlockY()); + } + if(str.contains("z")) { + location.setZ(0.5 + location.getBlockZ()); + } + if(str.contains("w")) { + location.setYaw(Location.normalizeYaw(location.getYaw())); + } + if(str.contains("p")) { + location.setPitch(Location.normalizePitch(location.getPitch())); + } + save(); + } + + private void save() { + object.add("name", name); + YAPIONObject loc = new YAPIONObject(); + loc.add("x", location.getX()); + loc.add("y", location.getY()); + loc.add("z", location.getZ()); + loc.add("yaw", location.getYaw()); + loc.add("pitch", location.getPitch()); + object.add("location", loc); + object.add("creator", creator); } } From 02c634fb00d9ebf56613dd7c6909bb4dc1ebe33f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 11 Nov 2021 22:14:11 +0100 Subject: [PATCH 4/7] Update Warp and WarpCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - .../steamwar/bausystem/features/warp/Warp.java | 18 +----------------- .../bausystem/features/warp/WarpCommand.java | 9 ++++----- .../bausystem/features/warp/WarpGui.java | 8 ++++---- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4458cbf0..86bc6032 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -555,7 +555,6 @@ WARP_GUI_NO=§cHier giebt es noch keine Warps WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke WARP_INFO_NAME=§7Name: §e{0} WARP_INFO_CREATOR=§7Ersteller: §e{0} -WARP_INFO_CREATED=§7Erstellt am: §e{0} WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java index 9b5bb818..3cbc8737 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java @@ -33,10 +33,10 @@ import java.util.List; import java.util.Optional; import java.util.UUID; +// TODO: Rewrite! @Getter public class Warp { - private final Instant created; private final YAPIONObject object; private String name; private Location location; @@ -54,13 +54,10 @@ public class Warp { location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); mat = Material.getMaterial(object.getPlainValue("material")); creator = object.getPlainValue("owner"); - created = Instant.ofEpochSecond(object.getPlainValue("time")); } private Warp() { object = new YAPIONObject(); - object.add("time", Instant.now().getEpochSecond()); - created = Instant.ofEpochSecond(object.getPlainValue("time")); } public static List getWarps() { @@ -144,18 +141,5 @@ public class Warp { if(str.contains("p")) { location.setPitch(Location.normalizePitch(location.getPitch())); } - save(); - } - - private void save() { - object.add("name", name); - YAPIONObject loc = new YAPIONObject(); - loc.add("x", location.getX()); - loc.add("y", location.getY()); - loc.add("z", location.getZ()); - loc.add("yaw", location.getYaw()); - loc.add("pitch", location.getPitch()); - object.add("location", loc); - object.add("creator", creator); } } 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 8f6aa0d2..8a7e4e27 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -153,11 +153,10 @@ public class WarpCommand extends SWCommand { BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATOR", player, warp.getCreator()); - BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATED", player, Timestamp.from(warp.getCreated()).toLocalDateTime()); - player.sendMessage("§7X: §e" + warp.getX()); - player.sendMessage("§7Y: §e" + warp.getY()); - player.sendMessage("§7Z: §e" + warp.getZ()); - BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.toLocation().distance(player.getLocation())); + player.sendMessage("§7X: §e" + warp.getLocation().getX()); + player.sendMessage("§7Y: §e" + warp.getLocation().getY()); + player.sendMessage("§7Z: §e" + warp.getLocation().getZ()); + BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation())); } @SuppressWarnings("BooleanMethodIsAlwaysInverted") diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java index b1c7fc47..b8bc50f0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java @@ -38,10 +38,10 @@ public class WarpGui { Warp.getWarps().forEach(warp -> entries.add(new SWListInv.SWListEntry<>(new SWItem( warp.getMat(), "§e" + warp.getName(), - Arrays.asList("§7X: §e" + (int) warp.getX(), - "§7Y: §e" + (int) warp.getY(), - "§7Z: §e" + (int) warp.getZ(), - BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.toLocation().distance(player.getLocation()))), + Arrays.asList("§7X: §e" + (int) warp.getLocation().getX(), + "§7Y: §e" + (int) warp.getLocation().getY(), + "§7Z: §e" + (int) warp.getLocation().getZ(), + BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.getLocation().distance(player.getLocation()))), false, clickType -> { } From 8535213deb40caae0b9f40020c524c95699371c6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 Nov 2021 11:35:04 +0100 Subject: [PATCH 5/7] Update every message stuff Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 11 +++++++++++ .../bausystem/features/warp/WarpCommand.java | 18 ++++++++---------- .../bausystem/features/warp/WarpGui.java | 15 ++++++++------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 86bc6032..d889d762 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -547,12 +547,23 @@ PANZERN_PROGRESS = §e{0} §7Blöcke übrig, §e{1} §7Blöcke pro Sekunde, §e{ PANZERN_DONE = §aZuende gepanzert # Warp +WARP_DISALLOWED = §cDu darfst hier nicht das Warp System nutzen +WARP_LOC_X = §7X§8: §e{0} +WARP_LOC_Y = §7Y§8: §e{0} +WARP_LOC_Z = §7Z§8: §e{0} WARP_EXISTS=§7Der Warp mit dem namen §e{0} §7existiert bereits WARP_NAME_RESERVED=§7Du kannst nicht §c{0} §7als name für einen Warp nutzen WARP_CREATED=§7Der Warp §e{0} §7wurde erstellt +WARP_DELETE_HOVER=§e{0} §7löschen WARP_DELETED=§e{0} §7wurde gelöcht +WARP_TELEPORT_HOVER=§7Zu §e{0} §7teleportieren +WARP_MATERIAL_CHOOSE=Material auswählen +WARP_GUI_NAME=Warps WARP_GUI_NO=§cHier giebt es noch keine Warps WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke +WARP_LIST_PREVIOUS_PAGE=§eVorherige Seite +WARP_LIST_PAGE=§e Seite ({0}/{1}) »» +WARP_LIST_NEXT_PAGE=§eNächste Seite WARP_INFO_NAME=§7Name: §e{0} WARP_INFO_CREATOR=§7Ersteller: §e{0} WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt 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 8a7e4e27..467add09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -21,7 +21,6 @@ package de.steamwar.bausystem.features.warp; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; @@ -35,7 +34,6 @@ import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Material; import org.bukkit.entity.Player; -import java.sql.Timestamp; import java.util.List; import java.util.stream.Collectors; @@ -122,23 +120,23 @@ public class WarpCommand extends SWCommand { component.setText(warp.getName()); component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName())); component.setColor(ChatColor.YELLOW); - component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§7Zu §e" + warp.getName() + " §7teleportieren"))); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("WARP_TELEPORT_HOVER", player, warp.getName())))); player.spigot().sendMessage(component); } TextComponent beforePage = new TextComponent("««"); if (page > 0) { beforePage.setColor(ChatColor.YELLOW); - beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eVorherige Seite").create())); + beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("WARP_LIST_PREVIOUS_PAGE", player)).create())); beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page - 1))); } else { beforePage.setColor(ChatColor.RED); } - TextComponent nextPage = new TextComponent(" Seite (" + (page + 1) + "/" + Math.max(pageCount, 1) + ") »»"); + TextComponent nextPage = new TextComponent(BauSystem.MESSAGE.parse("WARP_LIST_PAGE", player, page + 1, Math.max(pageCount, 1))); if (page < pageCount - 1) { nextPage.setColor(ChatColor.YELLOW); - nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eNächste Seite").create())); + nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("WARP_LIST_NEXT_PAGE", player)).create())); nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page + 1))); } else { nextPage.setColor(ChatColor.RED); @@ -153,16 +151,16 @@ public class WarpCommand extends SWCommand { BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATOR", player, warp.getCreator()); - player.sendMessage("§7X: §e" + warp.getLocation().getX()); - player.sendMessage("§7Y: §e" + warp.getLocation().getY()); - player.sendMessage("§7Z: §e" + warp.getLocation().getZ()); + BauSystem.MESSAGE.sendPrefixless("WARP_LOC_X", player, warp.getLocation().getX()); + BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Y", player, warp.getLocation().getY()); + BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Z", player, warp.getLocation().getZ()); BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation())); } @SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean permissionCheck(Player player) { if (!Permission.hasPermission(player, Permission.WORLD)) { - player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Du darfst hier nicht den Warp verändern"); + BauSystem.MESSAGE.send("WARP_DISALLOWED", player); return false; } return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java index b8bc50f0..e143acbe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java @@ -38,16 +38,17 @@ public class WarpGui { Warp.getWarps().forEach(warp -> entries.add(new SWListInv.SWListEntry<>(new SWItem( warp.getMat(), "§e" + warp.getName(), - Arrays.asList("§7X: §e" + (int) warp.getLocation().getX(), - "§7Y: §e" + (int) warp.getLocation().getY(), - "§7Z: §e" + (int) warp.getLocation().getZ(), + Arrays.asList( + BauSystem.MESSAGE.parse("WARP_LOC_X", player, (int) warp.getLocation().getX()), + BauSystem.MESSAGE.parse("WARP_LOC_Y", player, (int) warp.getLocation().getY()), + BauSystem.MESSAGE.parse("WARP_LOC_Z", player, (int) warp.getLocation().getZ()), BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.getLocation().distance(player.getLocation()))), false, clickType -> { } ), warp))); - SWListInv inv = new SWListInv<>(player, "Warps", false, entries, (clickType, warp) -> { + SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("WARP_GUI_NAME", player), false, entries, (clickType, warp) -> { if (clickType.isRightClick() && Permission.hasPermission(player, Permission.WORLD)) { openWarpGui(player, warp); } else { @@ -65,14 +66,14 @@ public class WarpGui { public static void openWarpGui(Player player, Warp warp) { SWInventory inv = new SWInventory(player, 9, warp.getName()); - inv.setItem(0, new SWItem(Material.ENDER_PEARL, "§7Zu §e" + warp.getName() + " §7teleportieren", clickType -> { + inv.setItem(0, new SWItem(Material.ENDER_PEARL, BauSystem.MESSAGE.parse("WARP_TELEPORT_HOVER", player, warp.getName()), clickType -> { player.closeInventory(); warp.teleport(player); })); inv.setItem(2, new SWItem(warp.getMat(), "§e" + warp.getMat().name(), clickType -> changeMaterial(player, warp))); - inv.setItem(8, new SWItem(Material.BARRIER, "§e" + warp.getName() + " §7löschen", clickType -> { + inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("WARP_DELETE_HOVER", player, warp.getName()), clickType -> { player.closeInventory(); warp.delete(); })); @@ -87,7 +88,7 @@ public class WarpGui { materials.add(new SWListInv.SWListEntry<>(new SWItem(value, "§e" + value.name()), value)); } - SWListInv inv = new SWListInv<>(player, "Material auswählen", materials, (clickType, material) -> { + SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("WARP_MATERIAL_CHOOSE", player), materials, (clickType, material) -> { player.closeInventory(); warp.setMat(material); }); From ce532fbb6ddbc6b623846ebc1c86033213387b92 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 Nov 2021 17:36:00 +0100 Subject: [PATCH 6/7] Update Warp and WarpCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - .../bausystem/features/warp/Warp.java | 107 +++++------------- .../bausystem/features/warp/WarpCommand.java | 34 ++++-- .../bausystem/linkage/LinkageType.java | 4 +- .../bausystem/worlddata/WorldData.java | 4 +- 5 files changed, 62 insertions(+), 88 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index d889d762..3fa20bd1 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -565,7 +565,6 @@ WARP_LIST_PREVIOUS_PAGE=§eVorherige Seite WARP_LIST_PAGE=§e Seite ({0}/{1}) »» WARP_LIST_NEXT_PAGE=§eNächste Seite WARP_INFO_NAME=§7Name: §e{0} -WARP_INFO_CREATOR=§7Ersteller: §e{0} WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt WARP_HELP_3=§8/§ewarp info §8[§7Name§8] - §7Infos zu einem Punkt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java index 3cbc8737..c163c03a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/Warp.java @@ -24,28 +24,29 @@ import lombok.Getter; import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent; -import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; // TODO: Rewrite! @Getter public class Warp { - private final YAPIONObject object; + private static Map warpMap = new HashMap<>(); + private String name; private Location location; private Material mat; - private String creator; - private Warp(YAPIONObject object) { - this.object = object; - name = object.getPlainValue("name"); + public Warp(String name, Player player) { + this.name = name; + this.location = player.getLocation(); + this.mat = Material.COMPASS; + warpMap.put(name, this); + } + + public Warp(String name, YAPIONObject object) { + this.name = name; double x = object.getPlainValue("x"); double y = object.getPlainValue("y"); double z = object.getPlainValue("z"); @@ -53,55 +54,34 @@ public class Warp { float pitch = object.getPlainValue("pitch"); location = new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch); mat = Material.getMaterial(object.getPlainValue("material")); - creator = object.getPlainValue("owner"); + warpMap.put(name, this); } - private Warp() { - object = new YAPIONObject(); + public YAPIONObject output() { + YAPIONObject yapionObject = new YAPIONObject(); + yapionObject.add("x", location.getX()); + yapionObject.add("y", location.getY()); + yapionObject.add("z", location.getZ()); + yapionObject.add("yaw", location.getYaw()); + yapionObject.add("pitch", location.getPitch()); + yapionObject.add("material", mat.toString()); + return yapionObject; + } + + public static Set getWarpNames() { + return warpMap.keySet(); } public static List getWarps() { - List warpList = new ArrayList<>(); - YAPIONArray warpsObject = WorldData.getWarpData(); - warpsObject.forEach(yapionAnyType -> warpList.add(new Warp((YAPIONObject) yapionAnyType))); - return warpList; + return new ArrayList<>(warpMap.values()); } - public static Optional getWarp(String name) { - YAPIONArray warpsObject = WorldData.getWarpData(); - return warpsObject.stream().filter(yapionAnyType -> name.equals(((YAPIONObject) yapionAnyType).getPlainValueOrDefault("name", null))).map(yapionAnyType -> new Warp((YAPIONObject) yapionAnyType)).findAny(); - } - - public static Warp createWarp(String name, double x, double y, double z, float yaw, float pitch, Material mat, String creator) { - Warp warp = new Warp(); - warp.setName(name); - warp.setLocation(new Location(Bukkit.getWorlds().get(0), x, y, z, yaw, pitch)); - warp.setMat(mat); - warp.setCreator(creator); - YAPIONArray warpsObject = WorldData.getWarpData(); - warpsObject.add(warp.object); - - return warp; - } - - public static Warp createWarp(String name, Player player, Material mat) { - Location loc = player.getLocation(); - return createWarp(name, loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), mat, player.getName()); - } - - public void setName(String name) { - this.name = name; - object.add("name", name); + public static Warp getWarp(String name) { + return warpMap.get(name); } public void setMat(Material mat) { this.mat = mat; - object.add("material", mat.name()); - } - - public void setCreator(String creator) { - this.creator = creator; - object.add("owner", creator); } public void setLocation(Location location) { @@ -109,37 +89,12 @@ public class Warp { } public void delete() { - YAPIONArray warpsObject = WorldData.getWarpData(); - warpsObject.removeIf(yapionAnyType -> ((YAPIONObject) yapionAnyType).getPlainValue("name").equals(name)); + warpMap.remove(name); + WorldData.getWarpData().remove(name); } public void teleport(Player player) { player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); player.playSound(location, Sound.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1, 1); } - - public void normalize(String str) { - /* - x > x - y > y - z > z - w > yaw - p > pitch - */ - if(str.contains("x")) { - location.setX(0.5 + location.getBlockX()); - } - if(str.contains("y")) { - location.setY(location.getBlockY()); - } - if(str.contains("z")) { - location.setZ(0.5 + location.getBlockZ()); - } - if(str.contains("w")) { - location.setYaw(Location.normalizeYaw(location.getYaw())); - } - if(str.contains("p")) { - location.setPitch(Location.normalizePitch(location.getPitch())); - } - } } 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 467add09..3629d620 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -21,8 +21,11 @@ package de.steamwar.bausystem.features.warp; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.linkage.Disable; +import de.steamwar.bausystem.linkage.Enable; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; @@ -33,12 +36,17 @@ import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Material; import org.bukkit.entity.Player; +import yapion.hierarchy.types.YAPIONArray; +import yapion.hierarchy.types.YAPIONObject; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Linked(LinkageType.COMMAND) -public class WarpCommand extends SWCommand { +@Linked(LinkageType.DISABLE_LINK) +@Linked(LinkageType.ENABLE_LINK) +public class WarpCommand extends SWCommand implements Disable, Enable { private static final String[] FORBIDDEN_NAMES = new String[]{ "add", "create", "delete", "list", "info", "gui" @@ -50,9 +58,7 @@ public class WarpCommand extends SWCommand { @ClassMapper(Warp.class) public static TypeMapper getWarpMapper() { - return SWCommandUtils.createMapper(s -> Warp.getWarp(s).orElse(null), (commandSender, s) -> { - return Warp.getWarps().stream().map(Warp::getName).collect(Collectors.toList()); - }); + return SWCommandUtils.createMapper(Warp::getWarp, (commandSender, s) -> new ArrayList<>(Warp.getWarpNames())); } @Register(help = true) @@ -80,11 +86,11 @@ public class WarpCommand extends SWCommand { return; } } - if (Warp.getWarp(name).isPresent()) { + if (Warp.getWarp(name) != null) { BauSystem.MESSAGE.send("WARP_EXISTS", player, name); return; } - Warp.createWarp(name, player, Material.BEACON); + new Warp(name, player); BauSystem.MESSAGE.send("WARP_CREATED", player, name); } @@ -150,7 +156,6 @@ public class WarpCommand extends SWCommand { public void warpInfo(Player player, Warp warp) { BauSystem.MESSAGE.send("COMMAND_HELP_HEAD", player, warp.getName()); BauSystem.MESSAGE.sendPrefixless("WARP_INFO_NAME", player, warp.getName()); - BauSystem.MESSAGE.sendPrefixless("WARP_INFO_CREATOR", player, warp.getCreator()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_X", player, warp.getLocation().getX()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Y", player, warp.getLocation().getY()); BauSystem.MESSAGE.sendPrefixless("WARP_LOC_Z", player, warp.getLocation().getZ()); @@ -178,4 +183,19 @@ public class WarpCommand extends SWCommand { player.performCommand("warp list " + String.join(" ", args)); } } + + @Override + public void enable() { + WorldData.getWarpData().forEach((name, yapionAnyType) -> { + new Warp(name, (YAPIONObject) yapionAnyType); + }); + } + + @Override + public void disable() { + YAPIONObject yapionObject = WorldData.getWarpData(); + for (Warp warp : Warp.getWarps()) { + yapionObject.add(warp.getName(), warp.output()); + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java index 30c1d5b5..7d033602 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java @@ -47,8 +47,8 @@ public enum LinkageType { // NORMAL COMMAND(-1, false, SWCommand.class::isAssignableFrom), - ENABLE_LINK(0, false, Enable.class::isInstance, o -> ((Enable) o).enable()), - DISABLE_LINK(0, true, Disable.class::isInstance, o -> ((Disable) o).disable()), + ENABLE_LINK(0, false, Enable.class::isAssignableFrom, o -> ((Enable) o).enable()), + DISABLE_LINK(0, true, Disable.class::isAssignableFrom, o -> ((Disable) o).disable()), PLAIN(1, false, clazz -> true), LISTENER(2, false, Listener.class::isAssignableFrom, o -> Bukkit.getPluginManager().registerEvents((Listener) o, BauSystem.getInstance())), UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o)), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java index def31d3a..a07729e0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/WorldData.java @@ -48,8 +48,8 @@ public class WorldData { return getWorldData().getYAPIONObjectOrSetDefault("regions", new YAPIONObject()); } - public YAPIONArray getWarpData() { - return getWorldData().getYAPIONArrayOrSetDefault("warps", new YAPIONArray()); + public YAPIONObject getWarpData() { + return getWorldData().getYAPIONObjectOrSetDefault("warps", new YAPIONObject()); } public YAPIONObject getSimulatorData() { From 0ff5a3d728c91854bb97b27ca70bad5618161be4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 12 Nov 2021 17:44:01 +0100 Subject: [PATCH 7/7] Fix WarpGUI Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 ++ .../de/steamwar/bausystem/features/warp/WarpGui.java | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3fa20bd1..2451aca1 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -561,6 +561,8 @@ WARP_MATERIAL_CHOOSE=Material auswählen WARP_GUI_NAME=Warps WARP_GUI_NO=§cHier giebt es noch keine Warps WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke +WARP_GUI_LCLICK=§7Links klicken zum teleportieren +WARP_GUI_RCLICK=§7Rechts klicken zum editieren WARP_LIST_PREVIOUS_PAGE=§eVorherige Seite WARP_LIST_PAGE=§e Seite ({0}/{1}) »» WARP_LIST_NEXT_PAGE=§eNächste Seite diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java index e143acbe..7c5c87a6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpGui.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; +import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -31,6 +32,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +@UtilityClass public class WarpGui { public static void openGui(Player player) { @@ -42,7 +44,11 @@ public class WarpGui { BauSystem.MESSAGE.parse("WARP_LOC_X", player, (int) warp.getLocation().getX()), BauSystem.MESSAGE.parse("WARP_LOC_Y", player, (int) warp.getLocation().getY()), BauSystem.MESSAGE.parse("WARP_LOC_Z", player, (int) warp.getLocation().getZ()), - BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.getLocation().distance(player.getLocation()))), + BauSystem.MESSAGE.parse("WARP_GUI_DISTANCE", player, (int) warp.getLocation().distance(player.getLocation())), + "", + BauSystem.MESSAGE.parse("WARP_GUI_LCLICK", player), + BauSystem.MESSAGE.parse("WARP_GUI_RCLICK", player) + ), false, clickType -> { } @@ -84,7 +90,7 @@ public class WarpGui { public static void changeMaterial(Player player, Warp warp) { List> materials = new ArrayList<>(); for (Material value : Material.values()) { - if (value.isLegacy() || value.isAir()) continue; + if (value.isLegacy() || value.isAir() || !value.isBlock() || !value.isItem()) continue; materials.add(new SWListInv.SWListEntry<>(new SWItem(value, "§e" + value.name()), value)); }