Started working on Language.java, a.k.a customizable messages

This commit is contained in:
Matheus 2024-03-19 06:29:50 -04:00
parent 379232dd05
commit 6e4f5dbd0f
4 changed files with 52 additions and 17 deletions

View File

@ -0,0 +1,39 @@
package dev.lugami.otaku;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
public enum Language {
PEARL_COOLDOWN("COOLDOWN.PEARL"),
REKIT_COOLDOWN("COOLDOWN.REKIT");
private String path;
public String format(Object... objects) {
return new MessageFormat(ChatColor.translateAlternateColorCodes('&',
Main.getInstance().getLangConfig().getString(path))).format(objects);
}
public List<String> formatLines(Object... objects) {
List<String> lines = new ArrayList<>();
if (Main.getInstance().getLangConfig().get(path) instanceof String) {
lines.add(new MessageFormat(ChatColor.translateAlternateColorCodes('&',
Main.getInstance().getLangConfig().getString(path))).format(objects));
} else {
for (String string : Main.getInstance().getLangConfig().getStringList(path)) {
lines.add(new MessageFormat(ChatColor.translateAlternateColorCodes('&', string))
.format(objects));
}
}
return lines;
}
}

View File

@ -34,10 +34,7 @@ import java.util.Arrays;
public class Main extends JavaPlugin {
@Getter @Setter private static Main instance;
@Getter private BasicConfigurationFile mainConfig;
@Getter private BasicConfigurationFile scoreboardConfig;
@Getter private BasicConfigurationFile profileConfig;
@Getter private BasicConfigurationFile kitsConfig;
@Getter private BasicConfigurationFile mainConfig, scoreboardConfig, profileConfig, kitsConfig, langConfig;
@Getter @Setter private Honcho honcho;
@Getter private Essentials essentials;
@Getter private Assemble board;
@ -53,6 +50,7 @@ public class Main extends JavaPlugin {
scoreboardConfig = new BasicConfigurationFile(this, "scoreboard");
profileConfig = new BasicConfigurationFile(this, "profiles");
kitsConfig = new BasicConfigurationFile(this, "kits");
langConfig = new BasicConfigurationFile(this, "lang");
board = new Assemble(this, new Board(), 2, false, AssembleStyle.MODIFIED, true);
try {
saveMethodType = SaveMethodType.valueOf(mainConfig.getString("SAVE_METHOD"));

View File

@ -1,5 +1,6 @@
package dev.lugami.otaku.listener;
import dev.lugami.otaku.Language;
import dev.lugami.otaku.Main;
import dev.lugami.otaku.events.FFAJoinEvent;
import dev.lugami.otaku.events.FFAQuitEvent;
@ -102,7 +103,9 @@ public class FFAListener implements Listener {
}
if (Profile.getOrCreate(event.getPlayer()).getReKitCooldown() != null && !Profile.getOrCreate(event.getPlayer()).getReKitCooldown().hasExpired()) {
event.setCancelled(true);
event.getPlayer().sendMessage(CC.translate(CC.RED + "You're still on cooldown. &7(Cooldown: " + Profile.getOrCreate(event.getPlayer()).getReKitCooldown().getTimeLeft() + ")"));
//Profile.getOrCreate(event.getPlayer()).getReKitCooldown().getTimeLeft()
//"You're still on cooldown. &7(Cooldown: " + Profile.getOrCreate(event.getPlayer()).getReKitCooldown().getTimeLeft() + ")"
event.getPlayer().sendMessage(CC.translate(Language.REKIT_COOLDOWN.format(Profile.getOrCreate(event.getPlayer()).getReKitCooldown().getTimeLeft())));
} else {
setupKit(event.getPlayer(), event.getKit());
Profile.getOrCreate(event.getPlayer()).setReKitCooldown(new Cooldown(60_000));
@ -184,7 +187,8 @@ public class FFAListener implements Listener {
if (itemStack.getType() == Material.ENDER_PEARL) {
if (Profile.getOrCreate(player).getFFA().getKitRules().isEnderpearlCooldown()) {
if (Main.getInstance().getEnderpearlManager().isPearlCooldown(player)) {
event.getPlayer().sendMessage(CC.RED + "You're still in cooldown!" + CC.GRAY + " (Remaining: " + Main.getInstance().getEnderpearlManager().getPearlCooldown(event.getPlayer()) + "s)");
// CC.RED + "You're still in cooldown!" + CC.GRAY + " (Remaining: " + Main.getInstance().getEnderpearlManager().getPearlCooldown(event.getPlayer()) + "s)"
event.getPlayer().sendMessage(CC.translate(Language.PEARL_COOLDOWN.format(Main.getInstance().getEnderpearlManager().getPearlCooldown(event.getPlayer()))));
event.setCancelled(true);
} else {
Main.getInstance().getEnderpearlManager().setPearlCooldown(player, true);
@ -197,25 +201,16 @@ public class FFAListener implements Listener {
@EventHandler
public void onDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
Profile profile = Profile.getOrCreate(player);
if (profile.getState() == ProfileState.PLAYING) {
event.setCancelled(profile.getFFA().getKitRules().isNoFall());
if (Profile.getOrCreate((Player) event.getEntity()).getState() == ProfileState.PLAYING) event.setCancelled(Profile.getOrCreate((Player) event.getEntity()).getFFA().getKitRules().isNoFall());
}
}
} else {
return;
}
}
@EventHandler
public void onDamage2(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (Profile.getOrCreate(player).getFFA().getKitRules().isNoDamage()) {
event.setDamage(0.0);
}
if (Profile.getOrCreate((Player) event.getEntity()).getFFA().getKitRules().isNoDamage()) event.setDamage(0.0);
}
}

View File

@ -0,0 +1,3 @@
COOLDOWN:
REKIT: "You're still on re-kit cooldown. &7[{0}s]"
PEARL: "You're still on pearl cooldown. &7[{0}s]"