init: 预发行1.0版本

Signed-off-by: 502647092 <admin@yumc.pw>
merge/1/MERGE
502647092 2016-08-25 03:55:15 +08:00
commit 015a39fb83
22 changed files with 1166 additions and 0 deletions

31
.classpath Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
# Eclipse stuff
/.settings
# netbeans
/nbproject
# we use maven!
/build.xml
# maven
/target
/repo
# vim
.*.sw[a-p]
# various other potential build files
/build
/bin
/dist
/manifest.mf
/world
# Mac filesystem dust
*.DS_Store
# intellij
*.iml
*.ipr
*.iws
.idea/
# Project Stuff
/src/main/resources/Soulbound
# Atlassian Stuff
/atlassian-ide-plugin.xml

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MiaoScript</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

BIN
lib/PlaceholderAPI.jar Normal file

Binary file not shown.

113
pom.xml Normal file
View File

@ -0,0 +1,113 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId>
<version>1.0</version>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>pw.yumc:YumCore</include>
<include>cn.citycraft:PluginHelper</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>pw.yumc.YumCore</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
<relocation>
<pattern>cn.citycraft.PluginHelper</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<update.description></update.description>
<update.changes></update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>jtb</id>
<name>YUMC</name>
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.10.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>PluginHelper</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>PlaceholderAPI</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,127 @@
package pw.yumc.MiaoScript;
import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import me.clip.placeholderapi.PlaceholderAPI;
import pw.yumc.MiaoScript.commands.MSCommands;
import pw.yumc.MiaoScript.data.DataManager;
import pw.yumc.MiaoScript.event.EventManager;
import pw.yumc.MiaoScript.middleware.EventMiddleware;
import pw.yumc.MiaoScript.script.ScriptManager;
import pw.yumc.MiaoScript.script.ScriptPlaceholder;
import pw.yumc.YumCore.config.FileConfig;
public class MiaoScript extends JavaPlugin {
private FileConfig config;
private DataManager dataManager;
private EventManager eventManager;
private EventMiddleware eventMiddleware;
private ScriptManager scriptManager;
@Override
public FileConfiguration getConfig() {
return config;
}
/**
* @return
*/
public DataManager getDataManager() {
return dataManager;
}
/**
* @return
*/
public EventManager getEventManager() {
return eventManager;
}
/**
* @return
*/
public EventMiddleware getEventMiddleware() {
return eventMiddleware;
}
/**
* @return
*/
public ScriptManager getScriptManager() {
return scriptManager;
}
/**
*
*/
public void loadConfig() {
dataManager = new DataManager(new FileConfig("data.yml"));
eventManager = new EventManager(new FileConfig("event.yml"));
scriptManager = new ScriptManager(new FileConfig("script.yml"));
}
/**
*
*/
public void loadEvents() {
eventManager.registerAll();
}
@Override
public void onEnable() {
new MSCommands();
loadConfig();
loadEvents();
register();
}
@Override
public void onLoad() {
saveDefault();
config = new FileConfig();
eventMiddleware = new EventMiddleware();
}
/**
*
*/
public void register() {
PlaceholderAPI.registerPlaceholderHook("miaoscript", new ScriptPlaceholder());
PlaceholderAPI.registerPlaceholderHook("ms", new ScriptPlaceholder());
}
/**
*
*/
public void reload() {
HandlerList.unregisterAll(this);
onLoad();
loadConfig();
loadEvents();
}
/**
*
*/
private void saveDefault() {
saveJs("bed.js");
saveJs("welcome.js");
saveJs("checkchat.js");
}
/**
*
*
* @param name
* JS
*/
private void saveJs(final String name) {
if (!new File(getDataFolder(), "js" + File.separatorChar + name).exists()) {
saveResource("js" + File.separatorChar + name, false);
}
}
}

View File

@ -0,0 +1,48 @@
package pw.yumc.MiaoScript.commands;
import org.bukkit.command.CommandSender;
import pw.yumc.MiaoScript.MiaoScript;
import pw.yumc.MiaoScript.event.EventInfo;
import pw.yumc.MiaoScript.event.EventManager;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.commands.CommandArgument;
import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandManager;
import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Help;
public class MSCommands implements CommandExecutor {
MiaoScript plugin = P.getPlugin();
public MSCommands() {
new CommandManager("ms", this);
}
@Cmd(permission = "MiaoScript.debug")
@Help("切换调试模式")
public void debug(final CommandArgument e) {
EventManager.debug = !EventManager.debug;
e.getSender().sendMessage("§6调试模式: " + (EventManager.debug ? "§a开启" : "§c关闭"));
}
@Cmd(permission = "MiaoScript.listen")
@Help("查看监听列表")
public void listen(final CommandArgument e) {
final CommandSender sender = e.getSender();
for (final EventInfo ei : plugin.getEventManager().getEvents().values()) {
sender.sendMessage(String.format("§6名称: §a%s §6事件: §a%s §6优先级: §a%s", ei.getName(), ei.getClazz().substring(ei.getClazz().lastIndexOf(".") + 1), ei.getPriority()));
sender.sendMessage("§6脚本列表: ");
for (final String script : ei.getScripts()) {
sender.sendMessage(String.format("§6- §e%s", script));
}
}
}
@Cmd(permission = "MiaoScript.reload")
@Help("重载配置文件")
public void reload(final CommandArgument e) {
plugin.reload();
e.getSender().sendMessage("§a配置文件已重新载入!");
}
}

View File

@ -0,0 +1,31 @@
package pw.yumc.MiaoScript.data;
import pw.yumc.YumCore.config.FileConfig;
/**
*
*
* @author
* @since 2016825 2:02:03
*/
public class DataManager {
FileConfig data;
public DataManager(final FileConfig config) {
this.data = config;
}
/**
* @return
*/
public FileConfig getData() {
return data;
}
/**
*
*/
public void save() {
data.save();
}
}

View File

@ -0,0 +1,76 @@
package pw.yumc.MiaoScript.event;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import pw.yumc.YumCore.config.ConfigNode;
import pw.yumc.YumCore.config.InjectConfigurationSection;
/**
*
*
* @author
* @since 2016824 1:06:34
*/
public class EventInfo extends InjectConfigurationSection {
private transient String name;
@ConfigNode(path = "class")
private String clazz;
private String priority;
private List<String> scripts;
public EventInfo(final String name, final ConfigurationSection config) {
super(config);
this.name = name;
clearEmpty();
}
/**
*
*
* @param scripts
*
* @return
*/
public void clearEmpty() {
final Set<String> cq = new HashSet<>();
for (final String s : scripts) {
if (!s.trim().isEmpty()) {
cq.add(s);
}
}
scripts = new LinkedList<>(cq);
}
/**
* @return
*/
public String getClazz() {
return clazz;
}
/**
* @return
*/
public String getName() {
return name;
}
/**
* @return
*/
public String getPriority() {
return priority == null || "".equalsIgnoreCase(priority) ? "NORMAL" : priority;
}
/**
* @return
*/
public List<String> getScripts() {
return scripts;
}
}

View File

@ -0,0 +1,168 @@
package pw.yumc.MiaoScript.event;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.plugin.EventExecutor;
import me.clip.placeholderapi.PlaceholderAPI;
import pw.yumc.MiaoScript.MiaoScript;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
/**
*
*
* @author
* @since 2016824 12:51:48
*/
public class EventManager implements Listener {
public static boolean debug = false;
private static String identifier = "%s_%s";
private final MiaoScript plugin = P.getPlugin();
/**
*
*/
private final List<EventInfo> eventInfos = new ArrayList<>();
/**
*
*/
private final Map<String, EventInfo> events = new HashMap<>();
public EventManager(final ConfigurationSection config) {
for (final String event : config.getKeys(false)) {
final ConfigurationSection e = config.getConfigurationSection(event);
if (e == null) {
continue;
}
eventInfos.add(new EventInfo(event, e));
}
}
public void debug(final String msg) {
if (debug) {
Log.info(msg);
}
}
/**
*
*
* @param event
*
* @param priority
*
* @return
*/
public EventInfo getEvent(final Event event, final EventPriority priority) {
return getEvent(getIdentifier(event.getClass(), priority));
}
/**
*
*
* @param name
*
* @return
*/
public EventInfo getEvent(final String name) {
return events.get(name);
}
/**
* @return
*/
public Map<String, EventInfo> getEvents() {
return events;
}
/**
*
*
* @param event
*
* @param priority
*
* @return
*/
public String getIdentifier(final Class<? extends Event> event, final EventPriority priority) {
return String.format(identifier, event.getSimpleName(), priority.name());
}
/**
*
*
* @param ei
*
*/
public void printInfo(final EventInfo ei) {
debug(String.format("名称: %s 事件: %s 优先级: %s", ei.getName(), ei.getClazz().substring(ei.getClazz().lastIndexOf(".") + 1), ei.getPriority()));
debug("脚本列表: ");
}
/**
*
*
* @param eventInfo
*
*/
@SuppressWarnings("unchecked")
public boolean register(final EventInfo eventInfo) {
try {
final Class<? extends Event> clazz = (Class<? extends Event>) Class.forName(eventInfo.getClazz());
final EventPriority priority = EventPriority.valueOf(eventInfo.getPriority());
events.put(getIdentifier(clazz, priority), eventInfo);
Bukkit.getPluginManager().registerEvent(clazz, this, priority, new EventExecutor() {
@Override
public void execute(final Listener listener, final Event event) throws EventException {
final EventInfo ei = plugin.getEventManager().getEvent(event, priority);
if (ei == null) {
Log.debug(String.format("事件 %s_%s 未找到对应处理脚本!", event.getEventName(), priority.name()));
return;
}
debug("========== MiaoScript Debug ==========");
printInfo(ei);
if (event instanceof PlayerEvent) {
final PlayerEvent pe = (PlayerEvent) event;
for (final String script : ei.getScripts()) {
final String result = PlaceholderAPI.setPlaceholders(plugin.getEventMiddleware().generate(pe), script);
debug(String.format("- %s 返回值: %s", script, result));
}
} else {
Log.debug(String.format("事件 %s 未继承 PlayerEvent 可能无法正常调用!", event.getEventName()));
}
debug("========== MiaoScript Debug ==========");
}
}, plugin);
return true;
} catch (final ClassNotFoundException e) {
Log.warning(String.format("事件 %s 的监听类 %s 未找到!", eventInfo.getName(), eventInfo.getClazz()));
} catch (final Exception e) {
Log.warning(String.format("事件 %s 的注册失败 %s: %s!", eventInfo.getName(), e.getClass().getName(), e.getMessage()));
}
return false;
}
/**
*
*/
public void registerAll() {
int count = 0;
for (final EventInfo ei : eventInfos) {
if (!ei.getScripts().isEmpty() && register(ei)) {
count++;
}
}
Log.info(String.format("已注册 %s 个事件...", count));
}
}

View File

@ -0,0 +1,117 @@
package pw.yumc.MiaoScript.middleware;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import pw.yumc.YumCore.bukkit.P;
/**
*
*
* @author
* @since 2016825 12:45:39
*/
public class EventMiddleware {
public static String key = "EventMiddleware";
/**
*
*
* @param event
*
* @return Player
*/
public Player generate(final PlayerEvent event) {
final Player player = event.getPlayer();
player.setMetadata(key, new EventMetaData(event));
return player;
}
/**
*
*
* @param player
*
* @return
*/
public Event get(final Player player) {
for (final MetadataValue mv : player.getMetadata(key)) {
if (mv.getOwningPlugin().getName().equals(P.getName())) {
player.removeMetadata(key, P.instance);
return (Event) mv.value();
}
}
return null;
}
/**
*
*
* @author
* @since 2016825 12:47:53
*/
public class EventMetaData implements MetadataValue {
Event event;
public EventMetaData(final Event event) {
this.event = event;
}
@Override
public boolean asBoolean() {
return false;
}
@Override
public byte asByte() {
return 0;
}
@Override
public double asDouble() {
return 0;
}
@Override
public float asFloat() {
return 0;
}
@Override
public int asInt() {
return 0;
}
@Override
public long asLong() {
return 0;
}
@Override
public short asShort() {
return 0;
}
@Override
public String asString() {
return event.getEventName();
}
@Override
public Plugin getOwningPlugin() {
return P.instance;
}
@Override
public void invalidate() {
}
@Override
public Object value() {
return event;
}
}
}

View File

@ -0,0 +1,88 @@
package pw.yumc.MiaoScript.script;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import org.bukkit.configuration.ConfigurationSection;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.InjectConfigurationSection;
import pw.yumc.YumCore.config.Nullable;
/**
*
*
* @author
* @since 2016824 12:52:09
*/
public class ScriptInfo extends InjectConfigurationSection {
public transient static final File dir = new File(P.getDataFolder(), "js");
public transient static Charset UTF_8 = Charset.forName("UTF-8");
static {
if (!dir.exists()) {
dir.mkdirs();
}
}
private String expression;
@Nullable
private String type;
@Nullable
private String trueResult;
@Nullable
private String falseResult;
public ScriptInfo(final ConfigurationSection config) {
super(config);
if ("boolean".equalsIgnoreCase(type) && (trueResult == null || falseResult == null)) {
Log.warning(String.format("脚本 %s 返回缺少返回结果!", config.getCurrentPath()));
}
if (expression.startsWith("file:")) {
final String fileName = expression.substring(5).trim();
try {
final File file = new File(dir, fileName);
if (!file.exists()) {
file.createNewFile();
Log.warning(String.format("JS文件 %s 不存在 已创建新文件 请添加脚本信息!", fileName));
} else {
expression = new String(Files.readAllBytes(file.toPath()), UTF_8);
}
} catch (final IOException e) {
Log.warning(String.format("JS文件 %s 读取失败 异常: %s", fileName, e.getMessage()));
expression = "";
}
}
}
/**
* @return
*/
public String getExpression() {
return expression;
}
/**
* @return False
*/
public String getFalseResult() {
return falseResult;
}
/**
* @return True
*/
public String getTrueResult() {
return trueResult;
}
/**
* @return
*/
public String getType() {
return type;
}
}

View File

@ -0,0 +1,38 @@
package pw.yumc.MiaoScript.script;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import cn.citycraft.PluginHelper.kit.Log;
/**
*
*
* @author
* @since 2016824 12:51:48
*/
public class ScriptManager {
Map<String, ScriptInfo> scripts = new HashMap<>();
public ScriptManager(final ConfigurationSection config) {
final Set<String> keys = config.getKeys(false);
for (final String key : keys) {
scripts.put(key, new ScriptInfo(config.getConfigurationSection(key)));
}
Log.info(String.format("已加载 %s 个变量...", keys.size()));
}
/**
*
*
* @param name
*
* @return
*/
public ScriptInfo getScript(final String name) {
return scripts.get(name);
}
}

View File

@ -0,0 +1,91 @@
package pw.yumc.MiaoScript.script;
import java.util.WeakHashMap;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderHook;
import pw.yumc.MiaoScript.MiaoScript;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.PlayerConfig;
/**
*
*
* @author
* @since 2016824 12:51:59
*/
public class ScriptPlaceholder extends PlaceholderHook {
private static String invalid = "无效的脚本: %s";
private static String typeError = "脚本 %s 返回值错误";
private static String EMPTY = "";
private final MiaoScript plugin = P.getPlugin();
private ScriptEngine engine;
private final WeakHashMap<String, PlayerConfig> playerdatas = new WeakHashMap<>();
public ScriptPlaceholder() {
this("javascript");
}
public ScriptPlaceholder(final String engineType) {
try {
engine = new ScriptEngineManager().getEngineByName(engineType);
} catch (final NullPointerException ex) {
Log.warning("无效的解析引擎! 已设为默认值 'javascript'");
engine = new ScriptEngineManager().getEngineByName("javascript");
}
engine.put("Bukkit", Bukkit.getServer());
engine.put("Server", Bukkit.getServer());
engine.put("Data", plugin.getDataManager().getData());
engine.put("Prefix", Log.getPrefix());
engine.put("Log", P.getLogger());
}
@Override
public String onPlaceholderRequest(final Player p, final String key) {
final ScriptInfo script = plugin.getScriptManager().getScript(key);
if (script == null) {
return EMPTY;
}
String expression = script.getExpression();
expression = PlaceholderAPI.setPlaceholders(p, expression);
try {
engine.put("Player", p);
if (!playerdatas.containsKey(p.getName())) {
playerdatas.put(p.getName(), new PlayerConfig(p));
}
engine.put("PlayerData", playerdatas.get(p.getName()));
final Event event = plugin.getEventMiddleware().get(p);
if (event != null) {
engine.put("Event", event);
}
Object result = engine.eval(expression);
if (result == null) {
return EMPTY;
}
if ("boolean".equalsIgnoreCase(script.getType())) {
if (!(result instanceof Boolean)) {
return String.format(typeError, key);
}
if (((Boolean) result).booleanValue()) {
result = script.getTrueResult();
} else {
result = script.getFalseResult();
}
}
return PlaceholderAPI.setPlaceholders(p, String.valueOf(result));
} catch (final ScriptException ex) {
Log.warning(String.format("脚本 %s 格式错误...", key));
ex.printStackTrace();
return String.format(invalid, key);
}
}
}

View File

View File

@ -0,0 +1,3 @@
dirList:
- 你妈逼
- 我操

View File

@ -0,0 +1,32 @@
PlayerJoin:
#Event Class Full Name
class: org.bukkit.event.player.PlayerJoinEvent
#EventPriority Allow Value: LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR
priority: LOWEST
#Script List
scripts:
- '%ms_welcome%'
PlayerDrop:
#Event Class Full Name
class: org.bukkit.event.player.PlayerDropItemEvent
#EventPriority Allow Value: LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR
priority: LOWEST
#Script List
scripts:
- '%ms_checkDrop%'
PlayerChat:
#Event Class Full Name
class: org.bukkit.event.player.AsyncPlayerChatEvent
#EventPriority Allow Value: LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR
priority: LOWEST
#Script List
scripts:
- '%ms_checkChat%'
PlayerCommandPreprocess:
#Event Class Full Name
class: org.bukkit.event.player.PlayerCommandPreprocessEvent
#EventPriority Allow Value: LOWEST, LOW, NORMAL, HIGH, HIGHEST, MONITOR
priority: LOWEST
#Script List
scripts:
- '%ms_bed%'

View File

@ -0,0 +1,20 @@
var msg = Event.getMessage();
var command = msg.substring(1);
switch (command) {
case "setbed":
Event.setCancelled(true);
PlayerData.set("bed", Player.getLocation());
PlayerData.save();
Player.sendMessage(Prefix + "&a您的床位设置成功 使用&b/gobed &a即可回家!");
break;
case "gobed":
Event.setCancelled(true);
if (PlayerData.isSet("bed")) {
Player.teleport(PlayerData.getLocation("bed"));
Player.sendMessage(Prefix + "&a已传送您回床!");
} else {
Player.sendMessage(Prefix + "&c请先使用 &b/setbed &c设置您的床位!");
}
default:
break;
}

View File

@ -0,0 +1,8 @@
var dirs = Data.getStringList("dirChat");
var msg = Event.getMessage();
for (i in dirs) {
if (msg.contains(dirs[i])) {
Event.setCancelled(true);
Player.sendMessage("&6[&b警告&6] &c请不要讲脏话!");
}
}

View File

@ -0,0 +1,5 @@
if( Player.getName() == "Mr_jtb" ){
Bukkit.broadcastMessage("&6[&a公告&6] &c热烈欢迎 &aMiaoScript &c作者 &b喵♂呜&c!");
} else {
Player.sendMessage("&6[&bMiaoScript&6] &c欢迎来到 &b" + Bukkit.getServerName() + " &c服务器!");
}

View File

@ -0,0 +1,23 @@
name: ${project.artifactId}
description: ${project.description}
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
version: ${project.version}-git-${env.GIT_COMMIT}
author: 喵♂呜
website: ${ciManagement.url}
depend:
- PlaceholderAPI
commands:
${project.artifactId}:
description: ${project.artifactId} - ${project.description}
aliases:
- ms
usage: §b使用/${project.artifactId} help 查看帮助!
permission: ${project.artifactId}.reload
permission-message: §c你没有 <permission> 的权限来执行此命令!
permissions:
${project.artifactId}.use:
description: ${project.artifactId} 使用!
default: true
${project.artifactId}.reload:
description: 重新载入插件!
default: op

View File

@ -0,0 +1,86 @@
#脚本名称
#xxxxx:
# 脚本表达式
# expression: | [这里写"|"则下方缩进均为一行 请看案例]
# if( x = y ) {
# 省略代码
# }
# expression: "Player.getDisplayName()"
# PS: JS表达式 支持调用Bukkit的内部方法
# 当前支持Bukkit(Server),Player,Event
# Bukkit(或Server): 调用的是服务器数据
# - getOnlinePlayer().size(): 在线玩家数量
# - broadcastMessage('xxx'): 公告xxx
# - getConsoleSender(): 获得控制台
# - dispatchCommand(Bukkit.getConsoleSender(),"xxx"): 控制台执行xxx命令
# - dispatchCommand(Player,"xxx"): 玩家执行xxx命令
# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html
#
# Player: 调用玩家对象 常用方法有:
# - getName(): 玩家名称
# - getDisplayName(): 玩家显示名称
# - hasPermission("xxx"): 判断玩家是否有xxx权限
# - sendMessage("xxx"): 向玩家发送xxx消息
# - isOp():是否为OP
# - setFlying(true 或 false): 设置飞行
# - setHealth(20): 设置玩家血量
# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html
#
# Event: 调用事件 不同事件有不同的参数 常用方法如下:
# - setCancelled(true): 用于取消事件
# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerEvent.html
#
# [Data, PlayerData(玩家数据)]: 调用数据存储 若崩服数据可能丢失
# - set("key","value"): 保存一条键为key值为value的数据
# - get("key"): 获得键为key的值
# - getStringList("dirChat"): 获得键为dirChat的字符串列表
# - save(): 保存数据到硬盘
# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/ConfigurationSection.html
#
# Log: 调用插件日志系统
# - info("xxx"): 输出信息xxx到日志
# - warning("xxx"): 输出警告xxx
# 更多的方法请查询: http://docs.oracle.com/javase/7/docs/api/java/util/logging/Logger.html
#
# type: "boolean" 或 "string" 不写 默认为string
# #下面两个参数 当type为boolean时才有效
# trueResult: '&c管理员' [脚本返回True时的返回值]
# falseResult: '&a玩家' [脚本返回False时的返回值]
#
#脚本名称
welcome:
#脚本表达式
expression: 'file: welcome.js'
#物品丢弃检测
checkDrop:
expression: |
if( Event.getItemDrop().getItemStack().getType().name().contains("DIAMOND") ){
Player.sendMessage("&6[&b警告&6] &c您可能丢弃了一件贵重物品!");
}
#聊天检测
checkChat:
expression: 'file: checkchat.js'
#获得玩家前缀
getPrefix:
expression: Player.isOp()
#脚本返回值
type: boolean
#脚本返回True时的返回值
trueResult: '&c管理员'
#脚本返回False时的返回值
falseResult: '&a玩家'
#获取玩家的显示名称
getDisplayName:
expression: Player.getDisplayName()
type: string
#开启玩家飞行模式
flyon:
expression: 'Player.setAllowFlight(true);Player.sendMessage("&6[&bMiaoScript&6] &a已为您开启飞行模式!")'
#关闭玩家飞行模式
flyoff:
expression: |
Player.setAllowFlight(false);
Player.sendMessage("&6[&bMiaoScript&6] &a已为您关闭飞行模式!");
#设置床
bed:
expression: 'file: bed.js'