9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-23 08:59:34 +00:00

internal improvements

This commit is contained in:
XiaoMoMi
2024-08-20 14:41:19 +08:00
parent d0579eac39
commit 9059ef6de5
7 changed files with 62 additions and 58 deletions

View File

@@ -33,7 +33,7 @@ public interface Action<T> {
*/
void trigger(Context<T> context);
static Action<?> empty() {
return EmptyAction.INSTANCE;
static <T> Action<T> empty() {
return EmptyAction.instance();
}
}

View File

@@ -24,11 +24,13 @@ import org.bukkit.entity.Player;
* An implementation of the Action interface that represents an empty action with no behavior.
* This class serves as a default action to prevent NPE.
*/
public class EmptyAction implements Action<Player> {
public class EmptyAction<T> implements Action<T> {
public static final EmptyAction INSTANCE = new EmptyAction();
public static <T> EmptyAction<T> instance() {
return new EmptyAction<>();
}
@Override
public void trigger(Context<Player> context) {
public void trigger(Context<T> context) {
}
}

View File

@@ -23,12 +23,14 @@ import org.bukkit.entity.Player;
/**
* Represents an empty requirement that always returns true when checking conditions.
*/
public class EmptyRequirement implements Requirement<Player> {
public class EmptyRequirement<T> implements Requirement<T> {
public static final EmptyRequirement INSTANCE = new EmptyRequirement();
public static <T> EmptyRequirement<T> instance() {
return new EmptyRequirement<>();
}
@Override
public boolean isSatisfied(Context<Player> context) {
public boolean isSatisfied(Context<T> context) {
return true;
}
}

View File

@@ -35,7 +35,7 @@ public interface Requirement<T> {
*/
boolean isSatisfied(Context<T> context);
static Requirement<?> empty() {
return EmptyRequirement.INSTANCE;
static <T> Requirement<T> empty() {
return EmptyRequirement.instance();
}
}

View File

@@ -57,7 +57,7 @@ public class WorldGuardRegion {
}
} else {
BukkitCustomFishingPlugin.getInstance().getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at region requirement which is expected be `Section` or `StringList`");
return EmptyRequirement.INSTANCE;
return EmptyRequirement.instance();
}
}
int finalMode = mode;

View File

@@ -110,11 +110,11 @@ public class BukkitActionManager implements ActionManager<Player> {
@Override
public Action<Player> parseAction(Section section) {
if (section == null) return EmptyAction.INSTANCE;
if (section == null) return Action.empty();
ActionFactory<Player> factory = getActionFactory(section.getString("type"));
if (factory == null) {
plugin.getPluginLogger().warn("Action type: " + section.getString("type") + " doesn't exist.");
return EmptyAction.INSTANCE;
return Action.empty();
}
return factory.process(section.get("value"), section.getDouble("chance", 1d));
}
@@ -140,7 +140,7 @@ public class BukkitActionManager implements ActionManager<Player> {
ActionFactory<Player> factory = getActionFactory(type);
if (factory == null) {
plugin.getPluginLogger().warn("Action type: " + type + " doesn't exist.");
return EmptyAction.INSTANCE;
return Action.empty();
}
return factory.process(args, 1);
}
@@ -225,7 +225,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at message-nearby action which should be Section");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -288,7 +288,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at command-nearby action which should be Section");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -340,7 +340,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at actionbar-nearby action which should be Section");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -412,7 +412,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-amount action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
registerAction("durability", (args, chance) -> {
@@ -445,7 +445,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at durability action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
registerAction("give-item", (args, chance) -> {
@@ -475,7 +475,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at give-item action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -586,7 +586,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at conditional action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
registerAction("priority", (args, chance) -> {
@@ -618,7 +618,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at priority action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -656,7 +656,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at potion-effect action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -677,7 +677,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at sound action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -697,7 +697,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-exp action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -722,7 +722,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
registerAction("random-title", (args, chance) -> {
@@ -748,7 +748,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at random-title action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
registerAction("title-nearby", (args, chance) -> {
@@ -776,7 +776,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at title-nearby action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
});
}
@@ -829,7 +829,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at fake-item action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
}));
}
@@ -876,7 +876,7 @@ public class BukkitActionManager implements ActionManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at hologram action which is expected to be `Section`");
return EmptyAction.INSTANCE;
return Action.empty();
}
}));
}

View File

@@ -126,12 +126,12 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
String type = section.getString("type");
if (type == null) {
plugin.getPluginLogger().warn("No requirement type found at " + section.getRouteAsString());
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
var factory = getRequirementFactory(type);
if (factory == null) {
plugin.getPluginLogger().warn("Requirement type: " + type + " not exists");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
return factory.process(section.get("value"), actionList, runActions);
}
@@ -142,7 +142,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
RequirementFactory<Player> factory = getRequirementFactory(type);
if (factory == null) {
plugin.getPluginLogger().warn("Requirement type: " + type + " doesn't exist.");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
return factory.process(value);
}
@@ -220,7 +220,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at competition requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -254,7 +254,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at item-in-hand requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -278,7 +278,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at plugin-level requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -334,7 +334,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at || requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -355,7 +355,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at && requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -635,7 +635,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
for (String e : ListUtils.toList(args)) {
plugin.getPluginLogger().warn(" - " + e);
}
return EmptyRequirement.INSTANCE;
return Requirement.empty();
});
}
@@ -827,7 +827,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at cooldown requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -898,7 +898,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at < requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("<=", (args, actions, runActions) -> {
@@ -912,7 +912,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at <= requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!=", (args, actions, runActions) -> {
@@ -926,7 +926,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at != requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("==", (args, actions, runActions) -> {
@@ -940,7 +940,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at == requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement(">=", (args, actions, runActions) -> {
@@ -954,7 +954,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at >= requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement(">", (args, actions, runActions) -> {
@@ -968,7 +968,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at > requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("regex", (args, actions, runActions) -> {
@@ -982,7 +982,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at regex requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("startsWith", (args, actions, runActions) -> {
@@ -996,7 +996,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at startsWith requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!startsWith", (args, actions, runActions) -> {
@@ -1010,7 +1010,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !startsWith requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("endsWith", (args, actions, runActions) -> {
@@ -1024,7 +1024,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at endsWith requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!endsWith", (args, actions, runActions) -> {
@@ -1038,7 +1038,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !endsWith requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("contains", (args, actions, runActions) -> {
@@ -1052,7 +1052,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at contains requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!contains", (args, actions, runActions) -> {
@@ -1066,7 +1066,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !contains requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("in-list", (args, actions, runActions) -> {
@@ -1080,7 +1080,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at in-list requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!in-list", (args, actions, runActions) -> {
@@ -1094,7 +1094,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !in-list requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("equals", (args, actions, runActions) -> {
@@ -1109,7 +1109,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at equals requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
registerRequirement("!equals", (args, actions, runActions) -> {
@@ -1123,7 +1123,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
};
} else {
plugin.getPluginLogger().warn("Invalid value type: " + args.getClass().getSimpleName() + " found at !equals requirement which is expected be `Section`");
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
});
}
@@ -1135,7 +1135,7 @@ public class BukkitRequirementManager implements RequirementManager<Player> {
PotionEffectType type = PotionEffectType.getByName(split[0]);
if (type == null) {
plugin.getPluginLogger().warn("Potion effect doesn't exist: " + split[0]);
return EmptyRequirement.INSTANCE;
return Requirement.empty();
}
int required = Integer.parseInt(split[1]);
String operator = potions.substring(split[0].length(), potions.length() - split[1].length());