From e5541c55e36dee95b63a4fe4ac65ceadf3b8a325 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 11 Jul 2021 17:52:47 +0200 Subject: [PATCH] Add WorldEditListener Signed-off-by: yoyosource --- .../features/world/WorldEditListener_15.java | 33 +++++++++++ .../features/world/WorldEditListener.java | 56 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/features/world/WorldEditListener_15.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/world/WorldEditListener_15.java b/BauSystem_15/src/de/steamwar/bausystem/features/world/WorldEditListener_15.java new file mode 100644 index 00000000..031034ed --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/features/world/WorldEditListener_15.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.world; + +import com.sk89q.worldedit.WorldEdit; + +public class WorldEditListener_15 { + + static boolean isWorldEditCommand(String command) { + if (command.startsWith("/")) { + command = command.replaceFirst("/", ""); + } + command = command.toLowerCase(); + return WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getCommandManager().containsCommand(command); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java new file mode 100644 index 00000000..b234b483 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -0,0 +1,56 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.world; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.core.VersionedCallable; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +@Linked(LinkageType.LISTENER) +public class WorldEditListener implements Listener { + + @EventHandler + public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent e) { + if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return; + + Player p = e.getPlayer(); + + if (!Permission.hasPermission(p, Permission.WORLDEDIT)) { + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier kein WorldEdit benutzen"); + e.setCancelled(true); + } + } + + private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"}; + + private boolean isWorldEditCommand(String command) { + for (String shortcut : shortcutCommands) { + if (command.startsWith(shortcut)) return true; + } + + return VersionedCallable.call(new VersionedCallable<>(() -> WorldEditListener_15.isWorldEditCommand(command), 15)); + } +}