Skip to content

Commit

Permalink
[1.4.2-dev1]更新CrypticLib,兼容1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiyodaXiaoYi committed Nov 12, 2023
1 parent 6d98f90 commit 26f46b1
Show file tree
Hide file tree
Showing 19 changed files with 1,959 additions and 57 deletions.
73 changes: 27 additions & 46 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,43 @@ plugins {
`java-library`
`maven-publish`
id("com.github.johnrengelman.shadow").version("7.1.2")
id("io.papermc.paperweight.userdev").version("1.5.5")
}

repositories {
mavenLocal()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://jitpack.io")
maven("https://repo.rosewooddev.io/repository/public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.maven.apache.org/maven2/")
maven("https://mvn.lumine.io/repository/maven-public/")
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
maven("http://repo.crypticlib.com:8081/repository/maven-public/") {
isAllowInsecureProtocol = true
}
mavenCentral()
}

dependencies {
implementation("com.github.YufiriaMazenta:CrypticLib:1.0.9")
implementation(project(":common"))
implementation(project(":v1_20_R2"))
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:24.0.1")
compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("org.black_ixx:playerpoints:3.2.5")
compileOnly("net.luckperms:api:5.4")
compileOnly("me.clip:placeholderapi:2.11.1")
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.5.0b")
compileOnly("com.github.oraxen:oraxen:1.160.0")
compileOnly("io.lumine:Mythic-Dist:5.3.5")
implementation("com.crypticlib:CrypticLib:0.0.5")
}

group = "com.github.yufiriamazenta"
version = "2.0.0-dev2"
version = "1.4.2-dev1"
var pluginVersion: String = version.toString() + "-" + SimpleDateFormat("yyyyMMdd").format(System.currentTimeMillis())
java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

publishing {
publications.create<MavenPublication>("maven") {
Expand All @@ -43,49 +59,14 @@ tasks {
expand(props)
}
}
build {
dependsOn(shadowJar)
}
compileJava {
options.encoding = "UTF-8"
}
assemble {
dependsOn(shadowJar)
}
shadowJar {
archiveFileName.set("Craftorithm-$version.jar")
relocate("crypticlib", "com.github.yufiriamazenta.craftorithm.crypticlib")
}
assemble {
dependsOn(shadowJar)
}
}

subprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
tasks {
compileJava {
options.encoding = "UTF-8"
}
}
repositories {
mavenLocal()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://jitpack.io")
maven("https://repo.rosewooddev.io/repository/public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://repo.maven.apache.org/maven2/")
maven("https://mvn.lumine.io/repository/maven-public/")
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
mavenCentral()
}
dependencies {
compileOnly("org.jetbrains:annotations:24.0.1")
compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("com.github.YufiriaMazenta:CrypticLib:1.0.9")
}
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.yufiriamazenta.craftorithm.bstat;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import crypticlib.CrypticLib;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -78,7 +79,7 @@ public Metrics(JavaPlugin plugin, int serviceId) {
enabled,
this::appendPlatformData,
this::appendServiceData,
submitDataTask -> CrypticLib.platform().scheduler().runTask(plugin, t -> submitDataTask.run()),
submitDataTask -> CrypticLib.platform().scheduler().runTask(plugin, submitDataTask),
plugin::isEnabled,
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
(message) -> this.plugin.getLogger().log(Level.INFO, message),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.github.yufiriamazenta.craftorithm.util;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.github.yufiriamazenta.craftorithm.config.Config;
import crypticlib.CrypticLib;
import crypticlib.util.MsgUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;

Expand All @@ -16,9 +14,9 @@
public class UpdateUtil {

public static void checkUpdate(CommandSender sender) {
if (!Config.BooleanConfig.CHECK_UPDATE.value())
if (!Craftorithm.getInstance().getConfig().getBoolean("check_update"))
return;
CrypticLib.platform().scheduler().runTaskAsync(Craftorithm.getInstance(), task -> {
CrypticLib.platform().scheduler().runTaskAsync(Craftorithm.getInstance(), () -> {
try {
URL url = new URL("https://api.github.com/repos/YufiriaMazenta/Craftorithm/releases/latest");
URLConnection conn = url.openConnection();
Expand All @@ -37,7 +35,7 @@ public static void checkUpdate(CommandSender sender) {
if (checkVersion(newVersion, ver)) {
String finalNewVersion = newVersion;
Bukkit.getScheduler().callSyncMethod(Craftorithm.getInstance(), () -> {
MsgUtil.sendMsg(sender, "new_version", ContainerUtil.newHashMap("<new_version>", finalNewVersion));
LangUtil.sendMsg(sender, "new_version", ContainerUtil.newHashMap("<new_version>", finalNewVersion));
return null;
});
}
Expand Down
5 changes: 0 additions & 5 deletions common/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ softdepend: [ Vault, LuckPerms, PlayerPoints, PlaceholderAPI, ItemsAdder, Oraxen
authors: [ YufiriaMazenta ]
folia-supported: true
website: https://github.com/YufiriaMazenta/Craftorithm
commands:
craftorithm:
aliases:
- craft
permission: craftorithm.command
permissions:
craftorithm.command:
description: Plugin command main permissions
128 changes: 128 additions & 0 deletions src/main/java/com/github/yufiriamazenta/craftorithm/Craftorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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.ConfigUpdater;
import com.github.yufiriamazenta.craftorithm.item.ItemManager;
import com.github.yufiriamazenta.craftorithm.listener.*;
import com.github.yufiriamazenta.craftorithm.menu.bukkit.BukkitMenuDispatcher;
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 crypticlib.BukkitPlugin;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
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.inventory.Recipe;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public final class Craftorithm extends BukkitPlugin implements Listener {

private static Craftorithm INSTANCE;
private int vanillaVersion;
private boolean hasLoadPluginRecipeMap = false;

public Craftorithm() {
INSTANCE = this;
}

@Override
public void enable() {
loadVanillaVersion();
saveDefaultConfig();
ConfigUpdater.INSTANCE.updateConfig();

ItemManager.loadItemManager();
RecipeManager.loadRecipeManager();
regListeners();
PluginHookUtil.hookPlugins();
initArcenciel();
loadBStat();

LangUtil.info("load.finish");
UpdateUtil.checkUpdate(Bukkit.getConsoleSender());
}

@Override
public void disable() {
RecipeManager.resetRecipes();
}

private void loadVanillaVersion() {
String versionStr = Bukkit.getBukkitVersion();
int index1 = versionStr.indexOf(".");
int index2 = versionStr.indexOf(".", index1 + 1);
versionStr = versionStr.substring(index1 + 1, index2);
try {
vanillaVersion = Integer.parseInt(versionStr);
} catch (NumberFormatException e) {
vanillaVersion = Integer.parseInt(versionStr.substring(0, versionStr.indexOf("-")));
}
}

private void loadBStat() {
Metrics metrics = new Metrics(this, 17821);
metrics.addCustomChart(new Metrics.SingleLineChart("recipes", () -> RecipeManager.getRecipeFileMap().keySet().size()));
}

private void regListeners() {
Bukkit.getPluginManager().registerEvents(CraftHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(RecipeUnlockHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(AnvilRecipeHandler.INSTANCE, this);
Bukkit.getPluginManager().registerEvents(BukkitMenuDispatcher.INSTANCE, this);
if (getVanillaVersion() >= 14)
Bukkit.getPluginManager().registerEvents(SmithingHandler.INSTANCE, this);
if (getVanillaVersion() >= 17)
Bukkit.getPluginManager().registerEvents(FurnaceSmeltHandler.INSTANCE, this);
}

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

public static Craftorithm getInstance() {
return INSTANCE;
}

public int getVanillaVersion() {
return vanillaVersion;
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer().isOp()) {
UpdateUtil.checkUpdate(event.getPlayer());
}
}

@EventHandler
public void onServerLoad(ServerLoadEvent event) {
if (!hasLoadPluginRecipeMap) {
hasLoadPluginRecipeMap = true;
Map<String, List<Recipe>> map = CraftorithmAPI.INSTANCE.getPluginRegRecipeMap();
Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator();
while (iterator.hasNext()) {
Recipe recipe = iterator.next();
NamespacedKey key = RecipeManager.getRecipeKey(recipe);
String namespace = key.getNamespace();
if (map.containsKey(namespace)) {
map.get(namespace).add(recipe);
} else {
List<Recipe> recipes = new ArrayList<>();
recipes.add(recipe);
map.put(namespace, recipes);
}
}
RecipeManager.loadRecipes();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.github.yufiriamazenta.craftorithm.arcenciel;

import com.github.yufiriamazenta.craftorithm.Craftorithm;
import com.github.yufiriamazenta.craftorithm.arcenciel.block.ListArcencielBlock;
import com.github.yufiriamazenta.craftorithm.arcenciel.block.StringArcencielBlock;
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.impl.YamlConfigWrapper;
import org.bukkit.entity.Player;

import java.util.List;

public enum ArcencielDispatcher implements IArcencielDispatcher {

INSTANCE;
private YamlConfigWrapper functionFile;

ArcencielDispatcher() {
regDefScriptKeyword();
}

@Override
public ReturnObj<Object> dispatchArcencielBlock(Player player, String arcencielBlockBody) {
if (arcencielBlockBody.contains("\n"))
return new ListArcencielBlock(arcencielBlockBody).exec(player);
else
return new StringArcencielBlock(arcencielBlockBody).exec(player);
}

@Override
public ReturnObj<Object> dispatchArcencielFunc(Player player, List<String> arcencielFuncBody) {
ReturnObj<Object> returnObj = new ReturnObj<>();
for (int i = 0; i < arcencielFuncBody.size(); i++) {
returnObj = dispatchArcencielBlock(player, arcencielFuncBody.get(i));
if (returnObj.getObj() instanceof Boolean && returnObj.getSignal().equals(ArcencielSignal.IF)) {
if (returnObj.getObj().equals(false) && i + 1 < arcencielFuncBody.size())
i ++;
}
if (returnObj.getSignal().equals(ArcencielSignal.END))
break;
}
return returnObj;
}

private void regDefScriptKeyword() {
StringArcencielBlock.regScriptKeyword(TokenIf.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenHasPerm.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenRunCmd.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenConsole.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenReturn.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenAll.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenAny.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenLevel.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakeLevel.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenPapi.INSTANCE);
if (PluginHookUtil.isEconomyLoaded()) {
StringArcencielBlock.regScriptKeyword(TokenMoney.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakeMoney.INSTANCE);
}
if (PluginHookUtil.isPlayerPointsLoaded()) {
StringArcencielBlock.regScriptKeyword(TokenPoints.INSTANCE);
StringArcencielBlock.regScriptKeyword(TokenTakePoints.INSTANCE);
}
}

public YamlConfigWrapper getFunctionFile() {
return functionFile;
}

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

public void loadFuncFile() {
if (functionFile == null)
functionFile = new YamlConfigWrapper(Craftorithm.getInstance(), "function.yml");
}

}
Loading

0 comments on commit 26f46b1

Please sign in to comment.