diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java index 0f8d83b..c9605f5 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommand.java @@ -24,6 +24,7 @@ import de.steamwar.command.TypeMapper; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SchematicSelector; import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.schematicsystem.providers.BauSystemProvider; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; @@ -134,11 +135,17 @@ public class SchematicCommand extends SWCommand { @Register("save") @Register("s") public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { + SteamwarUser user = getUser(player); + if((Punishment.isPunished(user, Punishment.PunishmentType.NoSchemReceiving, punishment -> player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst hier keine Schematics laden")) || + Punishment.isPunished(SteamwarUser.get(BauSystemProvider.use(BauSystemProvider::getOwner, 0)), Punishment.PunishmentType.NoSchemSharing, punishment -> player.sendMessage(SchematicSystem.PREFIX + "§cAuf diesem Bau kannst du keine Schematics speichern"))) && + Boolean.TRUE.equals(BauSystemProvider.use(bauSystemProvider -> bauSystemProvider.getOwner() != user.getId(), false))) { + player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst hier keine Schematics speichern"); + return; + } if (name.endsWith("/")) { player.sendMessage(SchematicSystem.PREFIX + "§cDu must auch einen Namen für die Schematic nach dem Ordner angeben"); return; } - SteamwarUser user = getUser(player); if (name.startsWith("/")) name = name.substring(1); String[] layers = name.split("/"); if (invalidSchemName(player, layers)) return; diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index ad71001..43e56e4 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -25,6 +25,7 @@ import de.steamwar.inventory.SWItem; import de.steamwar.schematicsystem.AutoCheckResult; import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.SchematicSystem; +import de.steamwar.schematicsystem.providers.BauSystemProvider; import de.steamwar.sql.*; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; @@ -45,7 +46,8 @@ public class SchematicCommandUtils { private static final List PUBLIC_TOGGLED = new ArrayList<>(); private static final List FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public")); - private SchematicCommandUtils() {} + private SchematicCommandUtils() { + } public static boolean invalidSchemName(Player player, String[] layers) { for (String layer : layers) { @@ -65,7 +67,7 @@ public class SchematicCommandUtils { player.sendMessage(SchematicSystem.PREFIX + "§cDer angegebene Schematicname enthält verbotene Zeichen"); return true; } - if(FORBIDDEN_NAMES.contains(layer.toLowerCase())) { + if (FORBIDDEN_NAMES.contains(layer.toLowerCase())) { player.sendMessage(SchematicSystem.PREFIX + "§cDer Pfad darf nicht \"§l" + layer + "§c\" enthalten"); return true; } @@ -236,7 +238,7 @@ public class SchematicCommandUtils { base.addExtra(rename); } - TextComponent delete = new TextComponent("[" + (node.getOwner()==user.getId()?"Löschen":"Entfernen") + "] "); + TextComponent delete = new TextComponent("[" + (node.getOwner() == user.getId() ? "Löschen" : "Entfernen") + "] "); delete.setColor(ChatColor.DARK_RED); delete.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("§e" + (node.isDir() ? "Ordner" : "Schematic") + " Löschen"))); delete.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem delete " + node.generateBreadcrumbs(user))); @@ -292,6 +294,13 @@ public class SchematicCommandUtils { } public static void loadSchem(Player player, SchematicNode node) { + SteamwarUser user = getUser(player); + if ((Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst hier keine Schematics laden")) && + Boolean.TRUE.equals(BauSystemProvider.use(bauSystemProvider -> bauSystemProvider.getOwner() != user.getId(), false))) || + (Boolean.TRUE.equals(BauSystemProvider.use(bauSystemProvider -> bauSystemProvider.getOwner() != user.getId(), false)) && + Punishment.isPunished(BauSystemProvider.use(bauSystemProvider -> SteamwarUser.get(bauSystemProvider.getOwner()), user), Punishment.PunishmentType.NoSchemSharing, punishment -> player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst auf diesem Bau keine Schematics laden")))) { + return; + } if (node.isDir()) { player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden"); return; @@ -311,7 +320,7 @@ public class SchematicCommandUtils { public static void download(Player player, SchematicNode node) { SteamwarUser user = getUser(player); - if(Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> { + if (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSharing, punishment -> { player.sendMessage(SchematicSystem.PREFIX + "§cDu darf keine Schematics Downloaden: §f§l" + punishment.getReason()); })) { return; @@ -327,7 +336,7 @@ public class SchematicCommandUtils { public static void changeType(Player player, SchematicNode node, SchematicType type, SchematicCommand.Extend extend) { SteamwarUser user = getUser(player); - if(Punishment.isPunished(user, + if (Punishment.isPunished(user, Punishment.PunishmentType.NoSchemSubmitting, punishment -> player.sendMessage(SchematicSystem.PREFIX + "§cDu darf keine Schematics einsenden: §f§l: " + punishment.getReason()))) { return; @@ -342,7 +351,7 @@ public class SchematicCommandUtils { return; } - if(!type.isAssignable()) { + if (!type.isAssignable()) { player.sendMessage(SchematicSystem.PREFIX + "§cZu diesem Typen können keine Schematics geändert werden."); } diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/BauSystemProvider.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/BauSystemProvider.java new file mode 100644 index 0000000..fa3120c --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/BauSystemProvider.java @@ -0,0 +1,56 @@ +package de.steamwar.schematicsystem.providers; + +import de.steamwar.schematicsystem.providers.impl.*; +import org.bukkit.Bukkit; + +import java.util.function.Consumer; +import java.util.function.Function; + +public interface BauSystemProvider { + + static T use(Function function, T def) { + return BauSystemProviderImplementor.use(function, def); + } + + static void use(Consumer consumer) { + BauSystemProviderImplementor.use(consumer); + } + + int getOwner(); + + class BauSystemProviderImplementor { + private BauSystemProviderImplementor() {} + + static boolean hasBausystem; + static BauSystemProvider bauSystemProvider; + + static { + try { + Class.forName("de.steamwar.bausystem.BauSystem"); + hasBausystem = true; + switch (Bukkit.getPluginManager().getPlugin("BauSystem").getDescription().getVersion()) { + case "2.0": + bauSystemProvider = new BauSystem2Provider(); + break; + case "1.0": + bauSystemProvider = new BauSystem1Provider(); + break; + default: + hasBausystem = false; + } + } catch (Exception e) { + hasBausystem = false; + } + } + + static T use(Function function, T def) { + if(!hasBausystem) return def; + return function.apply(bauSystemProvider); + } + + static void use(Consumer consumer) { + if(!hasBausystem) return; + consumer.accept(bauSystemProvider); + } + } +} diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem1Provider.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem1Provider.java new file mode 100644 index 0000000..50c966c --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem1Provider.java @@ -0,0 +1,28 @@ +package de.steamwar.schematicsystem.providers.impl; + +import de.steamwar.schematicsystem.providers.BauSystemProvider; + +import java.lang.reflect.Method; + +public class BauSystem1Provider implements BauSystemProvider { + + private static final Method BAUSYSTEM_GET_OWNER_ID; + + static { + try { + Class bausystem = Class.forName("de.steamwar.bausystem.BauSystem"); + BAUSYSTEM_GET_OWNER_ID = bausystem.getDeclaredMethod("getOwnerID"); + } catch (Exception e) { + throw new SecurityException(e); + } + } + + @Override + public int getOwner() { + try { + return (int) BAUSYSTEM_GET_OWNER_ID.invoke(null); + } catch (Exception e) { + throw new SecurityException(e); + } + } +} diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem2Provider.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem2Provider.java new file mode 100644 index 0000000..7e807cb --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/providers/impl/BauSystem2Provider.java @@ -0,0 +1,31 @@ +package de.steamwar.schematicsystem.providers.impl; + +import de.steamwar.schematicsystem.providers.BauSystemProvider; + +import java.lang.reflect.Method; + +public class BauSystem2Provider implements BauSystemProvider { + + private static final Method BAU_SERVER_GET_OWNER_ID; + private static final Object BAU_SERVER_INSTANCE; + + static { + try { + Class bauServer = Class.forName("de.steamwar.bausystem.config.BauServer"); + Method bauServerGet = bauServer.getDeclaredMethod("getInstance"); + BAU_SERVER_GET_OWNER_ID = bauServer.getMethod("getOwnerID"); + BAU_SERVER_INSTANCE = bauServerGet.invoke(null); + } catch (Exception e) { + throw new SecurityException(e); + } + } + + @Override + public int getOwner() { + try { + return (int) BAU_SERVER_GET_OWNER_ID.invoke(BAU_SERVER_INSTANCE); + } catch (Exception e) { + throw new SecurityException(e); + } + } +} diff --git a/SchematicSystem_Core/src/plugin.yml b/SchematicSystem_Core/src/plugin.yml index 457fdd9..c5d64da 100644 --- a/SchematicSystem_Core/src/plugin.yml +++ b/SchematicSystem_Core/src/plugin.yml @@ -2,6 +2,7 @@ name: SchematicSystem version: "2.0" authors: [Yaruma3341, Lixfel, Chaoscaot] depend: [SpigotCore, WorldEdit] +softdepend: [BauSystem] main: de.steamwar.schematicsystem.SchematicSystem website: steamwar.de api-version: "1.13"