parent
a82dfcf917
commit
5d0035282d
2
pom.xml
2
pom.xml
|
@ -145,7 +145,7 @@
|
|||
<dependency>
|
||||
<groupId>xyz.twovb</groupId>
|
||||
<artifactId>Toolbox</artifactId>
|
||||
<version>0.1</version>
|
||||
<version>0.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -7,14 +7,14 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
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.commands.impl.LevelCommand;
|
||||
import xyz.twovb.sgm.commands.impl.SGMCommand;
|
||||
import xyz.twovb.toolbox.managers.ConfigManager;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.managers.DatabaseManager;
|
||||
import xyz.twovb.toolbox.utils.ToolLogger;
|
||||
import xyz.twovb.toolbox.managers.PlaceholderManager;
|
||||
import xyz.twovb.toolbox.utils.CustomLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
@ -29,7 +29,7 @@ public final class SGM extends JavaPlugin {
|
|||
@Getter
|
||||
private FileConfiguration Messages;
|
||||
@Getter
|
||||
private ToolLogger toolLogger;
|
||||
private CustomLogger cLogger;
|
||||
private ConfigManager configManager;
|
||||
@Getter
|
||||
private DatabaseManager databaseManager;
|
||||
|
@ -38,14 +38,15 @@ public final class SGM extends JavaPlugin {
|
|||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
toolLogger = new ToolLogger(this);
|
||||
cLogger = new CustomLogger(this);
|
||||
configManager = new ConfigManager(this);
|
||||
Messages = configManager.loadConfig("messages.yml");
|
||||
this.saveDefaultConfig();
|
||||
BuildInfo = new YamlConfiguration();
|
||||
try {
|
||||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||
} catch (IOException | InvalidConfigurationException ignored) {}
|
||||
} catch (IOException | InvalidConfigurationException ignored) {
|
||||
}
|
||||
registerCommands();
|
||||
registerPlaceholders();
|
||||
connectToDatabase();
|
||||
|
@ -55,7 +56,7 @@ public final class SGM extends JavaPlugin {
|
|||
databaseManager = new DatabaseManager();
|
||||
try {
|
||||
databaseManager.connect(DatabaseManager.DatabaseType.SQLITE, this, "sgm");
|
||||
toolLogger.log("Connected to database!");
|
||||
cLogger.log("Connected to database!");
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -70,14 +71,7 @@ public final class SGM extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerCommands() {
|
||||
LiteCommandsBukkit.builder()
|
||||
// .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))
|
||||
.message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only"))
|
||||
.build();
|
||||
LiteCommandsBukkit.builder().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)).message(LiteBukkitMessages.PLAYER_ONLY, input -> Messages.getString("commands.player-only")).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +79,7 @@ public final class SGM extends JavaPlugin {
|
|||
try {
|
||||
databaseManager.close();
|
||||
} catch (SQLException e) {
|
||||
toolLogger.error(e);
|
||||
cLogger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ package xyz.twovb.sgm.games;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import xyz.twovb.toolbox.api.ToolPlayer;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -34,8 +34,8 @@ public interface Minigame extends Listener {
|
|||
CommandSender getOwner();
|
||||
default void sendMessageToAllPlayers(String message) {
|
||||
for (Player player : getPlayers()) {
|
||||
ToolPlayer toolPlayer = new ToolPlayer(player);
|
||||
toolPlayer.sendMessage(message);
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
cPlayer.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
129
src/main/java/xyz/twovb/sgm/games/impl/TestGame.java
Normal file
129
src/main/java/xyz/twovb/sgm/games/impl/TestGame.java
Normal file
|
@ -0,0 +1,129 @@
|
|||
package xyz.twovb.sgm.games.impl;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 26/6/2024
|
||||
*/
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TestGame implements Minigame {
|
||||
|
||||
final String name = "TestGame";
|
||||
private final UUID uuid;
|
||||
private CommandSender owner;
|
||||
private GameState state;
|
||||
private final List<Player> players;
|
||||
|
||||
public TestGame() {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.state = GameState.PRESTART;
|
||||
this.players = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void init(CommandSender owner) {
|
||||
// Perform initialization logic here
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
this.owner = owner;
|
||||
state = GameState.READY;
|
||||
owner.sendMessage("A new " + name + " instance with ID " + uuid + " has been created and is now ready!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (state == GameState.PRESTART) {
|
||||
state = GameState.STARTED;
|
||||
sendMessageToAllPlayers("The game has started!");
|
||||
for (Player player : players) {
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
}
|
||||
Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
// Stop game logic
|
||||
state = GameState.ENDING;
|
||||
Player winner;
|
||||
if (players.size() <= 1) {
|
||||
winner = players.get(0);
|
||||
winner.sendMessage("Congratulations on winning the game!");
|
||||
}
|
||||
players.clear(); // Clear player list
|
||||
GameManager.getActiveGames().remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
sendMessageToAllPlayers(player.getName() + " has joined the game!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (players.contains(player)) {
|
||||
removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (players.contains(player)) {
|
||||
sendMessageToAllPlayers(player.getName() + " was eliminated!");
|
||||
event.setDeathMessage("");
|
||||
removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getGameId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandSender getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user