13
0

Add Punishments #100

Zusammengeführt
Chaoscaot hat 8 Commits von punishments nach master 2022-01-29 15:06:49 +01:00 zusammengeführt
6 geänderte Dateien mit 139 neuen und 7 gelöschten Zeilen
Nur Änderungen aus Commit 897fdba6bb werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.command.TypeMapper;
import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SchematicSelector; import de.steamwar.inventory.SchematicSelector;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.providers.BauSystemProvider;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
@ -134,11 +135,17 @@ public class SchematicCommand extends SWCommand {
@Register("save") @Register("save")
@Register("s") @Register("s")
public void saveSchem(Player player, @Mapper("dirStringMapper") String name) { 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("/")) { if (name.endsWith("/")) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu must auch einen Namen für die Schematic nach dem Ordner angeben"); player.sendMessage(SchematicSystem.PREFIX + "§cDu must auch einen Namen für die Schematic nach dem Ordner angeben");
return; return;
} }
SteamwarUser user = getUser(player);
if (name.startsWith("/")) name = name.substring(1); if (name.startsWith("/")) name = name.substring(1);
String[] layers = name.split("/"); String[] layers = name.split("/");
if (invalidSchemName(player, layers)) return; 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.AutoCheckResult;
import de.steamwar.schematicsystem.CheckSchemType; import de.steamwar.schematicsystem.CheckSchemType;
import de.steamwar.schematicsystem.SchematicSystem; import de.steamwar.schematicsystem.SchematicSystem;
import de.steamwar.schematicsystem.providers.BauSystemProvider;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent; 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<Player> PUBLIC_TOGGLED = new ArrayList<>();
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public")); private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
private SchematicCommandUtils() {} private SchematicCommandUtils() {
}
public static boolean invalidSchemName(Player player, String[] layers) { public static boolean invalidSchemName(Player player, String[] layers) {
for (String layer : layers) { for (String layer : layers) {
@ -292,6 +294,13 @@ public class SchematicCommandUtils {
} }
public static void loadSchem(Player player, SchematicNode node) { 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()) { if (node.isDir()) {
player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden"); player.sendMessage(SchematicSystem.PREFIX + "§cDu kannst keine Ordner Laden");
return; return;

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" version: "2.0"
authors: [Yaruma3341, Lixfel, Chaoscaot] authors: [Yaruma3341, Lixfel, Chaoscaot]
depend: [SpigotCore, WorldEdit] depend: [SpigotCore, WorldEdit]
softdepend: [BauSystem]
main: de.steamwar.schematicsystem.SchematicSystem main: de.steamwar.schematicsystem.SchematicSystem
website: steamwar.de website: steamwar.de
api-version: "1.13" api-version: "1.13"