Skip to content

Commit

Permalink
less libs, less code, way too much more work
Browse files Browse the repository at this point in the history
  • Loading branch information
iiAhmedYT committed Jul 4, 2024
1 parent 04bd683 commit 21fee91
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 324 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ dependencies {
implementation "com.tcoded:FoliaLib:0.3.4"
implementation "org.bstats:bstats-bukkit:3.0.2"
implementation "com.github.Redempt:Crunch:2.0.3"
implementation "dev.dejvokep:boosted-yaml:1.3.2"

compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
compileOnly "com.comphenix.protocol:ProtocolLib:5.1.0"
Expand Down
201 changes: 64 additions & 137 deletions src/main/java/to/itsme/itsmyconfig/ItsMyConfig.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package to.itsme.itsmyconfig.command.impl;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import revxrsal.commands.annotation.*;
Expand All @@ -19,6 +21,7 @@
import to.itsme.itsmyconfig.util.Message;
import to.itsme.itsmyconfig.util.Utilities;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;

Expand Down Expand Up @@ -151,14 +154,24 @@ public void config(
final Placeholder placeholder,
@Named("value") final String value
) {
final Section section = placeholder.getSection();
final ConfigurationSection section = placeholder.getConfigurationSection();
final PlaceholderType type = PlaceholderType.find(section.getString("type"));
if (type == PlaceholderType.ANIMATION || type == PlaceholderType.RANDOM) {
actor.reply(Utilities.MM.deserialize("<red>Placeholder <yellow>" + placeholder + "</yellow>'s type is not supported via commands.</red>"));
return;
}

section.set("value", value);
final Configuration root = section.getRoot();
if (root instanceof YamlConfiguration) {
final YamlConfiguration conf = (YamlConfiguration) root;
try {
conf.save(conf.getCurrentPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}

actor.reply(Utilities.MM.deserialize("<green>Placeholder <yellow>" + placeholder + "</yellow>'s value was updated successfully!</green>"));
}

Expand Down
33 changes: 5 additions & 28 deletions src/main/java/to/itsme/itsmyconfig/hook/PAPIHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import to.itsme.itsmyconfig.ItsMyConfig;
import to.itsme.itsmyconfig.placeholder.Placeholder;
import to.itsme.itsmyconfig.progress.ProgressBar;
import to.itsme.itsmyconfig.placeholder.PlaceholderType;
import to.itsme.itsmyconfig.font.Font;

/**
Expand Down Expand Up @@ -121,8 +120,6 @@ public boolean persist() {
final String firstParam = splitParams[0].toLowerCase();
if ("font".equals(firstParam) && splitParams.length >= 3) {
return handleFont(splitParams);
} else if ("progress".equals(firstParam) && splitParams.length >= 4) {
return handleProgress(splitParams);
}
return handlePlaceholder(splitParams, player);
}
Expand All @@ -133,7 +130,7 @@ public boolean persist() {
* @param splitParams The array of parameters, where the font type is at index 1 and additional parameters are at subsequent indices.
* @return The processed font or an error message if the font type is unknown or if an error occurs during font processing.
*/
private String handleFont(String[] splitParams) {
private String handleFont(final String[] splitParams) {
String fontType = splitParams[1].toLowerCase();
if ("latin".equals(fontType)) {
try {
Expand All @@ -149,27 +146,6 @@ private String handleFont(String[] splitParams) {
return "ERROR";
}

/**
* Handles progress bar rendering and retrieval.
*
* @param splitParams The array of parameters containing the identifier, value, and maxValue of the progress bar.
* @return The rendered progress bar as a string, or an error message if the progress bar is not found or the parameters are invalid.
*/
private String handleProgress(final String[] splitParams) {
final String identifier = splitParams[1];
try {
double value = Double.parseDouble(splitParams[2]);
double maxValue = Double.parseDouble(splitParams[3]);
final ProgressBar progressBar = plugin.getProgressBarBucket().getProgressBar(identifier);
if (progressBar == null) {
return String.format("Not Found Progress Bar(%s)", identifier);
}
return ChatColor.translateAlternateColorCodes('&', progressBar.render(value, maxValue));
} catch (NumberFormatException e) {
return ILLEGAL_NUMBER_FORMAT_MSG;
}
}

/**
* Handles the placeholder based on the params and player.
*
Expand Down Expand Up @@ -198,7 +174,8 @@ private String handlePlaceholder(
final StringBuilder builder = new StringBuilder();
builder.append(firstParam);

switch (placeholder.getType()) {
final PlaceholderType type = placeholder.getType();
switch (type) {
case COLOR:
case COLORED_TEXT:
switch (firstParam.toLowerCase()) {
Expand All @@ -224,7 +201,7 @@ private String handlePlaceholder(
}
}

return placeholder.asString(player, builder.toString().split("::"));
return placeholder.asString(player, builder.toString().split(type == PlaceholderType.PROGRESS_BAR ? "_" : "::"));
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/to/itsme/itsmyconfig/placeholder/Placeholder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package to.itsme.itsmyconfig.placeholder;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -31,7 +30,7 @@ public abstract class Placeholder {
/**
* Represents the config section of the placeholder.
*/
private final Section section;
private final ConfigurationSection section;

/**
* Represents the type of a placeholder.
Expand All @@ -50,7 +49,7 @@ public abstract class Placeholder {
* Represents a placeholder data object.
*/
public Placeholder(
final Section section,
final ConfigurationSection section,
final PlaceholderType type
) {
this.type = type;
Expand All @@ -62,7 +61,7 @@ public Placeholder(
*
* @param section The ConfigurationSection containing requirement data.
*/
public void registerRequirement(final Section section) {
public void registerRequirement(final ConfigurationSection section) {
final String identifier = section.getString("type");
this.registerArgumentsFor(section, identifier);
this.requirements.add(
Expand All @@ -82,7 +81,7 @@ public void registerRequirement(final Section section) {
* @param argumentName the name of the argument in the ConfigurationSection
*/
private void registerArgumentsFor(
final Section section,
final ConfigurationSection section,
final String argumentName
) {
final String argumentValue = section.getString(argumentName);
Expand Down Expand Up @@ -196,9 +195,9 @@ protected void registerArguments(final String string) {
/**
* Retrieves a specific section from the YAML document.
*
* @return the {@link Section} object representing the specified section.
* @return the {@link ConfigurationSection} object representing the specified section.
*/
public Section getSection() {
public ConfigurationSection getConfigurationSection() {
return this.section;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum PlaceholderType {
* Represents the type of an animation placeholder.
*/
ANIMATION,
PROGRESS_BAR,
COLORED_TEXT;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package to.itsme.itsmyconfig.placeholder.type;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import to.itsme.itsmyconfig.placeholder.Placeholder;
import to.itsme.itsmyconfig.placeholder.PlaceholderType;
Expand All @@ -22,7 +22,7 @@ public final class AnimatedPlaceholder extends Placeholder {
* Represents an animated placeholder data object that rotates between different messages at a specified interval.
* Extends the PlaceholderData class.
*/
public AnimatedPlaceholder(final Section section) {
public AnimatedPlaceholder(final ConfigurationSection section) {
super(section, PlaceholderType.ANIMATION);
final List<String> messages = section.getStringList("values");
this.queue = new ArrayBlockingQueue<>(messages.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package to.itsme.itsmyconfig.placeholder.type;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.kyori.adventure.text.format.*;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import to.itsme.itsmyconfig.placeholder.Placeholder;
import to.itsme.itsmyconfig.placeholder.PlaceholderType;
Expand Down Expand Up @@ -71,7 +71,7 @@ public final class ColorPlaceholder extends Placeholder {
/**
* Represents a color placeholder data object.
*/
public ColorPlaceholder(final Section section) {
public ColorPlaceholder(final ConfigurationSection section) {
super(section, PlaceholderType.COLOR);
this.value = section.getString("value", "").toLowerCase();

Expand Down Expand Up @@ -112,7 +112,7 @@ public ColorPlaceholder(final Section section) {
*
* @param configurationSection The ConfigurationSection containing the style properties.
*/
private void initializeStyle(Section configurationSection) {
private void initializeStyle(ConfigurationSection configurationSection) {
final Style.Builder builder = Style.style().color(TextColor.fromHexString(hexValue));

final StringBuilder propertiesBuilder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package to.itsme.itsmyconfig.placeholder.type;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import to.itsme.itsmyconfig.placeholder.Placeholder;
import to.itsme.itsmyconfig.placeholder.PlaceholderType;
Expand All @@ -28,7 +28,7 @@ public class ColoredTextPlaceholder extends Placeholder {

private final String miniText;

public ColoredTextPlaceholder(final Section section) {
public ColoredTextPlaceholder(final ConfigurationSection section) {
super(section, PlaceholderType.COLORED_TEXT);
this.miniText = section.getString("value", "");
this.registerArguments(this.miniText);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package to.itsme.itsmyconfig.placeholder.type;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import to.itsme.itsmyconfig.placeholder.Placeholder;
import to.itsme.itsmyconfig.placeholder.PlaceholderType;
Expand All @@ -12,7 +12,7 @@ public class ListPlaceholder extends Placeholder {

private final List<String> list;

public ListPlaceholder(final Section section) {
public ListPlaceholder(final ConfigurationSection section) {
super(section, PlaceholderType.LIST);
this.list = section.getStringList("values");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package to.itsme.itsmyconfig.placeholder.type;

import dev.dejvokep.boostedyaml.block.implementation.Section;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import redempt.crunch.CompiledExpression;
import redempt.crunch.Crunch;
Expand All @@ -17,7 +17,7 @@ public final class MathPlaceholder extends Placeholder {
private final int precision;
private final RoundingMode mode;

public MathPlaceholder(final Section section) {
public MathPlaceholder(final ConfigurationSection section) {
super(section, PlaceholderType.MATH);
final String value = section.getString("value");
this.registerArguments(value);
Expand Down
Loading

0 comments on commit 21fee91

Please sign in to comment.