better crossplatform method init

This commit is contained in:
Flemmli97 2022-02-27 17:25:31 +01:00
parent 174d6b64f0
commit 72411f6f2f
29 changed files with 172 additions and 188 deletions

View File

@ -1,3 +1,7 @@
Flan 1.7.3
================
- Internal changes
Flan 1.7.2 Flan 1.7.2
================ ================
- Internal changes - Internal changes

View File

@ -2,11 +2,15 @@ package io.github.flemmli97.flan;
import io.github.flemmli97.flan.api.permission.PermissionRegistry; import io.github.flemmli97.flan.api.permission.PermissionRegistry;
import io.github.flemmli97.flan.config.ConfigHandler; import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.platform.ClaimPermissionCheck;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays;
public class Flan { public class Flan {
@ -33,4 +37,32 @@ public class Flan {
public static void error(String msg, Object... o) { public static void error(String msg, Object... o) {
Flan.logger.error(msg, o); Flan.logger.error(msg, o);
} }
@SuppressWarnings("unchecked")
public static <T> T getPlatformInstance(Class<T> abstractClss, String... impls) {
if(impls == null || impls.length == 0)
throw new IllegalStateException("Couldn't create an instance of " + abstractClss + ". No implementations provided!");
Class<?> clss = null;
int i = 0;
while(clss == null && i < impls.length) {
try {
clss = Class.forName(impls[i]);
} catch (ClassNotFoundException ignored) {
}
i++;
}
if(clss == null)
Flan.logger.fatal("No Implementation of " + abstractClss + " found with given paths " + Arrays.toString(impls));
if (clss != null && abstractClss.isAssignableFrom(clss)) {
try {
Constructor<T> constructor = (Constructor<T>) clss.getDeclaredConstructor();
return constructor.newInstance();
} catch (NoSuchMethodException e) {
Flan.logger.fatal("Implementation of " + clss + " needs to provide an no arg constructor");
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
throw new IllegalStateException("Couldn't create an instance of " + abstractClss);
}
} }

View File

@ -56,10 +56,10 @@ public class ObjectToPermissionMap {
public static void reload(MinecraftServer server) { public static void reload(MinecraftServer server) {
blockToPermission.clear(); blockToPermission.clear();
itemToPermission.clear(); itemToPermission.clear();
for (Block block : CrossPlatformStuff.instance().registryBlocks().getIterator()) { for (Block block : CrossPlatformStuff.INSTANCE.registryBlocks().getIterator()) {
blockPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(block)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> blockToPermission.put(block, sub.get())); blockPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(block)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> blockToPermission.put(block, sub.get()));
} }
for (Item item : CrossPlatformStuff.instance().registryItems().getIterator()) { for (Item item : CrossPlatformStuff.INSTANCE.registryItems().getIterator()) {
itemPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(item)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> itemToPermission.put(item, sub.get())); itemPermissionBuilder.entrySet().stream().filter(e -> e.getKey().test(item)).map(Map.Entry::getValue).findFirst().ifPresent(sub -> itemToPermission.put(item, sub.get()));
} }
for (String s : ConfigHandler.config.itemPermission) { for (String s : ConfigHandler.config.itemPermission) {
@ -77,9 +77,9 @@ public class ObjectToPermissionMap {
} }
} else { } else {
if (remove) if (remove)
itemToPermission.remove(CrossPlatformStuff.instance().registryItems().getFromId(new ResourceLocation(sub[0]))); itemToPermission.remove(CrossPlatformStuff.INSTANCE.registryItems().getFromId(new ResourceLocation(sub[0])));
else else
itemToPermission.put(CrossPlatformStuff.instance().registryItems().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1])); itemToPermission.put(CrossPlatformStuff.INSTANCE.registryItems().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1]));
} }
} }
for (String s : ConfigHandler.config.blockPermission) { for (String s : ConfigHandler.config.blockPermission) {
@ -96,9 +96,9 @@ public class ObjectToPermissionMap {
}); });
} else { } else {
if (remove) if (remove)
blockToPermission.remove(CrossPlatformStuff.instance().registryBlocks().getFromId(new ResourceLocation(sub[0]))); blockToPermission.remove(CrossPlatformStuff.INSTANCE.registryBlocks().getFromId(new ResourceLocation(sub[0])));
else else
blockToPermission.put(CrossPlatformStuff.instance().registryBlocks().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1])); blockToPermission.put(CrossPlatformStuff.INSTANCE.registryBlocks().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1]));
} }
} }
} }

View File

@ -268,7 +268,7 @@ public class Claim implements IPermissionContainer {
perm = PermissionRegistry.FAKEPLAYER; perm = PermissionRegistry.FAKEPLAYER;
} }
} }
InteractionResult res = ClaimPermissionCheck.instance().check(player, perm, pos); InteractionResult res = ClaimPermissionCheck.INSTANCE.check(player, perm, pos);
if (res != InteractionResult.PASS) if (res != InteractionResult.PASS)
return res != InteractionResult.FAIL; return res != InteractionResult.FAIL;
if (perm != null) { if (perm != null) {
@ -634,7 +634,7 @@ public class Claim implements IPermissionContainer {
else else
this.leaveSubtitle = null; this.leaveSubtitle = null;
JsonObject potion = ConfigHandler.fromJson(obj, "Potions"); JsonObject potion = ConfigHandler.fromJson(obj, "Potions");
potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.instance().registryStatusEffects().getFromId(new ResourceLocation(e.getKey())), e.getValue().getAsInt())); potion.entrySet().forEach(e -> this.potions.put(CrossPlatformStuff.INSTANCE.registryStatusEffects().getFromId(new ResourceLocation(e.getKey())), e.getValue().getAsInt()));
if (ConfigHandler.fromJson(obj, "AdminClaim", false)) if (ConfigHandler.fromJson(obj, "AdminClaim", false))
this.owner = null; this.owner = null;
else else
@ -704,7 +704,7 @@ public class Claim implements IPermissionContainer {
obj.addProperty("LeaveTitle", this.leaveTitle == null ? "" : Component.Serializer.toJson(this.leaveTitle)); obj.addProperty("LeaveTitle", this.leaveTitle == null ? "" : Component.Serializer.toJson(this.leaveTitle));
obj.addProperty("LeaveSubtitle", this.leaveSubtitle == null ? "" : Component.Serializer.toJson(this.leaveSubtitle)); obj.addProperty("LeaveSubtitle", this.leaveSubtitle == null ? "" : Component.Serializer.toJson(this.leaveSubtitle));
JsonObject potions = new JsonObject(); JsonObject potions = new JsonObject();
this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.instance().registryStatusEffects().getIDFrom(effect).toString(), amp)); this.potions.forEach((effect, amp) -> potions.addProperty(CrossPlatformStuff.INSTANCE.registryStatusEffects().getIDFrom(effect).toString(), amp));
obj.add("Potions", potions); obj.add("Potions", potions);
if (this.parent != null) if (this.parent != null)
obj.addProperty("Parent", this.parent.toString()); obj.addProperty("Parent", this.parent.toString());

View File

@ -90,7 +90,7 @@ public class ClaimStorage implements IPermissionStorage {
player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("minClaimSize"), ConfigHandler.config.minClaimsize), ChatFormatting.RED), false); player.displayClientMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("minClaimSize"), ConfigHandler.config.minClaimsize), ChatFormatting.RED), false);
return false; return false;
} }
if (!data.isAdminIgnoreClaim() && ConfigHandler.config.maxClaims != -1 && !PermissionNodeHandler.instance().permBelowEqVal(player, PermissionNodeHandler.permMaxClaims, this.playerClaimMap.getOrDefault(player.getUUID(), Sets.newHashSet()).size() + 1, ConfigHandler.config.maxClaims)) { if (!data.isAdminIgnoreClaim() && ConfigHandler.config.maxClaims != -1 && !PermissionNodeHandler.INSTANCE.permBelowEqVal(player, PermissionNodeHandler.permMaxClaims, this.playerClaimMap.getOrDefault(player.getUUID(), Sets.newHashSet()).size() + 1, ConfigHandler.config.maxClaims)) {
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("maxClaims"), ChatFormatting.RED), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("maxClaims"), ChatFormatting.RED), false);
return false; return false;
} }

View File

@ -52,46 +52,46 @@ public class CommandClaim {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean dedicated) { public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean dedicated) {
LiteralArgumentBuilder<CommandSourceStack> builder = Commands.literal("flan") LiteralArgumentBuilder<CommandSourceStack> builder = Commands.literal("flan")
.then(Commands.literal("reload").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdReload, true)).executes(CommandClaim::reloadConfig)) .then(Commands.literal("reload").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdReload, true)).executes(CommandClaim::reloadConfig))
.then(Commands.literal("addClaim").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.claimCreate)) .then(Commands.literal("addClaim").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.claimCreate))
.then(Commands.argument("from", BlockPosArgument.blockPos()).then(Commands.argument("to", BlockPosArgument.blockPos()).executes(CommandClaim::addClaim))) .then(Commands.argument("from", BlockPosArgument.blockPos()).then(Commands.argument("to", BlockPosArgument.blockPos()).executes(CommandClaim::addClaim)))
.then(Commands.literal("all").executes(CommandClaim::addClaimAll)) .then(Commands.literal("all").executes(CommandClaim::addClaimAll))
.then(Commands.literal("rect").then(Commands.argument("x", IntegerArgumentType.integer()).then(Commands.argument("z", IntegerArgumentType.integer()).executes(ctx -> CommandClaim.addClaimRect(ctx, IntegerArgumentType.getInteger(ctx, "x"), IntegerArgumentType.getInteger(ctx, "z"))))))) .then(Commands.literal("rect").then(Commands.argument("x", IntegerArgumentType.integer()).then(Commands.argument("z", IntegerArgumentType.integer()).executes(ctx -> CommandClaim.addClaimRect(ctx, IntegerArgumentType.getInteger(ctx, "x"), IntegerArgumentType.getInteger(ctx, "z")))))))
.then(Commands.literal("menu").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdMenu)).executes(CommandClaim::openMenu)) .then(Commands.literal("menu").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdMenu)).executes(CommandClaim::openMenu))
.then(Commands.literal("setHome").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdHome)).executes(CommandClaim::setClaimHome)) .then(Commands.literal("setHome").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdHome)).executes(CommandClaim::setClaimHome))
.then(Commands.literal("trapped").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTrapped)).executes(CommandClaim::trapped)) .then(Commands.literal("trapped").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTrapped)).executes(CommandClaim::trapped))
.then(Commands.literal("name").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdName)).then(Commands.argument("name", StringArgumentType.string()).executes(CommandClaim::nameClaim))) .then(Commands.literal("name").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdName)).then(Commands.argument("name", StringArgumentType.string()).executes(CommandClaim::nameClaim)))
.then(Commands.literal("unlockDrops").executes(CommandClaim::unlockDrops) .then(Commands.literal("unlockDrops").executes(CommandClaim::unlockDrops)
.then(Commands.argument("players", GameProfileArgument.gameProfile()).requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdUnlockAll, true)).executes(CommandClaim::unlockDropsPlayers))) .then(Commands.argument("players", GameProfileArgument.gameProfile()).requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdUnlockAll, true)).executes(CommandClaim::unlockDropsPlayers)))
.then(Commands.literal("personalGroups").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdPGroup)).executes(CommandClaim::openPersonalGroups)) .then(Commands.literal("personalGroups").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdPGroup)).executes(CommandClaim::openPersonalGroups))
.then(Commands.literal("claimInfo").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdInfo)).executes(ctx -> CommandClaim.claimInfo(ctx, Claim.InfoType.ALL)) .then(Commands.literal("claimInfo").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdInfo)).executes(ctx -> CommandClaim.claimInfo(ctx, Claim.InfoType.ALL))
.then(Commands.argument("type", StringArgumentType.word()).suggests((src, b) -> CommandHelpers.enumSuggestion(Claim.InfoType.class, b)).executes(CommandClaim::claimInfo))) .then(Commands.argument("type", StringArgumentType.word()).suggests((src, b) -> CommandHelpers.enumSuggestion(Claim.InfoType.class, b)).executes(CommandClaim::claimInfo)))
.then(Commands.literal("transferClaim").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTransfer)).then(Commands.argument("player", GameProfileArgument.gameProfile()).executes(CommandClaim::transferClaim))) .then(Commands.literal("transferClaim").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTransfer)).then(Commands.argument("player", GameProfileArgument.gameProfile()).executes(CommandClaim::transferClaim)))
.then(Commands.literal("delete").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteClaim)) .then(Commands.literal("delete").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteClaim))
.then(Commands.literal("deleteAll").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteAllClaim)) .then(Commands.literal("deleteAll").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteAllClaim))
.then(Commands.literal("deleteSubClaim").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteSubClaim)) .then(Commands.literal("deleteSubClaim").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteSubClaim))
.then(Commands.literal("deleteAllSubClaims").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteAllSubClaim)) .then(Commands.literal("deleteAllSubClaims").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTransfer)).executes(CommandClaim::deleteAllSubClaim))
.then(Commands.literal("list").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdList)).executes(CommandClaim::listClaims).then(Commands.argument("player", GameProfileArgument.gameProfile()).requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdListAll, true)) .then(Commands.literal("list").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdList)).executes(CommandClaim::listClaims).then(Commands.argument("player", GameProfileArgument.gameProfile()).requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdListAll, true))
.executes(cmd -> listClaims(cmd, GameProfileArgument.getGameProfiles(cmd, "player"))))) .executes(cmd -> listClaims(cmd, GameProfileArgument.getGameProfiles(cmd, "player")))))
.then(Commands.literal("switchMode").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdClaimMode)).executes(CommandClaim::switchClaimMode)) .then(Commands.literal("switchMode").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdClaimMode)).executes(CommandClaim::switchClaimMode))
.then(Commands.literal("adminMode").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdAdminMode, true)).executes(CommandClaim::switchAdminMode)) .then(Commands.literal("adminMode").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdAdminMode, true)).executes(CommandClaim::switchAdminMode))
.then(Commands.literal("readGriefPrevention").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdGriefPrevention, true)).executes(CommandClaim::readGriefPreventionData)) .then(Commands.literal("readGriefPrevention").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdGriefPrevention, true)).executes(CommandClaim::readGriefPreventionData))
.then(Commands.literal("setAdminClaim").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdAdminSet, true)).then(Commands.argument("toggle", BoolArgumentType.bool()).executes(CommandClaim::toggleAdminClaim))) .then(Commands.literal("setAdminClaim").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdAdminSet, true)).then(Commands.argument("toggle", BoolArgumentType.bool()).executes(CommandClaim::toggleAdminClaim)))
.then(Commands.literal("listAdminClaims").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdAdminList, true)).executes(CommandClaim::listAdminClaims)) .then(Commands.literal("listAdminClaims").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdAdminList, true)).executes(CommandClaim::listAdminClaims))
.then(Commands.literal("adminDelete").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdAdminDelete, true)).executes(CommandClaim::adminDelete) .then(Commands.literal("adminDelete").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdAdminDelete, true)).executes(CommandClaim::adminDelete)
.then(Commands.literal("all").then(Commands.argument("players", GameProfileArgument.gameProfile()) .then(Commands.literal("all").then(Commands.argument("players", GameProfileArgument.gameProfile())
.executes(CommandClaim::adminDeleteAll)))) .executes(CommandClaim::adminDeleteAll))))
.then(Commands.literal("giveClaimBlocks").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdAdminGive, true)).then(Commands.argument("players", GameProfileArgument.gameProfile()) .then(Commands.literal("giveClaimBlocks").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdAdminGive, true)).then(Commands.argument("players", GameProfileArgument.gameProfile())
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks)))) .then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))))
.then(Commands.literal("buyBlocks").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdBuy, false)) .then(Commands.literal("buyBlocks").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdBuy, false))
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::buyClaimBlocks))) .then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::buyClaimBlocks)))
.then(Commands.literal("sellBlocks").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdSell, false)) .then(Commands.literal("sellBlocks").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdSell, false))
.then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::sellClaimBlocks))) .then(Commands.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::sellClaimBlocks)))
.then(Commands.literal("claimMessage").then(Commands.argument("type", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"enter", "leave"}, b)) .then(Commands.literal("claimMessage").then(Commands.argument("type", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"enter", "leave"}, b))
.then(Commands.argument("title", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"title", "subtitle"}, b)) .then(Commands.argument("title", StringArgumentType.word()).suggests((ctx, b) -> SharedSuggestionProvider.suggest(new String[]{"title", "subtitle"}, b))
.then(Commands.literal("text").then(Commands.argument("component", ComponentArgument.textComponent()).executes(ctx -> CommandClaim.editClaimMessages(ctx, ComponentArgument.getComponent(ctx, "component"))))) .then(Commands.literal("text").then(Commands.argument("component", ComponentArgument.textComponent()).executes(ctx -> CommandClaim.editClaimMessages(ctx, ComponentArgument.getComponent(ctx, "component")))))
.then(Commands.literal("string").then(Commands.argument("message", StringArgumentType.string()).executes(CommandClaim::editClaimMessages)))))) .then(Commands.literal("string").then(Commands.argument("message", StringArgumentType.string()).executes(CommandClaim::editClaimMessages))))))
.then(Commands.literal("group").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdGroup)) .then(Commands.literal("group").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdGroup))
.then(Commands.literal("add").then(Commands.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup))) .then(Commands.literal("add").then(Commands.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup)))
.then(Commands.literal("remove").then(Commands.argument("group", StringArgumentType.string()) .then(Commands.literal("remove").then(Commands.argument("group", StringArgumentType.string())
.suggests(CommandHelpers::groupSuggestion).executes(CommandClaim::removeGroup))) .suggests(CommandHelpers::groupSuggestion).executes(CommandClaim::removeGroup)))
@ -111,14 +111,14 @@ public class CommandClaim {
} }
return SharedSuggestionProvider.suggest(list, build); return SharedSuggestionProvider.suggest(list, build);
}).executes(CommandClaim::removePlayer)))))) }).executes(CommandClaim::removePlayer))))))
.then(Commands.literal("teleport").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdTeleport)) .then(Commands.literal("teleport").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdTeleport))
.then(Commands.literal("self").then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, ctx.getSource().getPlayerOrException().getUUID())) .then(Commands.literal("self").then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, ctx.getSource().getPlayerOrException().getUUID()))
.executes(CommandClaim::teleport))) .executes(CommandClaim::teleport)))
.then(Commands.literal("admin").then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, null)) .then(Commands.literal("admin").then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, null))
.executes(CommandClaim::teleportAdminClaims))) .executes(CommandClaim::teleportAdminClaims)))
.then(Commands.literal("other").then(Commands.argument("player", GameProfileArgument.gameProfile()).then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, CommandHelpers.singleProfile(ctx, "player").getId())) .then(Commands.literal("other").then(Commands.argument("player", GameProfileArgument.gameProfile()).then(Commands.argument("claim", StringArgumentType.string()).suggests((ctx, b) -> CommandHelpers.claimSuggestions(ctx, b, CommandHelpers.singleProfile(ctx, "player").getId()))
.executes(src -> CommandClaim.teleport(src, CommandHelpers.singleProfile(src, "player").getId())))))) .executes(src -> CommandClaim.teleport(src, CommandHelpers.singleProfile(src, "player").getId()))))))
.then(Commands.literal("permission").requires(src -> PermissionNodeHandler.instance().perm(src, PermissionNodeHandler.cmdPermission)) .then(Commands.literal("permission").requires(src -> PermissionNodeHandler.INSTANCE.perm(src, PermissionNodeHandler.cmdPermission))
.then(Commands.literal("personal").then(Commands.argument("group", StringArgumentType.string()).suggests(CommandHelpers::personalGroupSuggestion) .then(Commands.literal("personal").then(Commands.argument("group", StringArgumentType.string()).suggests(CommandHelpers::personalGroupSuggestion)
.then(Commands.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> CommandHelpers.permSuggestions(ctx, b, true)) .then(Commands.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> CommandHelpers.permSuggestions(ctx, b, true))
.then(Commands.argument("toggle", StringArgumentType.word()) .then(Commands.argument("toggle", StringArgumentType.word())
@ -194,7 +194,7 @@ public class CommandClaim {
} }
if (!enoughBlocks) { if (!enoughBlocks) {
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("ownerTransferNoBlocks"), ChatFormatting.RED), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("ownerTransferNoBlocks"), ChatFormatting.RED), false);
if (PermissionNodeHandler.instance().perm(context.getSource(), PermissionNodeHandler.cmdAdminMode, true)) if (PermissionNodeHandler.INSTANCE.perm(context.getSource(), PermissionNodeHandler.cmdAdminMode, true))
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("ownerTransferNoBlocksAdmin"), ChatFormatting.RED), false); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("ownerTransferNoBlocksAdmin"), ChatFormatting.RED), false);
return 0; return 0;
} }

View File

@ -44,7 +44,7 @@ public class BuySellHandler {
} }
switch (this.buyType) { switch (this.buyType) {
case MONEY -> { case MONEY -> {
return CommandCurrency.instance().buyClaimBlocks(player, blocks, this.buyAmount, message); return CommandCurrency.INSTANCE.buyClaimBlocks(player, blocks, this.buyAmount, message);
} }
case ITEM -> { case ITEM -> {
int deduct = Mth.ceil(blocks * this.buyAmount); int deduct = Mth.ceil(blocks * this.buyAmount);
@ -111,7 +111,7 @@ public class BuySellHandler {
} }
switch (this.sellType) { switch (this.sellType) {
case MONEY -> { case MONEY -> {
return CommandCurrency.instance().sellClaimBlocks(player, blocks, this.sellAmount, message); return CommandCurrency.INSTANCE.sellClaimBlocks(player, blocks, this.sellAmount, message);
} }
case ITEM -> { case ITEM -> {
ItemStack[] stacks = this.ingredient.getItems(); ItemStack[] stacks = this.ingredient.getItems();

View File

@ -124,7 +124,7 @@ public class Config {
}))); })));
public Config(MinecraftServer server) { public Config(MinecraftServer server) {
File configDir = CrossPlatformStuff.instance().configPath().resolve("flan").toFile(); File configDir = CrossPlatformStuff.INSTANCE.configPath().resolve("flan").toFile();
try { try {
if (!configDir.exists()) if (!configDir.exists())
configDir.mkdirs(); configDir.mkdirs();
@ -162,9 +162,9 @@ public class Config {
this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist); this.worldWhitelist = ConfigHandler.fromJson(obj, "worldWhitelist", this.worldWhitelist);
if (obj.has("claimingItem")) if (obj.has("claimingItem"))
this.claimingItem = CrossPlatformStuff.instance().registryItems().getFromId(new ResourceLocation((obj.get("claimingItem").getAsString()))); this.claimingItem = CrossPlatformStuff.INSTANCE.registryItems().getFromId(new ResourceLocation((obj.get("claimingItem").getAsString())));
if (obj.has("inspectionItem")) if (obj.has("inspectionItem"))
this.inspectionItem = CrossPlatformStuff.instance().registryItems().getFromId(new ResourceLocation((obj.get("inspectionItem").getAsString()))); this.inspectionItem = CrossPlatformStuff.INSTANCE.registryItems().getFromId(new ResourceLocation((obj.get("inspectionItem").getAsString())));
this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime); this.claimDisplayTime = ConfigHandler.fromJson(obj, "claimDisplayTime", this.claimDisplayTime);
this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel); this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel);
@ -259,8 +259,8 @@ public class Config {
obj.add("blacklistedWorlds", arr); obj.add("blacklistedWorlds", arr);
obj.addProperty("worldWhitelist", this.worldWhitelist); obj.addProperty("worldWhitelist", this.worldWhitelist);
obj.addProperty("claimingItem", CrossPlatformStuff.instance().registryItems().getIDFrom(this.claimingItem).toString()); obj.addProperty("claimingItem", CrossPlatformStuff.INSTANCE.registryItems().getIDFrom(this.claimingItem).toString());
obj.addProperty("inspectionItem", CrossPlatformStuff.instance().registryItems().getIDFrom(this.inspectionItem).toString()); obj.addProperty("inspectionItem", CrossPlatformStuff.INSTANCE.registryItems().getIDFrom(this.inspectionItem).toString());
obj.addProperty("claimDisplayTime", this.claimDisplayTime); obj.addProperty("claimDisplayTime", this.claimDisplayTime);
obj.addProperty("permissionLevel", this.permissionLevel); obj.addProperty("permissionLevel", this.permissionLevel);

View File

@ -229,7 +229,7 @@ public class LangManager {
public LangManager() { public LangManager() {
this.loadDefault(); this.loadDefault();
Path configDir = CrossPlatformStuff.instance().configPath().resolve("flan").resolve("lang"); Path configDir = CrossPlatformStuff.INSTANCE.configPath().resolve("flan").resolve("lang");
this.confDir = configDir; this.confDir = configDir;
try { try {
File dir = configDir.toFile(); File dir = configDir.toFile();
@ -261,7 +261,7 @@ public class LangManager {
} }
File def = configDir.resolve("en_us.json").toFile(); File def = configDir.resolve("en_us.json").toFile();
if (!def.exists()) { if (!def.exists()) {
File legacy = CrossPlatformStuff.instance().configPath().resolve("flan").resolve("flan_lang.json").toFile(); File legacy = CrossPlatformStuff.INSTANCE.configPath().resolve("flan").resolve("flan_lang.json").toFile();
Map<String, String> translation; Map<String, String> translation;
Map<String, String[]> translationArr; Map<String, String[]> translationArr;
if (legacy.exists()) { if (legacy.exists()) {

View File

@ -47,7 +47,7 @@ public class BlockInteractEvents {
ClaimStorage storage = ClaimStorage.get((ServerLevel) world); ClaimStorage storage = ClaimStorage.get((ServerLevel) world);
IPermissionContainer claim = storage.getForPermissionCheck(pos); IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) { if (claim != null) {
ResourceLocation id = CrossPlatformStuff.instance().registryBlocks().getIDFrom(state.getBlock()); ResourceLocation id = CrossPlatformStuff.INSTANCE.registryBlocks().getIDFrom(state.getBlock());
if (contains(id, world.getBlockEntity(pos), ConfigHandler.config.breakBlockBlacklist, ConfigHandler.config.breakBETagBlacklist)) if (contains(id, world.getBlockEntity(pos), ConfigHandler.config.breakBlockBlacklist, ConfigHandler.config.breakBETagBlacklist))
return true; return true;
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) { if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
@ -75,7 +75,7 @@ public class BlockInteractEvents {
IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos()); IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos());
if (claim != null) { if (claim != null) {
BlockState state = world.getBlockState(hitResult.getBlockPos()); BlockState state = world.getBlockState(hitResult.getBlockPos());
ResourceLocation id = CrossPlatformStuff.instance().registryBlocks().getIDFrom(state.getBlock()); ResourceLocation id = CrossPlatformStuff.INSTANCE.registryBlocks().getIDFrom(state.getBlock());
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos()); BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
if (contains(id, blockEntity, ConfigHandler.config.interactBlockBlacklist, ConfigHandler.config.interactBETagBlacklist)) if (contains(id, blockEntity, ConfigHandler.config.interactBlockBlacklist, ConfigHandler.config.interactBETagBlacklist))
return InteractionResult.PASS; return InteractionResult.PASS;
@ -107,7 +107,7 @@ public class BlockInteractEvents {
LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity); LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity);
return InteractionResult.FAIL; return InteractionResult.FAIL;
} }
if (!ConfigHandler.config.lenientBlockEntityCheck || CrossPlatformStuff.instance().isInventoryTile(blockEntity)) { if (!ConfigHandler.config.lenientBlockEntityCheck || CrossPlatformStuff.INSTANCE.isInventoryTile(blockEntity)) {
if (claim.canInteract(player, PermissionRegistry.OPENCONTAINER, hitResult.getBlockPos(), true)) if (claim.canInteract(player, PermissionRegistry.OPENCONTAINER, hitResult.getBlockPos(), true))
return InteractionResult.PASS; return InteractionResult.PASS;
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY()); PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
@ -129,7 +129,7 @@ public class BlockInteractEvents {
return true; return true;
if (blockEntity != null && !tagList.isEmpty()) { if (blockEntity != null && !tagList.isEmpty()) {
CompoundTag nbt = blockEntity.saveWithoutMetadata(); CompoundTag nbt = blockEntity.saveWithoutMetadata();
return tagList.stream().anyMatch(tag -> CrossPlatformStuff.instance().blockDataContains(nbt, tag)); return tagList.stream().anyMatch(tag -> CrossPlatformStuff.INSTANCE.blockDataContains(nbt, tag));
} }
return false; return false;
} }

View File

@ -105,7 +105,7 @@ public class EntityInteractEvents {
} }
public static boolean canInteract(Entity entity) { public static boolean canInteract(Entity entity) {
ResourceLocation id = CrossPlatformStuff.instance().registryEntities().getIDFrom(entity.getType()); ResourceLocation id = CrossPlatformStuff.INSTANCE.registryEntities().getIDFrom(entity.getType());
return ConfigHandler.config.ignoredEntityTypes.contains(id.getNamespace()) return ConfigHandler.config.ignoredEntityTypes.contains(id.getNamespace())
|| ConfigHandler.config.ignoredEntityTypes.contains(id.toString()) || ConfigHandler.config.ignoredEntityTypes.contains(id.toString())
|| entity.getTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains); || entity.getTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);

View File

@ -148,7 +148,7 @@ public class ItemInteractEvents {
} }
public static void claimLandHandling(ServerPlayer player, BlockPos target) { public static void claimLandHandling(ServerPlayer player, BlockPos target) {
if (!PermissionNodeHandler.instance().perm(player, PermissionNodeHandler.claimCreate, false)) { if (!PermissionNodeHandler.INSTANCE.perm(player, PermissionNodeHandler.claimCreate, false)) {
player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("noPermission"), ChatFormatting.DARK_RED), true); player.displayClientMessage(PermHelper.simpleColoredText(ConfigHandler.langManager.get("noPermission"), ChatFormatting.DARK_RED), true);
return; return;
} }

View File

@ -60,7 +60,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) { protected void fillInventoryWith(Player player, SeparateInv inv, Claim claim) {
Map<MobEffect, Integer> potions = claim.getPotions(); Map<MobEffect, Integer> potions = claim.getPotions();
List<MobEffect> key = Lists.newArrayList(potions.keySet()); List<MobEffect> key = Lists.newArrayList(potions.keySet());
key.sort(Comparator.comparing(eff -> CrossPlatformStuff.instance().registryStatusEffects().getIDFrom(eff).toString())); key.sort(Comparator.comparing(eff -> CrossPlatformStuff.INSTANCE.registryStatusEffects().getIDFrom(eff).toString()));
for (int i = 0; i < 54; i++) { for (int i = 0; i < 54; i++) {
if (i == 0) { if (i == 0) {
ItemStack close = new ItemStack(Items.TNT); ItemStack close = new ItemStack(Items.TNT);
@ -84,7 +84,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
ItemStack effectStack = new ItemStack(Items.POTION); ItemStack effectStack = new ItemStack(Items.POTION);
TranslatableComponent txt = new TranslatableComponent(effect.getDescriptionId()); TranslatableComponent txt = new TranslatableComponent(effect.getDescriptionId());
Collection<MobEffectInstance> inst = Collections.singleton(new MobEffectInstance(effect, 0, potions.get(effect))); Collection<MobEffectInstance> inst = Collections.singleton(new MobEffectInstance(effect, 0, potions.get(effect)));
effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.instance().registryStatusEffects().getIDFrom(effect).toString()); effectStack.getOrCreateTag().putString("FlanEffect", CrossPlatformStuff.INSTANCE.registryStatusEffects().getIDFrom(effect).toString());
effectStack.getTag().putInt("CustomPotionColor", PotionUtils.getColor(inst)); effectStack.getTag().putInt("CustomPotionColor", PotionUtils.getColor(inst));
effectStack.setHoverName(txt.setStyle(txt.getStyle().withItalic(false).applyFormat(ChatFormatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), ChatFormatting.DARK_BLUE))); effectStack.setHoverName(txt.setStyle(txt.getStyle().withItalic(false).applyFormat(ChatFormatting.DARK_BLUE)).append(ServerScreenHelper.coloredGuiText("-" + potions.get(effect), ChatFormatting.DARK_BLUE)));
inv.updateStack(i, effectStack); inv.updateStack(i, effectStack);
@ -111,7 +111,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> { player.getServer().execute(() -> StringResultScreenHandler.createNewStringResult(player, (s) -> {
String[] potion = s.split(";"); String[] potion = s.split(";");
int amp = 1; int amp = 1;
MobEffect effect = CrossPlatformStuff.instance().registryStatusEffects().getFromId(new ResourceLocation(potion[0])); MobEffect effect = CrossPlatformStuff.INSTANCE.registryStatusEffects().getFromId(new ResourceLocation(potion[0]));
if (effect == null || (effect == MobEffects.LUCK && !potion[0].equals("minecraft:luck"))) { if (effect == null || (effect == MobEffects.LUCK && !potion[0].equals("minecraft:luck"))) {
ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f); ServerScreenHelper.playSongToPlayer(player, SoundEvents.VILLAGER_NO, 1, 1f);
return; return;
@ -145,7 +145,7 @@ public class PotionEditScreenHandler extends ServerOnlyScreenHandler<Claim> {
ItemStack stack = slot.getItem(); ItemStack stack = slot.getItem();
if (!stack.isEmpty() && this.removeMode) { if (!stack.isEmpty() && this.removeMode) {
String effect = stack.getOrCreateTag().getString("FlanEffect"); String effect = stack.getOrCreateTag().getString("FlanEffect");
this.claim.removePotion(CrossPlatformStuff.instance().registryStatusEffects().getFromId(new ResourceLocation(effect))); this.claim.removePotion(CrossPlatformStuff.INSTANCE.registryStatusEffects().getFromId(new ResourceLocation(effect)));
slot.set(ItemStack.EMPTY); slot.set(ItemStack.EMPTY);
ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f); ServerScreenHelper.playSongToPlayer(player, SoundEvents.BAT_DEATH, 1, 1f);
} }

View File

@ -1,17 +1,16 @@
package io.github.flemmli97.flan.platform; package io.github.flemmli97.flan.platform;
import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.api.permission.ClaimPermission; import io.github.flemmli97.flan.api.permission.ClaimPermission;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
public abstract class ClaimPermissionCheck { public interface ClaimPermissionCheck {
protected static ClaimPermissionCheck INSTANCE; ClaimPermissionCheck INSTANCE = Flan.getPlatformInstance(ClaimPermissionCheck.class,
"io.github.flemmli97.flan.fabric.platform.ClaimPermissionCheckImpl",
"io.github.flemmli97.flan.forge.platform.ClaimPermissionCheckImpl");
public static ClaimPermissionCheck instance() { InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos);
return INSTANCE;
}
public abstract InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos);
} }

View File

@ -1,5 +1,6 @@
package io.github.flemmli97.flan.platform; package io.github.flemmli97.flan.platform;
import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.SimpleRegistryWrapper; import io.github.flemmli97.flan.SimpleRegistryWrapper;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
@ -10,25 +11,23 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import java.nio.file.Path; import java.nio.file.Path;
public abstract class CrossPlatformStuff { public interface CrossPlatformStuff {
protected static CrossPlatformStuff INSTANCE; CrossPlatformStuff INSTANCE = Flan.getPlatformInstance(CrossPlatformStuff.class,
"io.github.flemmli97.flan.fabric.platform.CrossPlatformStuffImpl",
"io.github.flemmli97.flan.forge.platform.CrossPlatformStuffImpl");
public static CrossPlatformStuff instance() { Path configPath();
return INSTANCE;
}
public abstract Path configPath(); SimpleRegistryWrapper<MobEffect> registryStatusEffects();
public abstract SimpleRegistryWrapper<MobEffect> registryStatusEffects(); SimpleRegistryWrapper<Block> registryBlocks();
public abstract SimpleRegistryWrapper<Block> registryBlocks(); SimpleRegistryWrapper<Item> registryItems();
public abstract SimpleRegistryWrapper<Item> registryItems(); SimpleRegistryWrapper<EntityType<?>> registryEntities();
public abstract SimpleRegistryWrapper<EntityType<?>> registryEntities(); boolean isInventoryTile(BlockEntity blockEntity);
public abstract boolean isInventoryTile(BlockEntity blockEntity); boolean blockDataContains(CompoundTag nbt, String tag);
public abstract boolean blockDataContains(CompoundTag nbt, String tag);
} }

View File

@ -1,19 +1,18 @@
package io.github.flemmli97.flan.platform.integration.currency; package io.github.flemmli97.flan.platform.integration.currency;
import io.github.flemmli97.flan.Flan;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import java.util.function.Consumer; import java.util.function.Consumer;
public abstract class CommandCurrency { public interface CommandCurrency {
protected static CommandCurrency INSTANCE; CommandCurrency INSTANCE = Flan.getPlatformInstance(CommandCurrency.class,
"io.github.flemmli97.flan.fabric.platform.integration.currency.CommandCurrencyImpl",
"io.github.flemmli97.flan.forge.platform.integration.currency.CommandCurrencyImpl");
public static CommandCurrency instance() { boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message);
return INSTANCE;
}
public abstract boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message); boolean buyClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message);
public abstract boolean buyClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message);
} }

View File

@ -1,64 +1,63 @@
package io.github.flemmli97.flan.platform.integration.permissions; package io.github.flemmli97.flan.platform.integration.permissions;
import io.github.flemmli97.flan.Flan;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
public abstract class PermissionNodeHandler { public interface PermissionNodeHandler {
public static final String cmdReload = "flan.command.reload"; String cmdReload = "flan.command.reload";
public static final String cmdGriefPrevention = "flan.command.read.griefprevention"; String cmdGriefPrevention = "flan.command.read.griefprevention";
public static final String claimCreate = "flan.claim.create"; String claimCreate = "flan.claim.create";
public static final String cmdMenu = "flan.command.menu"; String cmdMenu = "flan.command.menu";
public static final String cmdTrapped = "flan.command.trapped"; String cmdTrapped = "flan.command.trapped";
public static final String cmdPGroup = "flan.command.personal"; String cmdPGroup = "flan.command.personal";
public static final String cmdInfo = "flan.command.info"; String cmdInfo = "flan.command.info";
public static final String cmdTransfer = "flan.command.transfer"; String cmdTransfer = "flan.command.transfer";
public static final String cmdDelete = "flan.command.delete"; String cmdDelete = "flan.command.delete";
public static final String cmdDeleteAll = "flan.command.delete.all"; String cmdDeleteAll = "flan.command.delete.all";
public static final String cmdDeleteSub = "flan.command.delete.sub"; String cmdDeleteSub = "flan.command.delete.sub";
public static final String cmdDeleteSubAll = "flan.command.delete.sub.all"; String cmdDeleteSubAll = "flan.command.delete.sub.all";
public static final String cmdList = "flan.command.list"; String cmdList = "flan.command.list";
public static final String cmdListAll = "flan.command.list.all"; String cmdListAll = "flan.command.list.all";
public static final String cmdClaimMode = "flan.command.claim.mode"; String cmdClaimMode = "flan.command.claim.mode";
public static final String cmdAdminMode = "flan.command.admin.mode"; String cmdAdminMode = "flan.command.admin.mode";
public static final String cmdAdminSet = "flan.command.admin.claim"; String cmdAdminSet = "flan.command.admin.claim";
public static final String cmdAdminList = "flan.command.admin.list"; String cmdAdminList = "flan.command.admin.list";
public static final String cmdAdminDelete = "flan.command.admin.delete"; String cmdAdminDelete = "flan.command.admin.delete";
public static final String cmdAdminGive = "flan.command.admin.give"; String cmdAdminGive = "flan.command.admin.give";
public static final String cmdGroup = "flan.command.group"; String cmdGroup = "flan.command.group";
public static final String cmdPermission = "flan.command.permission"; String cmdPermission = "flan.command.permission";
public static final String cmdSell = "flan.command.buy"; String cmdSell = "flan.command.buy";
public static final String cmdBuy = "flan.command.sell"; String cmdBuy = "flan.command.sell";
public static final String cmdUnlockAll = "flan.command.unlock.all"; String cmdUnlockAll = "flan.command.unlock.all";
public static final String cmdName = "flan.command.name"; String cmdName = "flan.command.name";
public static final String cmdHome = "flan.command.home"; String cmdHome = "flan.command.home";
public static final String cmdTeleport = "flan.command.teleport"; String cmdTeleport = "flan.command.teleport";
public static final String permClaimBlocks = "flan.claim.blocks.max"; String permClaimBlocks = "flan.claim.blocks.max";
public static final String permMaxClaims = "flan.claims.amount"; String permMaxClaims = "flan.claims.amount";
protected static PermissionNodeHandler INSTANCE; PermissionNodeHandler INSTANCE = Flan.getPlatformInstance(PermissionNodeHandler.class,
"io.github.flemmli97.flan.fabric.platform.integration.permissions.PermissionNodeHandlerImpl",
"io.github.flemmli97.flan.forge.platform.integration.permissions.PermissionNodeHandlerImpl");
public static PermissionNodeHandler instance() { default boolean perm(CommandSourceStack src, String perm) {
return INSTANCE; return this.perm(src, perm, false);
} }
public boolean perm(CommandSourceStack src, String perm) { boolean perm(CommandSourceStack src, String perm, boolean adminCmd);
return perm(src, perm, false);
}
public abstract boolean perm(CommandSourceStack src, String perm, boolean adminCmd); boolean perm(ServerPlayer src, String perm, boolean adminCmd);
public abstract boolean perm(ServerPlayer src, String perm, boolean adminCmd); boolean permBelowEqVal(ServerPlayer src, String perm, int val, int fallback);
public abstract boolean permBelowEqVal(ServerPlayer src, String perm, int val, int fallback);
} }

View File

@ -105,7 +105,7 @@ public class PlayerClaimData implements IPlayerData {
} }
private boolean canIncrease(int blocks) { private boolean canIncrease(int blocks) {
return PermissionNodeHandler.instance().permBelowEqVal(this.player, PermissionNodeHandler.permClaimBlocks, blocks, ConfigHandler.config.maxClaimBlocks); return PermissionNodeHandler.INSTANCE.permBelowEqVal(this.player, PermissionNodeHandler.permClaimBlocks, blocks, ConfigHandler.config.maxClaimBlocks);
} }
@Override @Override

View File

@ -8,10 +8,6 @@ import io.github.flemmli97.flan.event.EntityInteractEvents;
import io.github.flemmli97.flan.event.ItemInteractEvents; import io.github.flemmli97.flan.event.ItemInteractEvents;
import io.github.flemmli97.flan.event.PlayerEvents; import io.github.flemmli97.flan.event.PlayerEvents;
import io.github.flemmli97.flan.event.WorldEvents; import io.github.flemmli97.flan.event.WorldEvents;
import io.github.flemmli97.flan.fabric.platform.ClaimPermissionCheckImpl;
import io.github.flemmli97.flan.fabric.platform.CrossPlatformStuffImpl;
import io.github.flemmli97.flan.fabric.platform.integration.currency.fabric.CommandCurrencyImpl;
import io.github.flemmli97.flan.fabric.platform.integration.permissions.fabric.PermissionNodeHandlerImpl;
import io.github.flemmli97.flan.fabric.platform.integration.playerability.PlayerAbilityEvents; import io.github.flemmli97.flan.fabric.platform.integration.playerability.PlayerAbilityEvents;
import io.github.flemmli97.flan.player.PlayerDataHandler; import io.github.flemmli97.flan.player.PlayerDataHandler;
import io.github.flemmli97.flan.scoreboard.ClaimCriterias; import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
@ -44,10 +40,6 @@ public class FlanFabric implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
CrossPlatformStuffImpl.init();
ClaimPermissionCheckImpl.init();
CommandCurrencyImpl.init();
PermissionNodeHandlerImpl.init();
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks); PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
AttackBlockCallback.EVENT.register(BlockInteractEvents::startBreakBlocks); AttackBlockCallback.EVENT.register(BlockInteractEvents::startBreakBlocks);
UseBlockCallback.EVENT.addPhaseOrdering(EventPhase, Event.DEFAULT_PHASE); UseBlockCallback.EVENT.addPhaseOrdering(EventPhase, Event.DEFAULT_PHASE);

View File

@ -7,11 +7,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
public class ClaimPermissionCheckImpl extends ClaimPermissionCheck { public class ClaimPermissionCheckImpl implements ClaimPermissionCheck {
public static void init() {
INSTANCE = new ClaimPermissionCheckImpl();
}
@Override @Override
public InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) { public InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) {

View File

@ -16,11 +16,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import java.nio.file.Path; import java.nio.file.Path;
public class CrossPlatformStuffImpl extends CrossPlatformStuff { public class CrossPlatformStuffImpl implements CrossPlatformStuff {
public static void init() {
INSTANCE = new CrossPlatformStuffImpl();
}
@Override @Override
public Path configPath() { public Path configPath() {

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.fabric.platform.integration.currency.fabric; package io.github.flemmli97.flan.fabric.platform.integration.currency;
import io.github.flemmli97.flan.Flan; import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.claim.PermHelper; import io.github.flemmli97.flan.claim.PermHelper;
@ -14,11 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.function.Consumer; import java.util.function.Consumer;
public class CommandCurrencyImpl extends CommandCurrency { public class CommandCurrencyImpl implements CommandCurrency {
public static void init() {
INSTANCE = new CommandCurrencyImpl();
}
@Override @Override
public boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) { public boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.fabric.platform.integration.permissions.fabric; package io.github.flemmli97.flan.fabric.platform.integration.permissions;
import dev.ftb.mods.ftbranks.api.FTBRanksAPI; import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
import io.github.flemmli97.flan.Flan; import io.github.flemmli97.flan.Flan;
@ -8,11 +8,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
public class PermissionNodeHandlerImpl extends PermissionNodeHandler { public class PermissionNodeHandlerImpl implements PermissionNodeHandler {
public static void init() {
INSTANCE = new PermissionNodeHandlerImpl();
}
@Override @Override
public boolean perm(CommandSourceStack src, String perm, boolean adminCmd) { public boolean perm(CommandSourceStack src, String perm, boolean adminCmd) {

View File

@ -6,10 +6,6 @@ import io.github.flemmli97.flan.forge.forgeevent.EntityInteractEventsForge;
import io.github.flemmli97.flan.forge.forgeevent.ItemInteractEventsForge; import io.github.flemmli97.flan.forge.forgeevent.ItemInteractEventsForge;
import io.github.flemmli97.flan.forge.forgeevent.ServerEvents; import io.github.flemmli97.flan.forge.forgeevent.ServerEvents;
import io.github.flemmli97.flan.forge.forgeevent.WorldEventsForge; import io.github.flemmli97.flan.forge.forgeevent.WorldEventsForge;
import io.github.flemmli97.flan.forge.platform.ClaimPermissionCheckImpl;
import io.github.flemmli97.flan.forge.platform.CrossPlatformStuffImpl;
import io.github.flemmli97.flan.forge.platform.integration.currency.forge.CommandCurrencyImpl;
import io.github.flemmli97.flan.forge.platform.integration.permissions.forge.PermissionNodeHandlerImpl;
import io.github.flemmli97.flan.scoreboard.ClaimCriterias; import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.EventPriority;
@ -23,10 +19,6 @@ public class FlanForge {
public static final String MODID = "flan"; public static final String MODID = "flan";
public FlanForge() { public FlanForge() {
CrossPlatformStuffImpl.init();
ClaimPermissionCheckImpl.init();
CommandCurrencyImpl.init();
PermissionNodeHandlerImpl.init();
Flan.ftbRanks = ModList.get().isLoaded("ftbranks"); Flan.ftbRanks = ModList.get().isLoaded("ftbranks");
Flan.diceMCMoneySign = ModList.get().isLoaded("dicemcmm"); Flan.diceMCMoneySign = ModList.get().isLoaded("dicemcmm");

View File

@ -8,11 +8,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
public class ClaimPermissionCheckImpl extends ClaimPermissionCheck { public class ClaimPermissionCheckImpl implements ClaimPermissionCheck {
public static void init() {
INSTANCE = new ClaimPermissionCheckImpl();
}
@Override @Override
public InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) { public InteractionResult check(ServerPlayer player, ClaimPermission permission, BlockPos pos) {

View File

@ -17,11 +17,7 @@ import net.minecraftforge.registries.ForgeRegistries;
import java.nio.file.Path; import java.nio.file.Path;
public class CrossPlatformStuffImpl extends CrossPlatformStuff { public class CrossPlatformStuffImpl implements CrossPlatformStuff {
public static void init() {
INSTANCE = new CrossPlatformStuffImpl();
}
@Override @Override
public Path configPath() { public Path configPath() {

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.forge.platform.integration.currency.forge; package io.github.flemmli97.flan.forge.platform.integration.currency;
import dicemc.money.MoneyMod; import dicemc.money.MoneyMod;
import dicemc.money.storage.MoneyWSD; import dicemc.money.storage.MoneyWSD;
@ -14,11 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer; import java.util.function.Consumer;
public class CommandCurrencyImpl extends CommandCurrency { public class CommandCurrencyImpl implements CommandCurrency {
public static void init() {
INSTANCE = new CommandCurrencyImpl();
}
@Override @Override
public boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) { public boolean sellClaimBlocks(ServerPlayer player, int blocks, float value, Consumer<Component> message) {

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.forge.platform.integration.permissions.forge; package io.github.flemmli97.flan.forge.platform.integration.permissions;
import dev.ftb.mods.ftbranks.api.FTBRanksAPI; import dev.ftb.mods.ftbranks.api.FTBRanksAPI;
import io.github.flemmli97.flan.Flan; import io.github.flemmli97.flan.Flan;
@ -7,11 +7,7 @@ import io.github.flemmli97.flan.platform.integration.permissions.PermissionNodeH
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
public class PermissionNodeHandlerImpl extends PermissionNodeHandler { public class PermissionNodeHandlerImpl implements PermissionNodeHandler {
public static void init() {
INSTANCE = new PermissionNodeHandlerImpl();
}
@Override @Override
public boolean perm(CommandSourceStack src, String perm, boolean adminCmd) { public boolean perm(CommandSourceStack src, String perm, boolean adminCmd) {

View File

@ -10,7 +10,7 @@ forge_version=1.18.1-39.0.14
loader_version=0.12.8 loader_version=0.12.8
# Mod Properties # Mod Properties
mod_version=1.7.2 mod_version=1.7.3
maven_group=io.github.flemmli97 maven_group=io.github.flemmli97
archives_base_name=flan archives_base_name=flan