Skip to content

Commit

Permalink
Fix equip command to conform with configuration changes
Browse files Browse the repository at this point in the history
Fix instancing usage from balloon core
  • Loading branch information
IanTapply22 committed Jun 19, 2024
1 parent 643d120 commit 54b9b11
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
22 changes: 20 additions & 2 deletions src/main/java/net/jeqo/bloons/balloon/BalloonCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void removeSingleBalloon(SingleBalloonType balloon) {
* @param ID The ID of the balloon, type java.lang.String
* @return The balloon with the specified name, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType/null
*/
public static MultipartBalloonType getMultipartBalloonByID(String ID) {
public MultipartBalloonType getMultipartBalloonByID(String ID) {
// Loop over every balloon in the registered balloons list
for (MultipartBalloonType balloon : getMultipartBalloonTypes()) {
// Check if the balloon's name matches the specified name
Expand All @@ -120,7 +120,7 @@ public static MultipartBalloonType getMultipartBalloonByID(String ID) {
* @param ID The ID of the balloon, type java.lang.String
* @return The single balloon with the specified ID, type net.jeqo.bloons.balloon.single.SingleBalloonType/null
*/
public static SingleBalloonType getSingleBalloonByID(String ID) {
public SingleBalloonType getSingleBalloonByID(String ID) {
// Loop over every single balloon in the registered balloons list
for (SingleBalloonType balloon : getSingleBalloonTypes()) {
// Check if the single balloon's name matches the specified name
Expand All @@ -132,4 +132,22 @@ public static SingleBalloonType getSingleBalloonByID(String ID) {
// Return null if the single balloon is not found
return null;
}

/**
* Checks if the registered balloons list contains a balloon with the specified ID
* @param ID The ID of the balloon, type java.lang.String
* @return Whether the balloon is in the registered balloons list, type boolean
*/
public boolean containsMultipartBalloon(String ID) {
return getMultipartBalloonByID(ID) != null;
}

/**
* Checks if the registered balloons list contains a single balloon with the specified ID
* @param ID The ID of the balloon, type java.lang.String
* @return Whether the single balloon is in the registered balloons list, type boolean
*/
public boolean containsSingleBalloon(String ID) {
return getSingleBalloonByID(ID) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private void initializeBalloon() {
*/
public ItemStack getConfiguredBalloonVisual(String balloonID) {
MessageTranslations messageTranslations = new MessageTranslations(Bloons.getInstance());
SingleBalloonType singleBalloonType = BalloonCore.getSingleBalloonByID(balloonID);
SingleBalloonType singleBalloonType = Bloons.getBalloonCore().getSingleBalloonByID(balloonID);

// If there isn't a configuration for the balloon, log an error and return null
if (singleBalloonType == null) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/jeqo/bloons/commands/CommandEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloon;
import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloonBuilder;
import net.jeqo.bloons.balloon.single.SingleBalloon;
import net.jeqo.bloons.balloon.single.SingleBalloonType;
import net.jeqo.bloons.commands.manager.Command;
import net.jeqo.bloons.commands.manager.types.CommandPermission;
import net.jeqo.bloons.configuration.ConfigConfiguration;
Expand Down Expand Up @@ -43,13 +44,13 @@ public boolean execute(CommandSender sender, String[] args) {
String balloonID = args[0];
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());

if (!this.getPlugin().getConfig().contains(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID) && !this.getPlugin().getConfig().contains(ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID)) {
if (!Bloons.getBalloonCore().containsSingleBalloon(balloonID) && !Bloons.getBalloonCore().containsMultipartBalloon(balloonID)) {
Component balloonNotFoundMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("balloon-not-found"));
player.sendMessage(balloonNotFoundMessage);
return false;
}

if (!player.hasPermission(this.getPlugin().getConfig().getString(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID + ".permission", ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID)) || !player.hasPermission(this.getPlugin().getConfig().getString(ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID + ".permission", ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID))) {
if (!player.hasPermission(Bloons.getBalloonCore().getSingleBalloonByID(balloonID).getPermission())|| !player.hasPermission(Bloons.getBalloonCore().getMultipartBalloonByID(balloonID).getPermission())) {
Component noPermissionMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("no-permission"));
player.sendMessage(noPermissionMessage);
return false;
Expand Down Expand Up @@ -82,10 +83,10 @@ public boolean execute(CommandSender sender, String[] args) {

MultipartBalloonManagement.setPlayerBalloon(player.getUniqueId(), balloon);

String balloonName = messageTranslations.getString(ConfigConfiguration.MULTIPART_BALLOON_SECTION + balloonID + ".name");
Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", balloonName));
Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", type.getName()));
player.sendMessage(equippedMessage);
} else {
SingleBalloonType singleBalloonType = Bloons.getBalloonCore().getSingleBalloonByID(balloonID);

// Call the equip event and check if it's cancelled, if it is, don't spawn the balloon or do anything
SingleBalloonEquipEvent singleBalloonEquipEvent = new SingleBalloonEquipEvent(player, balloonID);
Expand All @@ -97,8 +98,7 @@ public boolean execute(CommandSender sender, String[] args) {
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID);

String balloonName = messageTranslations.getString(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID + ".name");
Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", balloonName));
Component equippedMessage = messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("equipped", singleBalloonType.getName()));
player.sendMessage(equippedMessage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotN
ArrayList<SingleBalloonType> singleBalloonTypes = BalloonCore.getSingleBalloonTypes();
ArrayList<MultipartBalloonType> multipartBalloonTypes = BalloonCore.getMultipartBalloonTypes();

if (singleBalloonTypes == null && multipartBalloonTypes == null) return false;
if (singleBalloonTypes == null || multipartBalloonTypes == null) {
Logger.logError("Single balloon types or multipart balloon types are null.");
return false;
}

for (SingleBalloonType singleBalloon : singleBalloonTypes) {
if (singleBalloon == null) continue;
Expand Down

0 comments on commit 54b9b11

Please sign in to comment.