From 059e76eb2da3bcd82d871fa7163777b3563f21a0 Mon Sep 17 00:00:00 2001 From: Caaarlowsz Date: Sat, 28 Dec 2024 19:51:49 -0300 Subject: [PATCH] Adding config.yml. --- .../caaarlowsz/pvp/PlayerListeners.java | 9 ++-- .../com/github/caaarlowsz/pvp/PvPClassic.java | 1 + .../com/github/caaarlowsz/pvp/PvPCommand.java | 12 ++--- .../github/caaarlowsz/pvp/SpawnCommand.java | 8 ++-- .../com/github/caaarlowsz/pvp/Strings.java | 45 +++++++++++++++++++ src/main/resources/config.yml | 8 ++++ 6 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/github/caaarlowsz/pvp/Strings.java create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/com/github/caaarlowsz/pvp/PlayerListeners.java b/src/main/java/com/github/caaarlowsz/pvp/PlayerListeners.java index c2d3239..c9dfb79 100644 --- a/src/main/java/com/github/caaarlowsz/pvp/PlayerListeners.java +++ b/src/main/java/com/github/caaarlowsz/pvp/PlayerListeners.java @@ -22,7 +22,7 @@ private void onPlayerJoin(PlayerJoinEvent event) { if (player.teleportToSpawn()) player.giveKit(); - event.setJoinMessage("§7" + player.getDisplayName() + " entrou no servidor."); + event.setJoinMessage(Strings.getJoinMessage().replace("{player_name}", player.getDisplayName())); } @EventHandler(priority = EventPriority.NORMAL) @@ -33,9 +33,10 @@ private void onPlayerDeath(PlayerDeathEvent event) { Player killer = player.getKiller(); if (killer != null && killer != player) - event.setDeathMessage("§e" + killer.getDisplayName() + " §ematou " + player.getDisplayName() + "§e."); + event.setDeathMessage(Strings.getKillMessage().replace("{killer_name}", killer.getDisplayName()) + .replace("{player_name}", player.getDisplayName())); else - event.setDeathMessage("§e" + player.getDisplayName() + " §emorreu."); + event.setDeathMessage(Strings.getDeathMessage().replace("{player_name}", player.getDisplayName())); } @EventHandler(priority = EventPriority.NORMAL) @@ -52,6 +53,6 @@ private void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); PvPClassic.removePlayer(player); - event.setQuitMessage("§7" + player.getDisplayName() + " saiu do servidor."); + event.setQuitMessage(Strings.getQuitMessage().replace("{player_name}", player.getDisplayName())); } } \ No newline at end of file diff --git a/src/main/java/com/github/caaarlowsz/pvp/PvPClassic.java b/src/main/java/com/github/caaarlowsz/pvp/PvPClassic.java index 57f6809..9213c65 100644 --- a/src/main/java/com/github/caaarlowsz/pvp/PvPClassic.java +++ b/src/main/java/com/github/caaarlowsz/pvp/PvPClassic.java @@ -37,6 +37,7 @@ public static PvPClassic getPlugin() { @Override public void onEnable() { super.onEnable(); + this.saveDefaultConfig(); PluginManager pm = Bukkit.getPluginManager(); pm.registerEvents(new PlayerListeners(), this); diff --git a/src/main/java/com/github/caaarlowsz/pvp/PvPCommand.java b/src/main/java/com/github/caaarlowsz/pvp/PvPCommand.java index f67d061..d43ef57 100644 --- a/src/main/java/com/github/caaarlowsz/pvp/PvPCommand.java +++ b/src/main/java/com/github/caaarlowsz/pvp/PvPCommand.java @@ -10,25 +10,25 @@ public final class PvPCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (!sender.hasPermission("pvp.manage")) { - sender.hasPermission("§cVocê não possui permissão para usar este comando."); + if (!sender.hasPermission(cmd.getPermission())) { + sender.hasPermission(cmd.getPermissionMessage()); return true; } if (args.length == 0) { - sender.sendMessage("§cUse: /" + label + " [setspawn]"); + sender.sendMessage(cmd.getUsage()); return true; } if (args[0].equalsIgnoreCase("setspawn")) { if (!(sender instanceof Player)) { - sender.sendMessage("§cApenas jogadores podem usar este comando."); + sender.sendMessage(Strings.getCommandOnlyPlayers()); return true; } Location loc = ((Player) sender).getLocation(); loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - sender.sendMessage("§aVocê definiu a posição do spawn em " + loc.getBlockX() + ", " + loc.getBlockY() + ", " - + loc.getBlockZ() + "."); + sender.sendMessage(Strings.getSetSpawnSuccess().replace("{x}", String.valueOf(loc.getBlockX())) + .replace("{y}", String.valueOf(loc.getBlockY())).replace("{z}", String.valueOf(loc.getBlockZ()))); return true; } return true; diff --git a/src/main/java/com/github/caaarlowsz/pvp/SpawnCommand.java b/src/main/java/com/github/caaarlowsz/pvp/SpawnCommand.java index 2b3cbd8..df00391 100644 --- a/src/main/java/com/github/caaarlowsz/pvp/SpawnCommand.java +++ b/src/main/java/com/github/caaarlowsz/pvp/SpawnCommand.java @@ -13,14 +13,14 @@ public final class SpawnCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { - sender.sendMessage("§cApenas jogadores podem usar este comando."); + sender.sendMessage(Strings.getCommandOnlyPlayers()); return true; } PvPPlayer player = PvPClassic.getPlayer((Player) sender); if (player.getGameMode() == GameMode.CREATIVE && player.teleportToSpawn()) { player.giveKit(); - player.sendMessage("§aTeleportado para o spawn."); + player.sendMessage(Strings.getToSpawn()); return true; } @@ -28,11 +28,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String inv.setArmorContents(null); inv.clear(); player.setHealth(4); - player.sendMessage("§6Teleportando para o spawn... §8(aguarde 3s)"); + player.sendMessage(Strings.getWaitToSpawn()); Bukkit.getScheduler().runTaskLater(PvPClassic.getPlugin(), () -> { if (player.teleportToSpawn()) { player.giveKit(); - player.sendMessage("§aTeleportado para o spawn."); + player.sendMessage(Strings.getToSpawn()); } }, 60); return true; diff --git a/src/main/java/com/github/caaarlowsz/pvp/Strings.java b/src/main/java/com/github/caaarlowsz/pvp/Strings.java new file mode 100644 index 0000000..0c7a622 --- /dev/null +++ b/src/main/java/com/github/caaarlowsz/pvp/Strings.java @@ -0,0 +1,45 @@ +package com.github.caaarlowsz.pvp; + +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; + +public final class Strings { + + private static FileConfiguration config = PvPClassic.getPlugin().getConfig(); + + public static String getJoinMessage() { + return color(config.getString("join-message")); + } + + public static String getQuitMessage() { + return color(config.getString("quit-message")); + } + + public static String getDeathMessage() { + return color(config.getString("death-message")); + } + + public static String getKillMessage() { + return color(config.getString("kill-message")); + } + + public static String getCommandOnlyPlayers() { + return color(config.getString("command-only-players")); + } + + public static String getSetSpawnSuccess() { + return color(config.getString("setspawn-success")); + } + + public static String getToSpawn() { + return color(config.getString("to-spawn")); + } + + public static String getWaitToSpawn() { + return color(config.getString("wait-to-spawn")); + } + + private static String color(String input) { + return ChatColor.translateAlternateColorCodes('&', input); + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..aa496a2 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,8 @@ +join-message: '&7{player_name} joined the server.' +quit-message: '&7{player_name} left the server.' +death-message: '&e{player_name} died.' +kill-message: '&e{player_name} was killed by {killer_name}.' +command-only-players: '&cCommand for players only.' +setspawn-success: '&aYou set the spawn position to {x}, {y}, {z}.' +wait-to-spawn: '&6Teleporting from spawn... &7(wait 3s)' +to-spawn: '&aTeleported to spawn.' \ No newline at end of file