Improved util codestyle

This commit is contained in:
Auxilor 2020-12-25 20:59:53 +00:00
parent 69704c0550
commit 6ab858651e
20 changed files with 65 additions and 43 deletions

View File

@ -8,7 +8,7 @@ public class AshArtifact extends Artifact {
public AshArtifact() {
super(
"ash_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -8,7 +8,7 @@ public class CrimsonArtifact extends Artifact {
public CrimsonArtifact() {
super(
"crimson_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -8,7 +8,7 @@ public class SoulArtifact extends Artifact {
public SoulArtifact() {
super(
"soul_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -8,7 +8,7 @@ public class SoulFireArtifact extends Artifact {
public SoulFireArtifact() {
super(
"soul_fire_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -8,7 +8,7 @@ public class TearArtifact extends Artifact {
public TearArtifact() {
super(
"tear_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -8,7 +8,7 @@ public class WarpedArtifact extends Artifact {
public WarpedArtifact() {
super(
"warped_artifact",
Prerequisite.MinVer1_16
Prerequisite.MINIMUM_1_16
);
}

View File

@ -13,7 +13,7 @@ public class Economical extends EcoEnchant {
public Economical() {
super(
"economical", EnchantmentType.NORMAL,
Prerequisite.HasPaper
Prerequisite.HAS_PAPER
);
}

View File

@ -24,7 +24,7 @@ public class Plasmic extends EcoEnchant {
private static final Material[] items;
static {
if(Prerequisite.MinVer1_16.isMet()) {
if(Prerequisite.MINIMUM_1_16.isMet()) {
items = new Material[]{
Material.DIAMOND_HELMET,
Material.DIAMOND_CHESTPLATE,

View File

@ -23,12 +23,13 @@ public class StringUtils {
* @param player The player to translate placeholders with respect to.
* @return The message, translated.
*/
public String translate(@NotNull String message,
public String translate(@NotNull final String message,
@Nullable final Player player) {
message = PlaceholderManager.translatePlaceholders(message, player);
message = translateHexColorCodes(message);
message = ChatColor.translateAlternateColorCodes('&', message);
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(message));
String processedMessage = message;
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
processedMessage = translateHexColorCodes(processedMessage);
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(processedMessage));
}
/**
@ -38,11 +39,12 @@ public class StringUtils {
* @return The message, translated.
* @see StringUtils#translate(String, Player)
*/
public String translate(@NotNull String message) {
message = PlaceholderManager.translatePlaceholders(message, null);
message = translateHexColorCodes(message);
message = ChatColor.translateAlternateColorCodes('&', message);
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(message));
public String translate(@NotNull final String message) {
String processedMessage = message;
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, null);
processedMessage = translateHexColorCodes(processedMessage);
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(processedMessage));
}
private static String translateHexColorCodes(String message) {

View File

@ -68,8 +68,8 @@ public class VectorUtils {
public Vector[] getCircle(final int radius) {
ArrayList<Vector> circleVecs = new ArrayList<>();
int xoffset = -radius;
int zoffset = -radius;
double xoffset = -radius;
double zoffset = -radius;
while (zoffset <= radius) {
while (xoffset <= radius) {

View File

@ -2,10 +2,11 @@ package com.willfp.eco.util.config.configs;
import com.willfp.eco.util.config.BaseConfig;
/**
* Wrapper for config.yml
*/
public class Config extends BaseConfig {
/**
* Config.yml.
*/
public Config() {
super("config", true);
}

View File

@ -83,6 +83,8 @@ public class EntityDeathByEntityEvent extends Event {
/**
* Internal bukkit.
*
* @return The handlers.
*/
public static HandlerList getHandlerList() {
return HANDLERS;

View File

@ -39,6 +39,8 @@ class NaturalExpGainBuilder {
/**
* Build a new {@link NaturalExpGainEvent} given a specific reason.
*
* @param reason The {@link BuildReason}.
*/
NaturalExpGainBuilder(@NotNull final BuildReason reason) {
this.reason = reason;

View File

@ -54,7 +54,7 @@ public class NaturalExpGainListeners implements Listener {
* @param event The even to listen for.
*/
@EventHandler
public void onExpBottle(ExpBottleEvent event) {
public void onExpBottle(@NotNull final ExpBottleEvent event) {
NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.BOTTLE);
builtEvent.setLocation(event.getEntity().getLocation());

View File

@ -1,5 +1,7 @@
package com.willfp.eco.util.extensions;
import org.jetbrains.annotations.NotNull;
/**
* Called when the extension is made incorrectly.
*/
@ -14,7 +16,7 @@ public class MalformedExtensionException extends RuntimeException {
*
* @param errorMessage The error message to show.
*/
public MalformedExtensionException(String errorMessage) {
public MalformedExtensionException(@NotNull final String errorMessage) {
super(errorMessage);
}
}

View File

@ -1,12 +1,9 @@
package com.willfp.eco.util.integrations;
/**
* Interface for all integrations with optional dependencies
*/
public interface Integration {
/**
* Get the name of integration
* @return The name
* Get the name of integration.
* @return The name.
*/
String getPluginName();
}

View File

@ -1,20 +1,36 @@
package com.willfp.eco.util.integrations;
import com.willfp.eco.util.lambda.Callable;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class IntegrationLoader {
/**
* The lambda to be ran if the plugin is present.
*/
private final Callable callable;
/**
* The plugin to require to load the integration.
*/
@Getter
private final String pluginName;
public IntegrationLoader(String pluginName, Callable onLoad) {
/**
* Create a new Integration Loader.
*
* @param pluginName The plugin to require.
* @param onLoad The lambda to be ran if the plugin is present.
*/
public IntegrationLoader(@NotNull final String pluginName,
@NotNull final Callable onLoad) {
this.callable = onLoad;
this.pluginName = pluginName;
}
public String getPluginName() {
return pluginName;
}
/**
* Load the integration.
*/
public void load() {
callable.call();
}

View File

@ -1,9 +1,9 @@
package com.willfp.eco.util.lambda;
/**
* Functional Interface to return a value of a given type
* Functional Interface to return a value of a given type.
*
* @param <A> The type to return
* @param <A> The type to return.
*/
@FunctionalInterface
public interface ObjectCallable<A> {

View File

@ -14,12 +14,12 @@ public class Prerequisite {
/**
* All existing prerequisites are registered on creation.
*/
private static final List<Prerequisite> values = new ArrayList<>();
private static final List<Prerequisite> VALUES = new ArrayList<>();
/**
* Requires the server to be running minecraft version 1.16 or higher.
*/
public static final Prerequisite MinVer1_16 = new Prerequisite(
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
() -> !Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].contains("15"),
"Requires minimum server version of 1.16"
);
@ -27,7 +27,7 @@ public class Prerequisite {
/**
* Requires the server to be running an implementation of paper.
*/
public static final Prerequisite HasPaper = new Prerequisite(
public static final Prerequisite HAS_PAPER = new Prerequisite(
() -> ClassUtils.exists("com.destroystokyo.paper.event.player.PlayerElytraBoostEvent"),
"Requires server to be running paper (or a fork)"
);
@ -60,7 +60,7 @@ public class Prerequisite {
this.isMetCallable = isMetCallable;
this.isMet = isMetCallable.call();
this.description = description;
values.add(this);
VALUES.add(this);
}
/**
@ -74,7 +74,7 @@ public class Prerequisite {
* Update all prerequisites' {@link Prerequisite#isMet}.
*/
public static void update() {
values.forEach(Prerequisite::refresh);
VALUES.forEach(Prerequisite::refresh);
}
/**

View File

@ -291,7 +291,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
}
});
if (!Prerequisite.HasPaper.isMet()) {
if (!Prerequisite.HAS_PAPER.isMet()) {
this.getLog().error("");
this.getLog().error("----------------------------");
this.getLog().error("");