Skip to content
This repository has been archived by the owner on Dec 29, 2024. It is now read-only.

Commit

Permalink
Adding config.yml.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caaarlowsz committed Dec 28, 2024
1 parent 25a90a7 commit 059e76e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/github/caaarlowsz/pvp/PlayerListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()));
}
}
1 change: 1 addition & 0 deletions src/main/java/com/github/caaarlowsz/pvp/PvPClassic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/github/caaarlowsz/pvp/PvPCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/caaarlowsz/pvp/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ 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;
}

PlayerInventory inv = player.getInventory();
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;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/github/caaarlowsz/pvp/Strings.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
8 changes: 8 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -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.'

0 comments on commit 059e76e

Please sign in to comment.