Separate command class, fix processor parent POM

This commit is contained in:
Norbi Peti 2020-02-25 17:34:25 +01:00
parent 393c9c9b08
commit 05720afdf8
4 changed files with 33 additions and 37 deletions

View file

@ -1,6 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> 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> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
<artifactId>CorePOM</artifactId>
<version>master-SNAPSHOT</version>
<relativePath>../CorePOM</relativePath>
</parent>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
@ -21,12 +27,6 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<parent>
<groupId>com.github.TBMCPlugins</groupId>
<artifactId>ChromaCore</artifactId>
<version>master-SNAPSHOT</version>
</parent>
<groupId>com.github.TBMCPlugins.ChromaCore</groupId>
<artifactId>ButtonProcessor</artifactId> <artifactId>ButtonProcessor</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>

View file

@ -54,7 +54,6 @@ public class SpawnComponent extends Component<MainPlugin> implements PluginMessa
if ("ChromaCore-Spawn".equals(subchannel)) { if ("ChromaCore-Spawn".equals(subchannel)) {
// Use the code sample in the 'Response' sections below to read // Use the code sample in the 'Response' sections below to read
// the data. // the data.
System.out.println("Heh nice");
short len = in.readShort(); short len = in.readShort();
byte[] msgbytes = new byte[len]; byte[] msgbytes = new byte[len];
in.readFully(msgbytes); in.readFully(msgbytes);

View file

@ -129,15 +129,11 @@ public abstract class Component<TP extends JavaPlugin> {
throw new UnregisteredComponentException(component); throw new UnregisteredComponentException(component);
if (component.enabled == enabled) return; //Don't do anything if (component.enabled == enabled) return; //Don't do anything
if (component.enabled = enabled) { if (component.enabled = enabled) {
//System.out.println("Updating config for "+component.getClassName());
updateConfig(component.getPlugin(), component); updateConfig(component.getPlugin(), component);
//System.out.println("Enabling "+component.getClassName());
component.enable(); component.enable();
if (ButtonPlugin.configGenAllowed(component)) { if (ButtonPlugin.configGenAllowed(component)) {
//System.out.println("Pregenning config for "+component.getClassName());
IHaveConfig.pregenConfig(component, null); IHaveConfig.pregenConfig(component, null);
} }
//System.out.println("Done enabling "+component.getClassName());
} else { } else {
component.disable(); component.disable();
ButtonPlugin.getCommand2MC().unregisterCommands(component); ButtonPlugin.getCommand2MC().unregisterCommands(component);

View file

@ -19,7 +19,6 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -83,8 +82,6 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
p = MainPlugin.permission.playerHas(sender instanceof Player ? ((Player) sender).getLocation().getWorld().getName() : null, (OfflinePlayer) sender, perm); p = MainPlugin.permission.playerHas(sender instanceof Player ? ((Player) sender).getLocation().getWorld().getName() : null, (OfflinePlayer) sender, perm);
else else
p = false; //Use sender's method p = false; //Use sender's method
//System.out.println("playerHas " + perm + ": " + p);
//System.out.println("hasPermission: " + sender.hasPermission(perm));
if (!p) p = sender.hasPermission(perm); if (!p) p = sender.hasPermission(perm);
} else break; //If any of the permissions aren't granted then don't allow } else break; //If any of the permissions aren't granted then don't allow
} }
@ -158,14 +155,11 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
private void handleTabComplete(TabCompleteEvent event) { private void handleTabComplete(TabCompleteEvent event) {
String commandline = event.getBuffer(); String commandline = event.getBuffer();
CommandSender sender = event.getSender(); CommandSender sender = event.getSender();
//System.out.println("tab");
for (int i = commandline.length(); i != -1; i = commandline.lastIndexOf(' ', i - 1)) { for (int i = commandline.length(); i != -1; i = commandline.lastIndexOf(' ', i - 1)) {
String subcommand = commandline.substring(0, i).toLowerCase(); String subcommand = commandline.substring(0, i).toLowerCase();
if (subcommand.length() == 0 || subcommand.charAt(0) != '/') subcommand = '/' + subcommand; //Console if (subcommand.length() == 0 || subcommand.charAt(0) != '/') subcommand = '/' + subcommand; //Console
//System.out.println("Subcommand: " + subcommand);
SubcommandData<ICommand2MC> sd = subcommands.get(subcommand); //O(1) SubcommandData<ICommand2MC> sd = subcommands.get(subcommand); //O(1)
if (sd == null) continue; if (sd == null) continue;
//System.out.println("ht: " + Arrays.toString(sd.helpText));
Arrays.stream(sd.helpText).skip(1).map(ht -> new HashMap.SimpleEntry<>(ht, subcommands.get(ht))).filter(e -> e.getValue() != null) Arrays.stream(sd.helpText).skip(1).map(ht -> new HashMap.SimpleEntry<>(ht, subcommands.get(ht))).filter(e -> e.getValue() != null)
.filter(kv -> kv.getKey().startsWith(commandline)) .filter(kv -> kv.getKey().startsWith(commandline))
.filter(kv -> hasPermission(sender, kv.getValue().command, kv.getValue().method)) .filter(kv -> hasPermission(sender, kv.getValue().command, kv.getValue().method))
@ -266,19 +260,26 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
private void registerOfficially(ICommand2MC command) { private void registerOfficially(ICommand2MC command) {
if(!shouldRegisterOfficially) return; if(!shouldRegisterOfficially) return;
try { try {
var cmdmap=(SimpleCommandMap)Bukkit.getServer().getClass().getMethod("getCommandMap").invoke(Bukkit.getServer()); var cmdmap = (SimpleCommandMap) Bukkit.getServer().getClass().getMethod("getCommandMap").invoke(Bukkit.getServer());
var path = command.getCommandPath(); var path = command.getCommandPath();
int x = path.indexOf(' '); int x = path.indexOf(' ');
var mainPath = path.substring(0, x == -1 ? path.length() : x); var mainPath = path.substring(0, x == -1 ? path.length() : x);
cmdmap.register(command.getPlugin().getName(), new Command(mainPath) { cmdmap.register(command.getPlugin().getName(), new BukkitCommand(mainPath));
@Override
public boolean execute(CommandSender commandSender, String s, String[] strings) {
return true;
}
});
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Failed to register command in command map!", e); TBMCCoreAPI.SendException("Failed to register command in command map!", e);
shouldRegisterOfficially=false; shouldRegisterOfficially = false;
}
}
private static class BukkitCommand extends Command {
protected BukkitCommand(String name) {
super(name);
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
sender.sendMessage("§cThe command wasn't executed for some reason... (command processing failed)");
return true;
} }
} }
} }