Add BauSystem module

Fix ci java version
Fix LinkageProcessor
This commit is contained in:
2024-08-05 13:28:50 +02:00
parent 41d31e6c9c
commit 3366a30b0c
526 changed files with 43550 additions and 149479 deletions
@@ -0,0 +1,172 @@
package de.steamwar.bausystem.features.util;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.script.ScriptCommand;
import de.steamwar.bausystem.features.script.ScriptRunner;
import de.steamwar.bausystem.features.world.WorldEditListener;
import de.steamwar.bausystem.utils.WorldEditUtils;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.luaj.vm2.LuaValue;
import java.lang.reflect.Field;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
@Linked
public class BindCommand extends SWCommand implements Listener {
private static final boolean hasFAWE = Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null;
@Linked
public static class UnBindCommand extends SWCommand {
public UnBindCommand() {
super("unbind");
}
@Register
public void generic(Player player) {
bindInternal(player);
}
}
private static final CommandMap commandMap;
static {
Field knownCommandsField;
try {
knownCommandsField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
knownCommandsField.setAccessible(true);
commandMap = (CommandMap)knownCommandsField.get(Bukkit.getServer());
} catch (IllegalAccessException | NoSuchFieldException var2) {
Bukkit.shutdown();
throw new SecurityException("Oh shit. Commands cannot be registered.", var2);
}
}
private static final NamespacedKey KEY = SWUtils.getNamespaceKey("command");
public BindCommand() {
super("bind");
}
@Register(description = "OTHER_BIND_HELP")
public void bind(@Validator Player player, @Mapper("command") @ErrorMessage("OTHER_BIND_ERROR") String... command) {
bindInternal(player, command);
}
private static void bindInternal(Player player, String... command) {
ItemStack item = player.getInventory().getItemInMainHand();
ItemMeta meta = item.getItemMeta();
if (meta == null) {
BauSystem.MESSAGE.send("OTHER_BIND_UNBINDABLE", player);
return;
}
if (command.length != 0) {
String commandText = String.join(" ", command);
meta.getPersistentDataContainer().set(KEY, PersistentDataType.STRING, commandText);
meta.setDisplayName(BauSystem.MESSAGE.parse("OTHER_BIND_LORE", player, commandText));
BauSystem.MESSAGE.send("OTHER_BIND_MESSAGE_BIND", player, commandText);
} else {
meta.getPersistentDataContainer().remove(KEY);
meta.setDisplayName(null);
BauSystem.MESSAGE.send("OTHER_BIND_MESSAGE_UNBIND", player);
}
item.setItemMeta(meta);
player.getInventory().setItemInMainHand(item);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.hasItem()) return;
if(!Permission.BUILD.hasPermission(event.getPlayer())) return;
ItemStack itemStack = event.getItem();
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
String command = meta.getPersistentDataContainer().get(KEY, PersistentDataType.STRING);
if (command == null) {
return;
}
event.setCancelled(true);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(event.getPlayer(), "/" + command);
Bukkit.getPluginManager().callEvent(preprocessEvent);
if (preprocessEvent.isCancelled()) return;
String processedCommand = preprocessEvent.getMessage().substring(1);
Bukkit.getLogger().log(Level.INFO, event.getPlayer().getName() + " dispatched command: " + processedCommand);
String[] commandSplit = processedCommand.split(" ");
if (!commandSplit[0].equals("select") && hasFAWE && WorldEditListener.isWorldEditCommand("/" + commandSplit[0])) {
EditSession editSession = WorldEditUtils.getEditSession(event.getPlayer());
Actor actor = BukkitAdapter.adapt(event.getPlayer());
WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().handleCommandOnCurrentThread(new CommandEvent(actor, processedCommand, editSession));
editSession.flushSession();
WorldEditUtils.addToPlayer(event.getPlayer(), editSession);
} else {
Bukkit.getServer().dispatchCommand(event.getPlayer(), processedCommand);
}
}, 1);
}
@Mapper(value = "command", local = true)
public TypeMapper<String> getCommandMapper() {
return new TypeMapper<String>() {
@Override
public String map(CommandSender sender, PreviousArguments previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
if (previousArguments.mappedArgs.length == 0) return null;
Object[] args = (Object[]) previousArguments.mappedArgs[previousArguments.mappedArgs.length - 1];
List<String> tabCompletes;
if (args.length == 0) {
tabCompletes = commandMap.tabComplete(sender, "");
} else {
tabCompletes = commandMap.tabComplete(sender, Arrays.stream(args).map(Objects::toString).collect(Collectors.joining(" ")) + " ");
}
if (tabCompletes == null) return null;
if (args.length == 0) {
tabCompletes = tabCompletes.stream()
.map(t -> t.substring(1))
.filter(t -> !t.equals("bind"))
.collect(Collectors.toList());
tabCompletes.addAll(ScriptRunner.getCommandsOfPlayer((Player) sender));
return tabCompletes.stream()
.filter(t -> !t.contains(":"))
.collect(Collectors.toList());
}
return tabCompletes;
}
};
}
}
@@ -0,0 +1,49 @@
package de.steamwar.bausystem.features.util;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
@Linked
public class BookReplaceCommand extends SWCommand {
public BookReplaceCommand() {
super("bookreplace");
}
@Register("color")
public void color(@Validator Player player) {
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta instanceof BookMeta) {
BookMeta bookMeta = (BookMeta) itemMeta;
replace(bookMeta, '&', '§');
itemStack.setItemMeta(bookMeta);
player.getInventory().setItemInMainHand(itemStack);
}
}
@Register("uncolor")
public void uncolor(@Validator Player player) {
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta instanceof BookMeta) {
BookMeta bookMeta = (BookMeta) itemMeta;
replace(bookMeta, '§', '&');
itemStack.setItemMeta(bookMeta);
player.getInventory().setItemInMainHand(itemStack);
}
}
private void replace(BookMeta bookMeta, char oldChar, char newChar) {
List<String> stringList = bookMeta.getPages();
for (int i = 0; i < stringList.size(); i++) {
bookMeta.setPage(i + 1, stringList.get(i).replace(oldChar, newChar));
}
}
}
@@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Linked
public class ClearCommand extends SWCommand {
public ClearCommand() {
super("clear");
}
@Register(description = "OTHER_CLEAR_HELP_SELF")
public void genericClearCommand(Player p) {
clear(p);
BauSystem.MESSAGE.send("OTHER_CLEAR_CLEARED", p);
}
@Register(description = "OTHER_CLEAR_HELP_PLAYER")
public void clearPlayerCommand(@Validator Player p, Player target) {
clear(target);
BauSystem.MESSAGE.send("OTHER_CLEAR_FROM", target, p.getName());
BauSystem.MESSAGE.send("OTHER_CLEAR_TO", p, target.getName());
}
private void clear(Player player) {
player.getInventory().clear();
player.getInventory().setHelmet(new ItemStack(Material.AIR));
player.getInventory().setChestplate(new ItemStack(Material.AIR));
player.getInventory().setLeggings(new ItemStack(Material.AIR));
player.getInventory().setBoots(new ItemStack(Material.AIR));
}
}
@@ -0,0 +1,40 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Linked
public class DebugStickCommand extends SWCommand {
public DebugStickCommand() {
super("debugstick");
}
@Register(description = "DEBUG_STICK_COMMAND_HELP")
public void genericCommand(@Validator Player p) {
SWUtils.giveItemToPlayer(p, new ItemStack(Material.DEBUG_STICK));
}
}
@@ -0,0 +1,62 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.Set;
@Linked
public class DeclutterCommand extends SWCommand {
public DeclutterCommand() {
super("declutter", "cleanup");
}
@Register(description = "OTHER_DECLUTTER_HELP")
public void genericCommand(Player p) {
Inventory inventory = p.getInventory();
Set<ItemStack> containedItems = new HashSet<>();
inventory.forEach(itemStack -> {
if (itemStack == null) {
return;
}
if (containedItems.stream().anyMatch(itemStack::isSimilar)) {
itemStack.setAmount(0);
return;
}
if (itemStack.getAmount() > 1) {
itemStack.setAmount(1);
}
containedItems.add(itemStack);
});
BauSystem.MESSAGE.send("OTHER_DECLUTTER_DONE", p);
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Linked
public class DragonEggCommand extends SWCommand {
public DragonEggCommand() {
super("dragonegg", "enderdragon", "dragon", "egg", "enderei", "ender");
}
@Register(description = "DRAGON_EGG_COMMAND_HELP")
public void genericCommand(Player p) {
SWUtils.giveItemToPlayer(p, new ItemStack(Material.DRAGON_EGG, 1));
}
}
@@ -0,0 +1,60 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
@Linked
public class GamemodeCommand extends SWCommand {
public GamemodeCommand() {
super("gamemode", "gm", "g");
}
@Register(help = true)
public void help(final Player p, final String... args) {
BauSystem.MESSAGE.sendPrefixless("OTHER_GAMEMODE_UNKNOWN", p);
BauSystem.MESSAGE.sendPrefixless("OTHER_GAMEMODE_POSSIBLE", p);
}
@Register
public void genericCommand(final Player p) {
if (NoClipCommand.getNOCLIPS().contains(p)) {
p.performCommand("noclip");
return;
}
if (p.getGameMode() == GameMode.CREATIVE) {
p.setGameMode(GameMode.SPECTATOR);
} else {
p.setGameMode(GameMode.CREATIVE);
}
}
@Register
public void gamemodeCommand(final Player p, final GameMode gameMode) {
if (NoClipCommand.getNOCLIPS().contains(p)) {
p.performCommand("noclip");
}
p.setGameMode(gameMode);
}
}
@@ -0,0 +1,78 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionSelectionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.concurrent.atomic.AtomicLong;
@Linked
public class KillAllCommand extends SWCommand {
private static final World WORLD = Bukkit.getWorlds().get(0);
public KillAllCommand() {
super("killall", "removeall");
}
@Register(description = "OTHER_KILLALL_HELP_SELF")
public void genericCommand(@Validator Player player) {
genericCommand(player, RegionSelectionType.LOCAL);
}
@Register(description = "OTHER_KILLALL_HELP_ALL")
public void genericCommand(@Validator Player player, RegionSelectionType regionSelectionType) {
Region region = Region.getRegion(player.getLocation());
AtomicLong count = new AtomicLong(0);
if (regionSelectionType == RegionSelectionType.GLOBAL || GlobalRegion.getInstance() == region) {
WORLD.getEntities()
.stream()
.filter(e -> !(e instanceof Player))
.forEach(entity -> {
entity.remove();
count.incrementAndGet();
});
SWUtils.actionBar(current -> BauSystem.MESSAGE.parse("OTHER_KILLALL_GLOBAL", current, count.get()));
} else {
WORLD.getEntities()
.stream()
.filter(e -> !(e instanceof Player))
.filter(e -> region.inRegion(e.getLocation(), RegionType.NORMAL, RegionExtensionType.NORMAL))
.forEach(entity -> {
entity.remove();
count.incrementAndGet();
});
RegionUtils.actionBar(region, "OTHER_KILLALL_REGION", count.get());
}
}
}
@@ -0,0 +1,274 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.world.WorldEditListener;
import de.steamwar.bausystem.shared.EnumDisplay;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.linkage.Linked;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
@Linked
public class MaterialCommand extends SWCommand implements Listener {
public MaterialCommand() {
super("material", "baumaterial");
WorldEditListener.addCommandExclusion("material");
}
private Map<Player, Search> searchMap = new HashMap<>();
@Getter
@Setter
static class Search {
SearchType transparent = SearchType.IGNORE;
SearchType solid = SearchType.IGNORE;
SearchType gravity = SearchType.IGNORE;
SearchType occluding = SearchType.IGNORE;
SearchType interacteable = SearchType.IGNORE;
SearchType flammable = SearchType.IGNORE;
SearchType burnable = SearchType.IGNORE;
SearchType waterloggable = SearchType.IGNORE;
SearchType unmoveable = SearchType.IGNORE;
String blastResistance = ">=0";
String name = "";
}
@AllArgsConstructor
enum SearchType implements EnumDisplay {
TRUE("MATERIAL_SEARCH_PROPERTY_TRUE", b -> b),
FALSE("MATERIAL_SEARCH_PROPERTY_FALSE", b -> !b),
IGNORE("MATERIAL_SEARCH_PROPERTY_IGNORE", b -> true);
@Getter
private String chatValue;
private Predicate<Boolean> predicate;
public boolean test(boolean b) {
return predicate.test(b);
}
public SearchType next() {
switch (this) {
case TRUE:
return FALSE;
case FALSE:
return IGNORE;
case IGNORE:
return TRUE;
}
return IGNORE;
}
}
@Register
public void materialGUI(Player p) {
materialGUI(p, searchMap.get(p));
}
private static final Map<String, BiConsumer<Search, SearchType>> elements = new HashMap<>();
static {
elements.put("-transparent", (search, searchType) -> search.transparent = searchType);
elements.put("-solid", (search, searchType) -> search.solid = searchType);
elements.put("-gravity", (search, searchType) -> search.gravity = searchType);
elements.put("-occluding", (search, searchType) -> search.occluding = searchType);
elements.put("-interacteable", (search, searchType) -> search.interacteable = searchType);
elements.put("-flammable", (search, searchType) -> search.flammable = searchType);
elements.put("-burnable", (search, searchType) -> search.burnable = searchType);
elements.put("-waterloggable", (search, searchType) -> search.waterloggable = searchType);
elements.put("-unmoveable", (search, searchType) -> search.unmoveable = searchType);
}
@Register
public void search(Player p, @Mapper("search") String... searches) {
Search search = new Search();
for (String s : searches) {
boolean has = false;
for (Map.Entry<String, BiConsumer<Search, SearchType>> element: elements.entrySet()) {
if (s.startsWith(element.getKey() + ":")) {
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().length() + 1).toUpperCase()));
has = true;
} else if (s.startsWith(element.getKey().substring(0, 2) + ":")) {
element.getValue().accept(search, SearchType.valueOf(s.substring(element.getKey().substring(0, 2).length() + 1).toUpperCase()));
has = true;
}
if (has) break;
}
if (has) continue;
switch (s.toLowerCase()) {
case "-br:":
case "-blastresistance:":
s = s.substring(s.indexOf(':') + 1).replace('_', ' ');
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
search.blastResistance = s;
}
break;
default:
search.name = s;
break;
}
}
materialGUI(p, search);
}
@Mapper(value = "search", local = true)
private TypeMapper<String> searchMapper() {
List<String> results = new ArrayList<>();
for (String s : Arrays.asList("-transparent", "-solid", "-gravity", "-occluding", "-interacteable", "-flammable", "-burnable", "-waterloggable")) {
results.add(s + ":true");
results.add(s + ":false");
results.add(s + ":ignore");
s = s.substring(0, 2);
results.add(s + ":true");
results.add(s + ":false");
results.add(s + ":ignore");
}
return new TypeMapper<String>() {
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return s;
}
@Override
public Collection<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
List<String> tabCompletes = new ArrayList<>();
tabCompletes.addAll(results);
tabCompletes.add(s);
return tabCompletes;
}
};
}
public void materialGUI(Player p, Search search) {
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
MaterialLazyInit.materialData.forEach(data -> {
if (data.is(search)) {
swListEntries.add(data.toSWItem(p));
}
});
SWListInv<Material> materialSWListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("MATERIAL_INV_NAME", p, swListEntries.size(), MaterialLazyInit.materialData.size()), false, swListEntries, (clickType, material) -> {
if (material.isItem()) {
SWUtils.giveItemToPlayer(p, new ItemStack(material, 1));
}
});
materialSWListInv.setItem(49, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p), clickType -> {
searchGUI(p);
}));
materialSWListInv.open();
}
private void searchGUI(Player p) {
SWInventory swInventory = new SWInventory(p, 54, BauSystem.MESSAGE.parse("MATERIAL_SEARCH", p));
Search search = searchMap.get(p);
swInventory.setItem(45, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("MATERIAL_BACK", p), clickType -> {
materialGUI(p);
}));
swInventory.setItem(10, new SWItem(Material.NAME_TAG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.name), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_NAME", p), search.name);
swAnvilInv.setCallback(s -> {
search.name = s;
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.setItem(19, new SWItem(Material.GLASS, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_TRANSPARENT", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.transparent.getChatValue(), p)), clickType -> {
search.transparent = search.transparent.next();
searchGUI(p);
}));
swInventory.setItem(20, new SWItem(Material.BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_SOLID", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.solid.getChatValue(), p)), clickType -> {
search.solid = search.solid.next();
searchGUI(p);
}));
swInventory.setItem(21, new SWItem(Material.BLACK_CONCRETE_POWDER, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_GRAVITY", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.gravity.getChatValue(), p)), clickType -> {
search.gravity = search.gravity.next();
searchGUI(p);
}));
swInventory.setItem(22, new SWItem(Material.BIRCH_LOG, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_OCCLUDING", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.occluding.getChatValue(), p)), clickType -> {
search.occluding = search.occluding.next();
searchGUI(p);
}));
swInventory.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_INTERACTEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.interacteable.getChatValue(), p)), clickType -> {
search.interacteable = search.interacteable.next();
searchGUI(p);
}));
swInventory.setItem(24, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_FLAMMABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.flammable.getChatValue(), p)), clickType -> {
search.flammable = search.flammable.next();
searchGUI(p);
}));
swInventory.setItem(25, new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BURNABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.burnable.getChatValue(), p)), clickType -> {
search.burnable = search.burnable.next();
searchGUI(p);
}));
swInventory.setItem(28, new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_WATERLOGGABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.waterloggable.getChatValue(), p)), clickType -> {
search.waterloggable = search.waterloggable.next();
searchGUI(p);
}));
swInventory.setItem(29, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_UNMOVEABLE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, BauSystem.MESSAGE.parse(search.unmoveable.getChatValue(), p)), clickType -> {
search.unmoveable = search.unmoveable.next();
searchGUI(p);
}));
swInventory.setItem(34, new SWItem(Material.NETHER_BRICK, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p) + BauSystem.MESSAGE.parse("MATERIAL_SEARCH_VALUE", p, search.blastResistance), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("MATERIAL_SEARCH_BLASTRESISTANCE", p), search.blastResistance);
swAnvilInv.setCallback(s -> {
if (s.isEmpty() || s.matches("((([><]=?)|!|=)\\d+(\\.|,\\d+)?)( ((([><]=?)|!|=)\\d+(\\.|,\\d+)?))*")) {
search.blastResistance = s;
}
searchGUI(p);
});
swAnvilInv.open();
}));
swInventory.open();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
searchMap.put(event.getPlayer(), new Search());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
searchMap.remove(event.getPlayer());
}
}
@@ -0,0 +1,174 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class MaterialLazyInit {
static List<MaterialData> materialData = new ArrayList<>();
static {
for (Material value : Material.values()) {
if (!value.isBlock()) {
continue;
}
if (value.isLegacy()) {
continue;
}
materialData.add(new MaterialData(value));
}
}
static class MaterialData {
private Material material;
private Material originalMaterial;
private String name;
private double blastResistance;
private double hardness;
private boolean transparent;
private boolean solid;
private boolean gravity;
private boolean occluding;
private boolean interacteable;
private boolean flammable;
private boolean burnable;
private boolean waterloggable;
private boolean unmoveable;
public MaterialData(Material material) {
this.originalMaterial = material;
name = material.name();
blastResistance = material.getBlastResistance();
hardness = material.getHardness();
transparent = material.isTransparent();
solid = material.isSolid();
gravity = material.hasGravity();
occluding = material.isOccluding();
interacteable = material.isInteractable();
flammable = material.isFlammable();
burnable = material.isBurnable();
BlockData blockData = material.createBlockData();
waterloggable = blockData instanceof Waterlogged;
if (material.isBlock()) {
Block block = Bukkit.getWorlds().get(0).getBlockAt(0, 0, 0);
block.setType(material);
unmoveable = block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getState() instanceof TileState;
}
if (material.isItem() && material != Material.AIR) {
this.material = material;
} else {
this.material = Material.GHAST_TEAR;
}
}
public SWListInv.SWListEntry<Material> toSWItem(Player p) {
List<String> lore = new ArrayList<>();
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BLAST_RESISTANCE", p, blastResistance));
lore.add(BauSystem.MESSAGE.parse(blastResistance > 9 ? "MATERIAL_TNT_UNBREAKABLE" : "MATERIAL_TNT_BREAKABLE", p));
lore.add(BauSystem.MESSAGE.parse("MATERIAL_HARDNESS", p, hardness));
if (transparent) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_TRANSPARENT", p));
}
if (solid) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_SOLID", p));
}
if (gravity) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_GRAVITY", p));
}
if (occluding) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_OCCLUDING", p));
}
if (interacteable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_INTERACTABLE", p));
}
if (flammable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_FLAMMABLE", p));
}
if (burnable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_BURNABLE", p));
}
if (waterloggable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_WATERLOGGABLE", p));
}
if (unmoveable) {
lore.add(BauSystem.MESSAGE.parse("MATERIAL_UNMOVABLE", p));
}
return new SWListInv.SWListEntry<>(new SWItem(material, "§e" + name, lore, false, clickType -> {
}), originalMaterial);
}
public boolean is(MaterialCommand.Search search) {
boolean result = true;
result &= search.transparent.test(transparent);
result &= search.solid.test(solid);
result &= search.gravity.test(gravity);
result &= search.occluding.test(occluding);
result &= search.interacteable.test(interacteable);
result &= search.flammable.test(flammable);
result &= search.burnable.test(burnable);
result &= search.waterloggable.test(waterloggable);
result &= search.unmoveable.test(unmoveable);
if (!result) {
return false;
}
if (!search.blastResistance.isEmpty()) {
String[] strings = search.blastResistance.split(" ");
for (String string : strings) {
string = string.replace(",", ".");
if (string.startsWith("=")) {
if (blastResistance != Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith(">=")) {
if (blastResistance < Double.parseDouble(string.substring(2))) return false;
} else if (string.startsWith("<=")) {
if (blastResistance > Double.parseDouble(string.substring(2)))return false;
} else if (string.startsWith(">")) {
if (blastResistance <= Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith("<")) {
if (blastResistance >= Double.parseDouble(string.substring(1))) return false;
} else if (string.startsWith("!")) {
if (blastResistance == Double.parseDouble(string.substring(1))) return false;
}
}
}
if (search.name.isEmpty()) {
return true;
}
return Pattern.compile(search.name.toLowerCase().replace(".", ".+").replace(" ", ".")).asPredicate().test(name.toLowerCase());
}
}
}
@@ -0,0 +1,64 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import yapion.hierarchy.types.YAPIONObject;
@Linked
public class NightVisionCommand extends SWCommand implements Listener {
public NightVisionCommand() {
super("nightvision", "nv", "light");
}
@Register(description = "NIGHT_VISION_HELP")
public void genericCommand(Player p) {
YAPIONObject yapionObject = Config.getInstance().get(p);
boolean value = !yapionObject.getBooleanOrDefault("nightvision", false);
yapionObject.put("nightvision", value);
setNightVision(p, value);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
setNightVision(event.getPlayer(), Config.getInstance().get(event.getPlayer()).getBooleanOrDefault("nightvision", false));
}
private void setNightVision(Player p, boolean value) {
if (p.hasPotionEffect(PotionEffectType.NIGHT_VISION) && !value) {
p.removePotionEffect(PotionEffectType.NIGHT_VISION);
BauSystem.MESSAGE.sendPrefixless("NIGHT_VISION_OFF", p, ChatMessageType.ACTION_BAR);
} else if (!p.hasPotionEffect(PotionEffectType.NIGHT_VISION) && value) {
p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 255, false, false));
BauSystem.MESSAGE.sendPrefixless("NIGHT_VISION_ON", p, ChatMessageType.ACTION_BAR);
}
}
}
@@ -0,0 +1,168 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import com.comphenix.tinyprotocol.Reflection;
import com.comphenix.tinyprotocol.TinyProtocol;
import com.mojang.authlib.GameProfile;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
import de.steamwar.bausystem.utils.NMSWrapper;
import de.steamwar.command.SWCommand;
import de.steamwar.core.ProtocolWrapper;
import de.steamwar.linkage.Linked;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
@Linked
public class NoClipCommand extends SWCommand implements Listener {
public static final Class<?> gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange");
private static final Reflection.FieldAccessor<Float> floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0);
private static final Class<?> position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition");
private static final Class<?> positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook");
private static final Class<?> useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem");
private static final Class<?> blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig");
private static final Class<?> windowClick = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInWindowClick");
private static final Class<?> setSlotStack = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInSetCreativeSlot");
@Getter
private static final List<Player> NOCLIPS = new ArrayList<>();
private static final Map<Player, Long> LAST_TICKS = new HashMap<>();
public NoClipCommand() {
super("noclip", "nc");
BiFunction<Player, Object, Object> first = (player, o) -> {
if (NOCLIPS.contains(player)) {
if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o;
NMSWrapper.impl.setInternalGameMode(player, GameMode.SPECTATOR);
LAST_TICKS.put(player, TPSUtils.currentTick.get());
}
return o;
};
TinyProtocol.instance.addFilter(position, first);
TinyProtocol.instance.addFilter(positionLook, first);
BiFunction<Player, Object, Object> second = (player, o) -> {
if (NOCLIPS.contains(player)) {
NMSWrapper.impl.setInternalGameMode(player, GameMode.CREATIVE);
LAST_TICKS.put(player, TPSUtils.currentTick.get());
}
return o;
};
TinyProtocol.instance.addFilter(useItem, second);
TinyProtocol.instance.addFilter(blockDig, second);
TinyProtocol.instance.addFilter(windowClick, second);
BiFunction<Player, Object, Object> third = (player, o) -> {
if (NOCLIPS.contains(player)) {
NMSWrapper.impl.setSlotToItemStack(player, o);
}
return o;
};
TinyProtocol.instance.addFilter(setSlotStack, third);
}
@Register(help = true)
public void genericCommand(@Validator Player player) {
if (NOCLIPS.contains(player)) {
NOCLIPS.remove(player);
player.setGameMode(GameMode.CREATIVE);
} else {
player.setGameMode(GameMode.SPECTATOR);
NMSWrapper.impl.setPlayerBuildAbilities(player);
Object gameStateChangeObject = Reflection.newInstance(gameStateChange);
NMSWrapper.impl.setGameStateChangeReason(gameStateChangeObject);
floatFieldAccessor.set(gameStateChangeObject, 1F);
NOCLIPS.add(player);
BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player);
TinyProtocol.instance.sendPacket(player, gameStateChangeObject);
pseudoGameMode(player, GameMode.SPECTATOR);
}
}
@EventHandler
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
event.getNewSpectator().forEach(player -> {
if (NOCLIPS.contains(player)) {
NOCLIPS.remove(player);
player.setGameMode(GameMode.CREATIVE);
}
});
}
@EventHandler(ignoreCancelled = true)
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
if (NOCLIPS.contains(event.getPlayer())) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onBlock(BlockCanBuildEvent event) {
if (NOCLIPS.contains(event.getPlayer())) {
event.setBuildable(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
if (NOCLIPS.contains(event.getPlayer())) {
event.setCancelled(true);
event.getPlayer().setFlying(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (event.getCause() != PlayerTeleportEvent.TeleportCause.SPECTATE) {
return;
}
if (NOCLIPS.contains(event.getPlayer())) {
event.setCancelled(true);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
event.getPlayer().setSpectatorTarget(null);
}, 1L);
}
}
private static void pseudoGameMode(Player player, GameMode gameMode) {
TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), gameMode));
}
}
@@ -0,0 +1,154 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.linkage.Linked;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Piston;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@Linked
public class PistonCalculator implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return;
if (event.getClickedBlock() == null) return;
Block clickedBlock = event.getClickedBlock();
Material blockType = clickedBlock.getType();
if (!(blockType == Material.PISTON || blockType == Material.STICKY_PISTON)) return;
Piston piston = (Piston) clickedBlock.getBlockData();
if (blockType == Material.PISTON && piston.isExtended()) {
BauSystem.MESSAGE.sendPrefixless("PISTON_INFO", event.getPlayer(), ChatMessageType.ACTION_BAR, "§a", 0);
return;
}
boolean pulling = blockType == Material.STICKY_PISTON && (clickedBlock.getRelative(piston.getFacing()).getType() == Material.AIR || piston.isExtended());
CalculationResult result = calc(clickedBlock, piston.getFacing(), (pulling ? piston.getFacing().getOppositeFace() : piston.getFacing()));
result.entityServer.addPlayer(event.getPlayer());
BauSystem.MESSAGE.sendPrefixless("PISTON_INFO", event.getPlayer(), ChatMessageType.ACTION_BAR, result.unmovable ? "§c" : (result.tooMany ? "§e" : "§a"), result.amount);
}
private final BlockFace[] FACES = new BlockFace[]{BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
private CalculationResult calc(Block origin, BlockFace facing, BlockFace direction) {
Set<Block> blockSet = new HashSet<>();
Set<Location> unmovable = new HashSet<>();
Block calcOrigin = origin;
if (facing != direction) calcOrigin = origin.getRelative(facing, 3);
List<Block> toCalc = new LinkedList<>();
calcDirection(origin, null, calcOrigin, facing != direction ? origin.getRelative(facing) : null, facing, direction, blockSet, toCalc, unmovable);
while (!toCalc.isEmpty()) {
Block current = toCalc.remove(0);
blockSet.add(current);
Material type = current.getType();
if (type != Material.SLIME_BLOCK && type != Material.HONEY_BLOCK) continue;
Material oppositeType = type == Material.SLIME_BLOCK ? Material.HONEY_BLOCK : Material.SLIME_BLOCK;
for (BlockFace face : FACES) {
Block block = current.getRelative(face);
if (block.getType().isAir()) continue;
if (!isPiston(block) && (block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getPistonMoveReaction() == PistonMoveReaction.PUSH_ONLY || block.getState() instanceof TileState || block.getPistonMoveReaction() == PistonMoveReaction.BREAK)) continue;
if (block.getType() != oppositeType) {
if (!blockSet.contains(block)) toCalc.add(block);
calcDirection(null, origin, block, null, facing, direction, blockSet, toCalc, unmovable);
}
}
}
blockSet.remove(origin);
if (facing != direction) blockSet.remove(origin.getRelative(facing, 1));
REntityServer entityServer = new REntityServer();
for (Location loc : unmovable) {
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, loc.clone().add(0.5, 0, 0.5), Material.RED_STAINED_GLASS);
rFallingBlockEntity.setGlowing(true);
rFallingBlockEntity.setNoGravity(true);
rFallingBlockEntity.setInvisible(true);
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), entityServer::close, 20);
return new CalculationResult(blockSet.size(), blockSet.size() > 12, !unmovable.isEmpty(), entityServer);
}
private void calcDirection(Block origin, Block blockOrigin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set<Block> blockSet, List<Block> toCalc, Set<Location> unmovable) {
for (int i = 1; i < 24; i++) {
Block block = calcOrigin.getRelative(direction, i);
if (block.equals(ignore)) return;
if (block.getPistonMoveReaction() == PistonMoveReaction.BREAK) return;
if (!isPiston(block) && (block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getState() instanceof TileState)) {
unmovable.add(block.getLocation());
return;
}
if (block.getType().isAir()) return;
if (facing == direction && block.equals(blockOrigin)) {
unmovable.add(block.getLocation());
return;
}
if (facing != direction && (block.equals(origin) || block.getRelative(facing.getOppositeFace()).equals(origin))) return;
if (!blockSet.contains(block)) toCalc.add(block);
}
}
private boolean isPiston(Block block) {
BlockData blockData = block.getBlockData();
if (blockData instanceof Piston) {
return !((Piston) blockData).isExtended();
}
return false;
}
@AllArgsConstructor
@Getter
private static class CalculationResult {
private int amount;
private boolean tooMany;
private boolean unmovable;
private REntityServer entityServer;
}
}
@@ -0,0 +1,40 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class PistonCalculatorCommand extends SWCommand {
public PistonCalculatorCommand() {
super("piston", "pistoncalculator", "pistoncalc");
}
@Register
public void help(@Validator Player player) {
BauSystem.MESSAGE.send("PISTON_HELP_1", player);
BauSystem.MESSAGE.send("PISTON_HELP_2", player);
BauSystem.MESSAGE.send("PISTON_HELP_3", player);
}
}
@@ -0,0 +1,55 @@
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class SelectCommand extends SWCommand {
public SelectCommand() {
super("select");
}
@Register(description = {"SELECT_HELP", "SELECT_EXTENSION_HELP"})
public void baurahmenCommand(@Validator Player p, RegionType regionType, @OptionalValue("NORMAL") RegionExtensionType regionExtensionType) {
Region region = Region.getRegion(p.getLocation());
if (region.isGlobal()) {
BauSystem.MESSAGE.send("SELECT_GLOBAL_REGION", p);
return;
}
if (!region.hasType(regionType)) {
BauSystem.MESSAGE.send("SELECT_NO_TYPE", p, BauSystem.MESSAGE.parse(regionType.getChatValue(), p));
return;
}
if (regionExtensionType == RegionExtensionType.EXTENSION && !region.hasExtensionType(regionType)) {
BauSystem.MESSAGE.send("SELECT_NO_EXTENSION", p);
return;
}
setSelection(regionType, regionExtensionType, region, p);
}
@Register("tb")
public void baurahmenCommand(@Validator Player p, @OptionalValue("NORMAL") RegionExtensionType regionExtensionType) {
baurahmenCommand(p, RegionType.TESTBLOCK, regionExtensionType);
}
private void setSelection(RegionType regionType, RegionExtensionType regionExtensionType, Region region, Player p) {
Point minPoint = region.getMinPoint(regionType, regionExtensionType);
Point maxPoint = region.getMaxPoint(regionType, regionExtensionType);
FlatteningWrapper.impl.setSelection(p, minPoint, maxPoint);
BauSystem.MESSAGE.send("SELECT_MESSAGE", p, minPoint.getX(), minPoint.getY(), minPoint.getZ(), maxPoint.getX(), maxPoint.getY(), maxPoint.getZ());
}
}
@@ -0,0 +1,70 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.List;
import java.util.stream.Collectors;
@Linked
public class SkullCommand extends SWCommand {
public SkullCommand() {
super("skull", "head");
}
@Register(description = "SKULL_HELP")
public void giveCommand(@Validator Player p, @Mapper("player") @ErrorMessage("SKULL_INVALID") String skull) {
ItemStack is = SWItem.getPlayerSkull(skull).getItemStack();
SkullMeta sm = (SkullMeta) is.getItemMeta();
assert sm != null;
sm.setDisplayName(BauSystem.MESSAGE.parse("SKULL_ITEM", p, skull));
is.setItemMeta(sm);
SWUtils.giveItemToPlayer(p, is);
}
@Mapper(value = "player", local = true)
public TypeMapper<String> typeMapper() {
return new TypeMapper<String>() {
@Override
public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
if (s.startsWith(".")) return null;
return s;
}
@Override
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(s1 -> !s1.endsWith("")).collect(Collectors.toList());
}
};
}
}
@@ -0,0 +1,78 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class SlotCommand extends SWCommand {
public SlotCommand() {
super("slot", "s");
addDefaultHelpMessage("OTHER_NOCLIP_SLOT_INFO");
}
@Register
public void slotCommand(@Validator Player player, Integer slot) {
if (slot < 1 || slot > 9) {
BauSystem.MESSAGE.send("OTHER_SLOT_INVALID_SLOT", player);
return;
}
player.getInventory().setHeldItemSlot(slot - 1);
}
@Register(value = "pick", description = "OTHER_NOCLIP_SLOT_HELP_PICK")
public void eyedropBlock(@Validator Player player) {
Block block = player.getTargetBlockExact(6);
ItemStack itemStack;
if (block == null) {
return;
}
itemStack = new ItemStack(block.getType());
SWUtils.giveItemToPlayer(player, itemStack);
}
@Register(value = "drop", description = "OTHER_NOCLIP_SLOT_HELP_DROP")
public void dropBlock(@Validator Player player) {
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
}
@ClassMapper(value = Integer.class, local = true)
private TypeMapper<Integer> integerTypeMapper() {
return SWCommandUtils.createMapper(s -> {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
return null;
}
}, (commandSender, s) -> Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9"));
}
}
@@ -0,0 +1,58 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
@Linked
public class SpeedCommand extends SWCommand {
public SpeedCommand() {
super("speed");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
BauSystem.MESSAGE.sendPrefixless("SPEED_HELP", p);
BauSystem.MESSAGE.send("SPEED_CURRENT", p, (p.getFlySpeed() * 10F));
}
@Register
public void speedCommand(Player p, float speed) {
speed = speed / 10F;
if (speed < -1F) {
BauSystem.MESSAGE.send("SPEED_TOO_SMALL", p, speed);
} else if (speed > 1F) {
BauSystem.MESSAGE.send("SPEED_TOO_HIGH", p, speed);
} else {
p.setFlySpeed(speed);
p.setWalkSpeed(Math.min(speed + 0.1F, 1F));
BauSystem.MESSAGE.send("SPEED_CURRENT", p, (p.getFlySpeed() * 10F));
}
}
@Register({"default"})
public void speedCommand(Player p) {
speedCommand(p, 1);
}
}
@@ -0,0 +1,40 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@Linked
public class StructureVoidCommand extends SWCommand {
public StructureVoidCommand() {
super("structureVoid", "structure", "void", "structurevoid");
}
@Register(description = "STRUCTURE_VOID_COMMAND_HELP")
public void genericCommand(@Validator Player p) {
SWUtils.giveItemToPlayer(p, new ItemStack(Material.STRUCTURE_VOID, 1));
}
}
@@ -0,0 +1,61 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
@Linked
public class TNTClickListener implements Listener {
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
if (event.getHand() != EquipmentSlot.HAND) return;
Entity entity = event.getRightClicked();
if (event.getRightClicked() instanceof TNTPrimed) {
TNTPrimed tntPrimed = (TNTPrimed) entity;
long count = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class).stream().filter(e -> e.getLocation().distanceSquared(tntPrimed.getLocation()) < 0.1).count();
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", event.getPlayer());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ORDER", event.getPlayer(), getOrder(tntPrimed));
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", event.getPlayer(), tntPrimed.getFuseTicks());
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", event.getPlayer(), tntPrimed.getLocation().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", event.getPlayer(), tntPrimed.getLocation().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", event.getPlayer(), tntPrimed.getLocation().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", event.getPlayer(), tntPrimed.getVelocity().getX() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", event.getPlayer(), tntPrimed.getVelocity().getY() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", event.getPlayer(), tntPrimed.getVelocity().getZ() + "");
BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_COUNT", event.getPlayer(), count + "");
}
}
private int getOrder(Entity entity) {
return entity.getEntityId() - entity.getLocation().getWorld().getEntities().stream().filter(TNTPrimed.class::isInstance).map(Entity::getEntityId).min(Integer::compareTo).orElse(0);
}
}
@@ -0,0 +1,66 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.Linked;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import java.util.Random;
@Linked
public class TeleportCommand extends SWCommand {
private static final Random RAND = new Random();
public TeleportCommand() {
super("teleport", "tp");
}
@Register(description = "OTHER_TELEPORT_HELP")
public void genericCommand(Player p, Player target) {
if (p.getUniqueId().equals(target.getUniqueId())) {
BauSystem.MESSAGE.send("OTHER_TELEPORT_SELF_" + RAND.nextInt(5), p);
return;
}
p.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
}
@Register
public void locationCommand(Player p, int x, int y, int z) {
Location l = p.getLocation();
l.setX(x + 0.5);
l.setY(y);
l.setZ(z + 0.5);
p.teleport(l, PlayerTeleportEvent.TeleportCause.COMMAND);
}
@Register
public void locationCommand(Player p, double x, double y, double z) {
Location l = p.getLocation();
l.setX(x);
l.setY(y);
l.setZ(z);
p.teleport(l, PlayerTeleportEvent.TeleportCause.COMMAND);
}
}
@@ -0,0 +1,89 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.command.*;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
@Linked
public class TimeCommand extends SWCommand {
private static final List<String> tabCompletions = Arrays.asList("0", "6000", "12000", "18000");
public TimeCommand() {
super("time");
addDefaultHelpMessage("OTHER_TIME_HELP");
}
@Register
public void genericCommand(@Validator Player p, @OptionalValue("") @StaticValue({"set", ""}) String set, Time time) {
Bukkit.getWorlds().get(0).setTime(time.getValue());
BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p);
}
@Register
public void genericCommand(@Validator Player p, @OptionalValue("") @StaticValue({"set", ""}) String set, int time) {
if (time < 0 || time > 24000) {
BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p);
return;
}
Bukkit.getWorlds().get(0).setTime(time);
BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p);
}
@ClassMapper(value = int.class, local = true)
public TypeMapper<Integer> intTypeMapper() {
return SWCommandUtils.createMapper(s -> {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
return null;
}
}, s -> tabCompletions);
}
public enum Time {
NIGHT(18000),
DAY(6000),
DAWN(0),
SUNSET(12000),
NACHT(18000),
TAG(6000),
MORGEN(0),
ABEND(12000);
private final int value;
Time(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
}
@@ -0,0 +1,55 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class ClearBauGuiItem extends BauGuiItem {
public ClearBauGuiItem() {
super(29);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.BUCKET, BauSystem.MESSAGE.parse("OTHER_ITEMS_CLEAR_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
p.getInventory().clear();
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,55 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class DebugstickBauGuiItem extends BauGuiItem {
public DebugstickBauGuiItem() {
super(12);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.DEBUG_STICK, BauSystem.MESSAGE.parse("DEBUG_STICK_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
p.performCommand("debugstick");
return false;
}
@Override
public Permission permission() {
return Permission.BUILD;
}
}
@@ -0,0 +1,59 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.util.DeclutterCommand;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class DeclutterBauGuiItem extends BauGuiItem {
@LinkedInstance
public DeclutterCommand declutterCommand;
public DeclutterBauGuiItem() {
super(30);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.WATER_BUCKET, BauSystem.MESSAGE.parse("OTHER_ITEMS_DECLUTTER_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
declutterCommand.genericCommand(p);
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,71 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class GamemodeBauGuiItem extends BauGuiItem {
public GamemodeBauGuiItem() {
super(31);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("OTHER_ITEMS_GAMEMODE_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("OTHER_ITEMS_GAMEMODE_LORE_1", player), BauSystem.MESSAGE.parse("OTHER_ITEMS_GAMEMODE_LORE_2", player)), false, clickType -> {}).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
GameMode gameMode = p.getGameMode();
if (click.isRightClick()) {
if (gameMode != GameMode.CREATIVE) {
p.setGameMode(GameMode.CREATIVE);
} else {
p.setGameMode(GameMode.SPECTATOR);
}
} else if (click.isLeftClick()) {
if (gameMode != GameMode.SURVIVAL) {
p.setGameMode(GameMode.SURVIVAL);
} else {
p.setGameMode(GameMode.ADVENTURE);
}
}
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.util.KillAllCommand;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.bausystem.region.utils.RegionSelectionType;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class KillAllBauGuiItem extends BauGuiItem {
@LinkedInstance
public KillAllCommand killAllCommand;
public KillAllBauGuiItem() {
super(32);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.LAVA_BUCKET, BauSystem.MESSAGE.parse("OTHER_ITEMS_KILLALL_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("OTHER_ITEMS_KILLALL_LORE_1", player), BauSystem.MESSAGE.parse("OTHER_ITEMS_KILLALL_LORE_2", player)), false, clickType -> {}).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
if (click.isShiftClick()) {
killAllCommand.genericCommand(p, RegionSelectionType.GLOBAL);
} else {
killAllCommand.genericCommand(p, RegionSelectionType.LOCAL);
}
return false;
}
@Override
public Permission permission() {
return Permission.BUILD;
}
}
@@ -0,0 +1,55 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class NavWandBauGuiItem extends BauGuiItem {
public NavWandBauGuiItem() {
super(27);
}
@Override public Permission permission() {
return Permission.MEMBER;
}
@Override public ItemStack getItem(Player player) {
return new SWItem(Material.COMPASS, BauSystem.MESSAGE.parse("NAVIGATION_WAND", player), Arrays.asList(BauSystem.MESSAGE.parse("NAVIGATION_WAND_LEFT_CLICK", player), BauSystem.MESSAGE.parse("NAVIGATION_WAND_RIGHT_CLICK", player)), false, clickType -> {
}).getItemStack();
}
@Override public boolean click(ClickType click, Player p) {
p.performCommand("/wand -n");
p.closeInventory();
return false;
}
}
@@ -0,0 +1,69 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
@Linked
public class NightVisionBauGuiItem extends BauGuiItem {
public NightVisionBauGuiItem() {
super(11);
}
@Override
public ItemStack getItem(Player player) {
if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
ItemStack itemStack = new ItemStack(Material.POTION);
PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
meta.setColor(PotionEffectType.NIGHT_VISION.getColor());
meta.setDisplayName(BauSystem.MESSAGE.parse("NIGHT_VISION_ITEM_ON", player));
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
meta.setCustomModelData(1);
itemStack.setItemMeta(meta);
return itemStack;
} else {
return SWUtils.setCustomModelData(new SWItem(Material.GLASS_BOTTLE, BauSystem.MESSAGE.parse("NIGHT_VISION_ITEM_OFF", player)), 1).getItemStack();
}
}
@Override
public boolean click(ClickType click, Player p) {
p.performCommand("nv");
return true;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,34 @@
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class SchemBauGuiItem extends BauGuiItem {
public SchemBauGuiItem() {
super(35);
}
@Override
public Permission permission() {
return Permission.BUILD;
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.CHEST, BauSystem.MESSAGE.parse("SCHEMATIC_GUI_ITEM", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.performCommand("schematic gui");
return false;
}
}
@@ -0,0 +1,106 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@Linked
public class SelectBauGuiItem extends BauGuiItem {
private static final Map<Player, LastSelect> LAST_SELECT_MAP = new HashMap<>();
public SelectBauGuiItem() {
super(13);
}
private static void selectExtension(Player p, RegionType type) {
p.closeInventory();
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("SELECT_ITEM_CHOOSE_EXTENSION", p));
inv.setItem(2, new SWItem(Material.END_STONE, BauSystem.MESSAGE.parse("SELECT_ITEM_NORMAL_EXTENSION", p), clickType -> selectFinish(p, type, RegionExtensionType.NORMAL)));
inv.setItem(6, new SWItem(Material.PISTON, BauSystem.MESSAGE.parse("SELECT_ITEM_EXTENDED_EXTENSION", p), clickType -> selectFinish(p, type, RegionExtensionType.EXTENSION)));
inv.open();
}
private static void selectFinish(Player p, RegionType type, RegionExtensionType extensionType) {
p.closeInventory();
LAST_SELECT_MAP.put(p, new LastSelect(type, extensionType));
p.performCommand("select " + type.name() + " " + extensionType.toString());
}
@Override
public ItemStack getItem(Player player) {
LastSelect last = LAST_SELECT_MAP.getOrDefault(player, new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
return new SWItem(Material.SCAFFOLDING, BauSystem.MESSAGE.parse("SELECT_ITEM_SELECT", player), Arrays.asList(BauSystem.MESSAGE.parse("SELECT_ITEM_AUSWAHL", player, BauSystem.MESSAGE.parse(last.type.getChatValue(), player), last.extensionType.name()), BauSystem.MESSAGE.parse("SELECT_ITEM_RIGHT_CLICK", player)), false, clickType -> {
}).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
if (click == ClickType.RIGHT) {
p.closeInventory();
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("SELECT_ITEM_CHOOSE_SELECTION", p));
inv.setItem(2, new SWItem(Material.REDSTONE_BLOCK, BauSystem.MESSAGE.parse("SELECT_ITEM_BAURAHMEN", p), clickType -> selectExtension(p, RegionType.BUILD)));
inv.setItem(4, new SWItem(Material.LECTERN, BauSystem.MESSAGE.parse("SELECT_ITEM_BAUPLATTFORM", p), clickType -> selectFinish(p, RegionType.NORMAL, RegionExtensionType.NORMAL)));
inv.setItem(6, new SWItem(Material.END_STONE, BauSystem.MESSAGE.parse("SELECT_ITEM_TESTBLOCK", p), clickType -> selectExtension(p, RegionType.TESTBLOCK)));
inv.open();
} else {
p.closeInventory();
LastSelect last = LAST_SELECT_MAP.getOrDefault(p, new LastSelect(RegionType.BUILD, RegionExtensionType.NORMAL));
p.performCommand("select " + last.getType().name() + " " + last.getExtensionType().toString());
}
return false;
}
@Override
public Permission permission() {
return Permission.BUILD;
}
@AllArgsConstructor
private static class LastSelect {
@Getter
private final RegionType type;
@Getter
private final RegionExtensionType extensionType;
@Override
public String toString() {
return type.getChatValue() + " " + extensionType.name().toLowerCase(Locale.ROOT);
}
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@Linked
public class SkullBauGuiItem extends BauGuiItem {
public SkullBauGuiItem() {
super(16);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.PLAYER_HEAD, BauSystem.MESSAGE.parse("SKULL_GUI_ITEM_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
SWAnvilInv inv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("ANVIL_INV_NAME",p));
inv.setItem(Material.NAME_TAG);
inv.setCallback(s -> p.performCommand("skull " + s));
inv.open();
return false;
}
@Override
public Permission permission() {
return Permission.BUILD;
}
}
@@ -0,0 +1,62 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class SpeedBauGuiItem extends BauGuiItem {
public SpeedBauGuiItem() {
super(17);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.SUGAR, BauSystem.MESSAGE.parse("SPEED_ITEM", player), Arrays.asList(BauSystem.MESSAGE.parse("SPEED_ITEM_LORE", player) + player.getFlySpeed() * 10f), false, clickType -> {
}).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
SWAnvilInv inv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("SPEED_TAB_NAME", p));
inv.setItem(Material.SUGAR);
inv.setCallback(s -> p.performCommand("speed " + s));
inv.open();
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
@Linked
public class TeleportBauGuiItem extends BauGuiItem {
public TeleportBauGuiItem() {
super(10);
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.ENDER_PEARL, BauSystem.MESSAGE.parse("OTHER_ITEMS_TELEPORT_NAME", player)).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
SWListInv<UUID> inv = new SWListInv<>(p, BauSystem.MESSAGE.parse("OTHER_ITEMS_TELEPORT_GUI_NAME", p), SWListInv.createPlayerList(p.getUniqueId()), (clickType, o) -> {
Player t = Bukkit.getPlayer(o);
if (t == null) {
BauSystem.MESSAGE.send("OTHER_ITEMS_TELEPORT_PLAYER_OFFLINE", p);
} else {
p.performCommand("tp " + t.getName());
}
});
inv.open();
return false;
}
@Override
public Permission permission() {
return Permission.MEMBER;
}
}
@@ -0,0 +1,58 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.util.items;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Arrays;
@Linked
public class WorldEditBauGuiItem extends BauGuiItem {
public WorldEditBauGuiItem() {
super(26);
}
@Override
public Permission permission() {
return Permission.BUILD;
}
@Override
public ItemStack getItem(Player player) {
return new SWItem(Material.WOODEN_AXE, BauSystem.MESSAGE.parse("WORLDEDIT_WAND", player), Arrays.asList(BauSystem.MESSAGE.parse("WORLDEDIT_LEFTCLICK", player), BauSystem.MESSAGE.parse("WORLDEDIT_RIGHTCLICK", player)), false, clickType -> {
}).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.performCommand("/wand");
p.closeInventory();
return false;
}
}