Skip to content

Commit

Permalink
Clean up entire codebase and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IanTapply22 committed Jun 13, 2024
1 parent 51b4108 commit ba65186
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ public void run() {

@Override
public void run() {
Location ownerLocation = getBalloonOwner().getLocation();
// Gets the constantly updated owners location
Location balloonOwnerLocation = getBalloonOwner().getLocation();

// Calculate the Y offset using a sine function with adjusted amplitude
double sinValue = Math.sin(yOffset);
double newY = ownerLocation.getY() + 2 + amplitude * sinValue; // Adjust the amplitude and offset as needed
double newY = balloonOwnerLocation.getY() + 2 + amplitude * sinValue; // Adjust the amplitude and offset as needed

// Adjust the nose amplitude based on the sine value
double noseOffset = noseAmplitude * sinValue;

// Calculate the midpoint between Point A and Point B
// Calculate the midpoint between Point A and Point B in the leading balloon
double midpointX = (getTentacle().getPointA().x + getTentacle().getPointB().x) / 2.0;
double midpointZ = (getTentacle().getPointA().z + getTentacle().getPointA().z) / 2.0;

Expand All @@ -120,16 +122,16 @@ public void run() {
getBalloonChicken().setLeashHolder(getBalloonOwner());

// Constantly teleport the balloons
getTentacle().follow((float) ownerLocation.getX(), (float) (newY + noseOffset), (float) ownerLocation.getZ());
getTentacle().follow((float) balloonOwnerLocation.getX(), (float) (newY + noseOffset), (float) balloonOwnerLocation.getZ());
getTentacle().show();

// Make the other segments follow
ModelNode next = getTentacle().parent;
ModelNode next = getTentacle().getParent();
while (next != null) {
next.follow();
next.show();

next = next.parent;
next = next.getParent();
}

// Increment the yOffset based on the speed for the next iteration
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/jeqo/bloons/balloon/single/SingleBalloon.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.jeqo.bloons.events.balloon.single.SingleBalloonEquipEvent;
import net.jeqo.bloons.events.balloon.single.SingleBalloonForceUnequipEvent;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.BalloonManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.ColorManagement;
import net.jeqo.bloons.utils.MessageTranslations;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -208,15 +208,15 @@ public void initializeBalloonChicken() {
public static void checkBalloonRemovalOrAdd(final Player player, final String balloonID) {
new BukkitRunnable() {
public void run() {
SingleBalloon initialBalloon = Bloons.playerSingleBalloons.get(player.getUniqueId());
SingleBalloon initialBalloon = Bloons.getPlayerSingleBalloons().get(player.getUniqueId());
if (initialBalloon != null) return;

SingleBalloonForceUnequipEvent unequipEvent = new SingleBalloonForceUnequipEvent(player, null);
unequipEvent.callEvent();

if (unequipEvent.isCancelled()) return;

BalloonManagement.removeBalloon(player, null);
SingleBalloonManagement.removeBalloon(player, null);

SingleBalloonEquipEvent equipEvent = new SingleBalloonEquipEvent(player, balloonID);
equipEvent.callEvent();
Expand All @@ -225,8 +225,8 @@ public void run() {

SingleBalloon balloon = new SingleBalloon(player, balloonID);
balloon.runTaskTimer(Bloons.getInstance(), 0L, 1L);
Bloons.playerSingleBalloons.put(player.getUniqueId(), balloon);
Bloons.playerSingleBalloonID.put(player.getUniqueId(), balloonID);
Bloons.getPlayerSingleBalloons().put(player.getUniqueId(), balloon);
Bloons.getPlayerSingleBalloonID().put(player.getUniqueId(), balloonID);

}
}.runTaskLater(Bloons.getInstance(), 1L);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/jeqo/bloons/commands/CommandEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
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.utils.BalloonManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.MessageTranslations;
import net.jeqo.bloons.utils.MultipartBalloonManagement;
import net.jeqo.bloons.utils.management.MultipartBalloonManagement;
import net.kyori.adventure.text.Component;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -75,7 +75,7 @@ public boolean execute(CommandSender sender, String[] args) {
if (multipartBalloonEquipEvent.isCancelled()) return false;

MultipartBalloonBuilder builder = new MultipartBalloonBuilder(type, player);
BalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
MultipartBalloon balloon = builder.build();
balloon.initialize();
balloon.run();
Expand All @@ -94,7 +94,7 @@ public boolean execute(CommandSender sender, String[] args) {
if (singleBalloonEquipEvent.isCancelled()) return false;

// Check if a balloon needs to be added or removed
BalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID);

String balloonName = messageTranslations.getString(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID + ".name");
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
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.utils.BalloonManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.MessageTranslations;
import net.jeqo.bloons.utils.MultipartBalloonManagement;
import net.jeqo.bloons.utils.management.MultipartBalloonManagement;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -73,7 +73,7 @@ public boolean execute(CommandSender sender, String[] args) {
if (multipartBalloonEquipEvent.isCancelled()) return false;

MultipartBalloonBuilder builder = new MultipartBalloonBuilder(type, player);
BalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
MultipartBalloon balloon = builder.build();
balloon.initialize();
balloon.run();
Expand All @@ -92,7 +92,7 @@ public boolean execute(CommandSender sender, String[] args) {
if (singleBalloonEquipEvent.isCancelled()) return false;

// Check if a balloon needs to be added or removed
BalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID);

String balloonName = messageTranslations.getString(ConfigConfiguration.SINGLE_BALLOON_SECTION + balloonID + ".name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import net.jeqo.bloons.balloon.single.SingleBalloon;
import net.jeqo.bloons.commands.manager.Command;
import net.jeqo.bloons.commands.manager.enums.CommandPermission;
import net.jeqo.bloons.events.balloon.multipart.MultipartBalloonEquipEvent;
import net.jeqo.bloons.events.balloon.multipart.MultipartBalloonUnequipEvent;
import net.jeqo.bloons.events.balloon.single.SingleBalloonUnequipEvent;
import net.jeqo.bloons.utils.BalloonManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.MessageTranslations;
import net.jeqo.bloons.utils.MultipartBalloonManagement;
import net.jeqo.bloons.utils.management.MultipartBalloonManagement;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -52,7 +51,7 @@ public boolean execute(CommandSender sender, String[] args) {

if (singleBalloonUnequipEvent.isCancelled()) return false;

BalloonManagement.removeBalloon(player, singleBalloon);
SingleBalloonManagement.removeBalloon(player, singleBalloon);
}

if (multipartBalloon != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/jeqo/bloons/commands/CommandUnequip.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import net.jeqo.bloons.commands.manager.enums.CommandPermission;
import net.jeqo.bloons.events.balloon.multipart.MultipartBalloonUnequipEvent;
import net.jeqo.bloons.events.balloon.single.SingleBalloonUnequipEvent;
import net.jeqo.bloons.utils.BalloonManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.MessageTranslations;
import net.jeqo.bloons.utils.MultipartBalloonManagement;
import net.jeqo.bloons.utils.management.MultipartBalloonManagement;
import net.kyori.adventure.text.Component;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -46,7 +46,7 @@ public boolean execute(CommandSender sender, String[] args) {

if (singleBalloonUnequipEvent.isCancelled()) return false;

BalloonManagement.removeBalloon(player, singleBalloon);
SingleBalloonManagement.removeBalloon(player, singleBalloon);
}

if (multipartBalloon != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.jeqo.bloons.configuration;

/**
* A class that contains configurations for the balloons and their entities
*/
public class BalloonConfiguration {
public static final String BALLOON_ARMOR_STAND_ID = "4001147"; // The display name of the armor stand
public static final String BALLOON_CHICKEN_ID = "4001148"; // The display name of the chicken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.jeqo.bloons.configuration;

/**
* A class that contains configurations for the plugin configuration file
*/
public class ConfigConfiguration {
public static final String SINGLE_BALLOON_SECTION = "single-balloons.";
public static final String MULTIPART_BALLOON_SECTION = "multipart-balloons.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.Getter;
import lombok.Setter;
import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloon;
import net.jeqo.bloons.balloon.single.SingleBalloon;
import net.jeqo.bloons.events.BloonsEvent;
import org.bukkit.entity.Player;

Expand Down
62 changes: 42 additions & 20 deletions src/main/java/net/jeqo/bloons/gui/menus/BalloonMenu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.jeqo.bloons.gui.menus;

import lombok.Getter;
import lombok.Setter;
import net.jeqo.bloons.Bloons;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.ColorManagement;
Expand All @@ -15,39 +17,52 @@
import java.util.List;
import java.util.UUID;


@Getter
public class BalloonMenu {

public ArrayList<Inventory> pages = new ArrayList<>();
@Setter
public UUID id;
public int currpage = 0;
@Setter
public int currentPageIndex = 0;
@Getter
public static HashMap<UUID, BalloonMenu> users = new HashMap<>();
MessageTranslations messageTranslations = new MessageTranslations(Bloons.getInstance());
private final MessageTranslations messageTranslations = new MessageTranslations(Bloons.getInstance());

/**
* Gets a blank GUI menu with the next page, previous page, and unequip buttons
* @param name The name of the GUI menu
* @return The blank GUI menu
*/
private Inventory getBlankPage(String name){
int pageSize = messageTranslations.getInt("menu-size");
int pageSize = this.getMessageTranslations().getInt("menu-size");
Inventory page = Bukkit.createInventory(null, pageSize, ColorManagement.fromHex(name));

ItemStack nextPage = new ItemStack(Material.valueOf(messageTranslations.getString("buttons.next-page.material")));
// Create next page button
ItemStack nextPage = new ItemStack(Material.valueOf(this.getMessageTranslations().getString("buttons.next-page.material")));
ItemMeta nextMeta = nextPage.getItemMeta();
assert nextMeta != null;
nextMeta.displayName(messageTranslations.getSerializedString(messageTranslations.getString("buttons.next-page.name")));
nextMeta.setCustomModelData(messageTranslations.getInt("buttons.next-page.custom-model-data"));
nextMeta.displayName(this.getMessageTranslations().getSerializedString(this.getMessageTranslations().getString("buttons.next-page.name")));
nextMeta.setCustomModelData(this.getMessageTranslations().getInt("buttons.next-page.custom-model-data"));
nextPage.setItemMeta(nextMeta);

ItemStack prevPage = new ItemStack(Material.valueOf(messageTranslations.getString("buttons.previous-page.material")));
// Create previous page button
ItemStack prevPage = new ItemStack(Material.valueOf(this.getMessageTranslations().getString("buttons.previous-page.material")));
ItemMeta prevMeta = prevPage.getItemMeta();
assert prevMeta != null;
prevMeta.displayName(messageTranslations.getSerializedString(messageTranslations.getString("buttons.previous-page.name")));;
prevMeta.setCustomModelData(messageTranslations.getInt("buttons.previous-page.custom-model-data"));
prevMeta.displayName(this.getMessageTranslations().getSerializedString(this.getMessageTranslations().getString("buttons.previous-page.name")));;
prevMeta.setCustomModelData(this.getMessageTranslations().getInt("buttons.previous-page.custom-model-data"));
prevPage.setItemMeta(prevMeta);

ItemStack removeBalloon = new ItemStack(Material.valueOf(messageTranslations.getString("buttons.unequip.material")));
// Create remove/unequip balloon button
ItemStack removeBalloon = new ItemStack(Material.valueOf(this.getMessageTranslations().getString("buttons.unequip.material")));
ItemMeta removeMeta = removeBalloon.getItemMeta();
assert removeMeta != null;
removeMeta.displayName(messageTranslations.getSerializedString(messageTranslations.getString("buttons.unequip.name")));;
removeMeta.setCustomModelData(messageTranslations.getInt("buttons.unequip.custom-model-data"));
removeMeta.displayName(this.getMessageTranslations().getSerializedString(this.getMessageTranslations().getString("buttons.unequip.name")));;
removeMeta.setCustomModelData(this.getMessageTranslations().getInt("buttons.unequip.custom-model-data"));
removeBalloon.setItemMeta(removeMeta);

// Add buttons to GUI
List<String> previousPageSlots = Bloons.getInstance().getConfig().getStringList("buttons.previous-page.slots");
for (String previousPageSlot : previousPageSlots) {
if (Integer.parseInt(previousPageSlot) < pageSize) {
Expand All @@ -74,11 +89,18 @@ private Inventory getBlankPage(String name){
Logger.logWarning("Next page button slot(s) out of bounds!");
}
}

return page;
}

public BalloonMenu(ArrayList<ItemStack> items, String name, Player p){
this.id = UUID.randomUUID();
/**
* Creates a new balloon menu
* @param items The items to display in the menu
* @param name The name of the menu
* @param player The player to open the menu for
*/
public BalloonMenu(ArrayList<ItemStack> items, String name, Player player){
this.setId(UUID.randomUUID());
Inventory page = getBlankPage(name);
int slot = 0;
for (int i = -1; i < items.size(); i++) {
Expand All @@ -88,15 +110,15 @@ public BalloonMenu(ArrayList<ItemStack> items, String name, Player p){
page.setItem(slot, items.get(i));
slot++;
}
if (slot == messageTranslations.getInt("balloon-slots")-1) {
pages.add(page);
if (slot == this.getMessageTranslations().getInt("balloon-slots")-1) {
this.getPages().add(page);
page = getBlankPage(name);
slot = 0;
}
}

pages.add(page);
p.openInventory(pages.get(currpage));
users.put(p.getUniqueId(), this);
this.getPages().add(page);
player.openInventory(this.getPages().get(this.getCurrentPageIndex()));
users.put(player.getUniqueId(), this);
}
}
Loading

0 comments on commit ba65186

Please sign in to comment.