Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

底层优化 #82

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.10.12-beta3"
version = "1.10.12-beta6"

plugins {
`java-library`
Expand Down Expand Up @@ -50,7 +50,10 @@ dependencies {
compileOnly("com.willfp:eco:6.74.2")
compileOnly("com.willfp:libreforge:4.71.6:all@jar")
compileOnly("com.ssomar:SCore:5.24.10.5")
implementation("com.crypticlib:CrypticLib:0.18.10-viewfix5")
implementation("com.crypticlib:bukkit:${rootProject.findProperty("crypticlibVer")}")
implementation("com.crypticlib:bukkit-ui:${rootProject.findProperty("crypticlibVer")}")
implementation("com.crypticlib:bukkit-conversation:${rootProject.findProperty("crypticlibVer")}")
implementation("com.crypticlib:bukkit-i18n:${rootProject.findProperty("crypticlibVer")}")
// implementation("de.tr7zw:item-nbt-api:2.12.4")
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crypticlibVer=1.8.0
Original file line number Diff line number Diff line change
@@ -1,61 +1,56 @@
package com.github.yufiriamazenta.craftorithm;

import com.github.yufiriamazenta.craftorithm.arcenciel.ArcencielDispatcher;
import com.github.yufiriamazenta.craftorithm.bstat.Metrics;
import com.github.yufiriamazenta.craftorithm.config.Languages;
import com.github.yufiriamazenta.craftorithm.config.PluginConfigs;
import com.github.yufiriamazenta.craftorithm.exception.UnsupportedVersionException;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.listener.ItemsAdderHandler;
import com.github.yufiriamazenta.craftorithm.listener.OtherPluginsListenerProxy;
import com.github.yufiriamazenta.craftorithm.listener.hook.OtherPluginsListenerManager;
import com.github.yufiriamazenta.craftorithm.recipe.RecipeManager;
import com.github.yufiriamazenta.craftorithm.util.LangUtil;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.util.UpdateUtil;
import com.github.yufiriamazenta.craftorithm.util.UpdateChecker;
import crypticlib.BukkitPlugin;
import crypticlib.CrypticLib;
import crypticlib.chat.MsgSender;
import crypticlib.CrypticLibBukkit;
import crypticlib.MinecraftVersion;
import crypticlib.chat.BukkitMsgSender;
import crypticlib.lifecycle.AutoTask;
import crypticlib.lifecycle.BukkitLifeCycleTask;
import crypticlib.lifecycle.LifeCycle;
import crypticlib.lifecycle.TaskRule;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.plugin.Plugin;

public final class Craftorithm extends BukkitPlugin implements Listener {
@AutoTask(
rules = {
@TaskRule(
lifeCycle = LifeCycle.RELOAD
)
}
)
public final class Craftorithm extends BukkitPlugin implements Listener, BukkitLifeCycleTask {

private static Craftorithm INSTANCE;

public Craftorithm() {
INSTANCE = this;
}

@Override
public void load() {
super.load();
}

@Override
public void enable() {
if (CrypticLib.minecraftVersion() < 11904) {
MsgSender.info("&c[Craftorithm] Unsupported Version");
if (MinecraftVersion.current().before(MinecraftVersion.V1_19_4)) {
BukkitMsgSender.INSTANCE.info("&c[Craftorithm] Unsupported Version");
throw new UnsupportedVersionException();
}
CrypticLib.setDebug(PluginConfigs.DEBUG.value());
PluginHookUtil.hookPlugins();

Bukkit.getPluginManager().registerEvents(this, this);
if (PluginHookUtil.isItemsAdderLoaded()) {
MsgSender.debug("[Craftorithm] Registering ItemsAdder Handler");
Bukkit.getPluginManager().registerEvents(ItemsAdderHandler.INSTANCE, this);
}

ItemManager.INSTANCE.loadItemManager();
initArcenciel();
CrypticLib.DEBUG = PluginConfigs.DEBUG.value();
loadBStat();

Bukkit.getPluginManager().registerEvents(OtherPluginsListenerProxy.INSTANCE, this);
LangUtil.info(Languages.LOAD_FINISH);
UpdateUtil.pullUpdateCheckRequest(Bukkit.getConsoleSender());
UpdateChecker.pullUpdateCheckRequest(Bukkit.getConsoleSender());
CrypticLibBukkit.scheduler().runTask(this, () -> {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerManager.INSTANCE.convertOtherPluginsListeners();
LangUtil.info(Languages.LOAD_FINISH);
});
}

@Override
Expand All @@ -70,10 +65,6 @@ private void loadBStat() {
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.INSTANCE.getRecipeGroups().size()));
}

private void initArcenciel() {
ArcencielDispatcher.INSTANCE.loadFuncFile();
}

public static Craftorithm instance() {
return INSTANCE;
}
Expand All @@ -82,16 +73,9 @@ public static CraftorithmAPI api() {
return CraftorithmAPI.INSTANCE;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer().isOp()) {
UpdateUtil.pullUpdateCheckRequest(event.getPlayer());
}
@Override
public void run(Plugin plugin, LifeCycle lifeCycle) {
CrypticLib.DEBUG = PluginConfigs.DEBUG.value();
}

@EventHandler
public void onServerLoad(ServerLoadEvent event) {
RecipeManager.INSTANCE.reloadRecipeManager();
OtherPluginsListenerProxy.INSTANCE.reloadOtherPluginsListener();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@
import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ArcencielSignal;
import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.arcenciel.token.*;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import crypticlib.config.ConfigWrapper;
import com.github.yufiriamazenta.craftorithm.hook.impl.PlayerPointsHooker;
import com.github.yufiriamazenta.craftorithm.hook.impl.VaultHooker;
import crypticlib.config.BukkitConfigWrapper;
import crypticlib.lifecycle.AutoTask;
import crypticlib.lifecycle.BukkitLifeCycleTask;
import crypticlib.lifecycle.LifeCycle;
import crypticlib.lifecycle.TaskRule;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.util.List;

public enum ArcencielDispatcher implements IArcencielDispatcher {
@AutoTask(
rules = {
@TaskRule(lifeCycle = LifeCycle.ENABLE, priority = 1),
@TaskRule(lifeCycle = LifeCycle.RELOAD)
}
)
public enum ArcencielDispatcher implements IArcencielDispatcher, BukkitLifeCycleTask {

INSTANCE;
private ConfigWrapper functionFile;
private BukkitConfigWrapper functionFile;

ArcencielDispatcher() {
regDefScriptKeyword();
}

@Override
Expand Down Expand Up @@ -55,27 +66,37 @@ private void regDefScriptKeyword() {
StringArcencielBlock.regScriptKeyword(TokenLevel.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakeLevel.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenPapi.INSTANCE);
if (PluginHookUtil.isEconomyLoaded()) {
if (VaultHooker.INSTANCE.isEconomyHooked()) {
StringArcencielBlock.regScriptKeyword(TokenMoney.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakeMoney.INSTANCE);
}
if (PluginHookUtil.isPlayerPointsLoaded()) {
if (PlayerPointsHooker.INSTANCE.isPlayerPointsHooked()) {
StringArcencielBlock.regScriptKeyword(TokenPoints.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakePoints.INSTANCE);
}
}

public ConfigWrapper functionFile() {
public BukkitConfigWrapper functionFile() {
return functionFile;
}

public List<String> getFunc(String funcName) {
return functionFile.config().getStringList(funcName);
}

public void loadFuncFile() {
if (functionFile == null)
functionFile = new ConfigWrapper(Craftorithm.instance(), "function.yml");
@Override
public void run(Plugin plugin, LifeCycle lifeCycle) {
switch (lifeCycle) {
case ENABLE -> {
functionFile = new BukkitConfigWrapper(Craftorithm.instance(), "function.yml");
functionFile.reloadConfig();
regDefScriptKeyword();
}
case RELOAD -> {
functionFile.reloadConfig();
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.CollectionsUtil;
import crypticlib.chat.TextProcessor;
import crypticlib.chat.BukkitTextProcessor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

Expand All @@ -18,7 +18,7 @@ protected TokenConsole() {

@Override
public ReturnObj<Boolean> exec(Player player, List<String> args) {
String command = TextProcessor.placeholder(player, CollectionsUtil.list2ArcencielBlock(args));
String command = BukkitTextProcessor.placeholder(player, CollectionsUtil.list2ArcencielBlock(args));
return new ReturnObj<>(Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.yufiriamazenta.craftorithm.arcenciel.token;

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueUtil;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueComparator;
import org.bukkit.entity.Player;

import java.util.List;
Expand All @@ -20,7 +20,7 @@ public ReturnObj<Boolean> exec(Player player, List<String> args) {
if (args.size() < 2)
result = player.getLevel() >= Integer.parseInt(args.get(0));
else
result = ScriptValueUtil.compare(player.getLevel(), Integer.parseInt(args.get(1)), args.get(0));
result = ScriptValueComparator.compare(player.getLevel(), Integer.parseInt(args.get(1)), args.get(0));
return new ReturnObj<>(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.yufiriamazenta.craftorithm.arcenciel.token;

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueUtil;
import com.github.yufiriamazenta.craftorithm.hook.impl.VaultHooker;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueComparator;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player;

Expand All @@ -18,12 +18,12 @@ protected TokenMoney() {

@Override
public ReturnObj<Boolean> exec(Player player, List<String> args) {
Economy economy = PluginHookUtil.getEconomy();
Economy economy = (Economy) VaultHooker.INSTANCE.economy();
boolean result;
if (args.size() < 2)
result = economy.getBalance(player) >= Double.parseDouble(args.get(0));
else
result = ScriptValueUtil.compare(economy.getBalance(player), Double.parseDouble(args.get(1)), args.get(0));
result = ScriptValueComparator.compare(economy.getBalance(player), Double.parseDouble(args.get(1)), args.get(0));
return new ReturnObj<>(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.CollectionsUtil;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueUtil;
import crypticlib.chat.TextProcessor;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueComparator;
import crypticlib.chat.BukkitTextProcessor;
import org.bukkit.entity.Player;

import java.util.List;
Expand All @@ -21,14 +21,14 @@ public ReturnObj<Boolean> exec(Player player, List<String> args) {
String papiStr;
if (args.size() > 2) {
papiStr = args.get(0);
papiStr = TextProcessor.placeholder(player, papiStr);
papiStr = BukkitTextProcessor.placeholder(player, papiStr);
String operator = args.get(1);
String valueStr = CollectionsUtil.list2ArcencielBlock(args.subList(2, args.size()));
return new ReturnObj<>(ScriptValueUtil.compare(papiStr, valueStr, operator));
return new ReturnObj<>(ScriptValueComparator.compare(papiStr, valueStr, operator));
} else {
papiStr = CollectionsUtil.list2ArcencielBlock(args);
papiStr = TextProcessor.placeholder(player, papiStr);
return new ReturnObj<>(Boolean.parseBoolean(TextProcessor.placeholder(player, papiStr)));
papiStr = BukkitTextProcessor.placeholder(player, papiStr);
return new ReturnObj<>(Boolean.parseBoolean(BukkitTextProcessor.placeholder(player, papiStr)));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.yufiriamazenta.craftorithm.arcenciel.token;

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueUtil;
import com.github.yufiriamazenta.craftorithm.hook.impl.PlayerPointsHooker;
import com.github.yufiriamazenta.craftorithm.util.ScriptValueComparator;
import org.black_ixx.playerpoints.PlayerPoints;
import org.black_ixx.playerpoints.PlayerPointsAPI;
import org.bukkit.entity.Player;

Expand All @@ -18,12 +19,12 @@ protected TokenPoints() {

@Override
public ReturnObj<Boolean> exec(Player player, List<String> args) {
PlayerPointsAPI api = PluginHookUtil.getPlayerPoints().getAPI();
PlayerPointsAPI api = ((PlayerPoints) PlayerPointsHooker.INSTANCE.playerPoints()).getAPI();
boolean result;
if (args.size() < 2)
result = api.look(player.getUniqueId()) >= Integer.parseInt(args.get(0));
else
result = ScriptValueUtil.compare(api.look(player.getUniqueId()), Integer.parseInt(args.get(1)), args.get(0));
result = ScriptValueComparator.compare(api.look(player.getUniqueId()), Integer.parseInt(args.get(1)), args.get(0));
return new ReturnObj<>(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.CollectionsUtil;
import crypticlib.chat.TextProcessor;
import crypticlib.chat.BukkitTextProcessor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

Expand All @@ -18,7 +18,7 @@ protected TokenRunCmd() {

@Override
public ReturnObj<Boolean> exec(Player player, List<String> args) {
String command = TextProcessor.placeholder(player, CollectionsUtil.list2ArcencielBlock(args));
String command = BukkitTextProcessor.placeholder(player, CollectionsUtil.list2ArcencielBlock(args));
return new ReturnObj<>(Bukkit.dispatchCommand(player, command));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.yufiriamazenta.craftorithm.arcenciel.token;

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.hook.impl.VaultHooker;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.entity.Player;

Expand All @@ -17,7 +17,7 @@ protected TokenTakeMoney() {

@Override
public ReturnObj<Double> exec(Player player, List<String> args) {
Economy economy = PluginHookUtil.getEconomy();
Economy economy = (Economy) VaultHooker.INSTANCE.economy();
if (args.isEmpty())
return new ReturnObj<>(economy.getBalance(player));
double value = Double.parseDouble(args.get(0));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.github.yufiriamazenta.craftorithm.arcenciel.token;

import com.github.yufiriamazenta.craftorithm.arcenciel.obj.ReturnObj;
import com.github.yufiriamazenta.craftorithm.util.PluginHookUtil;
import com.github.yufiriamazenta.craftorithm.hook.impl.PlayerPointsHooker;
import org.black_ixx.playerpoints.PlayerPoints;
import org.black_ixx.playerpoints.PlayerPointsAPI;
import org.bukkit.entity.Player;

Expand All @@ -17,7 +18,7 @@ protected TokenTakePoints() {

@Override
public ReturnObj<Integer> exec(Player player, List<String> args) {
PlayerPointsAPI api = PluginHookUtil.getPlayerPoints().getAPI();
PlayerPointsAPI api = ((PlayerPoints) PlayerPointsHooker.INSTANCE.playerPoints()).getAPI();
if (args.isEmpty())
return new ReturnObj<>(api.look(player.getUniqueId()));
int value = Integer.parseInt(args.get(0));
Expand Down
Loading
Loading