Skip to content

Commit

Permalink
Merge branch 'main' into meg-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Tapply authored Jun 23, 2024
2 parents 66c7b06 + 6a99d92 commit 0024b65
Show file tree
Hide file tree
Showing 113 changed files with 2,391 additions and 283 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
# Runs on Ubuntu latest (version 22.04)
ubunutu:
ubuntu:
name: 'Build Ubuntu Latest'
runs-on: ubuntu-latest
environment: jdk21-building
Expand All @@ -24,7 +24,14 @@ jobs:
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: ${{ vars.UBUNTU_DISTRIBUTION }}
cache: maven

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify
Expand All @@ -48,7 +55,14 @@ jobs:
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: ${{ vars.MACOS_DISTRIBUTION }}
cache: maven

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify
Expand All @@ -72,10 +86,17 @@ jobs:
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: ${{ vars.WINDOWS_DISTRIBUTION }}
cache: maven

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Run the Maven verify phase
run: mvn --batch-mode --update-snapshots verify

- name: Build with Maven
run: mvn -B package --file pom.xml
run: mvn -B package --file pom.xml
35 changes: 26 additions & 9 deletions .github/workflows/publish-javadoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,39 @@ on:
push:
branches:
- main
concurrency:
group: pages
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest
environment: jdk21-flat
permissions:
contents: read
pages: write
id-token: write
contents: write # if you have a protection rule on your repository, you'll need to give write permission to the workflow.
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK ${{ vars.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ vars.JAVA_VERSION }}
distribution: ${{ vars.JAVA_DISTRIBUTION }}

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Deploy JavaDoc 🚀
uses: MathieuSoysal/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy-mode: artifact
java-version: 21
javadoc-branch: javadoc
java-version: ${{ vars.JAVA_VERSION }}
target-folder: javadoc # url will be https://<username>.github.io/<repo>/javadoc, This can be left as nothing to generate javadocs in the root folder.
project: maven # or gradle
# subdirectories: moduleA moduleB #for subdirectories support, needs to be run with custom command
20 changes: 16 additions & 4 deletions src/main/java/net/jeqo/bloons/Bloons.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
import net.jeqo.bloons.listeners.multipart.MultipartBalloonPlayerJoinListener;
import net.jeqo.bloons.listeners.multipart.MultipartBalloonPlayerLeaveListener;
import net.jeqo.bloons.listeners.single.SingleBalloonPlayerListener;
import net.jeqo.bloons.utils.LanguageManagement;
import net.jeqo.bloons.utils.UpdateChecker;
import net.jeqo.bloons.message.Languages;
import net.jeqo.bloons.health.UpdateChecker;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.Metrics;
import net.jeqo.bloons.health.Metrics;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* The main class of the plugin that houses the core managers and the plugin instance
*/
public final class Bloons extends JavaPlugin {
@Getter @Setter
private static Bloons instance;
Expand All @@ -30,11 +33,20 @@ public final class Bloons extends JavaPlugin {
@Getter @Setter
private static BalloonCore balloonCore;

/**
* A map of all players with a single balloon
*/
@Getter @Setter
public static HashMap<UUID, SingleBalloon> playerSingleBalloons = new HashMap<>();
/**
* A map of all players with a single balloon and its ID
*/
@Getter @Setter
public static HashMap<UUID, String> playerSingleBalloonID = new HashMap<>();

/**
* A map of all players with a multipart balloon
*/
@Getter
public static final Map<UUID, MultipartBalloon> playerMultipartBalloons = new HashMap<>();

Expand All @@ -52,7 +64,7 @@ public void onEnable() {
*/

// Copy over language files
LanguageManagement.copyLanguageFiles();
Languages.copyLanguageFiles();

// Generate config(s) and set defaults
getConfig().options().copyDefaults();
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/jeqo/bloons/balloon/BalloonCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
@Setter @Getter
public class BalloonCore {
private JavaPlugin plugin;
/**
* Contains all valid and loaded multipart balloon types/configurations
*/
public ArrayList<MultipartBalloonType> multipartBalloonTypes = new ArrayList<>();
/**
* Contains all valid and loaded single balloon types/configurations
*/
public ArrayList<SingleBalloonType> singleBalloonTypes = new ArrayList<>();

/**
* Creates a new instance of the balloon core manager with preset registered balloons
* @param plugin The plugin instance, type org.bukkit.plugin.java.JavaPlugin
* @param balloons The balloons to register, type java.util.ArrayList<net.jeqo.bloons.balloon.multipart.MultipartBalloonType>
* @param singleBalloons The single balloons to register, type java.util.ArrayList<net.jeqo.bloons.balloon.single.SingleBalloonType>
* @param balloons The balloons to register, type java.util.ArrayList[net.jeqo.bloons.balloon.multipart.MultipartBalloonType]
* @param singleBalloons The single balloons to register, type java.util.ArrayList[net.jeqo.bloons.balloon.single.SingleBalloonType]
*/
public BalloonCore(JavaPlugin plugin, ArrayList<MultipartBalloonType> balloons, ArrayList<SingleBalloonType> singleBalloons) {
this.setPlugin(plugin);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/jeqo/bloons/balloon/model/BalloonModel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.jeqo.bloons.balloon.model;

import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.LanguageManagement;
import net.jeqo.bloons.message.Languages;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -53,13 +53,13 @@ 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(leatherMaterialPrefix)) {
Logger.logWarning(String.format(LanguageManagement.getMessage("material-not-dyeable"), material));
Logger.logWarning(String.format(Languages.getMessage("material-not-dyeable"), material));
return new ItemStack(material);
}

// Check if the provided color values are within the valid ranges of RGB
if (colourRed < 0 || colourRed > 255 || colourGreen < 0 || colourGreen > 255 || colourBlue < 0 || colourBlue > 255) {
Logger.logError(LanguageManagement.getMessage("invalid-rgb-values"));
Logger.logError(Languages.getMessage("invalid-rgb-values"));
return null;
}

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/net/jeqo/bloons/balloon/model/BalloonModelType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
* The type of segment that the model accommodates
*/
public enum BalloonModelType {
HEAD, // This is the head of the balloon, indexed as the last index in the multipart balloon
BODY, // Body, this accommodates the middle segments of the balloon
TAIL // This is the tail of the balloon, indexed as the first index in the multipart balloon (0)
/**
* This is the head of the balloon, indexed as the last index in the multipart balloon
*/
HEAD,
/**
* Accommodates the middle segments of the balloon
*/
BODY,
/**
* The tail of the balloon, indexed as the first index in the multipart balloon (0)
*/
TAIL
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import net.jeqo.bloons.balloon.model.BalloonModel;
import net.jeqo.bloons.balloon.model.BalloonModelType;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.utils.ColorManagement;
import net.jeqo.bloons.utils.LanguageManagement;
import org.bukkit.Color;
import net.jeqo.bloons.colors.Color;
import net.jeqo.bloons.message.Languages;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -45,7 +44,7 @@ public ItemStack getFinalizedModel() {

// Check if the material is valid
if (material == null) {
Logger.logError(String.format(LanguageManagement.getMessage("material-is-not-valid"), this.getMaterial()));
Logger.logError(String.format(Languages.getMessage("material-is-not-valid"), this.getMaterial()));
return null;
}

Expand All @@ -60,13 +59,13 @@ public ItemStack getFinalizedModel() {
// If everything provided isn't null and is valid, create the model with the specified color and custom model data
} else if (this.getColor().startsWith("#")) {
// Check if valid hex code via the utility in net.jeqo.bloons.utils.ColorManagement
if (!ColorManagement.isHexCode(this.getColor())) {
Logger.logError(String.format(LanguageManagement.getMessage("invalid-hex-code"), this.getColor()));
if (!Color.isHexCode(this.getColor())) {
Logger.logError(String.format(Languages.getMessage("invalid-hex-code"), this.getColor()));
return null;
}

// Convert the hex code to a valid org.bukkit.Color object
Color color = ColorManagement.hexToColor(this.getColor());
org.bukkit.Color color = Color.hexToColor(this.getColor());
return BalloonModel.createColouredModel(material, color, this.getCustomModelData());

// If the color is not a hex code and there is no custom model data, only return a raw org.bukkit.inventory.ItemStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ public class ModelNode {
double turningSplineInterpolation;

/**
* Builder for creating lead segment.
* @param x X-axis position, type float
* @param z Z-axis position, type float
* @param length Length of segment in blocks, type float
* @param index Index number of segment, type int
* Builder for creating lead segment.
* @param x X-axis position, type float
* @param y Y-axis position, type float
* @param z Z-axis position, type float
* @param length Length of segment in blocks, type float
* @param index Index number of segment, type int
* @param balloonType Type of balloon, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType
* @param balloonOwner Owner of the balloon, type org.bukkit.entity.Player
*/
public ModelNode(float x, float y, float z, float length, int index, MultipartBalloonType balloonType, Player balloonOwner, double maxNodeJointAngle, double yAxisInterpolation, double turningSplineInterpolation) {
this.setLength(length);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/jeqo/bloons/balloon/single/SingleBalloon.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
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.LanguageManagement;
import net.jeqo.bloons.utils.management.SingleBalloonManagement;
import net.jeqo.bloons.utils.ColorManagement;
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;
Expand Down Expand Up @@ -157,21 +157,21 @@ public ItemStack getConfiguredBalloonVisual(String balloonID) {

// If there isn't a configuration for the balloon, log an error and return null
if (singleBalloonType == null) {
Logger.logError(String.format(LanguageManagement.getMessage("balloon-not-set"), balloonID));
Logger.logError(String.format(Languages.getMessage("balloon-not-set"), balloonID));
return new ItemStack(Material.BARRIER);
}

// If the material of the balloon is not set, log an error and return null
if (singleBalloonType.getMaterial() == null) {
Logger.logError(String.format(LanguageManagement.getMessage("material-not-set"), balloonID));
Logger.logError(String.format(Languages.getMessage("material-not-set"), balloonID));
return new ItemStack(Material.BARRIER);
}

Material material = Material.getMaterial(singleBalloonType.getMaterial());

// If the material is not valid, log an error and return null
if (material == null) {
Logger.logError(String.format(LanguageManagement.getMessage("material-not-valid"), balloonID, singleBalloonType.getMaterial()));
Logger.logError(String.format(Languages.getMessage("material-not-valid"), balloonID, singleBalloonType.getMaterial()));
return new ItemStack(Material.BARRIER);
}

Expand All @@ -184,12 +184,12 @@ public ItemStack getConfiguredBalloonVisual(String balloonID) {
if (singleBalloonType.getColor() != null && singleBalloonType.getMaterial().startsWith(leatherMaterialPrefix)) {
// If the color of the balloon is set to potion, log a warning and return null
if (singleBalloonType.getColor().equalsIgnoreCase("potion")) {
Logger.logWarning(String.format(LanguageManagement.getMessage("material-not-dyeable"), material));
Logger.logWarning(String.format(Languages.getMessage("material-not-dyeable"), material));
return item;
}

LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta;
leatherArmorMeta.setColor(ColorManagement.hexToColor(singleBalloonType.getColor()));
leatherArmorMeta.setColor(Color.hexToColor(singleBalloonType.getColor()));
}

// Finally, set the item meta
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package net.jeqo.bloons.utils;
package net.jeqo.bloons.colors;

import org.bukkit.ChatColor;
import org.bukkit.Color;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* A class to convert messages with hex codes, and hex strings to Bukkit colors
*/
public class ColorManagement {
public class Color {

/**
* Converts a message with hex codes to a Bukkit color
Expand Down Expand Up @@ -37,6 +36,7 @@ public static String fromHex(String message) {
/**
* Checks if a string is a valid hex code
* @param string The string to check the validity of, type java.lang.String
* @return Whether the string is a valid hex code, type boolean
*/
public static boolean isHexCode(String string) {
return string.matches("#[a-fA-F0-9]{6}");
Expand All @@ -47,7 +47,7 @@ public static boolean isHexCode(String string) {
* @param string The hex string to convert, type java.lang.String
* @return The Bukkit color, type org.bukkit.Color
*/
public static Color hexToColor(String string) {
return Color.fromRGB(Integer.parseInt(string.substring(1), 16));
public static org.bukkit.Color hexToColor(String string) {
return org.bukkit.Color.fromRGB(Integer.parseInt(string.substring(1), 16));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.jeqo.bloons.utils;
package net.jeqo.bloons.colors;

import java.util.HashMap;
import java.util.Map;
Expand Down
Loading

0 comments on commit 0024b65

Please sign in to comment.