From 4228ea291dcf0ae6c1e39b4812582169f45cb3d2 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 21 Apr 2021 14:48:32 +0200 Subject: [PATCH] Fix and Add some GUI Stuff and All Region Items Signed-off-by: Chaoscaot --- .../bausystem/region/RegionUtils_15.java | 4 +- .../src/de/steamwar/bausystem/Permission.java | 6 +- .../bausystem/features/gui/BauGUI.java | 64 +++++++++- .../bausystem/features/gui/BauGUICommand.java | 14 +++ .../features/region/items/ColorGuiItem.java | 119 ++++++++++++++++++ .../features/region/items/FireGuiItem.java | 71 +++++++++++ .../features/region/items/FreezeGuiItem.java | 71 +++++++++++ .../features/region/items/ProtectGuiItem.java | 71 +++++++++++ .../features/region/items/ResetGuiItem.java | 88 +++++++++++++ .../region/items/TestblockGuiItem.java | 88 +++++++++++++ .../features/region/items/TntGuiItem.java | 108 ++++++++++++++++ .../steamwar/bausystem/linkage/GuiItem.java | 13 +- 12 files changed, 709 insertions(+), 8 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockGuiItem.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntGuiItem.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java b/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java index 701db61d..45c770bd 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/region/RegionUtils_15.java @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2020 SteamWar.de-Serverteam + * 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 @@ -31,7 +31,7 @@ public class RegionUtils_15 { return BlockVector3.at(point.getX(), point.getY(), point.getZ()); } - BlockType mapColor(BlockType original, Color color) { + public BlockType mapColor(BlockType original, Color color) { switch (color) { case WHITE: if (original == BlockTypes.YELLOW_CONCRETE) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 6ab9d142..519bb7f1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -42,10 +42,12 @@ public enum Permission { target.setWorldEdit(!target.isWorldEdit()); sendMessages(player, target.isWorldEdit(), target, "WorldEdit verwenden"); }), - MEMBER(bauweltMember -> true); + MEMBER(bauweltMember -> true), + OWNER(bauweltMember -> false); private final Predicate permissionPredicate; - private BiConsumer permissionChange = (player, bauweltMember) -> {}; + private final BiConsumer permissionChange = (player, bauweltMember) -> { + }; public boolean hasPermission(Player member) { if (member.getUniqueId().equals(BauServer.getInstance().getOwner())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java index ded935c2..d27dbf54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUI.java @@ -19,13 +19,19 @@ package de.steamwar.bausystem.features.gui; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.linkage.GuiItem; import de.steamwar.inventory.SWInventory; import lombok.experimental.UtilityClass; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; -import java.util.HashSet; -import java.util.Set; +import java.util.*; @UtilityClass public class BauGUI { @@ -35,6 +41,15 @@ public class BauGUI { private static final Set OPEN_INVS = new HashSet<>(); private static boolean updating = false; + private static final ItemStack GUI_ITEM; + + static { + GUI_ITEM = new ItemStack(Material.NETHER_STAR); + ItemMeta meta = GUI_ITEM.getItemMeta(); + meta.setDisplayName(ColorConfig.HIGHLIGHT + "Bau GUI"); + GUI_ITEM.setItemMeta(meta); + } + public static void addItem(GuiItem item) { ITEMS.add(item); } @@ -44,12 +59,23 @@ public class BauGUI { OPEN_INVS.add(p); } SWInventory inv = new SWInventory(p, 5 * 9, "Bau GUI"); - ITEMS.forEach(item -> inv.setItem(item.getSlot(), item.getItem(p), item::click)); + ITEMS.forEach(item -> inv.setItem(item.getSlot(), permissionLore(item.getItem(p), item.permission(), p), clickType -> { + if (item.permission().hasPermission(p)) { + if (item.click(clickType, p)) { + update(); + } + } else { + p.closeInventory(); + p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Du hast nicht genug rechte um dies zu tun"); + } + })); inv.addCloseCallback(clickType -> { if (!updating) { OPEN_INVS.remove(p); } }); + inv.open(); + System.out.println(Arrays.toString(ITEMS.toArray())); } public static void update() { @@ -57,4 +83,36 @@ public class BauGUI { OPEN_INVS.forEach(BauGUI::openBauGui); updating = false; } + + public static void giveItem(Player p) { + SWUtils.giveItemToPlayer(p, GUI_ITEM); + } + + private static ItemStack permissionLore(ItemStack itemStack, Permission permission, Player p) { + ItemMeta meta = itemStack.getItemMeta(); + if (!permission.hasPermission(p)) { + List lore = meta.getLore(); + if (lore == null) { + lore = Collections.singletonList(ColorConfig.ERROR + permissionString(permission)); + } else { + lore.add(ColorConfig.ERROR + permissionString(permission)); + } + meta.setLore(lore); + } + itemStack.setItemMeta(meta); + return itemStack; + } + + private static String permissionString(Permission permission) { + switch (permission) { + case OWNER: + return "Das ist nicht deine Bauwelt"; + case WORLD: + return "Du darfst hier die Welt nicht einstellen"; + case WORLDEDIT: + return "Du darfst hier kein Worldedit benutzen"; + default: + return "Du must ein Member der Bauwelt sein"; + } + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUICommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUICommand.java index 04f51c0d..dcaec145 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUICommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/gui/BauGUICommand.java @@ -19,11 +19,25 @@ package de.steamwar.bausystem.features.gui; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +@Linked(LinkageType.COMMAND) public class BauGUICommand extends SWCommand { protected BauGUICommand() { super("gui", "baugui"); } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + BauGUI.openBauGui(p); + } + + @Register("item") + public void giveItem(Player p) { + BauGUI.giveItem(p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorGuiItem.java new file mode 100644 index 00000000..50efc5f6 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ColorGuiItem.java @@ -0,0 +1,119 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Color; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Linked(LinkageType.GUI_ITEM) +public class ColorGuiItem extends GuiItem { + + public ColorGuiItem() { + super(2); + } + + private static Material mapColor(Color color) { + switch (color) { + case RED: + return Material.RED_CONCRETE; + case CYAN: + return Material.CYAN_CONCRETE; + case BLACK: + return Material.BLACK_CONCRETE; + case BLUE: + return Material.BLUE_CONCRETE; + case BROWN: + return Material.BROWN_CONCRETE; + case GRAY: + return Material.GRAY_CONCRETE; + case GREEN: + return Material.GREEN_CONCRETE; + case LIGHT_BLUE: + return Material.LIGHT_BLUE_CONCRETE; + case LIGHT_GRAY: + return Material.LIGHT_GRAY_CONCRETE; + case LIME: + return Material.LIME_CONCRETE; + case MAGENTA: + return Material.MAGENTA_CONCRETE; + case ORANGE: + return Material.ORANGE_CONCRETE; + case PINK: + return Material.PINK_CONCRETE; + case PURPLE: + return Material.PURPLE_CONCRETE; + case WHITE: + return Material.WHITE_CONCRETE; + default: + return Material.YELLOW_CONCRETE; + } + } + + @Override + public ItemStack getItem(Player player) { + Region region = Region.getRegion(player.getLocation()); + ColorMode mode = region.getPlain(Flag.COLOR, ColorMode.class); + ItemStack itemStack = new ItemStack(mapColor(mode.getColor())); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Color: " + ColorConfig.HIGHLIGHT + mode.getChatValue()); + itemStack.setItemMeta(meta); + return itemStack; + } + + @Override + public boolean click(ClickType click, Player p) { + p.closeInventory(); + ColorMode current = Region.getRegion(p.getLocation()).getPlain(Flag.COLOR, ColorMode.class); + List> items = new ArrayList<>(); + for (ColorMode value : ColorMode.values()) { + items.add(new SWListInv.SWListEntry<>(new SWItem(mapColor(value.getColor()), (byte) 0, value.getChatValue(), Collections.emptyList(), value == current, clickType -> { + }), value)); + } + SWListInv inv = new SWListInv(p, "Farbe Wählen", items, (clickType, colorMode) -> { + p.closeInventory(); + p.performCommand("color " + colorMode.getChatValue()); + }); + inv.open(); + return false; + } + + @Override + public Permission permission() { + return Permission.OWNER; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireGuiItem.java new file mode 100644 index 00000000..a6e98f54 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FireGuiItem.java @@ -0,0 +1,71 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Linked(LinkageType.GUI_ITEM) +public class FireGuiItem extends GuiItem { + + public FireGuiItem() { + super(3); + } + + @Override + public ItemStack getItem(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.getPlain(Flag.FIRE, FireMode.class) == FireMode.ALLOW) { + ItemStack itemStack = new ItemStack(Material.FIRE_CHARGE); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Feuer: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } else { + ItemStack itemStack = new ItemStack(Material.FIREWORK_STAR); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Feuer: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } + } + + @Override + public boolean click(ClickType click, Player p) { + p.performCommand("fire"); + return true; + } + + @Override + public Permission permission() { + return Permission.WORLD; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeGuiItem.java new file mode 100644 index 00000000..ea75366b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/FreezeGuiItem.java @@ -0,0 +1,71 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Linked(LinkageType.GUI_ITEM) +public class FreezeGuiItem extends GuiItem { + + public FreezeGuiItem() { + super(1); + } + + @Override + public ItemStack getItem(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.getPlain(Flag.FREEZE, FreezeMode.class) == FreezeMode.ACTIVE) { + ItemStack itemStack = new ItemStack(Material.GUNPOWDER); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Freeze: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } else { + ItemStack itemStack = new ItemStack(Material.REDSTONE); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Freeze: " + ColorConfig.HIGHLIGHT + "Ausgeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } + } + + @Override + public boolean click(ClickType click, Player p) { + p.performCommand("freeze"); + return true; + } + + @Override + public Permission permission() { + return Permission.WORLD; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectGuiItem.java new file mode 100644 index 00000000..ecfcb8e5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ProtectGuiItem.java @@ -0,0 +1,71 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Linked(LinkageType.GUI_ITEM) +public class ProtectGuiItem extends GuiItem { + + public ProtectGuiItem() { + super(4); + } + + @Override + public ItemStack getItem(Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.getPlain(Flag.PROTECT, ProtectMode.class) == ProtectMode.ACTIVE) { + ItemStack itemStack = new ItemStack(Material.OBSIDIAN); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Protect: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } else { + ItemStack itemStack = new ItemStack(Material.STONE); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "Protect: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } + } + + @Override + public boolean click(ClickType click, Player p) { + p.performCommand("protect"); + return true; + } + + @Override + public Permission permission() { + return Permission.WORLDEDIT; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetGuiItem.java new file mode 100644 index 00000000..81659904 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/ResetGuiItem.java @@ -0,0 +1,88 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.Schematic; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Linked(LinkageType.GUI_ITEM) +public class ResetGuiItem extends GuiItem { + + public ResetGuiItem() { + super(6); + } + + @Override + public ItemStack getItem(Player player) { + ItemStack itemStack = new ItemStack(Material.END_STONE); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.HIGHLIGHT + "Reset"); + itemStack.setItemMeta(meta); + return itemStack; + } + + @Override + public boolean click(ClickType click, Player p) { + if (click == ClickType.LEFT) { + p.closeInventory(); + p.performCommand("reset"); + } else { + List> schemList = new ArrayList<>(); + for (Schematic schem : Schematic.getSchemsAccessibleByUser(p.getUniqueId())) { + Material m; + if (schem.getItem().isEmpty()) + m = SWItem.getMaterial("CAULDRON_ITEM"); + else + m = SWItem.getMaterial(schem.getItem()); + + SWItem item = new SWItem(m, "§e" + schem.getSchemName(), Collections.singletonList("§7" + schem.getSchemType().name()), !schem.getSchemType().writeable(), clickType -> { + }); + schemList.add(new SWListInv.SWListEntry<>(item, schem)); + } + SWListInv inv = new SWListInv<>(p, "Reset Prototypen wählen", schemList, (clickType, schematic) -> { + p.closeInventory(); + p.performCommand("reset " + schematic.getSchemName()); + }); + p.closeInventory(); + inv.open(); + } + return false; + } + + @Override + public Permission permission() { + return Permission.WORLDEDIT; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockGuiItem.java new file mode 100644 index 00000000..ab662f24 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TestblockGuiItem.java @@ -0,0 +1,88 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.Schematic; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Linked(LinkageType.GUI_ITEM) +public class TestblockGuiItem extends GuiItem { + + public TestblockGuiItem() { + super(5); + } + + @Override + public ItemStack getItem(Player player) { + ItemStack itemStack = new ItemStack(Material.END_STONE); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.HIGHLIGHT + "Testblock"); + itemStack.setItemMeta(meta); + return itemStack; + } + + @Override + public boolean click(ClickType click, Player p) { + if (click == ClickType.LEFT) { + p.closeInventory(); + p.performCommand("testblock"); + } else { + p.closeInventory(); + List> schemList = new ArrayList<>(); + for (Schematic schem : Schematic.getSchemsAccessibleByUser(p.getUniqueId())) { + Material m; + if (schem.getItem().isEmpty()) + m = SWItem.getMaterial("CAULDRON_ITEM"); + else + m = SWItem.getMaterial(schem.getItem()); + + SWItem item = new SWItem(m, "§e" + schem.getSchemName(), Collections.singletonList("§7" + schem.getSchemType().name()), !schem.getSchemType().writeable(), clickType -> { + }); + schemList.add(new SWListInv.SWListEntry<>(item, schem)); + } + SWListInv inv = new SWListInv<>(p, "Testblock wählen", schemList, (clickType, schematic) -> { + p.closeInventory(); + p.performCommand("testblock " + schematic.getSchemName()); + }); + inv.open(); + } + return false; + } + + @Override + public Permission permission() { + return Permission.WORLDEDIT; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntGuiItem.java new file mode 100644 index 00000000..b2c18f8d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/items/TntGuiItem.java @@ -0,0 +1,108 @@ +/* + * 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.region.items; + +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.linkage.GuiItem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +@Linked(LinkageType.GUI_ITEM) +public class TntGuiItem extends GuiItem { + + public TntGuiItem() { + super(0); + } + + @Override + public ItemStack getItem(Player player) { + switch (Region.getRegion(player.getLocation()).getPlain(Flag.TNT, TNTMode.class)) { + case DENY: { + ItemStack itemStack = new ItemStack(Material.MINECART); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "TNT: " + ColorConfig.HIGHLIGHT + "Ausgeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } + case ONLY_TB: { + ItemStack itemStack = new ItemStack(Material.TNT_MINECART); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "TNT: " + ColorConfig.HIGHLIGHT + "nur Testblock"); + itemStack.setItemMeta(meta); + return itemStack; + } + default: { + ItemStack itemStack = new ItemStack(Material.TNT); + ItemMeta meta = itemStack.getItemMeta(); + meta.setDisplayName(ColorConfig.BASE + "TNT: " + ColorConfig.HIGHLIGHT + "Eingeschaltet"); + itemStack.setItemMeta(meta); + return itemStack; + } + } + } + + @Override + public boolean click(ClickType click, Player p) { + if (click == ClickType.LEFT) { + p.performCommand("tnt"); + return true; + } else { + p.closeInventory(); + SWInventory selector = new SWInventory(p, 9, "Tnt Modus"); + selector.setItem(1, new SWItem(Material.TNT, ColorConfig.HIGHLIGHT + "Einschalten", clickType -> updateTntMode(TNTMode.ALLOW, p))); + if (!Region.getRegion(p.getLocation()).isGlobal()) + selector.setItem(4, new SWItem(Material.TNT_MINECART, ColorConfig.HIGHLIGHT + "nur Testblock", clickType -> updateTntMode(TNTMode.ONLY_TB, p))); + selector.setItem(7, new SWItem(Material.MINECART, ColorConfig.HIGHLIGHT + "Ausschalten", clickType -> updateTntMode(TNTMode.DENY, p))); + selector.open(); + return false; + } + } + + private void updateTntMode(TNTMode mode, Player p) { + p.closeInventory(); + switch (mode) { + case ONLY_TB: + p.performCommand("tnt tb"); + break; + case ALLOW: + p.performCommand("tnt on"); + break; + default: + p.performCommand("tnt off"); + break; + } + } + + @Override + public Permission permission() { + return Permission.WORLD; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/GuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/GuiItem.java index 9288f2f9..3676d5d8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/GuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/GuiItem.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.linkage; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.gui.BauGUI; import lombok.AllArgsConstructor; import lombok.Getter; @@ -34,9 +35,19 @@ public abstract class GuiItem { public abstract ItemStack getItem(Player player); - public abstract boolean click(ClickType click); + public abstract boolean click(ClickType click, Player p); public void update() { BauGUI.update(); } + + public abstract Permission permission(); + + @Override + public String toString() { + return "GuiItem{" + + "slot=" + slot + + "class=" + this.getClass().getName() + + '}'; + } }