allow adding/overriding of item/block -> permission maps #106
This commit is contained in:
parent
36733ccb40
commit
be4099fa54
@ -2,6 +2,11 @@ Flan 1.6.5
|
|||||||
======================
|
======================
|
||||||
- Fix claims below 0 not working
|
- Fix claims below 0 not working
|
||||||
- Only kick players out of subclaim if the mainclaim allows them to stay
|
- Only kick players out of subclaim if the mainclaim allows them to stay
|
||||||
|
- New config "customItemPermission" and "customBlockPermission"
|
||||||
|
allows to specify a mapping of item/block to permission
|
||||||
|
example is endcrystals are mapped to the ENDCRYSTALPLACE permission internally
|
||||||
|
Syntax is <item/block>-<permission>
|
||||||
|
Use @ to indicate a tag
|
||||||
|
|
||||||
Flan 1.6.4
|
Flan 1.6.4
|
||||||
======================
|
======================
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package io.github.flemmli97.flan.api.permission;
|
package io.github.flemmli97.flan.api.permission;
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import io.github.flemmli97.flan.CrossPlatformStuff;
|
import io.github.flemmli97.flan.CrossPlatformStuff;
|
||||||
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.tags.SerializationTags;
|
||||||
|
import net.minecraft.tags.Tag;
|
||||||
import net.minecraft.world.item.BucketItem;
|
import net.minecraft.world.item.BucketItem;
|
||||||
import net.minecraft.world.item.EnderpearlItem;
|
import net.minecraft.world.item.EnderpearlItem;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
@ -57,6 +63,45 @@ public class ObjectToPermissionMap {
|
|||||||
for (Item item : CrossPlatformStuff.registryItems().getIterator()) {
|
for (Item item : CrossPlatformStuff.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) {
|
||||||
|
String[] sub = s.split("-");
|
||||||
|
boolean remove = sub[1].equals("NONE");
|
||||||
|
if (s.startsWith("@")) {
|
||||||
|
Tag<Item> t = SerializationTags.getInstance().getTagOrThrow(Registry.ITEM_REGISTRY, new ResourceLocation(sub[0].substring(1)), id -> new JsonSyntaxException("Unknown item tag '" + id + "'"));
|
||||||
|
if (t != null) {
|
||||||
|
t.getValues().forEach(i -> {
|
||||||
|
if (remove)
|
||||||
|
itemToPermission.remove(i);
|
||||||
|
else
|
||||||
|
itemToPermission.put(i, PermissionRegistry.get(sub[1]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (remove)
|
||||||
|
itemToPermission.remove(CrossPlatformStuff.registryItems().getFromId(new ResourceLocation(sub[0])));
|
||||||
|
else
|
||||||
|
itemToPermission.put(CrossPlatformStuff.registryItems().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : ConfigHandler.config.blockPermission) {
|
||||||
|
String[] sub = s.split("-");
|
||||||
|
boolean remove = sub[1].equals("NONE");
|
||||||
|
if (s.startsWith("@")) {
|
||||||
|
Tag<Block> t = SerializationTags.getInstance().getTagOrThrow(Registry.BLOCK_REGISTRY, new ResourceLocation(sub[0].substring(1)), id -> new JsonSyntaxException("Unknown item tag '" + id + "'"));
|
||||||
|
if (t != null)
|
||||||
|
t.getValues().forEach(i -> {
|
||||||
|
if (remove)
|
||||||
|
blockToPermission.remove(i);
|
||||||
|
else
|
||||||
|
blockToPermission.put(i, PermissionRegistry.get(sub[1]));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (remove)
|
||||||
|
blockToPermission.remove(CrossPlatformStuff.registryBlocks().getFromId(new ResourceLocation(sub[0])));
|
||||||
|
else
|
||||||
|
blockToPermission.put(CrossPlatformStuff.registryBlocks().getFromId(new ResourceLocation(sub[0])), PermissionRegistry.get(sub[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClaimPermission getFromBlock(Block block) {
|
public static ClaimPermission getFromBlock(Block block) {
|
||||||
|
@ -137,7 +137,7 @@ public class CommandClaim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int reloadConfig(CommandContext<CommandSourceStack> context) {
|
private static int reloadConfig(CommandContext<CommandSourceStack> context) {
|
||||||
ConfigHandler.reloadConfigs();
|
ConfigHandler.reloadConfigs(context.getSource().getServer());
|
||||||
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.configReload), true);
|
context.getSource().sendSuccess(PermHelper.simpleColoredText(ConfigHandler.lang.configReload), true);
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,12 @@ public class Config {
|
|||||||
"graves.marker" //vanilla tweaks
|
"graves.marker" //vanilla tweaks
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public List<String> itemPermission = Lists.newArrayList(
|
||||||
|
"@c:wrenches-INTERACTBLOCK"
|
||||||
|
);
|
||||||
|
public List<String> blockPermission = Lists.newArrayList(
|
||||||
|
);
|
||||||
|
|
||||||
public int dropTicks = 6000;
|
public int dropTicks = 6000;
|
||||||
|
|
||||||
public int inactivityTime = 30;
|
public int inactivityTime = 30;
|
||||||
@ -80,7 +86,7 @@ public class Config {
|
|||||||
|
|
||||||
public boolean log;
|
public boolean log;
|
||||||
|
|
||||||
public int configVersion = 3;
|
public int configVersion = 4;
|
||||||
public int preConfigVersion;
|
public int preConfigVersion;
|
||||||
|
|
||||||
public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> {
|
public Map<String, Map<ClaimPermission, Boolean>> defaultGroups = createHashMap(map -> {
|
||||||
@ -167,6 +173,11 @@ public class Config {
|
|||||||
this.entityTagIgnore.clear();
|
this.entityTagIgnore.clear();
|
||||||
ConfigHandler.arryFromJson(obj, "entityTagIgnore").forEach(e -> this.entityTagIgnore.add(e.getAsString()));
|
ConfigHandler.arryFromJson(obj, "entityTagIgnore").forEach(e -> this.entityTagIgnore.add(e.getAsString()));
|
||||||
|
|
||||||
|
this.itemPermission.clear();
|
||||||
|
ConfigHandler.arryFromJson(obj, "customItemPermission").forEach(e -> this.itemPermission.add(e.getAsString()));
|
||||||
|
this.blockPermission.clear();
|
||||||
|
ConfigHandler.arryFromJson(obj, "customBlockPermission").forEach(e -> this.blockPermission.add(e.getAsString()));
|
||||||
|
|
||||||
this.dropTicks = ConfigHandler.fromJson(obj, "dropTicks", this.dropTicks);
|
this.dropTicks = ConfigHandler.fromJson(obj, "dropTicks", this.dropTicks);
|
||||||
this.inactivityTime = ConfigHandler.fromJson(obj, "inactivityTimeDays", this.inactivityTime);
|
this.inactivityTime = ConfigHandler.fromJson(obj, "inactivityTimeDays", this.inactivityTime);
|
||||||
this.inactivityBlocksMax = ConfigHandler.fromJson(obj, "inactivityBlocksMax", this.inactivityBlocksMax);
|
this.inactivityBlocksMax = ConfigHandler.fromJson(obj, "inactivityBlocksMax", this.inactivityBlocksMax);
|
||||||
@ -260,6 +271,13 @@ public class Config {
|
|||||||
this.entityTagIgnore.forEach(entitiesTags::add);
|
this.entityTagIgnore.forEach(entitiesTags::add);
|
||||||
obj.add("entityTagIgnore", entitiesTags);
|
obj.add("entityTagIgnore", entitiesTags);
|
||||||
|
|
||||||
|
JsonArray itemPerms = new JsonArray();
|
||||||
|
this.itemPermission.forEach(itemPerms::add);
|
||||||
|
obj.add("customItemPermission", itemPerms);
|
||||||
|
JsonArray blockPerms = new JsonArray();
|
||||||
|
this.blockPermission.forEach(blockPerms::add);
|
||||||
|
obj.add("customBlockPermission", blockPerms);
|
||||||
|
|
||||||
obj.addProperty("dropTicks", this.dropTicks);
|
obj.addProperty("dropTicks", this.dropTicks);
|
||||||
obj.addProperty("inactivityTimeDays", this.inactivityTime);
|
obj.addProperty("inactivityTimeDays", this.inactivityTime);
|
||||||
obj.addProperty("inactivityBlocksMax", this.inactivityBlocksMax);
|
obj.addProperty("inactivityBlocksMax", this.inactivityBlocksMax);
|
||||||
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
@ -26,12 +27,13 @@ public class ConfigHandler {
|
|||||||
public static void serverLoad(MinecraftServer server) {
|
public static void serverLoad(MinecraftServer server) {
|
||||||
config = new Config(server);
|
config = new Config(server);
|
||||||
lang = new LangConfig(server);
|
lang = new LangConfig(server);
|
||||||
reloadConfigs();
|
reloadConfigs(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadConfigs() {
|
public static void reloadConfigs(MinecraftServer server) {
|
||||||
config.load();
|
config.load();
|
||||||
lang.load();
|
lang.load();
|
||||||
|
ObjectToPermissionMap.reload(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path getClaimSavePath(MinecraftServer server, ResourceKey<Level> reg) {
|
public static Path getClaimSavePath(MinecraftServer server, ResourceKey<Level> reg) {
|
||||||
|
@ -35,6 +35,10 @@ public class ConfigUpdater {
|
|||||||
ConfigHandler.config.interactBETagBlacklist.add(e.getAsString());
|
ConfigHandler.config.interactBETagBlacklist.add(e.getAsString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
map.put(4, old -> {
|
||||||
|
Flan.debug("Updating config to version 4");
|
||||||
|
ConfigHandler.config.itemPermission.add("@c:wrenches-INTERACTBLOCK");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
public static void updateConfig(int preVersion, JsonObject oldVals) {
|
public static void updateConfig(int preVersion, JsonObject oldVals) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package io.github.flemmli97.flan.fabric;
|
package io.github.flemmli97.flan.fabric;
|
||||||
|
|
||||||
import io.github.flemmli97.flan.Flan;
|
import io.github.flemmli97.flan.Flan;
|
||||||
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
|
|
||||||
import io.github.flemmli97.flan.commands.CommandClaim;
|
import io.github.flemmli97.flan.commands.CommandClaim;
|
||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||||
@ -50,9 +49,8 @@ public class FlanFabric implements ModInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void serverLoad(MinecraftServer server) {
|
public static void serverLoad(MinecraftServer server) {
|
||||||
ConfigHandler.serverLoad(server);
|
|
||||||
ObjectToPermissionMap.reload(server);
|
|
||||||
Flan.lockRegistry(server);
|
Flan.lockRegistry(server);
|
||||||
|
ConfigHandler.serverLoad(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serverFinishLoad(MinecraftServer server) {
|
public static void serverFinishLoad(MinecraftServer server) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package io.github.flemmli97.flan.forgeevent;
|
package io.github.flemmli97.flan.forgeevent;
|
||||||
|
|
||||||
import io.github.flemmli97.flan.Flan;
|
import io.github.flemmli97.flan.Flan;
|
||||||
import io.github.flemmli97.flan.api.permission.ObjectToPermissionMap;
|
|
||||||
import io.github.flemmli97.flan.commands.CommandClaim;
|
import io.github.flemmli97.flan.commands.CommandClaim;
|
||||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||||
import io.github.flemmli97.flan.event.PlayerEvents;
|
import io.github.flemmli97.flan.event.PlayerEvents;
|
||||||
@ -17,9 +16,8 @@ import net.minecraftforge.event.server.ServerStartedEvent;
|
|||||||
public class ServerEvents {
|
public class ServerEvents {
|
||||||
|
|
||||||
public static void serverStart(ServerAboutToStartEvent event) {
|
public static void serverStart(ServerAboutToStartEvent event) {
|
||||||
ConfigHandler.serverLoad(event.getServer());
|
|
||||||
ObjectToPermissionMap.reload(event.getServer());
|
|
||||||
Flan.lockRegistry(event.getServer());
|
Flan.lockRegistry(event.getServer());
|
||||||
|
ConfigHandler.serverLoad(event.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serverFinishLoad(ServerStartedEvent event) {
|
public static void serverFinishLoad(ServerStartedEvent event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user