mirror of
https://github.com/Verdurae/PlaceholderPlus.git
synced 2026-11-26 14:45:21 +08:00
updata
This commit is contained in:
1 parent
77517edc1d
commit
b22fb34efc
11 files changed
+281
-4
No files matched your search
+3
-1
@@ -15,10 +15,12 @@ repositories {
|
|||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = "https://oss.sonatype.org/content/groups/public/"
|
url = "https://oss.sonatype.org/content/groups/public/"
|
||||||
}
|
}
|
||||||
|
maven {url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
|
compileOnly "org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"
|
||||||
|
implementation 'me.clip:placeholderapi:2.11.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
def targetJavaVersion = 8
|
def targetJavaVersion = 8
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.verdurae.placeholderplus.API.Abstract;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
|
||||||
|
public abstract class SubJsPlaceholder extends PlaceholderExpansion {
|
||||||
|
public abstract @NotNull ScriptEngine getEngine();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean register() {
|
||||||
|
if (PlaceholderPlus.jsSupport) {
|
||||||
|
PlaceholderPlus.expansions.add(this);
|
||||||
|
return super.register();
|
||||||
|
}
|
||||||
|
PlaceholderPlus.logger.warning("你的运行Java中没有JS引擎," + getIdentifier() + "变量终止注册");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.verdurae.placeholderplus.API;
|
||||||
|
|
||||||
|
public class MathAPI {
|
||||||
|
public static <T extends Number> Number calculate(T number, String formula) {
|
||||||
|
double v = number.doubleValue();
|
||||||
|
if (formula.startsWith("+")) {
|
||||||
|
return v + Double.parseDouble(formula.substring(1));
|
||||||
|
} else if (formula.startsWith("-")) {
|
||||||
|
return v - Double.parseDouble(formula.substring(1));
|
||||||
|
} else if (formula.startsWith("*")) {
|
||||||
|
return v * Double.parseDouble(formula.substring(1));
|
||||||
|
} else if (formula.startsWith("/")) {
|
||||||
|
return v / Double.parseDouble(formula.substring(1));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package org.verdurae.placeholderplus.API;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||||
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PlayerAPI {
|
||||||
|
public static HashMap<String, PlayerData> playerData = new HashMap<>();
|
||||||
|
|
||||||
|
public static FileConfiguration getPlayerData(String playername) {
|
||||||
|
if (playerData.containsKey(playername)) return playerData.get(playername).data;
|
||||||
|
YamlConfiguration data = YamlConfiguration.loadConfiguration(new File(PlaceholderPlus.dataFolder, playername + ".yml"));
|
||||||
|
new PlayerData(playername, data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileConfiguration getPlayerData(Player player) {
|
||||||
|
return getPlayerData(player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package org.verdurae.placeholderplus.API;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||||
|
|
||||||
|
public class PluginAPI {
|
||||||
|
public static void saveAllPlayerData() {
|
||||||
|
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||||
|
playerData.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void loadOnlinePlayerData() {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
PlayerAPI.getPlayerData(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package org.verdurae.placeholderplus.Command;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.verdurae.placeholderplus.API.MathAPI;
|
||||||
|
import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||||
|
import org.verdurae.placeholderplus.API.PluginAPI;
|
||||||
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PlaceholderPlusCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
|
||||||
|
if (args.length < 2) {
|
||||||
|
sender.sendMessage("PlaceholderPlus:");
|
||||||
|
sender.sendMessage("/pp 玩家名 set 变量名 数值");
|
||||||
|
sender.sendMessage("/pp 玩家名 add 变量名 数值");
|
||||||
|
sender.sendMessage("/pp 玩家名 remove 变量名");
|
||||||
|
sender.sendMessage("/pp reload");
|
||||||
|
} else {
|
||||||
|
switch (args[1]) {
|
||||||
|
case "set":
|
||||||
|
PlayerAPI.getPlayerData(args[0]).set(args[2], args[3]);
|
||||||
|
break;
|
||||||
|
case "add":
|
||||||
|
PlayerAPI.getPlayerData(args[0]).set(args[2], MathAPI.calculate(PlayerAPI.getPlayerData(args[0]).getDouble(args[2]), args[3]));
|
||||||
|
break;
|
||||||
|
case "remove":
|
||||||
|
PlayerAPI.getPlayerData(args[0]).set(args[2], null);
|
||||||
|
break;
|
||||||
|
case "reload":
|
||||||
|
PlaceholderPlus.config = PlaceholderPlus.instance.getConfig();
|
||||||
|
PluginAPI.saveAllPlayerData();
|
||||||
|
PlayerAPI.playerData = new HashMap<>();
|
||||||
|
PluginAPI.loadOnlinePlayerData();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.verdurae.placeholderplus.Object;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||||
|
import org.verdurae.placeholderplus.PlaceholderPlus;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PlayerData {
|
||||||
|
public String name;
|
||||||
|
public FileConfiguration data;
|
||||||
|
|
||||||
|
public PlayerData(String name, FileConfiguration data) {
|
||||||
|
this.name = name;
|
||||||
|
if (data == null) data = new YamlConfiguration();
|
||||||
|
this.data = defaultData(data);
|
||||||
|
save();
|
||||||
|
PlayerAPI.playerData.put(name, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration defaultData(FileConfiguration data) {
|
||||||
|
Map<String, Object> value = PlaceholderPlus.config.getValues(true);
|
||||||
|
for (String key : value.keySet()) {
|
||||||
|
if (key.startsWith("Placeholders.")) {
|
||||||
|
if (!data.contains(key)) data.set(key.replace("Placeholders.", ""), value.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
data.save(PlaceholderPlus.dataFolder + "/" + name + ".yml");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,80 @@
|
|||||||
package org.verdurae.placeholderplus;
|
package org.verdurae.placeholderplus;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||||
|
import org.verdurae.placeholderplus.API.PluginAPI;
|
||||||
|
import org.verdurae.placeholderplus.Command.PlaceholderPlusCommand;
|
||||||
|
import org.verdurae.placeholderplus.Object.PlayerData;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public final class PlaceholderPlus extends JavaPlugin {
|
public final class PlaceholderPlus extends JavaPlugin {
|
||||||
|
public static PlaceholderPlus instance;
|
||||||
|
public static Logger logger;
|
||||||
|
public static FileConfiguration config;
|
||||||
|
public static boolean jsSupport = false;
|
||||||
|
public static ArrayList<PlaceholderExpansion> expansions = new ArrayList<>();
|
||||||
|
public static File dataFolder;
|
||||||
|
public static boolean autosave = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
instance = this;
|
||||||
|
logger = getLogger();
|
||||||
|
logger.info("准备加载");
|
||||||
|
logger.info("作者:Kaminy");
|
||||||
|
logger.info("这个插件是免费开源的,如果你花了钱,请去骂他");
|
||||||
|
try {
|
||||||
|
Class.forName("jdk.nashorn.api.scripting.NashornScriptEngine");
|
||||||
|
jsSupport = true;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
logger.warning("你的运行Java中没有JS引擎,无法使用JS变量功能噢");
|
||||||
|
logger.warning("解决办法:安装一个带有nashornJs引擎的插件或模组/使用Java15-的版本/催更我内置一个JS引擎");
|
||||||
|
logger.warning("状态决定类:jdk.nashorn.api.scripting.NashornScriptEngine");
|
||||||
|
}
|
||||||
|
saveDefaultConfig();
|
||||||
|
config = getConfig();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
logger.info("开始加载");
|
||||||
|
dataFolder = new File(getDataFolder(), "PlayerData");
|
||||||
|
dataFolder.mkdirs();
|
||||||
|
expansions.add(new ThisPlaceholder());
|
||||||
|
for (PlaceholderExpansion expansion : expansions) {
|
||||||
|
if (expansion.canRegister()) expansion.register();
|
||||||
|
}
|
||||||
|
PluginAPI.loadOnlinePlayerData();
|
||||||
|
getCommand("pp").setExecutor(new PlaceholderPlusCommand());
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
|
while (isEnabled() && autosave) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(300000);
|
||||||
|
logger.info("正在自动保存数据");
|
||||||
|
for (PlayerData playerData : PlayerAPI.playerData.values()) {
|
||||||
|
playerData.save();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
autosave = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
logger.info("插件卸载");
|
||||||
|
PluginAPI.saveAllPlayerData();
|
||||||
|
for (PlaceholderExpansion expansion : expansions) {
|
||||||
|
expansion.unregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.verdurae.placeholderplus;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.verdurae.placeholderplus.API.PlayerAPI;
|
||||||
|
|
||||||
|
public class ThisPlaceholder extends PlaceholderExpansion {
|
||||||
|
@Override
|
||||||
|
public @Nullable("null") String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||||
|
String a = PlayerAPI.getPlayerData(player.getName()).getString(params);
|
||||||
|
return (a == null) ? PlaceholderPlus.config.getString("Placeholders." + params) : a;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getIdentifier() {
|
||||||
|
return "pp";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getAuthor() {
|
||||||
|
return "Kaminy";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getVersion() {
|
||||||
|
return PlaceholderPlus.instance.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
JsImportPacket:
|
||||||
|
"Bukkit": "org.bukkit.Bukkit"
|
||||||
|
"Arrays": "java.util.Arrays"
|
||||||
|
"PAPI": "me.clip.placeholderapi.PlaceholderAPI"
|
||||||
|
|
||||||
|
Placeholders:
|
||||||
|
"test": "这是一个变量"
|
||||||
|
"test1": "这是另一个变量"
|
||||||
|
"test2": "最好不要留空"
|
||||||
|
"test3": "1"
|
||||||
|
"test4": "↑纯数值类型也是可以的,可以用指令和方法加减,但要保证是纯数字,可以有小数点"
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
name: PlaceholderPlus
|
name: PlaceholderPlus
|
||||||
version: '${version}'
|
version: '${version}'
|
||||||
main: org.verdurae.placeholderplus.PlaceholderPlus
|
main: org.verdurae.placeholderplus.PlaceholderPlus
|
||||||
|
author: Kaminy
|
||||||
|
depend:
|
||||||
|
- PlaceholderAPI
|
||||||
|
website: https://github.com/Verdurae/PlaceholderPlus
|
||||||
|
commands:
|
||||||
|
pp:
|
||||||
Reference in new issue
Block a user