Skip to content

Commit

Permalink
template patches
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Dec 25, 2023
1 parent a2b6a4c commit 246d06c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
17 changes: 14 additions & 3 deletions src/main/java/skylands/command/CreateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static void init(CommandDispatcher<ServerCommandSource> 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();
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/skylands/config/SkylandsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -46,6 +51,14 @@ public static void init() {
Skylands.config = SkylandsConfig.read();
}

public Optional<IslandTemplate> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skylands.config;
package skylands.config.template;

public class HubTemplate extends Template {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package skylands.config;
package skylands.config.template;

import skylands.config.PlayerPosition;

public class IslandTemplate extends Template {
public String netherTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package skylands.config;
package skylands.config.template;

import com.google.gson.annotations.JsonAdapter;
import net.minecraft.block.Block;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/skylands/logic/Island.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/skylands/logic/IslandStuck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 246d06c

Please sign in to comment.