|
|
|
@ -3,14 +3,12 @@ package xyz.soukup.ecoCraftCore.islands; |
|
|
|
import com.infernalsuite.asp.api.AdvancedSlimePaperAPI; |
|
|
|
import com.infernalsuite.asp.api.AdvancedSlimePaperAPI; |
|
|
|
import com.infernalsuite.asp.api.world.SlimeWorld; |
|
|
|
import com.infernalsuite.asp.api.world.SlimeWorld; |
|
|
|
import com.j256.ormlite.stmt.QueryBuilder; |
|
|
|
import com.j256.ormlite.stmt.QueryBuilder; |
|
|
|
import com.mojang.brigadier.Message; |
|
|
|
|
|
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType; |
|
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType; |
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType; |
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType; |
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
|
|
|
import com.mojang.brigadier.context.CommandContext; |
|
|
|
import com.mojang.brigadier.context.CommandContext; |
|
|
|
import io.papermc.paper.command.brigadier.CommandSourceStack; |
|
|
|
import io.papermc.paper.command.brigadier.CommandSourceStack; |
|
|
|
import io.papermc.paper.command.brigadier.Commands; |
|
|
|
import io.papermc.paper.command.brigadier.Commands; |
|
|
|
import net.kyori.adventure.text.Component; |
|
|
|
|
|
|
|
import org.bukkit.Location; |
|
|
|
import org.bukkit.Location; |
|
|
|
import org.bukkit.NamespacedKey; |
|
|
|
import org.bukkit.NamespacedKey; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
import org.bukkit.entity.Player; |
|
|
|
@ -24,9 +22,10 @@ import java.io.IOException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static xyz.soukup.ecoCraftCore.EcoCraftCore.config; |
|
|
|
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; |
|
|
|
import static xyz.soukup.ecoCraftCore.EcoCraftCore.plugin; |
|
|
|
|
|
|
|
|
|
|
|
public class IslandCommand { |
|
|
|
public class IslandAdminCommand { |
|
|
|
private final AdvancedSlimePaperAPI asp = AdvancedSlimePaperAPI.instance(); |
|
|
|
private final AdvancedSlimePaperAPI asp = AdvancedSlimePaperAPI.instance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +34,7 @@ public class IslandCommand { |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> tp = Commands.literal("tp") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> tp = Commands.literal("tp") |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
.executes(IslandCommand::teleport) |
|
|
|
.executes(IslandAdminCommand::teleport) |
|
|
|
.suggests(((context, builder) -> { |
|
|
|
.suggests(((context, builder) -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
QueryBuilder<Island, Integer> queryBuilder = DaoRegistry.getIslandDao().queryBuilder(); |
|
|
|
QueryBuilder<Island, Integer> queryBuilder = DaoRegistry.getIslandDao().queryBuilder(); |
|
|
|
@ -66,7 +65,7 @@ public class IslandCommand { |
|
|
|
})) |
|
|
|
})) |
|
|
|
.then(Commands.argument("display_name", StringArgumentType.string()) |
|
|
|
.then(Commands.argument("display_name", StringArgumentType.string()) |
|
|
|
.then(Commands.argument("description", StringArgumentType.greedyString()) |
|
|
|
.then(Commands.argument("description", StringArgumentType.greedyString()) |
|
|
|
.executes(IslandCommand::createWorld)))); |
|
|
|
.executes(IslandAdminCommand::createWorld)))); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> load = Commands.literal("load") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> load = Commands.literal("load") |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
@ -83,7 +82,7 @@ public class IslandCommand { |
|
|
|
throw new RuntimeException(e); |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
})) |
|
|
|
})) |
|
|
|
.executes(IslandCommand::loadWorld)); |
|
|
|
.executes(IslandAdminCommand::loadWorld)); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> loadTemplate = Commands.literal("loadTemplate") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> loadTemplate = Commands.literal("loadTemplate") |
|
|
|
.then(Commands.argument("name", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("name", StringArgumentType.word()) |
|
|
|
@ -100,7 +99,7 @@ public class IslandCommand { |
|
|
|
} |
|
|
|
} |
|
|
|
return builder.buildFuture(); |
|
|
|
return builder.buildFuture(); |
|
|
|
})) |
|
|
|
})) |
|
|
|
.executes(IslandCommand::loadTemplate)); |
|
|
|
.executes(IslandAdminCommand::loadTemplate)); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> template = Commands.literal("template") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> template = Commands.literal("template") |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("uuid", StringArgumentType.word()) |
|
|
|
@ -118,31 +117,31 @@ public class IslandCommand { |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then(Commands.argument("templateName", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("templateName", StringArgumentType.word()) |
|
|
|
.executes(IslandCommand::createTemplate))); |
|
|
|
.executes(IslandAdminCommand::createTemplate))); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> metadata = Commands.literal("metadata") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> metadata = Commands.literal("metadata") |
|
|
|
.then(Commands.argument("key", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("key", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("value", IntegerArgumentType.integer()) |
|
|
|
.then(Commands.argument("value", IntegerArgumentType.integer()) |
|
|
|
.executes(IslandCommand::setMetadata))); |
|
|
|
.executes(IslandAdminCommand::setMetadata))); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> metadataString = Commands.literal("metadataString") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> metadataString = Commands.literal("metadataString") |
|
|
|
.then(Commands.argument("key", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("key", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("value", StringArgumentType.string()) |
|
|
|
.then(Commands.argument("value", StringArgumentType.string()) |
|
|
|
.executes(IslandCommand::setMetadataString))); |
|
|
|
.executes(IslandAdminCommand::setMetadataString))); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> expand = Commands.literal("expand") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> expand = Commands.literal("expand") |
|
|
|
.then(Commands.argument("lenght", IntegerArgumentType.integer()) |
|
|
|
.then(Commands.argument("lenght", IntegerArgumentType.integer()) |
|
|
|
.executes(IslandCommand::expandIsland)); |
|
|
|
.executes(IslandAdminCommand::expandIsland)); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> listMetadata = Commands.literal("listMetadata") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> listMetadata = Commands.literal("listMetadata") |
|
|
|
.executes(IslandCommand::readAllMetadata); |
|
|
|
.executes(IslandAdminCommand::readAllMetadata); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> spawn = Commands.literal("spawn") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> spawn = Commands.literal("spawn") |
|
|
|
.executes(IslandCommand::setSpawn); |
|
|
|
.executes(IslandAdminCommand::setSpawn); |
|
|
|
|
|
|
|
|
|
|
|
LiteralArgumentBuilder<CommandSourceStack> enviroment = Commands.literal("environment") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> enviroment = Commands.literal("environment") |
|
|
|
.then(Commands.argument("environment", StringArgumentType.word()) |
|
|
|
.then(Commands.argument("environment", StringArgumentType.word()) |
|
|
|
.executes(IslandCommand::setEnvironment) |
|
|
|
.executes(IslandAdminCommand::setEnvironment) |
|
|
|
.suggests(((context, builder) -> { |
|
|
|
.suggests(((context, builder) -> { |
|
|
|
builder.suggest("normal"); |
|
|
|
builder.suggest("normal"); |
|
|
|
builder.suggest("nether"); |
|
|
|
builder.suggest("nether"); |
|
|
|
@ -150,7 +149,11 @@ public class IslandCommand { |
|
|
|
return builder.buildFuture(); |
|
|
|
return builder.buildFuture(); |
|
|
|
}))); |
|
|
|
}))); |
|
|
|
|
|
|
|
|
|
|
|
return Commands.literal("island") |
|
|
|
LiteralArgumentBuilder<CommandSourceStack> setDefaultIsland = Commands.literal("setDefaultIsland") |
|
|
|
|
|
|
|
.executes(IslandAdminCommand::setDefualtIsland); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Commands.literal("island-admin") |
|
|
|
|
|
|
|
.requires(commandSourceStack -> commandSourceStack.getSender().isOp()) |
|
|
|
.then(tp) |
|
|
|
.then(tp) |
|
|
|
.then(create) |
|
|
|
.then(create) |
|
|
|
.then(load) |
|
|
|
.then(load) |
|
|
|
@ -161,8 +164,20 @@ public class IslandCommand { |
|
|
|
.then(loadTemplate) |
|
|
|
.then(loadTemplate) |
|
|
|
.then(spawn) |
|
|
|
.then(spawn) |
|
|
|
.then(enviroment) |
|
|
|
.then(enviroment) |
|
|
|
.then(expand); |
|
|
|
.then(expand) |
|
|
|
|
|
|
|
.then(setDefaultIsland); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static int setDefualtIsland(CommandContext<CommandSourceStack> context){ |
|
|
|
|
|
|
|
if (!(context.getSource().getSender() instanceof Player player)) return 0; |
|
|
|
|
|
|
|
String uuid = player.getWorld().getName(); |
|
|
|
|
|
|
|
config.set("islands.spawn", uuid); |
|
|
|
|
|
|
|
plugin.saveConfig(); |
|
|
|
|
|
|
|
player.sendMessage("done."); |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -191,7 +206,8 @@ public class IslandCommand { |
|
|
|
private static int teleport(CommandContext<CommandSourceStack> context) { |
|
|
|
private static int teleport(CommandContext<CommandSourceStack> context) { |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
islandManager.teleport((Player) context.getSource().getSender(), context.getArgument("uuid", String.class)); |
|
|
|
Integer status = islandManager.teleport((Player) context.getSource().getSender(), context.getArgument("uuid", String.class)); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage(String.valueOf(status)); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -203,19 +219,23 @@ public class IslandCommand { |
|
|
|
String type = context.getArgument("type", String.class); |
|
|
|
String type = context.getArgument("type", String.class); |
|
|
|
String displayName = context.getArgument("display_name", String.class); |
|
|
|
String displayName = context.getArgument("display_name", String.class); |
|
|
|
String description = context.getArgument("description", String.class); |
|
|
|
String description = context.getArgument("description", String.class); |
|
|
|
islandManager.createIsland(type, displayName, description, "n", "n"); |
|
|
|
String uuid = islandManager.createIsland(type, displayName, description, "n", "n"); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage("Created island: " + uuid); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int loadWorld(CommandContext<CommandSourceStack> context) { |
|
|
|
private static int loadWorld(CommandContext<CommandSourceStack> context) { |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
islandManager.loadIsland(context.getArgument("uuid", String.class)); |
|
|
|
islandManager.loadIsland(context.getArgument("uuid", String.class)); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage("done."); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static int loadTemplate(CommandContext<CommandSourceStack> context) { |
|
|
|
private static int loadTemplate(CommandContext<CommandSourceStack> context) { |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
IslandManager islandManager = new IslandManager(); |
|
|
|
islandManager.loadIslandTemplate(context.getArgument("name", String.class)); |
|
|
|
islandManager.loadIslandTemplate(context.getArgument("name", String.class)); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage("done."); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -235,9 +255,8 @@ public class IslandCommand { |
|
|
|
String keyName = StringArgumentType.getString(context, "key"); |
|
|
|
String keyName = StringArgumentType.getString(context, "key"); |
|
|
|
Integer value = IntegerArgumentType.getInteger(context, "value"); |
|
|
|
Integer value = IntegerArgumentType.getInteger(context, "value"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player.getWorld().getPersistentDataContainer().set(new NamespacedKey(plugin, keyName), PersistentDataType.INTEGER, value); |
|
|
|
player.getWorld().getPersistentDataContainer().set(new NamespacedKey(plugin, keyName), PersistentDataType.INTEGER, value); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage(keyName + " set to " + value); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -248,7 +267,8 @@ public class IslandCommand { |
|
|
|
String value = StringArgumentType.getString(context, "value"); |
|
|
|
String value = StringArgumentType.getString(context, "value"); |
|
|
|
|
|
|
|
|
|
|
|
player.getWorld().getPersistentDataContainer().set(new NamespacedKey(plugin, keyName), PersistentDataType.STRING, value); |
|
|
|
player.getWorld().getPersistentDataContainer().set(new NamespacedKey(plugin, keyName), PersistentDataType.STRING, value); |
|
|
|
|
|
|
|
context.getSource().getSender().sendMessage(keyName + " set to " + value); |
|
|
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|