Skip to content

Commit

Permalink
update core
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Jun 16, 2023
1 parent 09aca6b commit 9dbf12f
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 179 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@
<artifactId>hscore-variable</artifactId>
<version>${core.version}</version>
</dependency>
<dependency>
<groupId>me.hsgamer</groupId>
<artifactId>hscore-bukkit-variable</artifactId>
<version>${core.version}</version>
</dependency>
<dependency>
<groupId>fr.mrmicky</groupId>
<artifactId>fastboard</artifactId>
<version>1.2.1</version>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/me/hsgamer/betterboard/BetterBoard.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package me.hsgamer.betterboard;

import com.ezylang.evalex.data.EvaluationValue;
import me.hsgamer.betterboard.command.ReloadCommand;
import me.hsgamer.betterboard.config.MainConfig;
import me.hsgamer.betterboard.hook.PlaceholderAPIHook;
import me.hsgamer.betterboard.listener.PlayerListener;
import me.hsgamer.betterboard.manager.BoardProviderManager;
import me.hsgamer.betterboard.manager.PlayerBoardManager;
import me.hsgamer.betterboard.manager.PluginVariableManager;
import me.hsgamer.betterboard.util.ExpressionUtil;
import me.hsgamer.hscore.bukkit.baseplugin.BasePlugin;
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
import me.hsgamer.hscore.bukkit.variable.BukkitVariableBundle;
import me.hsgamer.hscore.common.StringReplacer;
import me.hsgamer.hscore.variable.CommonVariableBundle;
import me.hsgamer.hscore.variable.VariableBundle;
import me.hsgamer.hscore.variable.VariableManager;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;

import java.math.BigDecimal;

public final class BetterBoard extends BasePlugin {
private static final VariableBundle globalVariableBundle = new VariableBundle();

private final MainConfig mainConfig = new MainConfig(this);

private final BoardProviderManager boardProviderManager = new BoardProviderManager(this);
Expand All @@ -30,10 +39,13 @@ public void enable() {
Permissions.register();

if (PlaceholderAPIHook.setupPlugin()) {
VariableManager.addExternalReplacer((original, uuid) -> PlaceholderAPIHook.setPlaceholders(original, Bukkit.getOfflinePlayer(uuid)));
VariableManager.GLOBAL.addExternalReplacer(StringReplacer.of((original, uuid) -> PlaceholderAPIHook.setPlaceholders(original, Bukkit.getOfflinePlayer(uuid))));
getLogger().info("Hooked into PlaceholderAPI");
}
PluginVariableManager.registerDefaultVariables();

CommonVariableBundle.registerVariables(globalVariableBundle);
BukkitVariableBundle.registerVariables(globalVariableBundle);
globalVariableBundle.register("condition_", StringReplacer.of(original -> ExpressionUtil.getResult(original).map(EvaluationValue::getNumberValue).map(BigDecimal::toString).orElse(null)));

registerListener(new PlayerListener(this));

Expand All @@ -52,8 +64,8 @@ public void disable() {
Permissions.unregister();
playerBoardManager.clearAll();
boardProviderManager.clearAll();
PluginVariableManager.unregisterAll();
VariableManager.clearExternalReplacers();
globalVariableBundle.unregisterAll();
VariableManager.GLOBAL.clearExternalReplacers();
}

public MainConfig getMainConfig() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/hsgamer/betterboard/board/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Board(BetterBoard instance, Player player) {
long update = MainConfig.UPDATE_TICKS.getValue();
boolean async = MainConfig.UPDATE_ASYNC.getValue();
update = Math.max(update, 0);
task = Scheduler.CURRENT.runEntityTaskTimer(instance, player, this, update, update, async);
task = Scheduler.plugin(instance).runner(async).runEntityTaskTimer(player, this, update, update);
}

public void cancel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import me.hsgamer.betterboard.provider.board.SimpleBoardProvider;
import me.hsgamer.hscore.builder.Builder;
import me.hsgamer.hscore.config.Config;
import me.hsgamer.hscore.config.PathString;

import java.util.Objects;
import java.util.Optional;

public class BoardProviderBuilder extends Builder<Config, BoardProvider> {
private static final PathString TYPE_PATH = new PathString("type");
public static final BoardProviderBuilder INSTANCE = new BoardProviderBuilder();

private BoardProviderBuilder() {
Expand All @@ -20,7 +23,7 @@ private BoardProviderBuilder() {
public void register(Class<? extends ConfigurableBoardProvider> clazz, String... name) {
register(config -> {
try {
ConfigurableBoardProvider provider = clazz.newInstance();
ConfigurableBoardProvider provider = clazz.getDeclaredConstructor().newInstance();
provider.loadFromConfig(config);
return provider;
} catch (Exception e) {
Expand All @@ -31,8 +34,8 @@ public void register(Class<? extends ConfigurableBoardProvider> clazz, String...
}

public Optional<BoardProvider> build(Config config) {
if (config.contains("type")) {
String type = config.getInstance("type", String.class);
if (config.contains(TYPE_PATH)) {
String type = Objects.toString(config.getNormalized(TYPE_PATH));
return build(type, config);
} else {
return build("simple", config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ConditionBuilder() {
public void register(Class<? extends ConfigurableCondition> clazz, String... name) {
register(object -> {
try {
ConfigurableCondition condition = clazz.newInstance();
ConfigurableCondition condition = clazz.getDeclaredConstructor().newInstance();
condition.loadFromObject(object);
return condition;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import me.hsgamer.betterboard.BetterBoard;
import me.hsgamer.betterboard.Permissions;
import me.hsgamer.betterboard.manager.PluginVariableManager;
import me.hsgamer.hscore.bukkit.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -30,10 +29,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String commandLab

instance.getPlayerBoardManager().clearAll();
instance.getBoardProviderManager().clearAll();
PluginVariableManager.unregisterAll();
instance.getMainConfig().reload();
instance.getBoardProviderManager().loadProviders();
PluginVariableManager.registerDefaultVariables();
for (Player player : Bukkit.getOnlinePlayers()) {
instance.getPlayerBoardManager().addBoard(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ExpressionCondition implements ConfigurableCondition {
@Override
public boolean check(Player player) {
return list.parallelStream()
.map(s -> VariableManager.setVariables(s, player.getUniqueId()))
.map(s -> VariableManager.GLOBAL.setVariables(s, player.getUniqueId()))
.noneMatch(s -> ExpressionUtil.getResult(s).map(evaluationValue -> !evaluationValue.getBooleanValue()).orElse(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class LevelCondition implements ConfigurableCondition {
private String value = "0";

public Integer getParsedValue(Player player) {
String parsed = VariableManager.setVariables(String.valueOf(value).trim(), player.getUniqueId());
String parsed = VariableManager.GLOBAL.setVariables(String.valueOf(value).trim(), player.getUniqueId());
return ExpressionUtil.getResult(parsed).map(EvaluationValue::getNumberValue).map(BigDecimal::intValue).orElse(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PermissionCondition implements ConfigurableCondition {
@Override
public boolean check(Player player) {
return list.stream()
.map(s -> VariableManager.setVariables(s, player.getUniqueId()))
.map(s -> VariableManager.GLOBAL.setVariables(s, player.getUniqueId()))
.allMatch(s -> hasPermission(player, s));
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/me/hsgamer/betterboard/config/MainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.hsgamer.hscore.bukkit.config.BukkitConfig;
import me.hsgamer.hscore.common.CollectionUtils;
import me.hsgamer.hscore.config.PathString;
import me.hsgamer.hscore.config.PathableConfig;
import me.hsgamer.hscore.config.path.BaseConfigPath;
import me.hsgamer.hscore.config.path.ConfigPath;
Expand All @@ -13,9 +14,9 @@
import java.util.List;

public class MainConfig extends PathableConfig {
public static final LongConfigPath UPDATE_TICKS = new LongConfigPath("update.ticks", 0L);
public static final BooleanConfigPath UPDATE_ASYNC = new BooleanConfigPath("update.async", true);
public static final ConfigPath<List<String>> PRIORITY_PROVIDERS = new BaseConfigPath<>("priority-providers", Collections.emptyList(), o -> CollectionUtils.createStringListFromObject(o, true));
public static final LongConfigPath UPDATE_TICKS = new LongConfigPath(new PathString("update", "ticks"), 0L);
public static final BooleanConfigPath UPDATE_ASYNC = new BooleanConfigPath(new PathString("update", "async"), true);
public static final ConfigPath<List<String>> PRIORITY_PROVIDERS = new BaseConfigPath<>(new PathString("priority-providers"), Collections.emptyList(), o -> CollectionUtils.createStringListFromObject(o, true));

public MainConfig(Plugin plugin) {
super(new BukkitConfig(plugin, "config.yml"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ private PlaceholderAPIHook() {
}

public static boolean setupPlugin() {
if (!Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
return false;
}
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}

public static boolean hasPlaceholders(String message) {
return PlaceholderAPI.containsPlaceholders(message);
return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
}

public static String setPlaceholders(String message, OfflinePlayer executor) {
Expand Down

This file was deleted.

Loading

0 comments on commit 9dbf12f

Please sign in to comment.