Skip to content

Commit

Permalink
Fix unequipping of balloons via the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
IanTapply22 committed Jun 20, 2024
1 parent f48da66 commit f758d7c
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/main/java/net/jeqo/bloons/listeners/BalloonMenuListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.jeqo.bloons.events.balloon.multipart.MultipartBalloonEquipEvent;
import net.jeqo.bloons.events.balloon.multipart.MultipartBalloonUnequipEvent;
import net.jeqo.bloons.events.balloon.single.SingleBalloonEquipEvent;
import net.jeqo.bloons.events.balloon.single.SingleBalloonUnequipEvent;
import net.jeqo.bloons.gui.menus.BalloonMenu;
import net.jeqo.bloons.utils.*;
import net.jeqo.bloons.utils.management.MultipartBalloonManagement;
Expand Down Expand Up @@ -142,22 +143,45 @@ else if(displayName.equals(ColorCodeConverter.adventureToColorCode(messageTransl
event.setCancelled(true);

if (!event.isShiftClick()) {
SingleBalloon balloon = Bloons.getPlayerSingleBalloons().get(player.getUniqueId());
SingleBalloon singleBalloon = Bloons.getPlayerSingleBalloons().get(player.getUniqueId());
MultipartBalloon multipartBalloon = Bloons.getPlayerMultipartBalloons().get(player.getUniqueId());

if (balloon == null) {
if (singleBalloon == null && multipartBalloon == null) {
// If no balloon equipped, play sound and send message notifying them
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO, 1, 1);
player.sendMessage(messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("not-equipped")));
} else {
if (messageTranslations.getString("close-on-unequip").equals("true")) player.closeInventory();
if (singleBalloon != null) {
if (messageTranslations.getString("close-on-unequip").equals("true")) player.closeInventory();

// Play sound and send message saying the balloon is unequipped
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, 1, 1);
player.sendMessage(messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("unequipped")));
}
SingleBalloonUnequipEvent singleBalloonUnequipEvent = new SingleBalloonUnequipEvent(player, singleBalloon);
singleBalloonUnequipEvent.callEvent();

if (singleBalloonUnequipEvent.isCancelled()) return;

SingleBalloonManagement.removeBalloon(player, singleBalloon);

// Play sound and send message saying the balloon is unequipped
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, 1, 1);
player.sendMessage(messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("unequipped")));
}

if (multipartBalloon != null) {
if (messageTranslations.getString("close-on-unequip").equals("true")) player.closeInventory();

// Remove the balloon
SingleBalloonManagement.removeBalloon(player, balloon);
MultipartBalloonUnequipEvent multipartBalloonEquipEvent = new MultipartBalloonUnequipEvent(player, multipartBalloon);
multipartBalloonEquipEvent.callEvent();

if (multipartBalloonEquipEvent.isCancelled()) return;

multipartBalloon.destroy();
MultipartBalloonManagement.removePlayerBalloon(player.getUniqueId());

// Play sound and send message saying the balloon is unequipped
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, 1, 1);
player.sendMessage(messageTranslations.getSerializedString(messageTranslations.getMessage("prefix"), messageTranslations.getMessage("unequipped")));
}
}
}

} else {
Expand Down

0 comments on commit f758d7c

Please sign in to comment.