Skip to content

Commit

Permalink
Configuration Sector Cleanup (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Tapply authored Jun 24, 2024
1 parent 614352f commit 73d3bed
Show file tree
Hide file tree
Showing 18 changed files with 440 additions and 524 deletions.
62 changes: 16 additions & 46 deletions src/main/java/net/jeqo/bloons/balloon/BalloonCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
@Setter @Getter
public class BalloonCore {
/**
* The plugin instance that runs the balloon core, type org.bukkit.plugin.java.JavaPlugin
*/
private JavaPlugin plugin;
/**
* Contains all valid and loaded multipart balloon types/configurations
Expand All @@ -25,18 +28,15 @@ public class BalloonCore {
* 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]
* Contains all example balloon files to copy to the plugin's data folder
*/
public BalloonCore(JavaPlugin plugin, ArrayList<MultipartBalloonType> balloons, ArrayList<SingleBalloonType> singleBalloons) {
this.setPlugin(plugin);
this.setMultipartBalloonTypes(balloons);
this.setSingleBalloonTypes(singleBalloons);
}
private final String[] exampleBalloons = new String[] {
"color_pack_example.yml",
"dyeable_example.yml",
"meg_example.yml",
"multipart_example.yml"
};

/**
* Creates a new empty balloon core instance
Expand Down Expand Up @@ -74,50 +74,19 @@ public void copyExampleBalloons() {
};

// Save all example files in the balloons folder in /resources
for (String example : exampleBalloons) {
File file = new File(Bloons.getInstance().getDataFolder() + File.separator + ConfigConfiguration.BALLOON_CONFIGURATION_FOLDER + example);
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);
}
}

/**
* Adds a balloon to the registered balloons list
* @param balloon The balloon to add, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType
*/
public void addMultipartBalloon(MultipartBalloonType balloon) {
this.getMultipartBalloonTypes().add(balloon);
}

/**
* Removes a balloon from the registered balloons list
* @param balloon The balloon to remove, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType
*/
public void removeMultipartBalloon(MultipartBalloonType balloon) {
this.getMultipartBalloonTypes().remove(balloon);
}

/**
* Adds a single balloon to the registered balloons list
* @param balloon The single balloon to add, type net.jeqo.bloons.balloon.single.SingleBalloonType
*/
public void addSingleBalloon(SingleBalloonType balloon) {
this.getSingleBalloonTypes().add(balloon);
}

/**
* Removes a single balloon from the registered balloons list
* @param balloon The single balloon to remove, type net.jeqo.bloons.balloon.single.SingleBalloonType
*/
public void removeSingleBalloon(SingleBalloonType balloon) {
this.getSingleBalloonTypes().remove(balloon);
}

/**
* Retrieves a balloon by its ID from the registered balloons list
* @param ID The ID of the balloon, type java.lang.String
* @return The balloon with the specified name, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType/null
* @return The balloon with the specified name, type net.jeqo.bloons.balloon.multipart.MultipartBalloonType
* Returns null if no balloon is found by the specified ID
*/
public MultipartBalloonType getMultipartBalloonByID(String ID) {
// Loop over every balloon in the registered balloons list
Expand All @@ -135,7 +104,8 @@ public MultipartBalloonType getMultipartBalloonByID(String ID) {
/**
* Retrieves a single balloon by its ID from the registered balloons list
* @param ID The ID of the balloon, type java.lang.String
* @return The single balloon with the specified ID, type net.jeqo.bloons.balloon.single.SingleBalloonType/null
* @return The single balloon with the specified ID, type net.jeqo.bloons.balloon.single.SingleBalloonType
* Returns null if no balloon is found by the specified ID
*/
public SingleBalloonType getSingleBalloonByID(String ID) {
// Loop over every single balloon in the registered balloons list
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
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 leatherMaterialPrefix = "LEATHER_"; // A constant to define a dyeable material
private static final String LEATHER_MATERIAL_PREFIX = "LEATHER_"; // A constant to define a dyeable material

/**
* Generates a coloured model with the specified colour and custom model data
Expand All @@ -23,7 +23,7 @@ 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(leatherMaterialPrefix)) {
if (!material.name().contains(LEATHER_MATERIAL_PREFIX)) {
Logger.logError("Material " + material.name() + " is not a dyeable material.");
return new ItemStack(material);
}
Expand Down Expand Up @@ -52,7 +52,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(leatherMaterialPrefix)) {
if (!material.name().contains(LEATHER_MATERIAL_PREFIX)) {
Logger.logWarning(String.format(Languages.getMessage("material-not-dyeable"), material));
return new ItemStack(material);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* The type of segment that the model accommodates
*/
public enum BalloonModelType {
public enum BalloonSegmentType {
/**
* This is the head of the balloon, indexed as the last index in the multipart balloon
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import lombok.Getter;
import lombok.Setter;
import net.jeqo.bloons.balloon.model.BalloonModel;
import net.jeqo.bloons.balloon.model.BalloonModelType;
import net.jeqo.bloons.balloon.model.BalloonSegmentType;
import net.jeqo.bloons.logger.Logger;
import net.jeqo.bloons.colors.Color;
import net.jeqo.bloons.message.Languages;
Expand All @@ -15,22 +15,35 @@
*/
@Getter @Setter
public class MultipartBalloonModel {
private BalloonModelType modelType;
private String material;
private String color;
private Integer customModelData;
/**
* The type of segment that the model accommodates
* This can either be the head, body, or tail of the balloon
*/
private BalloonSegmentType segmentType;
/**
* The material used to create the model
*/
private String material; // required
/**
* The color of the model
*/
private String color = "#ffffff"; // optional
/**
* The custom model data value stored in the item metadata
*/
private Integer customModelData; // required

/**
* Creates a new model for a multipart balloon
* @param modelType The type of model (head, body, tail), type net.jeqo.bloons.balloon.model.BalloonModelType
* @param segmentType The type of model (head, body, tail), type net.jeqo.bloons.balloon.model.BalloonModelType
* @param material The name of the Bukkit Material used to create the item, type java.lang.String
* @param color The color of the model as a hex color code value, type java.lang.String
* @param customModelData The custom model data value stored in the item metadata, type int
*/
public MultipartBalloonModel(BalloonModelType modelType, String material, String color, int customModelData) {
this.setModelType(modelType);
public MultipartBalloonModel(BalloonSegmentType segmentType, String material, String color, int customModelData) {
this.setSegmentType(segmentType);
this.setMaterial(material);
this.setColor(color);
if (!color.equals(this.getColor()) && color != null && !color.isEmpty()) this.setColor(color);
this.setCustomModelData(customModelData);
}

Expand Down
Loading

0 comments on commit 73d3bed

Please sign in to comment.