-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ChiyodaXiaoYi
committed
Nov 12, 2023
1 parent
6d98f90
commit 26f46b1
Showing
19 changed files
with
1,959 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/com/github/yufiriamazenta/craftorithm/Craftorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/github/yufiriamazenta/craftorithm/arcenciel/ArcencielDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
Oops, something went wrong.