Skip to content

Commit

Permalink
feat: Version 1.1.1-BETA - Minor Fixes (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Tapply authored Jun 7, 2024
1 parent ebb846c commit f57036d
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 76 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.jeqo</groupId>
<artifactId>bloons</artifactId>
<version>1.1.0-BETA</version>
<version>1.1.1-BETA</version>
<packaging>jar</packaging>

<name>Bloons</name>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/jeqo/bloons/Bloons.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.jeqo.bloons.utils.UpdateChecker;
import net.jeqo.bloons.listeners.BalloonUnleashListener;
import net.jeqo.bloons.listeners.ListenerCore;
import net.jeqo.bloons.listeners.MenuClickListener;
import net.jeqo.bloons.listeners.PlayerListener;
import net.jeqo.bloons.listeners.BalloonMenuListener;
import net.jeqo.bloons.listeners.BalloonPlayerListener;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.Metrics;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -42,9 +42,9 @@ public void onEnable() {
setListenerCore(new ListenerCore(getInstance()));

// Stage listeners
getListenerCore().stageListener(new PlayerListener());
getListenerCore().stageListener(new BalloonPlayerListener());
getListenerCore().stageListener(new BalloonUnleashListener());
getListenerCore().stageListener(new MenuClickListener());
getListenerCore().stageListener(new BalloonMenuListener());

// Register all handlers
getListenerCore().registerListeners();
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/jeqo/bloons/commands/CommandEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CommandEquip extends Command {
public CommandEquip(JavaPlugin plugin) {
super(plugin);
this.addCommandAlias("equip");
this.setCommandDescription("Equips a balloon to you");
this.setCommandDescription("Equip a balloon");
this.setCommandSyntax("/bloons equip <balloon>");
this.setRequiredPermission(CommandPermission.EQUIP);
}
Expand All @@ -34,15 +34,15 @@ public boolean execute(CommandSender sender, String[] args) {
}

String balloonID = args[0];
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());

if (!this.plugin.getConfig().contains("balloons." + balloonID)) {
if (!this.getPlugin().getConfig().contains("balloons." + balloonID)) {
Component balloonNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("balloon-not-found"));
player.sendMessage(balloonNotFoundMessage);
return false;
}

if (!player.hasPermission(this.plugin.getConfig().getString("balloons." + balloonID + ".permission", "balloons." + balloonID))) {
if (!player.hasPermission(this.getPlugin().getConfig().getString("balloons." + balloonID + ".permission", "balloons." + balloonID))) {
Component noPermissionMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("no-permission"));
player.sendMessage(noPermissionMessage);
return false;
Expand All @@ -54,7 +54,7 @@ public boolean execute(CommandSender sender, String[] args) {

if (singleBalloonEquipEvent.isCancelled()) return false;

BalloonManagement.removeBalloon(player, Bloons.playerBalloons.get(player.getUniqueId()));
BalloonManagement.removeBalloon(player, Bloons.getPlayerBalloons().get(player.getUniqueId()));
SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID);
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CommandForceEquip extends Command {
public CommandForceEquip(JavaPlugin plugin) {
super(plugin);
this.addCommandAlias("fequip");
this.setCommandDescription("Force equips a balloon to you");
this.setCommandDescription("Equip a balloon to a player");
this.setCommandSyntax("/bloons fequip <player> <balloon>");
this.setRequiredPermission(CommandPermission.FORCE);
}
Expand All @@ -30,7 +30,7 @@ public boolean execute(CommandSender sender, String[] args) {
}

Player player = Bukkit.getPlayer(args[0]);
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());

if (player == null) {
Component playerNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("player-not-found"));
Expand All @@ -39,7 +39,7 @@ public boolean execute(CommandSender sender, String[] args) {
}

String balloonID = args[1];
if (!this.plugin.getConfig().contains("balloons." + balloonID)) {
if (!this.getPlugin().getConfig().contains("balloons." + balloonID)) {
Component balloonNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("balloon-not-found"));
sender.sendMessage(balloonNotFoundMessage);
return false;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/jeqo/bloons/commands/CommandForceUnequip.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@ public class CommandForceUnequip extends Command {
public CommandForceUnequip(JavaPlugin plugin) {
super(plugin);
this.addCommandAlias("funequip");
this.setCommandDescription("Force unequips a balloon that you have equipped");
this.setCommandDescription("Unequip a balloon to a player");
this.setCommandSyntax("/bloons funequip <player>");
this.setRequiredPermission(CommandPermission.FORCE);
}

@Override
public boolean execute(CommandSender sender, String[] args) {
Player player = Bukkit.getPlayer(args[0]);
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());
if (player == null) {
Component playerNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("player-not-found"));
sender.sendMessage(playerNotFoundMessage);
return false;
}

SingleBalloon balloon = Bloons.playerBalloons.get(player.getUniqueId());
if (balloon == null) {
SingleBalloon singleBalloon = Bloons.getPlayerBalloons().get(player.getUniqueId());
if (singleBalloon == null) {
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO, 1, 1);
Component notEquippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("not-equipped"));
sender.sendMessage(notEquippedMessage);
return false;
}

SingleBalloonForceUnequipEvent singleBalloonForceEquipEvent = new SingleBalloonForceUnequipEvent(player, balloon);
SingleBalloonForceUnequipEvent singleBalloonForceEquipEvent = new SingleBalloonForceUnequipEvent(player, singleBalloon);
singleBalloonForceEquipEvent.callEvent();

if (singleBalloonForceEquipEvent.isCancelled()) return false;

BalloonManagement.removeBalloon(player, balloon);
BalloonManagement.removeBalloon(player, singleBalloon);
Component unequipSuccessfulMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("unequipped"));
sender.sendMessage(unequipSuccessfulMessage);
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/jeqo/bloons/commands/CommandReload.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.jeqo.bloons.Bloons;
import net.jeqo.bloons.commands.manager.Command;
import net.jeqo.bloons.commands.manager.enums.CommandPermission;
import net.jeqo.bloons.events.balloon.general.BloonsConfigReloadEvent;
import net.jeqo.bloons.events.general.BloonsConfigReloadEvent;
import net.jeqo.bloons.utils.MessageTranslations;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
Expand All @@ -15,14 +15,14 @@ public CommandReload(JavaPlugin plugin) {
super(plugin);
this.addCommandAlias("reload");
this.addCommandAlias("rl");
this.setCommandDescription("Reloads the bloons config");
this.setCommandDescription("Reload the Bloons config");
this.setCommandSyntax("/bloons reload");
this.setRequiredPermission(CommandPermission.RELOAD);
}

@Override
public boolean execute(CommandSender sender, String[] args) {
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());

BloonsConfigReloadEvent bloonsConfigReloadEvent = new BloonsConfigReloadEvent();
bloonsConfigReloadEvent.callEvent();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/jeqo/bloons/commands/CommandUnequip.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CommandUnequip extends Command {
public CommandUnequip(JavaPlugin plugin) {
super(plugin);
this.addCommandAlias("unequip");
this.setCommandDescription("Equips a balloon to you");
this.setCommandDescription("Unequip a balloon");
this.setCommandSyntax("/bloons unequip <balloon>");
this.setRequiredPermission(CommandPermission.UNEQUIP);
}
Expand All @@ -28,7 +28,7 @@ public boolean execute(CommandSender sender, String[] args) {
if (!(sender instanceof Player player)) return false;

SingleBalloon singleBalloon = Bloons.getPlayerBalloons().get(player.getUniqueId());
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());

if (singleBalloon == null) {
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO, 1, 1);
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/net/jeqo/bloons/commands/manager/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public abstract class Command {

protected JavaPlugin plugin;

@Setter
@Setter @Getter
private CommandPermission requiredPermission;
@Setter
@Setter @Getter
private CommandAccess requiredAccess = CommandAccess.ENABLED;
@Setter
@Setter @Getter
private String commandSyntax;
@Setter
private String commandDescription;
@Setter @Getter
public String commandDescription;
private final ArrayList<String> commandAliases = new ArrayList<>();

public Command(JavaPlugin providedPlugin) {
Expand All @@ -38,6 +38,13 @@ public void addCommandAlias(String alias) {
this.getCommandAliases().add(alias);
}

/**
* What's executed on the command run
* @param sender The sender of the command
* @param args The arguments of the command
* @return Whether the command was executed successfully
* @throws Exception If an error occurs during command execution
*/
public abstract boolean execute(CommandSender sender, String[] args) throws Exception;

/**
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/net/jeqo/bloons/commands/manager/CommandCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ public CommandCore(JavaPlugin providedPlugin) {
this.commands = new ArrayList<>();
this.messageTranslations = new MessageTranslations(this.getPlugin());

// Add any commands you want registered here
addCommand(new CommandEquip(this.getPlugin()));
addCommand(new CommandForceEquip(this.getPlugin()));
addCommand(new CommandForceUnequip(this.getPlugin()));
addCommand(new CommandReload(this.getPlugin()));
addCommand(new CommandUnequip(this.getPlugin()));

// Register all commands staged
registerCommands();

Objects.requireNonNull(this.plugin.getCommand("bloons")).setTabCompleter(new CommandTabCompleter());
Objects.requireNonNull(this.getPlugin().getCommand("bloons")).setTabCompleter(new CommandTabCompleter());
}

/**
Expand All @@ -57,6 +59,20 @@ public void registerCommands() {
Objects.requireNonNull(this.getPlugin().getCommand("bloons")).setExecutor(this);
}

/**
* Gets a commands description by its alias
* @param commandAlias The alias of the command
* @return The description of the command
*/
public String getCommandDescription(String commandAlias) {
for (Command command : this.getCommands()) {
if (command.getCommandAliases().contains(commandAlias)) {
return command.getCommandDescription();
}
}
return null;
}

/**
* Adds a command to the commands list
* @param command The command to add
Expand All @@ -75,7 +91,7 @@ public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotN
}

if (!player.hasPermission("bloons.menu")) {
Component noPermission = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("no-permission"));
Component noPermission = this.getMessageTranslations().getSerializedString(this.getMessageTranslations().getMessage("prefix"), this.getMessageTranslations().getMessage("no-permission"));
player.sendMessage(noPermission);
return true;
}
Expand All @@ -95,7 +111,7 @@ public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotN
}
}

new BalloonMenu(items, messageTranslations.getString("menu-title"), player);
new BalloonMenu(items, this.getMessageTranslations().getString("menu-title"), player);
return true;
}

Expand All @@ -107,7 +123,7 @@ public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotN
for (Command currentCommand : getCommands()) {
if (currentCommand.getCommandAliases().contains(subcommand)) {
if (!meetsRequirements(currentCommand, sender)) {
sender.sendMessage(messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("no-permission")));
sender.sendMessage(this.getMessageTranslations().getSerializedString(this.getMessageTranslations().getMessage("prefix"), this.getMessageTranslations().getMessage("no-permission")));
return false;
}

Expand Down Expand Up @@ -146,8 +162,8 @@ public boolean meetsRequirements(Command command, CommandSender sender) {
* @return Whether we should add the balloon to the menu
*/
private boolean shouldAddBalloon(Player player, String key) {
if (messageTranslations.getString("hide-balloons-without-permission").equalsIgnoreCase("true")) {
return player.hasPermission(messageTranslations.getString("balloons." + key + ".permission"));
if (this.getMessageTranslations().getString("hide-balloons-without-permission").equalsIgnoreCase("true")) {
return player.hasPermission(this.getMessageTranslations().getString("balloons." + key + ".permission"));
}
return true;
}
Expand All @@ -166,7 +182,7 @@ private ItemStack createBalloonItem(ConfigurationSection keySection, String key)
ItemMeta meta = item.getItemMeta();
if (meta == null) return null;

meta.setLocalizedName(messageTranslations.getString("balloons." + key + ".id"));
meta.setLocalizedName(this.getMessageTranslations().getString("balloons." + key + ".id"));
setBalloonLore(meta, keySection);
setBalloonDisplayName(meta, keySection);
meta.setCustomModelData(keySection.getInt("custom-model-data"));
Expand Down Expand Up @@ -196,7 +212,7 @@ private void setBalloonLore(ItemMeta meta, ConfigurationSection keySection) {
*/
private void setBalloonDisplayName(ItemMeta meta, ConfigurationSection keySection) {
String name = keySection.getString("name");
MessageTranslations messageTranslations = new MessageTranslations(this.plugin);
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());
if (name != null) {
meta.displayName(messageTranslations.getSerializedString(name));
}
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/net/jeqo/bloons/commands/utils/ErrorHandling.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
package net.jeqo.bloons.commands.utils;

import net.jeqo.bloons.utils.ColorManagement;
import net.jeqo.bloons.Bloons;
import net.jeqo.bloons.configuration.PluginConfiguration;
import net.jeqo.bloons.utils.MessageTranslations;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;

public class ErrorHandling {

public static void usage(CommandSender sender) {
sender.sendMessage("");
MessageTranslations messageTranslations = new MessageTranslations(Bloons.getInstance());

sender.sendMessage(Component.text(""));
if (sender.hasPermission("bloons.menu")) {
Component menuMessage = Component.text(ColorManagement.fromHex("#ff00cc/#e30ed5b#c61cddl#aa2be6o#8e39eeo#7147f7n#5555ffs &7- Open the balloon menu"));
Component menuMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons</gradient> <gray>- Open the balloon menu");
sender.sendMessage(menuMessage);
}

if (sender.hasPermission("bloons.equip")) {
Component equipMessage = Component.text(ColorManagement.fromHex("#ff00cc/#e30ed5b#c61cddl#aa2be6o#8e39eeq#7147fui#5555ffp &7- Equip a balloon"));
Component equipMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons equip</gradient> <gray>- " + Bloons.getCommandCore().getCommandDescription("equip"));
sender.sendMessage(equipMessage);
}

if (sender.hasPermission("bloons.unequip")) {
Component unequipMessage = Component.text(ColorManagement.fromHex("#ff00cc/#e30ed5b#c61cddl#aa2be6o#8e39eeu#7147fni#5555ffp &7- Unequip a balloon"));
Component unequipMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons unequip</gradient> <gray>- " + Bloons.getCommandCore().getCommandDescription("unequip"));
sender.sendMessage(unequipMessage);
}

if (sender.hasPermission("bloons.force")) {
Component forceEquipMessage = Component.text(ColorManagement.fromHex(" #ff00cc/#f107d0b#e30ed5l#d515d9o#c61cddo#b823e1n#aa2be6s #9c32eaf#8e39eee#8040f2q#7147f7u#634efbi#5555ffp &7- Equip a balloon to a player"));
Component forceUnequipMessage = Component.text(ColorManagement.fromHex(" #ff00cc/#f306d0b#e70cd3l#db12d7o#ce18dbo#c21eden#b624e2s #aa2be6f#9e31e9u#9237edn#863df0e#7943f4q#6d49f8u#614ffbi#5555ffp &7- Unequip a balloon from a player"));
Component forceEquipMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons fequip</gradient> <gray>- " + Bloons.getCommandCore().getCommandDescription("fequip"));
Component forceUnequipMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons funequip</gradient> <gray>- " + Bloons.getCommandCore().getCommandDescription("funequip"));
sender.sendMessage(forceEquipMessage);
sender.sendMessage(forceUnequipMessage);
}

if (sender.hasPermission("bloons.reload")) {
Component reloadMessage = Component.text(ColorManagement.fromHex(" #ff00cc/#f107d0b#e30ed5l#d515d9o#c61cddo#b823e1n#aa2be6r #9c32eeo#8e39ee1#8040f2l#7147f7o#634efbi#5555ffd &7- Reload the Bloons config"));
Component reloadMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>/bloons reload</gradient> <gray>- " + Bloons.getCommandCore().getCommandDescription("reload"));
sender.sendMessage(reloadMessage);
}

sender.sendMessage(Component.text(""));
Component creditsMessage = Component.text(ColorManagement.fromHex(" #ff00ccB#f406cfl#e80bd3o#dd11d6o#d217dan#c61cdds #bb22e01#b028e4.#a42de70#9933eb.#8e39ee1#823ef5-#7744f5B#6c4af8E#604ffcT#5555ffA &7- &fMade by Jeqo"));
Component creditsMessage = messageTranslations.getSerializedString(" <gradient:#ff00cc:#5555ff>Bloons " + PluginConfiguration.getVersion() + "</gradient> <gray>- <white>Made by " + PluginConfiguration.DEVELOPER_CREDITS);
sender.sendMessage(creditsMessage);
sender.sendMessage(Component.text(""));
}
Expand Down
Loading

0 comments on commit f57036d

Please sign in to comment.