Some more funny message refactoring
This commit is contained in:
parent
fc18c06d8e
commit
a3fd984591
@ -17,8 +17,9 @@ import me.topchetoeu.bedwars.engine.Config;
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.Team;
|
||||
import me.topchetoeu.bedwars.engine.TeamColor;
|
||||
import me.topchetoeu.bedwars.messaging.MessageParser;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class Commands {
|
||||
private static File confFile = new File(Main.getInstance().getDataFolder(), "config.yml");
|
||||
@ -32,11 +33,11 @@ public class Commands {
|
||||
if (bwp != null) {
|
||||
bwp.kill(bwp.getPlayer().getName() + " definitely died with no admin intervention.");
|
||||
}
|
||||
else return "Player is not in game!";
|
||||
else return MessageUtility.parser("commands.not-in-game").variable("player", p.getDisplayName()).parse();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else return "The game isn't started yet";
|
||||
else return MessageUtility.parser("commands.game-not-started").parse();
|
||||
});
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -50,11 +51,11 @@ public class Commands {
|
||||
Bukkit.broadcastMessage("Player " + p.getName() + " revived!");
|
||||
return null;
|
||||
}
|
||||
else return "Player is not in game!";
|
||||
else return MessageUtility.parser("commands.not-in-game").variable("player", p.getDisplayName()).parse();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else return "The game isn't started yet";
|
||||
else return MessageUtility.parser("commands.game-not-started").parse();
|
||||
});
|
||||
}
|
||||
|
||||
@ -62,20 +63,20 @@ public class Commands {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
if (!Game.isStarted()) {
|
||||
Game.start();
|
||||
sender.sendMessage("Started the game!");
|
||||
MessageUtility.parser("commands.start.success").send(sender);
|
||||
return null;
|
||||
}
|
||||
else return "The game is already started";
|
||||
else return MessageUtility.parser("commands.start.game-started").parse();
|
||||
});
|
||||
}
|
||||
public static Command stop(Command cmd) {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
if (Game.isStarted()) {
|
||||
Game.stop();
|
||||
sender.sendMessage("Stopped the game!");
|
||||
MessageUtility.parser("commands.stop.success").send(sender);
|
||||
return null;
|
||||
}
|
||||
else return "The game is not started";
|
||||
else return MessageUtility.parser("commands.start.game-not-started").parse();
|
||||
});
|
||||
}
|
||||
|
||||
@ -105,12 +106,12 @@ public class Commands {
|
||||
if (Config.instance.getColor(name.toLowerCase()) == null) {
|
||||
Config.instance.getColors().add(new TeamColor(name, wool, Color.fromRGB(r, g, b), chatColor));
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("New base was created!");
|
||||
MessageUtility.parser("commands.base-add.success").variable("base", name).send(sender);
|
||||
return null;
|
||||
}
|
||||
else return "Base with this name already exists!";
|
||||
else return MessageUtility.parser("commands.base-add.already-exists").variable("base", name).parse();
|
||||
}
|
||||
else return "Can't make modifications to the map while a game is ongoing!";
|
||||
else return MessageUtility.parser("commands.base-add.game-started").parse();
|
||||
});
|
||||
}
|
||||
|
||||
@ -121,7 +122,7 @@ public class Commands {
|
||||
TeamColor color = (TeamColor)args.get("team");
|
||||
Config.instance.getColors().remove(color);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base removed!");
|
||||
MessageUtility.parser("commands.base-remove").variable("base", color.getColorName()).send(sender);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@ -135,7 +136,7 @@ public class Commands {
|
||||
|
||||
color.setSpawnLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base spawn set");
|
||||
MessageUtility.parser("commands.base-spawn").variable("base", color.getColorName()).send(sender);
|
||||
|
||||
return null;
|
||||
});
|
||||
@ -150,7 +151,7 @@ public class Commands {
|
||||
|
||||
color.setGeneratorLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base generator set");
|
||||
MessageUtility.parser("commands.base-generator").variable("base", color.getColorName()).send(sender);
|
||||
|
||||
return null;
|
||||
});
|
||||
@ -165,7 +166,7 @@ public class Commands {
|
||||
|
||||
color.setBedLocation(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("Base bed set");
|
||||
MessageUtility.parser("commands.base-bed").variable("base", color.getColorName()).send(sender);
|
||||
|
||||
return null;
|
||||
});
|
||||
@ -177,14 +178,22 @@ public class Commands {
|
||||
List<TeamColor> colors = Config.instance.getColors();
|
||||
|
||||
if (colors.size() != 0) {
|
||||
sender.sendMessage("Bases:");
|
||||
MessageUtility.parser("commands.base-list.title").variable("count", colors.size()).send(sender);
|
||||
for (TeamColor color : colors) {
|
||||
ComponentBuilder cb = new ComponentBuilder().append(color.getName()).color(color.getChatColor());
|
||||
if (!color.isFullySpecified()) cb.append(" (not fully specified)").reset().italic(true);
|
||||
sender.spigot().sendMessage(cb.create());
|
||||
MessageParser parser = MessageUtility.parser("commands.base-list.not-fully-specified");
|
||||
|
||||
if (color.isFullySpecified()) parser = MessageUtility.parser("commands.base-list.fully-specified");
|
||||
|
||||
parser
|
||||
.variable("name", color.getColorName())
|
||||
.variable("woolId", color.getWoolMaterial().getKey())
|
||||
.variable("colorRed", color.getColor().getRed())
|
||||
.variable("colorGreen", color.getColor().getGreen())
|
||||
.variable("colorBlue", color.getColor().getBlue())
|
||||
.send(sender);
|
||||
}
|
||||
}
|
||||
else sender.sendMessage("No bases found.");
|
||||
else MessageUtility.parser("commands.base-list.no-bases").send(sender);
|
||||
|
||||
return null;
|
||||
});
|
||||
@ -195,7 +204,7 @@ public class Commands {
|
||||
return cmd
|
||||
.addChild(basesArg()).setRecursive(true)
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
if (!Game.isStarted()) return "A game hasn't been started yet.";
|
||||
if (!Game.isStarted()) return MessageUtility.parser("commands.game-not-started").parse();
|
||||
|
||||
List<TeamColor> colors = (List<TeamColor>)args.get("team");
|
||||
ArrayList<Team> teams = new ArrayList<>();
|
||||
@ -203,7 +212,7 @@ public class Commands {
|
||||
Team team = Game.instance.getTeam(color);
|
||||
|
||||
if (team == null) {
|
||||
return "The team color %s isn't in the game.".formatted(color.getName());
|
||||
return MessageUtility.parser("commands.break-bed.not-in-game").variable("team", color.getColorName()).parse();
|
||||
}
|
||||
|
||||
teams.add(team);
|
||||
@ -222,7 +231,7 @@ public class Commands {
|
||||
Location loc = (Location)args.get("location");
|
||||
Config.instance.getDiamondGenerators().add(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("§aGenerator added!");
|
||||
MessageUtility.parser("commands.generator-create.diamond").send(sender);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@ -231,7 +240,7 @@ public class Commands {
|
||||
Location loc = (Location)args.get("location");
|
||||
Config.instance.getEmeraldGenerators().add(loc);
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("§aGenerator added!");
|
||||
MessageUtility.parser("commands.generator-create.emerald").send(sender);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@ -239,7 +248,7 @@ public class Commands {
|
||||
return cmd.setExecutor((sender, _cmd, args) -> {
|
||||
Config.instance.getEmeraldGenerators().clear();
|
||||
Config.instance.save(confFile);
|
||||
sender.sendMessage("§aGenerators cleared!");
|
||||
MessageUtility.parser("commands.generator-create.clear").send(sender);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -18,6 +19,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import me.topchetoeu.bedwars.commandUtility.Command;
|
||||
import me.topchetoeu.bedwars.commandUtility.CommandExecutors;
|
||||
import me.topchetoeu.bedwars.engine.AttackCooldownEradicator;
|
||||
import me.topchetoeu.bedwars.engine.Config;
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.trader.Favourites;
|
||||
@ -34,6 +36,7 @@ import me.topchetoeu.bedwars.engine.trader.upgrades.FatigueTeamUpgrade;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.HealTeamUpgrade;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.ProtectionTeamUpgrade;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.SharpnessTeamUpgrade;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
|
||||
// TODO add permissions
|
||||
|
||||
@ -56,7 +59,11 @@ public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
private void stopTimer() {
|
||||
if (timerTask == null) return;
|
||||
Utility.broadcastTitle("Not enough players!", null, 10, 40, 5);
|
||||
Utility.broadcastTitle(
|
||||
MessageUtility.parser("pre-game.not-enough-players.title").parse(),
|
||||
MessageUtility.parser("pre-game.not-enough-players.subtitle").parse(),
|
||||
10, 40, 5
|
||||
);
|
||||
timerTask.cancel();
|
||||
timerTask = null;
|
||||
}
|
||||
@ -68,10 +75,20 @@ public class Main extends JavaPlugin implements Listener {
|
||||
stopTimer();
|
||||
return;
|
||||
}
|
||||
if (timer % 30 == 0 || timer == 15 || timer == 10)
|
||||
Utility.broadcastTitle("Starting in " + timer + " seconds!", null, 10, 40, 5);
|
||||
else if (timer <= 5)
|
||||
Utility.broadcastTitle("Starting in " + timer + " seconds!", null, 0, 20, 0);
|
||||
if (timer % 30 == 0 || timer == 15 || timer == 10) {
|
||||
Utility.broadcastTitle(
|
||||
MessageUtility.parser("pre-game.starting.title").variable("time", timer).parse(),
|
||||
MessageUtility.parser("pre-game.starting.subtitle").variable("time", timer).parse(),
|
||||
10, 40, 5
|
||||
);
|
||||
}
|
||||
else if (timer <= 5) {
|
||||
Utility.broadcastTitle(
|
||||
MessageUtility.parser("pre-game.starting.title").variable("time", timer).parse(),
|
||||
MessageUtility.parser("pre-game.starting.subtitle").variable("time", timer).parse(),
|
||||
0, 21, 0
|
||||
);
|
||||
}
|
||||
timer--;
|
||||
if (timer <= 0) {
|
||||
Game.start();
|
||||
@ -84,7 +101,6 @@ public class Main extends JavaPlugin implements Listener {
|
||||
// TODO make timing configurable
|
||||
if (!Game.isStarted()) {
|
||||
if (playerCount <= 1 || playerCount <= getGameSize() / 4) {
|
||||
Utility.broadcastTitle("Not enough players", "Waiting for more...", 0, 100, 0);
|
||||
stopTimer();
|
||||
}
|
||||
else if (playerCount <= getGameSize() / 2) {
|
||||
@ -130,7 +146,9 @@ public class Main extends JavaPlugin implements Listener {
|
||||
conf.createNewFile();
|
||||
Config.load(conf);
|
||||
File defaultFavs = new File(getDataFolder(), "default-favourites.yml");
|
||||
|
||||
|
||||
MessageUtility.load(new File(getDataFolder(), "messages.yml"));
|
||||
|
||||
if (!defaultFavs.exists())
|
||||
defaultFavs.createNewFile();
|
||||
|
||||
@ -141,7 +159,9 @@ public class Main extends JavaPlugin implements Listener {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
AttackCooldownEradicator.init(this);
|
||||
|
||||
YamlConfiguration sectionsConf = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "sections.yml"));
|
||||
|
||||
BlindnessTeamUpgrade.init(this);
|
||||
@ -187,36 +207,37 @@ public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
Commands.createDiamondGen(generator.literal("diamond"));
|
||||
Commands.createEmeraldGen(generator.literal("emerald", "em"));
|
||||
Commands.clearGens(generator.literal("emerald", "em"));
|
||||
Commands.clearGens(generator.literal("clear"));
|
||||
|
||||
Commands.breakBed(cmd.literal("breakbed", "cheat", "bedishonest", "abusepowers"));
|
||||
cmd.literal("villagertools", "villagers", "traders")
|
||||
.setHelpMessage("Gives you tools to manage traders")
|
||||
.setExecutor((sender, _cmd, args) -> {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
Traders.instance.give(p);
|
||||
return null;
|
||||
}
|
||||
else return MessageUtility.parser("commands.for-players").parse();
|
||||
|
||||
});
|
||||
cmd.register(this);
|
||||
// .attachCommand(new Command("respawn", "revive")
|
||||
// .setExecutor(Commands.revive)
|
||||
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
|
||||
// .attachCommand(new Command("breakbed", "eliminateteam")
|
||||
// .setExecutor(Commands.breakBed)
|
||||
// .setHelpMessage("Destoys the bed of a team")
|
||||
// )
|
||||
// .attachCommand(new Command("eliminate")
|
||||
// .setHelpMessage("Eliminates a player")
|
||||
// )
|
||||
// .attachCommand(new Command("killteam")
|
||||
// .setHelpMessage("Kills all players of a team")
|
||||
// )
|
||||
// .attachCommand(new Command("villagertools", "villager", "trader")
|
||||
// .setExecutor((sender, _cmd, alias, args) -> {
|
||||
// if (args.length == 0) {
|
||||
// if (sender instanceof Player) {
|
||||
// Player p = (Player)sender;
|
||||
// Traders.instance.give(p);
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .setHelpMessage("Gives you tools to manage traders")
|
||||
// )
|
||||
// .register(this);
|
||||
|
||||
// .attachCommand(new Command("respawn", "revive")
|
||||
// .setExecutor(Commands.revive)
|
||||
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
|
||||
// .attachCommand(new Command("breakbed", "eliminateteam")
|
||||
// .setExecutor(Commands.breakBed)
|
||||
// .setHelpMessage("Destoys the bed of a team")
|
||||
// )
|
||||
// .attachCommand(new Command("eliminate")
|
||||
// .setHelpMessage("Eliminates a player")
|
||||
// )
|
||||
// .attachCommand(new Command("killteam")
|
||||
// .setHelpMessage("Kills all players of a team")
|
||||
// )
|
||||
//
|
||||
// .register(this);
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
@ -25,13 +25,17 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
|
||||
public class Utility {
|
||||
public static void sendTitle(Player p, String title, String subtitle, int fadeIn, int duration, int fadeout) {
|
||||
p.sendTitle(title, subtitle, fadeIn, duration, fadeout);
|
||||
public static void sendTitle(Player p, BaseComponent[] title, BaseComponent[] subtitle, int fadeIn, int duration, int fadeout) {
|
||||
String _title = title == null ? null : BaseComponent.toLegacyText(title);
|
||||
String _subtitle = subtitle == null ? null : BaseComponent.toLegacyText(subtitle);
|
||||
p.sendTitle(_title, _subtitle, fadeIn, duration, fadeout);
|
||||
}
|
||||
public static void broadcastTitle(String title, String subtitle, int fadeIn, int duration, int fadeout) {
|
||||
public static void broadcastTitle(BaseComponent[] title, BaseComponent[] subtitle, int fadeIn, int duration, int fadeout) {
|
||||
Bukkit.getOnlinePlayers().forEach(v -> sendTitle(v, title, subtitle, fadeIn, duration, fadeout));
|
||||
}
|
||||
public static boolean isParsable(String val) {
|
||||
@ -57,11 +61,16 @@ public class Utility {
|
||||
i.setItemMeta(meta);
|
||||
return i;
|
||||
}
|
||||
public static TranslatableComponent getItemName(Material item) {
|
||||
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||
public static BaseComponent[] getItemName(Material item) {
|
||||
return getItemName(new ItemStack(item));
|
||||
}
|
||||
public static TranslatableComponent getItemName(ItemStack item) {
|
||||
return new TranslatableComponent(CraftItemStack.asNMSCopy(new ItemStack(item)).n());
|
||||
public static BaseComponent[] getItemName(ItemStack item) {
|
||||
if (item.getItemMeta().getDisplayName() != null && !item.getItemMeta().getDisplayName().isEmpty())
|
||||
return new ComponentBuilder().appendLegacy(item.getItemMeta().getDisplayName()).create();
|
||||
return new ComponentBuilder()
|
||||
.append(new TranslatableComponent(CraftItemStack.asNMSCopy(item).n()))
|
||||
.reset()
|
||||
.create();
|
||||
}
|
||||
public static void takeOne(Player p, EquipmentSlot e) {
|
||||
ItemStack i = p.getInventory().getItem(e);
|
||||
|
@ -24,6 +24,7 @@ import me.topchetoeu.bedwars.commandUtility.args.PlayerArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.StringArgParser;
|
||||
import me.topchetoeu.bedwars.commandUtility.args.Suggestions;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class Command {
|
||||
@ -150,12 +151,12 @@ public class Command {
|
||||
);
|
||||
else {
|
||||
if (toExecute.isRecursive() && !newArgs.containsKey(toExecute.name)) newArgs.put(toExecute.name, new ArrayList<>());
|
||||
err = toExecute.getExecutor().execute(sender, this, newArgs);
|
||||
if (err != null) sender.spigot().sendMessage(new ComponentBuilder()
|
||||
BaseComponent[] _err = toExecute.getExecutor().execute(sender, this, newArgs);
|
||||
if (_err != null && _err.length > 0) sender.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("Error: ")
|
||||
.color(ChatColor.DARK_RED)
|
||||
.append(err)
|
||||
.color(ChatColor.RED)
|
||||
.reset()
|
||||
.create()
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public interface CommandExecutor {
|
||||
String execute(CommandSender sender, Command cmd, Map<String, Object> args);
|
||||
BaseComponent[] execute(CommandSender sender, Command cmd, Map<String, Object> args);
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package me.topchetoeu.bedwars.engine;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AttackCooldownEradicator implements Listener{
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerJoinEvent e){
|
||||
setAttackSpeed(e.getPlayer(), 32);
|
||||
}
|
||||
|
||||
private void setAttackSpeed(Player player, double attackSpeed){
|
||||
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
|
||||
attribute.setBaseValue(attackSpeed);
|
||||
player.saveData();
|
||||
}
|
||||
|
||||
public static AttackCooldownEradicator init(JavaPlugin pl) {
|
||||
AttackCooldownEradicator instance = new AttackCooldownEradicator();
|
||||
Bukkit.getPluginManager().registerEvents(instance, pl);
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -12,11 +12,14 @@ import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.dealTypes.RankedDealType;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.world.entity.EnumItemSlot;
|
||||
|
||||
@ -213,8 +216,8 @@ public class BedwarsPlayer implements Listener, AutoCloseable {
|
||||
reviveTask = null;
|
||||
}
|
||||
Utility.sendTitle(player.getPlayer(),
|
||||
"You died!",
|
||||
String.format("Respawning in %.2f", revivalTimer),
|
||||
MessageUtility.parser("player.died.title").parse(),
|
||||
MessageUtility.parser("player.died.subtitle").variable("time", "%.2f".formatted(revivalTimer)).parse(),
|
||||
0, 4, 5
|
||||
);
|
||||
revivalTimer -= 0.1;
|
||||
@ -259,7 +262,6 @@ public class BedwarsPlayer implements Listener, AutoCloseable {
|
||||
}
|
||||
else revivalPending = true;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public void eliminate() {
|
||||
if (spectator) return;
|
||||
if (!dead) {
|
||||
@ -271,17 +273,30 @@ public class BedwarsPlayer implements Listener, AutoCloseable {
|
||||
Bukkit.getServer().broadcastMessage(String.format("%s was eliminated.", player.getName()));
|
||||
|
||||
if (team.decreaseRemainingPlayers() > 0) {
|
||||
// TODO fix these messages
|
||||
// Also, this deprecation is just fine :)
|
||||
player.getPlayer().sendTitle("You are dead", "You can only spectate your more intelligent friends");
|
||||
Utility.sendTitle(
|
||||
getOnlinePlayer(),
|
||||
MessageUtility.parser("player.solo.eliminated.title").parse(),
|
||||
MessageUtility.parser("player.solo.eliminated.subtitle").parse(),
|
||||
5, 40, 10
|
||||
);
|
||||
}
|
||||
else
|
||||
Bukkit.getServer().broadcastMessage(String.format("Team %s was eliminated.", team.getTeamColor().getName()));
|
||||
if (team.getPlayersCount() == 1) {
|
||||
player.getPlayer().sendTitle("You were eliminated!", "Now you can spectate");
|
||||
Utility.sendTitle(
|
||||
getOnlinePlayer(),
|
||||
MessageUtility.parser("player.solo.eliminated.title").parse(),
|
||||
MessageUtility.parser("player.solo.eliminated.subtitle").parse(),
|
||||
5, 40, 10
|
||||
);
|
||||
}
|
||||
else
|
||||
player.getPlayer().sendTitle("Your team was eliminated", "Your team fucked up bad time :(");
|
||||
Utility.sendTitle(
|
||||
getOnlinePlayer(),
|
||||
MessageUtility.parser("player.team.eliminated.title").parse(),
|
||||
MessageUtility.parser("player.team.eliminated.subtitle").parse(),
|
||||
5, 40, 10
|
||||
);
|
||||
|
||||
spectator = true;
|
||||
}
|
||||
@ -344,6 +359,9 @@ public class BedwarsPlayer implements Listener, AutoCloseable {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
Player p = (Player)e.getEntity();
|
||||
if (equals(p)) {
|
||||
AttributeInstance attribute = p.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
attribute.setBaseValue(16);
|
||||
p.saveData();
|
||||
if (e.getDamager() instanceof Player) {
|
||||
offender = (OfflinePlayer)e.getDamager();
|
||||
}
|
||||
|
@ -44,6 +44,9 @@ import org.bukkit.util.Vector;
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.dealTypes.RankedDealType;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class Game implements Listener, AutoCloseable {
|
||||
public static Game instance = null;
|
||||
@ -101,8 +104,16 @@ public class Game implements Listener, AutoCloseable {
|
||||
}
|
||||
|
||||
public void win(TeamColor color) {
|
||||
getTeam(color).sendTitle("You won!", "", 0, 20 * 5, 0);
|
||||
getTeam(color).sendTitleToOthers(color.getColorName() + " won!", "You lost :(", 0, 20 * 5, 0);
|
||||
getTeam(color).sendTitle(
|
||||
MessageUtility.parser("player.won.title").parse(),
|
||||
MessageUtility.parser("player.won.subtitle").parse(),
|
||||
0, 20 * 5, 0
|
||||
);
|
||||
getTeam(color).sendTitleToOthers(
|
||||
MessageUtility.parser("player.lost.title").variable("team", color.getColorName()).parse(),
|
||||
MessageUtility.parser("player.lost.subtitle").variable("team", color.getColorName()).parse(),
|
||||
0, 20 * 5, 0
|
||||
);
|
||||
stop(false);
|
||||
}
|
||||
|
||||
@ -223,10 +234,15 @@ public class Game implements Listener, AutoCloseable {
|
||||
if(!isPlaying(e.getPlayer())) {
|
||||
e.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
e.getPlayer().teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||
Utility.sendTitle(e.getPlayer(), "You are now spectating", null, 5, 35, 10);
|
||||
Utility.sendTitle(
|
||||
e.getPlayer(),
|
||||
MessageUtility.parser("player.midgame-spectator.title").parse(),
|
||||
MessageUtility.parser("player.midgame-spectator.subtitle").parse(),
|
||||
5, 35, 10
|
||||
);
|
||||
}
|
||||
else
|
||||
e.setJoinMessage(e.getPlayer().getName() + " reconnected.");
|
||||
e.setJoinMessage(BaseComponent.toLegacyText(MessageUtility.parser("player.reconnected").variable("name", e.getPlayer().getDisplayName()).parse()));
|
||||
}
|
||||
@EventHandler
|
||||
private void onInventoryClick(InventoryClickEvent e) {
|
||||
@ -388,7 +404,7 @@ public class Game implements Listener, AutoCloseable {
|
||||
removed.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
removed.getPlayer().teleport(new Location(removed.getPlayer().getLocation().getWorld(), 0, 80, 0));
|
||||
}
|
||||
if (removed.isOnline()) removed.getPlayer().sendMessage("You will be a spectator");
|
||||
if (removed.isOnline()) MessageUtility.parser("player.will-be-spectator").send(removed.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,14 +435,14 @@ public class Game implements Listener, AutoCloseable {
|
||||
|
||||
// TODO: Make times configurable
|
||||
for (Location loc : Config.instance.getDiamondGenerators()) {
|
||||
GeneratorLabel label = new GeneratorLabel("§cDiamond Generator", loc.clone().add(0, 1, 0));
|
||||
GeneratorLabel label = new GeneratorLabel(TextComponent.fromLegacyText("§cDiamond Generator"), loc.clone().add(0, 1, 0));
|
||||
Generator gen = new Generator(loc, 4, label);
|
||||
gen.addItem(Material.DIAMOND, 600);
|
||||
|
||||
diamondGens.add(gen);
|
||||
}
|
||||
for (Location loc : Config.instance.getEmeraldGenerators()) {
|
||||
GeneratorLabel label = new GeneratorLabel("§cEmerald Generator", loc.clone().add(0, 1, 0));
|
||||
GeneratorLabel label = new GeneratorLabel(TextComponent.fromLegacyText("§cEmerald Generator"), loc.clone().add(0, 1, 0));
|
||||
Generator gen = new Generator(loc, 2, label);
|
||||
gen.addItem(Material.EMERALD, 1200);
|
||||
|
||||
|
@ -7,10 +7,12 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
|
||||
public class GeneratorLabel {
|
||||
private HoverLabel label;
|
||||
private String firstLine;
|
||||
private BaseComponent[] firstLine;
|
||||
|
||||
private Hashtable<Material, Float> remainingTimes = new Hashtable<>();
|
||||
|
||||
@ -27,20 +29,20 @@ public class GeneratorLabel {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
ArrayList<BaseComponent[]> lines = new ArrayList<>();
|
||||
|
||||
lines.add(firstLine);
|
||||
lines.add(null);
|
||||
|
||||
for (Material item : remainingTimes.keySet()) {
|
||||
lines.add(String.format("%s in %.2f seconds", Utility.getItemName(item), remainingTimes.get(item)));
|
||||
lines.add(new ComponentBuilder().append(Utility.getItemName(item)).append(" in %.2f seconds".formatted(remainingTimes.get(item))).create());
|
||||
}
|
||||
|
||||
label.setData(lines);
|
||||
}
|
||||
|
||||
public GeneratorLabel(String firstLine, Location loc) {
|
||||
public GeneratorLabel(BaseComponent[] firstLine, Location loc) {
|
||||
this.firstLine = firstLine;
|
||||
label = new HoverLabel(loc, new ArrayList<String>());
|
||||
label = new HoverLabel(loc, new ArrayList<BaseComponent[]>());
|
||||
}
|
||||
}
|
||||
|
@ -9,18 +9,20 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class HoverLabel {
|
||||
private List<String> data;
|
||||
private List<BaseComponent[]> data;
|
||||
private List<ArmorStand> armorStands;
|
||||
private Location loc;
|
||||
|
||||
private ArmorStand generateArmorStand(Location loc, String name) {
|
||||
private ArmorStand generateArmorStand(Location loc, BaseComponent[] name) {
|
||||
if (name == null || name.equals("")) return null;
|
||||
ArmorStand as = (ArmorStand)loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
|
||||
|
||||
as.setGravity(false);
|
||||
as.setVisible(false);
|
||||
as.setCustomName(name);
|
||||
as.setCustomName(BaseComponent.toLegacyText(name));
|
||||
as.setCustomNameVisible(true);
|
||||
|
||||
return as;
|
||||
@ -52,10 +54,10 @@ public class HoverLabel {
|
||||
return loc;
|
||||
}
|
||||
|
||||
private Location replaceData(List<String> data, int n) {
|
||||
private Location replaceData(List<BaseComponent[]> data, int n) {
|
||||
Location loc = this.loc.clone();
|
||||
for (int i = 0; i < n; i++) {
|
||||
String line = data.get(i);
|
||||
BaseComponent[] line = data.get(i);
|
||||
|
||||
if (line == null || line.equals("")) {
|
||||
if (armorStands.get(i) != null) armorStands.get(i).remove();
|
||||
@ -63,7 +65,7 @@ public class HoverLabel {
|
||||
}
|
||||
else {
|
||||
if (armorStands.get(i) == null) armorStands.set(i, generateArmorStand(loc, line));
|
||||
else armorStands.get(i).setCustomName(line);
|
||||
else armorStands.get(i).setCustomName(BaseComponent.toLegacyText(line));
|
||||
}
|
||||
loc.add(0, -0.25, 0);
|
||||
}
|
||||
@ -71,7 +73,7 @@ public class HoverLabel {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public void setData(List<String> data) {
|
||||
public void setData(List<BaseComponent[]> data) {
|
||||
if (data.size() > this.data.size()) {
|
||||
Location loc = replaceData(data, this.data.size());
|
||||
|
||||
@ -94,13 +96,13 @@ public class HoverLabel {
|
||||
|
||||
this.data = data;
|
||||
}
|
||||
public List<String> getData() {
|
||||
public List<BaseComponent[]> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public HoverLabel(Location loc, List<String> data) {
|
||||
public HoverLabel(Location loc, List<BaseComponent[]> data) {
|
||||
this.loc = loc;
|
||||
this.data = new ArrayList<String>();
|
||||
this.data = new ArrayList<BaseComponent[]>();
|
||||
this.armorStands = new ArrayList<ArmorStand>();
|
||||
setData(data);
|
||||
}
|
||||
|
@ -27,7 +27,8 @@ import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class Team implements Listener, AutoCloseable {
|
||||
private TeamColor color;
|
||||
@ -66,13 +67,17 @@ public class Team implements Listener, AutoCloseable {
|
||||
for (BedwarsPlayer bwp : players) {
|
||||
if (bwp.isOnline()) {
|
||||
Player p = bwp.getOnlinePlayer();
|
||||
|
||||
MessageUtility.parser("team.bed-broken.notification")
|
||||
.variable("team", getTeamColor().getColorName())
|
||||
.variable("player", p == null ? "a very strong wind current" : p.getDisplayName())
|
||||
.broadcast();
|
||||
|
||||
ComponentBuilder cb = new ComponentBuilder().append(color.getColorName()).append("'s bed was destroyed").reset();
|
||||
if (player != null) cb.append(" by " + player.getName());
|
||||
cb.append(".");
|
||||
Bukkit.spigot().broadcast(cb.create());
|
||||
|
||||
Utility.sendTitle(p, "Bed destroyed!", "You will no longer respawn!", 5, 35, 10);
|
||||
Utility.sendTitle(p,
|
||||
MessageUtility.parser("team.bed-broken.title").parse(),
|
||||
MessageUtility.parser("team.bed-broken.subtitle").parse(),
|
||||
5, 35, 10
|
||||
);
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1, 1);
|
||||
}
|
||||
}
|
||||
@ -179,10 +184,10 @@ public class Team implements Listener, AutoCloseable {
|
||||
if (hasPlayer(e.getPlayer())) {
|
||||
e.setCancelled(true);
|
||||
if (getPlayersCount() == 1) {
|
||||
e.getPlayer().sendMessage("§4You may not destroy your bed.");
|
||||
MessageUtility.parser("player.solo.break-own-bed").send(e.getPlayer());
|
||||
}
|
||||
else {
|
||||
e.getPlayer().sendMessage("§4You may not destroy your team's bed.");
|
||||
MessageUtility.parser("player.team.break-own-bed").send(e.getPlayer());
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -195,17 +200,17 @@ public class Team implements Listener, AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(String msg) {
|
||||
public void sendMessage(BaseComponent[] msg) {
|
||||
for (BedwarsPlayer bwp : players) {
|
||||
if (bwp.isOnline()) bwp.getOnlinePlayer().sendMessage(msg);
|
||||
if (bwp.isOnline()) bwp.getOnlinePlayer().spigot().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
public void sendTitle(String title, String subtitle, int fadein, int duration, int fadeout) {
|
||||
public void sendTitle(BaseComponent[] title, BaseComponent[] subtitle, int fadein, int duration, int fadeout) {
|
||||
for (BedwarsPlayer bwp : players) {
|
||||
if (bwp.isOnline()) Utility.sendTitle(bwp.getOnlinePlayer(), title, subtitle, fadein, duration, fadeout);
|
||||
}
|
||||
}
|
||||
public void sendTitleToOthers(String title, String subtitle, int fadein, int duration, int fadeout) {
|
||||
public void sendTitleToOthers(BaseComponent[] title, BaseComponent[] subtitle, int fadein, int duration, int fadeout) {
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (players.stream().noneMatch(v -> v.getPlayer().getUniqueId().equals(p.getUniqueId())))
|
||||
Utility.sendTitle(p, title, subtitle, fadein, duration, fadeout);
|
||||
|
@ -23,9 +23,10 @@ import me.topchetoeu.bedwars.InventoryUtility;
|
||||
import me.topchetoeu.bedwars.Main;
|
||||
import me.topchetoeu.bedwars.Utility;
|
||||
import me.topchetoeu.bedwars.engine.trader.dealTypes.ItemDeal;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
// Very bad code.
|
||||
public class TraderGUI implements Listener {
|
||||
@ -46,14 +47,16 @@ public class TraderGUI implements Listener {
|
||||
}
|
||||
|
||||
public ItemStack generateDealItem(Deal d, boolean addFavouriteLore) {
|
||||
String name = "§r" + BaseComponent.toLegacyText(d.getDealName(player));
|
||||
if (d.alreadyBought(player)) name += " §4(already unlocked)";
|
||||
else name += String.format(" (%dx %s)",
|
||||
d.getPrice(player),
|
||||
BaseComponent.toLegacyText(Utility.getItemName(d.getPriceType(player)))
|
||||
);
|
||||
ComponentBuilder cb = new ComponentBuilder().append(d.getDealName(player));
|
||||
if (d.alreadyBought(player)) cb.append("(already unlocked)").color(ChatColor.DARK_RED);
|
||||
else cb
|
||||
.append(" (%dx ".formatted(d.getPrice(player)))
|
||||
.reset()
|
||||
.append(BaseComponent.toLegacyText(Utility.getItemName(d.getPriceType(player)))).color(ChatColor.DARK_RED)
|
||||
.append(")")
|
||||
.reset();
|
||||
|
||||
ItemStack item = Utility.copyNamedItem(d.getDealItem(player), name);
|
||||
ItemStack item = Utility.copyNamedItem(d.getDealItem(player), BaseComponent.toLegacyText(cb.create()));
|
||||
|
||||
if (addFavouriteLore) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
@ -155,7 +158,7 @@ public class TraderGUI implements Listener {
|
||||
|
||||
public void trade(Deal deal) {
|
||||
if (deal.alreadyBought(player)) {
|
||||
player.sendMessage("You already own this.");
|
||||
MessageUtility.parser("trade.already-unlocked").variable("name", deal.getDealName(player)).send(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
||||
}
|
||||
else {
|
||||
@ -173,7 +176,11 @@ public class TraderGUI implements Listener {
|
||||
|
||||
player.getInventory().setContents(inv);
|
||||
|
||||
player.spigot().sendMessage(new ComponentBuilder().append("You just purchased ").append(deal.getDealName(player)).create());
|
||||
MessageUtility.parser("trade.purchase")
|
||||
.variable("name", deal.getDealName(player))
|
||||
.variable("price", deal.getPrice(player))
|
||||
.variable("priceType", Utility.getItemName(deal.getPriceType(player)))
|
||||
.send(player);
|
||||
deal.commence(player);
|
||||
updateSection();
|
||||
if (player.getInventory().contains(Material.STONE_SWORD) ||
|
||||
@ -186,12 +193,11 @@ public class TraderGUI implements Listener {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_YES, 1, 1);
|
||||
}
|
||||
else {
|
||||
player.spigot().sendMessage(new ComponentBuilder()
|
||||
.append("You don't have enough ")
|
||||
.append(Utility.getItemName(deal.getPriceType(player)))
|
||||
.append(new TextComponent("!"))
|
||||
.create()
|
||||
);
|
||||
MessageUtility.parser("trade.not-enough-resources")
|
||||
.variable("name", deal.getDealName(player))
|
||||
.variable("price", deal.getPrice(player))
|
||||
.variable("priceType", Utility.getItemName(deal.getPriceType(player)))
|
||||
.send(player);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import me.topchetoeu.bedwars.engine.BedwarsPlayer;
|
||||
import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.WoodenSword;
|
||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@ -31,7 +32,6 @@ public class ItemDeal implements Deal {
|
||||
public BaseComponent[] getDealName(Player p) {
|
||||
ComponentBuilder builder = new ComponentBuilder()
|
||||
.append(Integer.toString(item.getAmount()))
|
||||
.color(ChatColor.WHITE)
|
||||
.append("x ")
|
||||
.append(Utility.getItemName(item));
|
||||
if (!implemented) builder.append(" (not implemented)").bold(true).color(ChatColor.RED);
|
||||
@ -54,7 +54,11 @@ public class ItemDeal implements Deal {
|
||||
@Override
|
||||
public void commence(Player p) {
|
||||
if (!implemented) {
|
||||
p.sendMessage("The item you're trying to buy is not implemented yet.");
|
||||
MessageUtility.parser("player.trade.not-implemented")
|
||||
.variable("name", getDealName(p))
|
||||
.variable("price", getPrice(p))
|
||||
.variable("priceType", getPriceType(p))
|
||||
.send(p);
|
||||
return;
|
||||
}
|
||||
ItemStack item = getDealItem(p);
|
||||
|
@ -104,8 +104,9 @@ public class Rank implements Listener {
|
||||
for (; i <= targetI; i++) {
|
||||
tiers.get(i).apply(inv, p, this);
|
||||
}
|
||||
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
p.getInventory().setContents(inv);
|
||||
p.getInventory().setArmorContents(armor);
|
||||
}
|
||||
|
||||
currentTier.put(player.getUniqueId(), target);
|
||||
@ -193,7 +194,9 @@ public class Rank implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack[] armor = p.getInventory().getArmorContents();
|
||||
p.getInventory().setContents(inv);
|
||||
p.getInventory().setArmorContents(armor);
|
||||
p.updateInventory();
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import me.topchetoeu.bedwars.engine.Game;
|
||||
import me.topchetoeu.bedwars.engine.Team;
|
||||
import me.topchetoeu.bedwars.engine.trader.Deal;
|
||||
import me.topchetoeu.bedwars.engine.trader.upgrades.TeamUpgrade;
|
||||
import me.topchetoeu.bedwars.messaging.MessageUtility;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@ -42,7 +43,10 @@ public class RankedUpgradeDeal implements Deal {
|
||||
if (upgrade == null) return;
|
||||
upgrade.addToTeam(t);
|
||||
upgrade.updateTeam(t);
|
||||
t.sendMessage(p.getName() + "§r purchased " + upgrade.getDisplayName() + "§r!");
|
||||
MessageUtility.parser("team.upgrade-purchased")
|
||||
.variable("player", p.getDisplayName())
|
||||
.variable("upgrade", getDealName(p))
|
||||
.send(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,7 +53,7 @@ public class EfficiencyTeamUpgrade implements TeamUpgrade {
|
||||
public void upgradeItem(ItemStack item) {
|
||||
if (item == null) return;
|
||||
|
||||
if (Utility.isArmor(item.getType())) {
|
||||
if (Utility.isTool(item.getType())) {
|
||||
item.addEnchantment(Enchantment.DIG_SPEED, level);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class ProtectionTeamUpgrade implements TeamUpgrade {
|
||||
@Override
|
||||
public void upgradeItem(ItemStack item) {
|
||||
if (item == null) return;
|
||||
if (Utility.isTool(item.getType())) {
|
||||
if (Utility.isArmor(item.getType())) {
|
||||
item.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, level);
|
||||
}
|
||||
}
|
||||
|
173
src/main/java/me/topchetoeu/bedwars/messaging/MessageParser.java
Normal file
173
src/main/java/me/topchetoeu/bedwars/messaging/MessageParser.java
Normal file
@ -0,0 +1,173 @@
|
||||
package me.topchetoeu.bedwars.messaging;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import me.topchetoeu.bedwars.engine.Team;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class MessageParser {
|
||||
private class ChatStyle {
|
||||
public ChatColor color = ChatColor.WHITE;
|
||||
public final HashSet<ChatColor> styles = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return color.toString() + String.join("", styles.stream().map(v -> v.toString()).toList());
|
||||
}
|
||||
}
|
||||
|
||||
private final Hashtable<String, Object> variables = new Hashtable<>();
|
||||
private final String raw;
|
||||
private final char colorChar = '&';
|
||||
|
||||
public MessageParser variable(String name, Object value) {
|
||||
variables.put(name, value);
|
||||
return this;
|
||||
}
|
||||
public MessageParser variables(Map<String, Object> map) {
|
||||
variables.putAll(map);
|
||||
return this;
|
||||
}
|
||||
|
||||
private ChatStyle getStyle(String str, ChatStyle _default) {
|
||||
boolean styling = false;
|
||||
ChatStyle style = new ChatStyle();
|
||||
style.color = _default.color;
|
||||
style.styles.addAll(_default.styles);
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
char curr = str.charAt(i);
|
||||
if (styling) {
|
||||
switch (curr) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
style.color = ChatColor.getByChar(curr);
|
||||
style.styles.clear();
|
||||
style.styles.addAll(_default.styles);
|
||||
break;
|
||||
case 'k':
|
||||
case 'l':
|
||||
case 'm':
|
||||
case 'n':
|
||||
case 'o':
|
||||
style.styles.add(ChatColor.getByChar(curr));
|
||||
break;
|
||||
case 'r':
|
||||
style.styles.clear();
|
||||
style.styles.addAll(_default.styles);
|
||||
style.color = _default.color;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
styling = false;
|
||||
}
|
||||
else if (curr == '§') styling = true;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
private String replaceVariables() {
|
||||
if (raw.length() < 2) return raw;
|
||||
String raw = this.raw + ';';
|
||||
raw = raw.replace(colorChar, '§');
|
||||
raw = raw.replace("§§", Character.toString(colorChar));
|
||||
|
||||
boolean varMode = false;
|
||||
StringBuilder varName = new StringBuilder();
|
||||
StringBuilder currText = new StringBuilder();
|
||||
ChatStyle _default = new ChatStyle();
|
||||
_default.color = ChatColor.WHITE;
|
||||
|
||||
for (int i = 1; i < raw.length(); i++) {
|
||||
char curr = raw.charAt(i - 1);
|
||||
char next = raw.charAt(i);
|
||||
boolean appendChar = false;
|
||||
|
||||
if (curr == '{') {
|
||||
if (next == '{') {
|
||||
appendChar = true;
|
||||
i++;
|
||||
}
|
||||
else varMode = true;
|
||||
}
|
||||
else if (curr == '}') {
|
||||
if (next == '}') {
|
||||
appendChar = true;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
Object val = variables.get(varName.toString());
|
||||
String strVal = "undefined";
|
||||
|
||||
if (val != null) {
|
||||
if (val instanceof BaseComponent[]) strVal = BaseComponent.toLegacyText((BaseComponent[])val);
|
||||
else strVal = val.toString();
|
||||
}
|
||||
ChatStyle color = getStyle(currText.toString(), _default);
|
||||
|
||||
|
||||
currText.append(strVal.replace(colorChar, '§').replace("§§", Character.toString(colorChar)));
|
||||
currText.append(color);
|
||||
varName.setLength(0);
|
||||
varMode = false;
|
||||
}
|
||||
}
|
||||
else appendChar = true;
|
||||
|
||||
if (appendChar) {
|
||||
if (varMode) varName.append(curr);
|
||||
else currText.append(curr);
|
||||
}
|
||||
}
|
||||
|
||||
return currText.toString();
|
||||
}
|
||||
|
||||
public BaseComponent[] parse() {
|
||||
if (raw == null) return null;
|
||||
return TextComponent.fromLegacyText(replaceVariables());
|
||||
}
|
||||
|
||||
public void send(CommandSender sender) {
|
||||
BaseComponent[] msg = parse();
|
||||
if (msg == null) msg = new BaseComponent[] { new TextComponent("Missing message from config.") };
|
||||
sender.spigot().sendMessage(msg);
|
||||
}
|
||||
public void send(Team team) {
|
||||
BaseComponent[] msg = parse();
|
||||
if (msg == null) msg = new BaseComponent[] { new TextComponent("Missing message from config.") };
|
||||
team.sendMessage(msg);
|
||||
}
|
||||
public void broadcast() {
|
||||
BaseComponent[] msg = parse();
|
||||
if (msg == null) msg = new BaseComponent[] { new TextComponent("Missing message from config.") };
|
||||
Bukkit.spigot().broadcast(msg);
|
||||
}
|
||||
|
||||
public MessageParser(String msg) {
|
||||
this.raw = msg;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package me.topchetoeu.bedwars.messaging;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class MessageUtility {
|
||||
private static YamlConfiguration config;
|
||||
|
||||
private MessageUtility() {
|
||||
|
||||
}
|
||||
|
||||
public static void load(File file) throws IOException {
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
config.save(file);
|
||||
}
|
||||
|
||||
public static MessageParser parser(String path) {
|
||||
Object obj = config.get(path);
|
||||
if (obj == null) return new MessageParser(null);
|
||||
else return new MessageParser(obj.toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user