Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip PaperMC Integration #48

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ buildNumber.properties

# Common working directory
run/

server/
29 changes: 12 additions & 17 deletions 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.0.0</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>Bloons</name>
Expand Down Expand Up @@ -56,11 +56,11 @@
<plugin>
<groupId>blue.lhf</groupId>
<artifactId>run-paper-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<configuration>
<minecraftVersion>1.20.4</minecraftVersion>
<minecraftVersion>1.21.4</minecraftVersion>
<acceptEula>true</acceptEula>
<serverDirectory>run</serverDirectory>
<serverDirectory>../server</serverDirectory>
<jvmFlags>
<flag>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:25566</flag>
</jvmFlags>
Expand All @@ -76,10 +76,6 @@
</build>

<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
Expand All @@ -89,6 +85,10 @@
<name>Lumine Public</name>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<pluginRepositories>
Expand All @@ -101,18 +101,13 @@
</pluginRepositories>

<dependencies>
<!-- PaperMC related dependencies -->
<!-- Spigot related dependencies -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
</dependency>

<!-- Java related dependencies -->
<dependency>
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/net/jeqo/bloons/Bloons.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ public void onDisable() {
}

// Clear all balloon data if it exists
if (getPlayerSingleBalloons() != null) {
getPlayerSingleBalloons().clear();
}
if (getPlayerSingleBalloons() != null) getPlayerSingleBalloons().clear();

// Unregister all listeners in the manager
getListenerCore().unregisterListeners();
Expand All @@ -143,9 +141,43 @@ public void updateChecker() {
// Resource ID for the plugin on SpigotMC
int resourceId = 106243;
new UpdateChecker(this, resourceId).getVersion(version -> {
if (!this.getDescription().getVersion().equals(version)) {
String currentVersion = this.getDescription().getVersion();

if (isVersionLower(currentVersion, version)) {
Logger.logUpdateNotificationConsole();
} else if (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;
}
}
22 changes: 14 additions & 8 deletions src/main/java/net/jeqo/bloons/balloon/BalloonCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,12 @@ public void initialize() {
* Copies the example balloons folder to the plugin's data folder if it doesn't exist
*/
public void copyExampleBalloons() {
// List of example balloon files
String[] exampleBalloons = new String[] {
"/color_pack_example.yml",
"/dyeable_example.yml",
"/multipart_example.yml"
};

// Save all example files in the balloons folder in /resources
for (String example : this.getExampleBalloons()) {
File file = new File(Bloons.getInstance().getDataFolder() + File.separator + ConfigConfiguration.BALLOON_CONFIGURATION_FOLDER + File.separator + example);
if (file.exists()) continue;

Bloons.getInstance().saveResource(ConfigConfiguration.BALLOON_CONFIGURATION_FOLDER + example, false);
Bloons.getInstance().saveResource(ConfigConfiguration.BALLOON_CONFIGURATION_FOLDER + File.separator + example, false);
}
}

Expand Down Expand Up @@ -120,6 +113,19 @@ public SingleBalloonType getSingleBalloonByID(String ID) {
return null;
}

public SingleBalloonType getSingleBalloonByName(String name) {
// Loop over every single balloon in the registered balloons list
for (SingleBalloonType balloon : this.getSingleBalloonTypes()) {
// Check if the single balloon's name matches the specified name
if (balloon.getName().equalsIgnoreCase(name)) {
return balloon;
}
}

// 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
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/net/jeqo/bloons/balloon/model/BalloonModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* A class to handle the creation of balloon models with custom model data and color metadata
*/
public class BalloonModel {
private static final String LEATHER_MATERIAL_PREFIX = "LEATHER_"; // A constant to define a dyeable material
private static final String DYEABLE_MATERIAL_PREFIX = "LEATHER_";

/**
* Generates a coloured model with the specified colour and custom model data
Expand All @@ -23,18 +23,20 @@ public class BalloonModel {
*/
public static ItemStack createColouredModel(Material material, Color colour, int customModelData) {
// Check if the material is dyeable and contains leather attributes
if (!material.name().contains(LEATHER_MATERIAL_PREFIX)) {
if (!material.name().contains(DYEABLE_MATERIAL_PREFIX)) {
Logger.logError("Material " + material.name() + " is not a dyeable material.");
return new ItemStack(material);
}

ItemStack generatedItem = new ItemStack(material);
LeatherArmorMeta generatedItemMeta = (LeatherArmorMeta) generatedItem.getItemMeta();
LeatherArmorMeta generatedItemLeatherMeta = (LeatherArmorMeta) generatedItem.getItemMeta();

if (generatedItemLeatherMeta == null) return generatedItem;

// Set the color and custom model data of the item in the metadata
generatedItemMeta.setColor(colour);
generatedItemMeta.setCustomModelData(customModelData);
generatedItem.setItemMeta(generatedItemMeta);
generatedItemLeatherMeta.setColor(colour);
generatedItemLeatherMeta.setCustomModelData(customModelData);
generatedItem.setItemMeta(generatedItemLeatherMeta);

return generatedItem;
}
Expand All @@ -52,7 +54,7 @@ public static ItemStack createColouredModel(Material material, Color colour, int
*/
public static ItemStack createColouredModel(Material material, int colourRed, int colourGreen, int colourBlue, int customModelData) {
// Check if the material is dyeable and contains leather attributes
if (!material.name().contains(LEATHER_MATERIAL_PREFIX)) {
if (!material.name().contains(DYEABLE_MATERIAL_PREFIX)) {
Logger.logWarning(String.format(Languages.getMessage("material-not-dyeable"), material));
return new ItemStack(material);
}
Expand All @@ -68,11 +70,11 @@ public static ItemStack createColouredModel(Material material, int colourRed, in
Color color = Color.fromRGB(colourRed, colourGreen, colourBlue);

// Set the color and custom model data of the item in the metadata
assert generatedItemMeta != null; // Equivalent of setting to regular leather colour, assume we aren't
generatedItemMeta.setColor(color);
generatedItemMeta.setCustomModelData(customModelData);
generatedItem.setItemMeta(generatedItemMeta);


return generatedItem;
}

Expand All @@ -86,6 +88,12 @@ public static ItemStack createBlankModel(Material material, int customModelData)
ItemStack generatedItem = new ItemStack(material);
ItemMeta generatedItemMeta = generatedItem.getItemMeta();

// Check if the item supports ItemMeta
if (generatedItemMeta == null) {
Logger.logError(String.format("The specified material does not support ItemMeta: %s", material));
return generatedItem;
}

// Set the custom model data of the item
generatedItemMeta.setCustomModelData(customModelData);
generatedItem.setItemMeta(generatedItemMeta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import net.jeqo.bloons.colors.ColorCodeConverter;

/**
* An object to store the data of a balloon created in the config.yml file
Expand Down Expand Up @@ -133,4 +134,8 @@ public MultipartBalloonType(String id, String permission, String name, String[]
this.setBodyModel(bodyModel); // required
this.setTailModel(tailModel); // required
}

public String getName() {
return ColorCodeConverter.adventureToColorCode(this.name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.jeqo.bloons.balloon.multipart.MultipartBalloonType;
import net.jeqo.bloons.balloon.multipart.nodes.MultipartBalloonNode;
import net.jeqo.bloons.configuration.BalloonConfiguration;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -58,8 +57,8 @@ public class MultipartBalloon {
public void initialize() {
// Things that only need to be set up once and not looped over
MultipartBalloonNode current = new MultipartBalloonNode((float) this.getOwner().getLocation().getX(), (float) this.getOwner().getLocation().getY(), (float) this.getOwner().getLocation().getZ(),
(float) ((float) this.getType().getDistanceBetweenNodes() + this.getType().getTailNodeOffset()), 0, getType(), this.getOwner(),
this.getType().getMaxNodeJointAngle(), this.getType().getYAxisInterpolation(), this.getType().getTurningSplineInterpolation());
(float) ((float) this.getType().getDistanceBetweenNodes() + this.getType().getTailNodeOffset()), 0, getType(), this.getOwner(),
this.getType().getMaxNodeJointAngle(), this.getType().getYAxisInterpolation(), this.getType().getTurningSplineInterpolation());

// Add the current node to the list of model nodes
this.getMultipartBalloonNodes().add(current);
Expand Down Expand Up @@ -95,7 +94,7 @@ public void initializeBalloonLead() {
this.getChicken().setAgeLock(true);
this.getChicken().setAware(false);
this.getChicken().setCollidable(false);
this.getChicken().customName(Component.text(BalloonConfiguration.BALLOON_CHICKEN_ID));
this.getChicken().setCustomName(BalloonConfiguration.BALLOON_CHICKEN_ID);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;

Expand Down Expand Up @@ -271,17 +270,18 @@ public EulerAngle calculateHeadPose(Vector pointA, Vector pointB) {
* Sets the correct position and item in the armor stand.
*/
public void display() {
EquipmentSlot slot = EquipmentSlot.HEAD;
// Sets the segments finalized models based on their position in the balloon
if (this.getIndex() == this.getBalloonType().getNodeCount() - 1) {
// Set the head model
this.getBalloonArmorStand().setItem(slot, this.getBalloonType().getHeadModel().getFinalizedModel());
} else if (this.getIndex() == 0) {
// Set the tail model
this.getBalloonArmorStand().setItem(slot, this.getBalloonType().getTailModel().getFinalizedModel());
} else {
// Set the body model
this.getBalloonArmorStand().setItem(slot, this.getBalloonType().getBodyModel().getFinalizedModel());
if (this.getBalloonArmorStand().getEquipment() != null) {
if (this.getIndex() == this.getBalloonType().getNodeCount() - 1) {
// Set the head model
this.getBalloonArmorStand().getEquipment().setHelmet(this.getBalloonType().getHeadModel().getFinalizedModel());
} else if (this.getIndex() == 0) {
// Set the tail model
this.getBalloonArmorStand().getEquipment().setHelmet(this.getBalloonType().getTailModel().getFinalizedModel());
} else {
// Set the body model
this.getBalloonArmorStand().getEquipment().setHelmet(this.getBalloonType().getBodyModel().getFinalizedModel());
}
}

// Creates a new Bukkit vector based on the position of the two points
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/net/jeqo/bloons/balloon/single/SingleBalloon.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import lombok.Setter;
import net.jeqo.bloons.Bloons;
import net.jeqo.bloons.configuration.BalloonConfiguration;
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.message.Languages;
import net.jeqo.bloons.management.SingleBalloonManagement;
import net.jeqo.bloons.colors.Color;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
Expand Down Expand Up @@ -127,7 +124,7 @@ public void initializeBalloonArmorStand() {
e.printStackTrace();
}
}
this.getArmorStand().customName(Component.text(BalloonConfiguration.BALLOON_ARMOR_STAND_ID));
this.getArmorStand().setCustomName(BalloonConfiguration.BALLOON_ARMOR_STAND_ID);
}

/**
Expand All @@ -143,7 +140,7 @@ public void initializeBalloonLead() {
this.getChicken().setAware(false);
this.getChicken().setCollidable(false);
this.getChicken().setLeashHolder(this.getPlayer());
this.getChicken().customName(Component.text(BalloonConfiguration.BALLOON_CHICKEN_ID));
this.getChicken().setCustomName(BalloonConfiguration.BALLOON_CHICKEN_ID);
}

/**
Expand Down Expand Up @@ -315,21 +312,9 @@ public void run() {
SingleBalloon initialBalloon = Bloons.getPlayerSingleBalloons().get(player.getUniqueId());
if (initialBalloon != null) return;

// Call the unequip event and check if it's cancelled
SingleBalloonForceUnequipEvent unequipEvent = new SingleBalloonForceUnequipEvent(player, null);
unequipEvent.callEvent();

if (unequipEvent.isCancelled()) return;

// Remove the balloon from the player
SingleBalloonManagement.removeBalloon(player, null);

// Call the equip event and check if it's cancelled
SingleBalloonEquipEvent equipEvent = new SingleBalloonEquipEvent(player, balloonID);
equipEvent.callEvent();

if (equipEvent.isCancelled()) return;

// Create a new balloon and add it to the player/start the runnables and add the player to the maps
SingleBalloon balloon = new SingleBalloon(player, balloonID);
balloon.runTaskTimer(Bloons.getInstance(), 0L, 1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import net.jeqo.bloons.colors.ColorCodeConverter;

/**
* Represents the contents of a configuration for a single balloon
Expand Down Expand Up @@ -106,4 +107,8 @@ public SingleBalloonType(String key, String id, String permission, String materi
this.setName(name);
this.setLore(lore);
}

public String getName() {
return ColorCodeConverter.adventureToColorCode(this.name);
}
}
Loading
Loading