13
0

Add a butt ton of Code for BauSystem
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaos 2022-01-27 21:17:50 +01:00
Ursprung e58ad971f6
Commit 897fdba6bb
6 geänderte Dateien mit 139 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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<Player> PUBLIC_TOGGLED = new ArrayList<>();
private static final List<String> 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.");
}

Datei anzeigen

@ -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> T use(Function<BauSystemProvider, T> function, T def) {
return BauSystemProviderImplementor.use(function, def);
}
static void use(Consumer<BauSystemProvider> 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> T use(Function<BauSystemProvider, T> function, T def) {
if(!hasBausystem) return def;
return function.apply(bauSystemProvider);
}
static void use(Consumer<BauSystemProvider> consumer) {
if(!hasBausystem) return;
consumer.accept(bauSystemProvider);
}
}
}

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

@ -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"