push
This commit is contained in:
parent
65c654d6e7
commit
a82dfcf917
|
@ -6,12 +6,11 @@ import lombok.Getter;
|
|||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import xyz.twovb.sgm.commands.impl.LevelCommand;
|
||||
import xyz.twovb.sgm.commands.impl.SGMCommand;
|
||||
import xyz.twovb.sgm.commands.handlers.InvalidArgsHandler;
|
||||
import xyz.twovb.sgm.commands.handlers.NoPermissionsHandler;
|
||||
import xyz.twovb.sgm.listeners.TestListener;
|
||||
import xyz.twovb.toolbox.managers.ConfigManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.managers.DatabaseManager;
|
||||
|
@ -56,7 +55,7 @@ public final class SGM extends JavaPlugin {
|
|||
databaseManager = new DatabaseManager();
|
||||
try {
|
||||
databaseManager.connect(DatabaseManager.DatabaseType.SQLITE, this, "sgm");
|
||||
toolLogger.log("Connected to database");
|
||||
toolLogger.log("Connected to database!");
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -72,8 +71,8 @@ public final class SGM extends JavaPlugin {
|
|||
|
||||
private void registerCommands() {
|
||||
LiteCommandsBukkit.builder()
|
||||
.settings(settings -> settings.fallbackPrefix("sgm").nativePermissions(false))
|
||||
.commands(new SGMCommand())
|
||||
// .settings(settings -> settings.fallbackPrefix("sgm").nativePermissions(false))
|
||||
.commands(new SGMCommand(), new LevelCommand())
|
||||
.invalidUsage(new InvalidArgsHandler())
|
||||
.missingPermission(new NoPermissionsHandler())
|
||||
.message(LiteBukkitMessages.PLAYER_NOT_FOUND, input -> Messages.getString("commands.invalid-player").replace("%player%", input))
|
||||
|
@ -81,15 +80,13 @@ public final class SGM extends JavaPlugin {
|
|||
.build();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new TestListener(), this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
try {
|
||||
databaseManager.close();
|
||||
} catch (SQLException e) {
|
||||
toolLogger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public class InvalidArgsHandler implements InvalidUsageHandler<CommandSender> {
|
|||
StringBuilder builder = new StringBuilder();
|
||||
builder.insert(0, "\n");
|
||||
if (schematic.isOnlyFirst()) {
|
||||
// borken idk why ill fix later
|
||||
message = message.replace("%usage%", "\n&8 - &7" + schematic.first());
|
||||
} else {
|
||||
List<String> schemes = schematic.all();
|
||||
|
|
|
@ -7,12 +7,13 @@ import dev.rollczi.litecommands.permission.MissingPermissionsHandler;
|
|||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
public class NoPermissionsHandler implements MissingPermissionsHandler<CommandSender> {
|
||||
@Override
|
||||
public void handle(Invocation<CommandSender> invocation, MissingPermissions missingPermissions, ResultHandlerChain<CommandSender> chain) {
|
||||
String permissions = missingPermissions.asJoinedText();
|
||||
CommandSender sender = invocation.sender();
|
||||
sender.sendMessage(SGM.getInstance().getMessages().getString("commands.no-permissions").replace("%permission%", permissions));
|
||||
sender.sendMessage(ChatUtils.translate(SGM.getInstance().getMessages().getString("commands.no-permissions").replace("%permission%", permissions)));
|
||||
}
|
||||
}
|
||||
|
|
35
src/main/java/xyz/twovb/sgm/commands/impl/LevelCommand.java
Normal file
35
src/main/java/xyz/twovb/sgm/commands/impl/LevelCommand.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import dev.rollczi.litecommands.annotations.argument.Arg;
|
||||
import dev.rollczi.litecommands.annotations.command.Command;
|
||||
import dev.rollczi.litecommands.annotations.context.Context;
|
||||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||
import dev.rollczi.litecommands.annotations.permission.Permission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.levels.LevelManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Command(name = "level")
|
||||
public class LevelCommand {
|
||||
|
||||
@Execute(name = "create")
|
||||
@Permission("sgm.levels.create")
|
||||
void create(@Context CommandSender sender, @Arg("name") Optional<String> LevelName) {
|
||||
LevelManager mm = new LevelManager();
|
||||
String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||
if (mm.createLevel(name)) {
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.new"), sender).replace("%level%", name)));
|
||||
} else {
|
||||
sender.sendMessage(ChatUtils.translate(PlaceholderManager.setPlaceholders(SGM.getInstance().getMessages().getString("sgm.level.exists"), sender).replace("%level%", name)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@ import dev.rollczi.litecommands.annotations.context.Context;
|
|||
import dev.rollczi.litecommands.annotations.execute.Execute;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import xyz.twovb.$REPO_NAME_LOWER.SGM
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
|
|
57
src/main/java/xyz/twovb/sgm/games/GameManager.java
Normal file
57
src/main/java/xyz/twovb/sgm/games/GameManager.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GameManager {
|
||||
|
||||
@Getter
|
||||
private static Map<UUID, Minigame> activeGames;
|
||||
|
||||
public static Minigame findGame(UUID gameId) {
|
||||
return activeGames.get(gameId);
|
||||
}
|
||||
|
||||
public static Minigame findGame(Player player) {
|
||||
for (Minigame game : activeGames.values()) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isInGame(Player player) {
|
||||
for (Minigame game : activeGames.values()) {
|
||||
if (game.getPlayers().contains(player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createGame(Minigame game, CommandSender owner) {
|
||||
game.init(owner);
|
||||
activeGames.put(game.getGameId(), game);
|
||||
}
|
||||
|
||||
public void addPlayerToGame(Player player, UUID gameId) {
|
||||
Minigame game = findGame(gameId);
|
||||
if (game.getState() == Minigame.GameState.READY && !game.getPlayers().contains(player) && !isInGame(player)) {
|
||||
game.addPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlayerFromGame(Player player, UUID gameId) {
|
||||
Minigame game = findGame(gameId);
|
||||
game.removePlayer(player);
|
||||
}
|
||||
|
||||
}
|
42
src/main/java/xyz/twovb/sgm/games/Minigame.java
Normal file
42
src/main/java/xyz/twovb/sgm/games/Minigame.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import xyz.twovb.toolbox.api.ToolPlayer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Minigame extends Listener {
|
||||
|
||||
enum GameState {
|
||||
PRESTART,
|
||||
READY,
|
||||
STARTED,
|
||||
ENDING
|
||||
}
|
||||
|
||||
void init(CommandSender owner);
|
||||
void start();
|
||||
void stop();
|
||||
void addPlayer(Player player);
|
||||
void removePlayer(Player player);
|
||||
List<Player> getPlayers();
|
||||
void onTick();
|
||||
String getName();
|
||||
UUID getGameId();
|
||||
GameState getState();
|
||||
CommandSender getOwner();
|
||||
default void sendMessageToAllPlayers(String message) {
|
||||
for (Player player : getPlayers()) {
|
||||
ToolPlayer toolPlayer = new ToolPlayer(player);
|
||||
toolPlayer.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/xyz/twovb/sgm/levels/Level.java
Normal file
11
src/main/java/xyz/twovb/sgm/levels/Level.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
public interface Level {
|
||||
String getName();
|
||||
World getWorld();
|
||||
}
|
40
src/main/java/xyz/twovb/sgm/levels/LevelManager.java
Normal file
40
src/main/java/xyz/twovb/sgm/levels/LevelManager.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LevelManager {
|
||||
|
||||
private final String path = SGM.getInstance().getDataFolder().getPath() + "/levels/";
|
||||
|
||||
public boolean createLevel(String name) {
|
||||
WorldCreator wc = new WorldCreator(path + name, new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||
if (new File(path + name).exists()) {
|
||||
return false;
|
||||
}
|
||||
wc.type(WorldType.FLAT);
|
||||
wc.generatorSettings("{\"layers\": [{\"block\": \"air\", \"height\": 1}], \"biome\":\"plains\"}");
|
||||
wc.generateStructures(false);
|
||||
World world = wc.createWorld();
|
||||
assert world != null;
|
||||
Location location = new Location(world, 0, 0, 0);
|
||||
Block block = location.subtract(0, 1, 0).getBlock();
|
||||
block.setType(Material.STONE);
|
||||
world.setSpawnLocation(location);
|
||||
world.setSpawnFlags(false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// public void deleteLevel(String name) {
|
||||
// World world = Bukkit.getWorld(new NamespacedKey(SGM.getInstance(), "level_" + name));
|
||||
// assert world != null;
|
||||
// Bukkit.unloadWorld(world, false);
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package xyz.twovb.sgm.listeners;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class TestListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
player.sendMessage("Hello " + player.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -8,3 +8,18 @@ commands:
|
|||
player-only: "&7You must be a player to run this command."
|
||||
no-permissions: "&7You do not have the required permission &e%permission%&7 to do this."
|
||||
wrong-args: "&7Invalid command usage. %usage%"
|
||||
sgm:
|
||||
game:
|
||||
new: "&7A new %game% has started and can now be joined!"
|
||||
not-found: "&7Game couldn't be found!"
|
||||
cant-start: "&7Game couldn't be started!"
|
||||
cant-join: "&7Could not join this game!"
|
||||
started: "&7Game has started!"
|
||||
joined: "&7%player% has joined the game!"
|
||||
left: "&7%player% has left the game."
|
||||
win: "&7Congratulations to %winner% for winning!"
|
||||
level:
|
||||
new: "&7A level with the name %level% has been created."
|
||||
deleted: "&7A level with the name %level% has been deleted."
|
||||
exists: "&7A level with the name %level% already exists."
|
||||
not-found: "&7Level couldn't be found!"
|
|
@ -4,3 +4,10 @@ main: '${project.mainClass}'
|
|||
author: '2vb'
|
||||
api-version: '1.20'
|
||||
softdepend: [PlaceholderAPI]
|
||||
permissions:
|
||||
sgm.levels:
|
||||
description: "Allows the user to manage levels"
|
||||
default: op
|
||||
children:
|
||||
sgm.levels.create: true
|
||||
sgm.levels.tp: true
|
Loading…
Reference in New Issue
Block a user