Skip to content

Commit

Permalink
feat: Version 2.1.1 - Organization Cleanup (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanTapply22 authored Jan 31, 2025
1 parent 531856c commit d48887e
Show file tree
Hide file tree
Showing 23 changed files with 181 additions and 131 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>2.1.0</version>
<version>2.1.1</version>
<packaging>jar</packaging>

<name>Bloons</name>
Expand Down
44 changes: 7 additions & 37 deletions src/main/java/net/jeqo/bloons/Bloons.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.jeqo.bloons.balloon.multipart.balloon.MultipartBalloon;
import net.jeqo.bloons.balloon.single.SingleBalloon;
import net.jeqo.bloons.commands.manager.CommandCore;
import net.jeqo.bloons.configuration.PluginConfiguration;
import net.jeqo.bloons.listeners.*;
import net.jeqo.bloons.listeners.multipart.MultipartBalloonPlayerJoinListener;
import net.jeqo.bloons.listeners.multipart.MultipartBalloonPlayerLeaveListener;
Expand All @@ -14,6 +15,7 @@
import net.jeqo.bloons.health.UpdateChecker;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.health.Metrics;
import net.jeqo.bloons.utils.VersionChecker;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
Expand Down Expand Up @@ -77,9 +79,9 @@ public void onEnable() {

// Stage listeners
getListenerCore().stageListener(new SingleBalloonPlayerListener());
getListenerCore().stageListener(new BalloonUnleashListener());
getListenerCore().stageListener(new BalloonChickenLeashListener());
getListenerCore().stageListener(new BalloonMenuListener());
getListenerCore().stageListener(new BalloonEntityListener());
getListenerCore().stageListener(new BalloonChickenEntityListener());

getListenerCore().stageListener(new MultipartBalloonPlayerJoinListener());
getListenerCore().stageListener(new MultipartBalloonPlayerLeaveListener());
Expand All @@ -88,9 +90,7 @@ public void onEnable() {
getListenerCore().registerListeners();

// Startup the metrics and update checker
// This is the ID of the plugin on bStats, this should be kept as a constant
int pluginId = 16872;
new Metrics(this, pluginId);
new Metrics(this, PluginConfiguration.BSTATS_PLUGIN_ID);
updateChecker();

// Copy over example balloons folder
Expand Down Expand Up @@ -143,41 +143,11 @@ public void updateChecker() {
new UpdateChecker(this, resourceId).getVersion(version -> {
String currentVersion = this.getDescription().getVersion();

if (isVersionLower(currentVersion, version)) {
if (VersionChecker.isVersionLower(currentVersion, version)) {
Logger.logUpdateNotificationConsole();
} else if (isVersionHigher(currentVersion, version)) {
} else if (VersionChecker.isVersionHigher(currentVersion, version)) {
Logger.logUnreleasedVersionNotification();
}
});
}

public boolean isVersionLower(String current, String latest) {
return compareVersions(current, latest) < 0;
}

public boolean isVersionHigher(String current, String latest) {
return compareVersions(current, latest) > 0;
}

/**
* Compares two version strings (e.g., "1.2.3" vs. "1.2.4").
* Returns:
* - A negative value if v1 < v2
* - Zero if v1 == v2
* - A positive value if v1 > v2
*/
public int compareVersions(String v1, String v2) {
String[] v1Parts = v1.split("\\.");
String[] v2Parts = v2.split("\\.");

int length = Math.max(v1Parts.length, v2Parts.length);
for (int i = 0; i < length; i++) {
int part1 = i < v1Parts.length ? Integer.parseInt(v1Parts[i]) : 0;
int part2 = i < v2Parts.length ? Integer.parseInt(v2Parts[i]) : 0;
if (part1 != part2) {
return Integer.compare(part1, part2);
}
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MultipartBalloonModel {
public MultipartBalloonModel(BalloonSegmentType segmentType, String material, String color, int customModelData) {
this.setSegmentType(segmentType);
this.setMaterial(material);
if (!color.equals(this.getColor()) && color != null && !color.isEmpty()) this.setColor(color);
if (!color.equals(this.getColor()) && !color.isEmpty()) this.setColor(color);
this.setCustomModelData(customModelData);
}

Expand Down
34 changes: 29 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 @@ -82,7 +82,11 @@ private void initializeBalloon() {
if (this.getType().getMegModelID() == null) {
// Create and set the balloons visual appearance/model
ItemMeta meta = this.getVisual().getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);

if (meta != null) {
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
}

this.getVisual().setItemMeta(meta);
}

Expand All @@ -95,6 +99,13 @@ private void initializeBalloon() {
* Initializes the balloon's armor stand entity with the proper configurations
*/
public void initializeBalloonArmorStand() {
if (this.getPlayerLocation().getWorld() == null) {
Logger.logError("Player world is not currently set. Could not initialize balloon, removing from player.");
// Remove the balloon from the player
SingleBalloonManagement.removeBalloon(player, null);
return;
}

this.setArmorStand(this.getPlayerLocation().getWorld().spawn(this.getPlayerLocation(), ArmorStand.class));
this.getArmorStand().setBasePlate(false);
this.getArmorStand().setVisible(false);
Expand All @@ -105,7 +116,9 @@ public void initializeBalloonArmorStand() {
this.getArmorStand().setMarker(true);
this.getArmorStand().setCollidable(false);
if (this.getType().getMegModelID() == null) {
this.getArmorStand().getEquipment().setHelmet(this.getVisual());
if (this.getArmorStand().getEquipment() != null) {
this.getArmorStand().getEquipment().setHelmet(this.getVisual());
}
} else {
try {
// Create the entity and tag it onto the armor stand
Expand All @@ -120,8 +133,7 @@ public void initializeBalloonArmorStand() {
// If an idle animation exists, play it initially
this.getAnimationHandler().playAnimation(this.getDefaultIdleAnimationID(), 0.3, 0.3, 1,true);
} catch (Exception e) {
Logger.logError("An error occurred while creating the MEG model for the balloon " + this.getType().getId() + "! This is because a MEG model error occurred.");
e.printStackTrace();
Logger.logError("An error occurred while creating the MEG model for the balloon " + this.getType().getId() + "! This is because a MEG model error occurred: " + e.getMessage());
}
}
this.getArmorStand().setCustomName(BalloonConfiguration.BALLOON_ARMOR_STAND_ID);
Expand All @@ -131,6 +143,13 @@ public void initializeBalloonArmorStand() {
* Initializes the balloon's lead to the player (chicken entity)
*/
public void initializeBalloonLead() {
if (this.getPlayerLocation().getWorld() == null) {
Logger.logError("Player world is not currently set. Could not initialize balloon, removing from player.");
// Remove the balloon from the player
SingleBalloonManagement.removeBalloon(player, null);
return;
}

this.setChicken(this.getPlayerLocation().getWorld().spawn(this.getPlayerLocation(), Chicken.class));
this.getChicken().setInvulnerable(true);
this.getChicken().setInvisible(true);
Expand Down Expand Up @@ -237,6 +256,8 @@ public synchronized void cancel() throws IllegalStateException {
* Spawns the particle effect when the balloon is removed
*/
public void spawnRemoveParticle() {
if (this.getMoveLocation().getWorld() == null) return;

this.getMoveLocation().getWorld().spawnParticle(Particle.CLOUD, this.getMoveLocation(), 5, 0.0D, 0.0D, 0.0D, 0.1D);
}

Expand Down Expand Up @@ -280,7 +301,10 @@ public ItemStack getConfiguredBalloonVisual(String balloonID) {
// Generate the item and set the custom model data meta
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(singleBalloonType.getCustomModelData());

if (meta != null) {
meta.setCustomModelData(singleBalloonType.getCustomModelData());
}

// If the color of the balloon is not set, log an error and return null
if (singleBalloonType.getColor() != null && singleBalloonType.getMaterial().startsWith(LEATHER_MATERIAL_PREFIX)) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/net/jeqo/bloons/commands/CommandEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
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.logger.Logger;
import net.jeqo.bloons.logger.LoggingLevel;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.management.SingleBalloonManagement;
import net.jeqo.bloons.message.MessageTranslations;
import net.jeqo.bloons.management.MultipartBalloonManagement;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
Expand Down Expand Up @@ -45,7 +46,6 @@ public boolean execute(CommandSender sender, String[] args) {
if (args.length < 1) usage(player);

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

// If the balloon ID isn't found in both balloon types, send a message to the player
if (Bloons.getBalloonCore().containsSingleBalloon(balloonID) && Bloons.getBalloonCore().containsMultipartBalloon(balloonID)) {
Expand Down Expand Up @@ -101,8 +101,13 @@ public boolean execute(CommandSender sender, String[] args) {
SingleBalloonManagement.removeBalloon(player, Bloons.getPlayerSingleBalloons().get(player.getUniqueId()));
SingleBalloon.checkBalloonRemovalOrAdd(player, balloonID);

String equippedMessage = Languages.getMessage("prefix") + String.format(Languages.getMessage("equipped"), singleBalloonType.getName());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', equippedMessage));
if (singleBalloonType == null) {
Logger.logToPlayer(LoggingLevel.ERROR, player, "The current balloon type is null! Please correct this in the config.");
return false;
} else {
String equippedMessage = Languages.getMessage("prefix") + String.format(Languages.getMessage("equipped"), singleBalloonType.getName());
player.sendMessage(ChatColor.translateAlternateColorCodes('&', equippedMessage));
}
}

// Play a sound regardless of the balloon type and when it executes successfully
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.jeqo.bloons.commands.manager.types.CommandPermission;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.management.SingleBalloonManagement;
import net.jeqo.bloons.message.MessageTranslations;
import net.jeqo.bloons.management.MultipartBalloonManagement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -43,7 +42,6 @@ public boolean execute(CommandSender sender, String[] args) {
if (args.length < 1) usage(sender);

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

// If the player isn't found, send a message to the sender
if (player == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.jeqo.bloons.commands.manager.types.CommandPermission;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.management.SingleBalloonManagement;
import net.jeqo.bloons.message.MessageTranslations;
import net.jeqo.bloons.management.MultipartBalloonManagement;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -27,7 +26,6 @@ public CommandForceUnequip(JavaPlugin plugin) {

@Override
public boolean execute(CommandSender sender, String[] args) {
MessageTranslations messageTranslations = new MessageTranslations(this.getPlugin());
Player player = Bukkit.getPlayer(args[0]);

// If the specified player doesn't exist, send a message to the sender
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/jeqo/bloons/commands/CommandReload.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.jeqo.bloons.commands.manager.Command;
import net.jeqo.bloons.commands.manager.types.CommandPermission;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.message.MessageTranslations;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -29,8 +28,6 @@ public CommandReload(JavaPlugin plugin) {

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

// Reload the main config.yml and its defaults
Bloons.getInstance().reloadConfig();
Bloons.getInstance().getConfig().options().copyDefaults();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/jeqo/bloons/commands/CommandUnequip.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.jeqo.bloons.commands.manager.types.CommandPermission;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.management.SingleBalloonManagement;
import net.jeqo.bloons.message.MessageTranslations;
import net.jeqo.bloons.management.MultipartBalloonManagement;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean onCommand(@NotNull CommandSender sender, org.bukkit.command.@NotN
ArrayList<SingleBalloonType> singleBalloonTypes = Bloons.getBalloonCore().getSingleBalloonTypes();
ArrayList<MultipartBalloonType> multipartBalloonTypes = Bloons.getBalloonCore().getMultipartBalloonTypes();

//
// Check if none are registered
if (singleBalloonTypes == null && multipartBalloonTypes == null) {
Logger.logError(ChatColor.translateAlternateColorCodes('&', Languages.getMessage("no-balloons-registered")));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.jeqo.bloons.Bloons;
import net.jeqo.bloons.configuration.PluginConfiguration;
import net.jeqo.bloons.message.MessageTranslations;
import org.bukkit.command.CommandSender;

/**
Expand All @@ -16,9 +15,6 @@ public class ErrorHandling {
* @param sender The sender of the command, type org.bukkit.command.CommandSender
*/
public static void usage(CommandSender sender) {
// MessageTranslations will need to adapt for plain text
MessageTranslations messageTranslations = new MessageTranslations(Bloons.getInstance());

sender.sendMessage(""); // Blank line for spacing
if (sender.hasPermission("bloons.menu")) {
String menuMessage = " §d/bloons §7- Open the balloon menu";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class PluginConfiguration {
// The base prefix to all commands within the plugin
public static final String COMMAND_BASE = "bloons";

// The bStats plugin resource ID used for metrics
public static final int BSTATS_PLUGIN_ID = 16872;

/**
* Get the version of the plugin from the pom.xml file
* @return The version of the plugin, type java.lang.String
Expand Down
Loading

0 comments on commit d48887e

Please sign in to comment.