mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-21 07:59:28 +00:00
Reworked effect registration
This commit is contained in:
@@ -23,11 +23,21 @@ public abstract class Effect implements BossTicker {
|
|||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a config error.
|
||||||
|
*
|
||||||
|
* @param message The error message.
|
||||||
|
*/
|
||||||
public void showConfigError(@NotNull final String message) {
|
public void showConfigError(@NotNull final String message) {
|
||||||
Bukkit.getLogger().warning("An effect is configured incorrectly!");
|
Bukkit.getLogger().warning("An effect is configured incorrectly!");
|
||||||
Bukkit.getLogger().warning(message);
|
Bukkit.getLogger().warning(message);
|
||||||
Bukkit.getLogger().warning("Usage: " + getUsage());
|
Bukkit.getLogger().warning("Usage: " + getUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get effect usage.
|
||||||
|
*
|
||||||
|
* @return The usage.
|
||||||
|
*/
|
||||||
public abstract String getUsage();
|
public abstract String getUsage();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
package com.willfp.ecobosses.bosses.effects;
|
package com.willfp.ecobosses.bosses.effects;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.willfp.ecobosses.bosses.effects.effects.DamageNearbyPlayers;
|
import com.willfp.ecobosses.bosses.effects.effects.DamageNearbyPlayers;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class Effects {
|
public class Effects {
|
||||||
|
/**
|
||||||
|
* Registered effects.
|
||||||
|
*/
|
||||||
|
private static final Map<String, Function<List<String>, Effect>> EFFECTS = new ImmutableMap.Builder<String, Function<List<String>, Effect>>()
|
||||||
|
.put("damage-nearby-players", DamageNearbyPlayers::new)
|
||||||
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get effect matching name.
|
* Get effect matching name.
|
||||||
*
|
*
|
||||||
@@ -19,12 +29,7 @@ public class Effects {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Effect getEffect(@NotNull final String name,
|
public Effect getEffect(@NotNull final String name,
|
||||||
@NotNull final List<String> args) {
|
@NotNull final List<String> args) {
|
||||||
switch (name.toLowerCase()) {
|
Function<List<String>, Effect> found = EFFECTS.get(name.toLowerCase());
|
||||||
case "damage-nearby-players":
|
return found == null ? null : found.apply(args);
|
||||||
return new DamageNearbyPlayers(args);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user