From 246d06c37a88a5b7d42479a57c6bde432249f940 Mon Sep 17 00:00:00 2001 From: PinkGoosik Date: Mon, 25 Dec 2023 16:33:43 +0500 Subject: [PATCH] template patches --- .../java/skylands/command/CreateCommand.java | 17 ++++++++++++++--- .../java/skylands/config/SkylandsConfig.java | 13 +++++++++++++ .../config/{ => template}/HubTemplate.java | 2 +- .../config/{ => template}/IslandTemplate.java | 4 +++- .../config/{ => template}/Metadata.java | 3 ++- .../config/{ => template}/Template.java | 5 ++++- src/main/java/skylands/logic/Island.java | 4 ++-- src/main/java/skylands/logic/IslandStuck.java | 2 +- ...necartMixin.java => VehicleEntityMixin.java} | 1 - 9 files changed, 40 insertions(+), 11 deletions(-) rename src/main/java/skylands/config/{ => template}/HubTemplate.java (80%) rename src/main/java/skylands/config/{ => template}/IslandTemplate.java (80%) rename src/main/java/skylands/config/{ => template}/Metadata.java (93%) rename src/main/java/skylands/config/{ => template}/Template.java (93%) rename src/main/java/skylands/mixin/world/protection/{MinecartMixin.java => VehicleEntityMixin.java} (95%) diff --git a/src/main/java/skylands/command/CreateCommand.java b/src/main/java/skylands/command/CreateCommand.java index 667a9e6..330be1c 100644 --- a/src/main/java/skylands/command/CreateCommand.java +++ b/src/main/java/skylands/command/CreateCommand.java @@ -31,7 +31,9 @@ static void init(CommandDispatcher dispatcher) { for(var template : Skylands.config.islandTemplates) { if(template.name.contains(remains)) { - builder.suggest(template.name); + if(template.permission == null || Permissions.check(player, template.permission)) { + builder.suggest(template.name); + } } } return builder.buildFuture(); @@ -64,14 +66,23 @@ static void run(ServerPlayerEntity player) { } } - static void run(ServerPlayerEntity player, String template) { + static void run(ServerPlayerEntity player, String templateName) { IslandStuck islands = Skylands.instance.islands; if(islands.get(player).isPresent()) { player.sendMessage(SkylandsTexts.prefixed("message.skylands.island_create.fail")); } else { - Island island = islands.create(player, template); + var template = Skylands.config.getIslandTemplate(templateName); + Island island; + + if(template.isPresent() && (template.get().permission == null || Permissions.check(player, template.get().permission))) { + island = islands.create(player, templateName); + } + else { + island = islands.create(player); + } + if(Skylands.config.teleportAfterIslandCreation) { island.visitAsMember(player); } diff --git a/src/main/java/skylands/config/SkylandsConfig.java b/src/main/java/skylands/config/SkylandsConfig.java index 807c238..38f3061 100644 --- a/src/main/java/skylands/config/SkylandsConfig.java +++ b/src/main/java/skylands/config/SkylandsConfig.java @@ -6,6 +6,10 @@ import com.google.gson.annotations.JsonAdapter; import net.fabricmc.loader.api.FabricLoader; import skylands.SkylandsMod; +import skylands.config.template.HubTemplate; +import skylands.config.template.IslandTemplate; +import skylands.config.template.Metadata; +import skylands.config.template.Template; import skylands.logic.Skylands; import java.io.BufferedReader; @@ -15,6 +19,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class SkylandsConfig { public static final Gson GSON = new GsonBuilder().setLenient().setPrettyPrinting().create(); @@ -46,6 +51,14 @@ public static void init() { Skylands.config = SkylandsConfig.read(); } + public Optional getIslandTemplate(String name) { + for(IslandTemplate template : islandTemplates) { + if(template.name.equals(name)) return Optional.of(template); + } + + return Optional.empty(); + } + public static SkylandsConfig read() { String filePath = FabricLoader.getInstance().getConfigDir().resolve("skylands.json").toString(); try { diff --git a/src/main/java/skylands/config/HubTemplate.java b/src/main/java/skylands/config/template/HubTemplate.java similarity index 80% rename from src/main/java/skylands/config/HubTemplate.java rename to src/main/java/skylands/config/template/HubTemplate.java index 2d6fe41..73e7592 100644 --- a/src/main/java/skylands/config/HubTemplate.java +++ b/src/main/java/skylands/config/template/HubTemplate.java @@ -1,4 +1,4 @@ -package skylands.config; +package skylands.config.template; public class HubTemplate extends Template { diff --git a/src/main/java/skylands/config/IslandTemplate.java b/src/main/java/skylands/config/template/IslandTemplate.java similarity index 80% rename from src/main/java/skylands/config/IslandTemplate.java rename to src/main/java/skylands/config/template/IslandTemplate.java index 3a1a2c7..0a43f41 100644 --- a/src/main/java/skylands/config/IslandTemplate.java +++ b/src/main/java/skylands/config/template/IslandTemplate.java @@ -1,4 +1,6 @@ -package skylands.config; +package skylands.config.template; + +import skylands.config.PlayerPosition; public class IslandTemplate extends Template { public String netherTemplate; diff --git a/src/main/java/skylands/config/Metadata.java b/src/main/java/skylands/config/template/Metadata.java similarity index 93% rename from src/main/java/skylands/config/Metadata.java rename to src/main/java/skylands/config/template/Metadata.java index 9b44089..b30ebe5 100644 --- a/src/main/java/skylands/config/Metadata.java +++ b/src/main/java/skylands/config/template/Metadata.java @@ -1,9 +1,10 @@ -package skylands.config; +package skylands.config.template; import com.google.gson.annotations.JsonAdapter; import net.minecraft.util.BlockRotation; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; +import skylands.config.BlockPosition; public class Metadata { diff --git a/src/main/java/skylands/config/Template.java b/src/main/java/skylands/config/template/Template.java similarity index 93% rename from src/main/java/skylands/config/Template.java rename to src/main/java/skylands/config/template/Template.java index edf3894..fa5eb37 100644 --- a/src/main/java/skylands/config/Template.java +++ b/src/main/java/skylands/config/template/Template.java @@ -1,4 +1,4 @@ -package skylands.config; +package skylands.config.template; import com.google.gson.annotations.JsonAdapter; import net.minecraft.block.Block; @@ -8,6 +8,7 @@ import net.minecraft.util.BlockMirror; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; +import skylands.config.PlayerPosition; public class Template { public String name; @@ -19,6 +20,8 @@ public class Template { @JsonAdapter(PlayerPosition.JsonAdapter.class) @Nullable public PlayerPosition playerVisitsPosition; + public String permission; + public Template(String name, String type, Metadata metadata, PlayerPosition playerSpawnPosition) { this.name = name; this.type = type; diff --git a/src/main/java/skylands/logic/Island.java b/src/main/java/skylands/logic/Island.java index 27538ff..0c41c57 100644 --- a/src/main/java/skylands/logic/Island.java +++ b/src/main/java/skylands/logic/Island.java @@ -24,9 +24,9 @@ import org.apache.commons.io.FileUtils; import skylands.SkylandsMod; import skylands.api.SkylandsAPI; -import skylands.config.IslandTemplate; +import skylands.config.template.IslandTemplate; import skylands.config.PlayerPosition; -import skylands.config.Template; +import skylands.config.template.Template; import skylands.util.SkylandsTexts; import xyz.nucleoid.fantasy.Fantasy; import xyz.nucleoid.fantasy.RuntimeWorldConfig; diff --git a/src/main/java/skylands/logic/IslandStuck.java b/src/main/java/skylands/logic/IslandStuck.java index 1946a98..e41a8a0 100644 --- a/src/main/java/skylands/logic/IslandStuck.java +++ b/src/main/java/skylands/logic/IslandStuck.java @@ -6,7 +6,7 @@ import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.Nullable; import skylands.SkylandsMod; -import skylands.config.IslandTemplate; +import skylands.config.template.IslandTemplate; import java.io.File; import java.util.ArrayList; diff --git a/src/main/java/skylands/mixin/world/protection/MinecartMixin.java b/src/main/java/skylands/mixin/world/protection/VehicleEntityMixin.java similarity index 95% rename from src/main/java/skylands/mixin/world/protection/MinecartMixin.java rename to src/main/java/skylands/mixin/world/protection/VehicleEntityMixin.java index dd38a9e..dea810b 100644 --- a/src/main/java/skylands/mixin/world/protection/MinecartMixin.java +++ b/src/main/java/skylands/mixin/world/protection/VehicleEntityMixin.java @@ -4,7 +4,6 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.entity.vehicle.VehicleEntity; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin;