-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor with eld-plugin, added partial reload for groovier
- Loading branch information
Showing
72 changed files
with
668 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<parent> | ||
<groupId>org.groovier</groupId> | ||
<artifactId>groovier-plugin</artifactId> | ||
<version>0.0.55-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>groovier-common</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>22</maven.compiler.source> | ||
<maven.compiler.target>22</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
88 changes: 88 additions & 0 deletions
88
...oovier-common/src/main/groovy/com/ericlam/mc/groovier/bungee/BungeeGroovierCommand.groovy
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,88 @@ | ||
package com.ericlam.mc.groovier.bungee | ||
|
||
import com.ericlam.mc.groovier.GroovierCore | ||
import com.ericlam.mc.groovier.ScriptLoader | ||
import com.ericlam.mc.groovier.ScriptLoadingException | ||
import net.md_5.bungee.api.ChatColor | ||
import net.md_5.bungee.api.CommandSender | ||
import net.md_5.bungee.api.chat.TextComponent | ||
import net.md_5.bungee.api.plugin.Command | ||
import net.md_5.bungee.api.plugin.Plugin | ||
import net.md_5.bungee.api.plugin.TabExecutor | ||
|
||
class BungeeGroovierCommand extends Command implements TabExecutor { | ||
|
||
private final GroovierCore core | ||
private final Plugin plugin | ||
|
||
BungeeGroovierCommand(GroovierCore core, Plugin plugin) { | ||
super("groovier", "groovier.use") | ||
this.core = core | ||
this.plugin = plugin | ||
} | ||
|
||
@Override | ||
void execute(CommandSender sender, String[] args) { | ||
if (hasPermission(sender)) { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}no permission.")) | ||
} | ||
if (args.length == 0) { | ||
sender.sendMessage(TextComponent.fromLegacy("Usage: /groovier reload [script] | version")) | ||
return | ||
} | ||
if (args[0].equalsIgnoreCase("reload")) { | ||
if (args.length == 1) { | ||
core.reloadAllScripts().whenComplete((v, ex) -> { | ||
if (ex != null) { | ||
if (ex instanceof ScriptLoadingException) { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GOLD}Script is still loading, please wait until complete.")) | ||
} else { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage())) | ||
ex.printStackTrace() | ||
} | ||
} else { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GREEN}Successfully reloaded scripts")) | ||
} | ||
}) | ||
} else { | ||
def script = args[1] | ||
try { | ||
def scriptClass = Class.forName(script) as Class<? extends ScriptLoader> | ||
core.reloadScript(scriptClass).whenComplete((v, ex) -> { | ||
if (ex != null) { | ||
if (ex instanceof ScriptLoadingException) { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GOLD}script ${scriptClass.simpleName} is still loading, please wait until complete.")) | ||
} else { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}Failed to reload script ${scriptClass.simpleName}: " + ex.getMessage())) | ||
ex.printStackTrace() | ||
} | ||
} else { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.GREEN}Successfully reloaded script ${scriptClass.simpleName}")) | ||
} | ||
}) | ||
} catch (ClassNotFoundException ignored) { | ||
sender.sendMessage(TextComponent.fromLegacy("${ChatColor.RED}Script class $script not found.")) | ||
} | ||
} | ||
return | ||
} else if (args[0].equalsIgnoreCase("version")) { | ||
sender.sendMessage(TextComponent.fromLegacy("Groovier v${plugin.getDescription().getVersion()} by ${plugin.getDescription().getAuthor()}")) | ||
return | ||
} | ||
sender.sendMessage(TextComponent.fromLegacy("Usage: /groovier reload [script] | version")) | ||
} | ||
|
||
@Override | ||
Iterable<String> onTabComplete(CommandSender sender, String[] args) { | ||
if (args.length == 1) { | ||
return ["reload", "version"] | ||
} | ||
if (args.length == 2 && args[0].equalsIgnoreCase("reload")) { | ||
return core.scriptLoaders | ||
.stream() | ||
.map { it.class.name } | ||
.toList() | ||
} | ||
return null | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
93 changes: 93 additions & 0 deletions
93
...oovier-common/src/main/groovy/com/ericlam/mc/groovier/spigot/SpigotGroovierCommand.groovy
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,93 @@ | ||
package com.ericlam.mc.groovier.spigot | ||
|
||
import com.ericlam.mc.groovier.GroovierCore | ||
import com.ericlam.mc.groovier.ScriptLoader | ||
import com.ericlam.mc.groovier.ScriptLoadingException | ||
import org.bukkit.ChatColor | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandExecutor | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.command.TabCompleter | ||
import org.bukkit.plugin.java.JavaPlugin | ||
import org.jetbrains.annotations.NotNull | ||
|
||
class SpigotGroovierCommand implements CommandExecutor, TabCompleter { | ||
|
||
private final JavaPlugin plugin | ||
private final GroovierCore core | ||
|
||
SpigotGroovierCommand(JavaPlugin plugin, GroovierCore core) { | ||
this.plugin = plugin | ||
this.core = core | ||
} | ||
|
||
@Override | ||
boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (!sender.hasPermission("groovier.use")) { | ||
sender.sendMessage("${ChatColor.RED}no permission") | ||
return false | ||
} | ||
if (args.length == 0) { | ||
sender.sendMessage("Usage: /groovier reload [script] | version") | ||
return true | ||
} | ||
var cmd = args[0].toLowerCase() | ||
switch (cmd) { | ||
case "reload": | ||
if (args.length == 1) { | ||
core.reloadAllScripts().whenComplete { v, ex -> | ||
if (ex != null) { | ||
if (ex instanceof ScriptLoadingException) { | ||
sender.sendMessage("${ChatColor.GOLD}Script is still loading, please wait until complete.") | ||
} else { | ||
sender.sendMessage("${ChatColor.RED}Failed to reload scripts: " + ex.getMessage()) | ||
ex.printStackTrace() | ||
} | ||
} else { | ||
sender.sendMessage("${ChatColor.GREEN}Successfully reloaded scripts") | ||
} | ||
} | ||
} else { | ||
def script = args[1] | ||
try { | ||
def scriptClass = Class.forName(script) as Class<? extends ScriptLoader> | ||
core.reloadScript(scriptClass).whenComplete((v, ex) -> { | ||
if (ex != null) { | ||
if (ex instanceof ScriptLoadingException) { | ||
sender.sendMessage("${ChatColor.GOLD}script ${scriptClass.simpleName} is still loading, please wait until complete.") | ||
} else { | ||
sender.sendMessage("${ChatColor.RED}Failed to reload script ${scriptClass.simpleName}: " + ex.getMessage()) | ||
ex.printStackTrace() | ||
} | ||
} else { | ||
sender.sendMessage("${ChatColor.GREEN}Successfully reloaded script ${scriptClass.simpleName}") | ||
} | ||
}) | ||
}catch (ClassNotFoundException ignored) { | ||
sender.sendMessage("${ChatColor.RED}Script class $script not found.") | ||
} | ||
} | ||
return true | ||
case "version": | ||
sender.sendMessage("Groovier v${plugin.getDescription().getVersion()} by ${plugin.getDescription().getAuthors().join(", ")}") | ||
return true | ||
default: | ||
sender.sendMessage("Usage: /groovier reload [script] | version") | ||
return true | ||
} | ||
} | ||
|
||
@Override | ||
List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { | ||
if (args.length == 1) { | ||
return ["reload", "version"] | ||
} | ||
if (args.length == 2 && args[0].equalsIgnoreCase("reload")) { | ||
return core.scriptLoaders | ||
.stream() | ||
.map { it.class.name } | ||
.toList() | ||
} | ||
return null | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.