Unconnected perm group & fixes

This commit is contained in:
Norbi Peti 2019-05-20 23:36:59 +02:00
parent 497c761cc0
commit a75397f2b0
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 34 additions and 49 deletions

View file

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:15.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TBMCPlugins.ButtonCore:Towny:master-98b73aaac3-1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.milkbowl:VaultAPI:master-68f14eca20-1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.13.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
<orderEntry type="library" name="Maven: org.mockito:mockito-core:2.7.20" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: net.bytebuddy:byte-buddy:1.6.11" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: net.bytebuddy:byte-buddy-agent:1.6.11" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.objenesis:objenesis:2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.16" level="project" />
<orderEntry type="module" module-name="ButtonProcessor" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:Essentials:2.13.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.vexsoftware:nuvotifier-universal:2.3.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
</component>
</module>

View file

@ -69,6 +69,13 @@ public class MainPlugin extends ButtonPlugin {
"{channel}] <{name}> {message}"); "{channel}] <{name}> {message}");
} }
/**
* The permission group for users that aren't online on the server. Currently this can happen for people using commands from Discord.
*/
public ConfigData<String> unconnPermGroup() {
return getIConfig().getData("unconnPermGroup", "unconnected");
}
@Override @Override
public void pluginEnable() { public void pluginEnable() {
// Logs "Plugin Enabled", registers commands // Logs "Plugin Enabled", registers commands

View file

@ -132,10 +132,12 @@ public abstract class Component<TP extends JavaPlugin> {
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) {
updateConfig(component.getPlugin(), component); updateConfig(component.getPlugin(), component);
System.out.println("Enabling component " + component.getClassName());
component.enable(); component.enable();
if (ButtonPlugin.configGenAllowed(component)) if (ButtonPlugin.configGenAllowed(component))
IHaveConfig.pregenConfig(component, null); IHaveConfig.pregenConfig(component, null);
} else { } else {
System.out.println("Disabling component " + component.getClassName());
component.disable(); component.disable();
component.plugin.saveConfig(); component.plugin.saveConfig();
TBMCChatAPI.RemoveCommands(component); TBMCChatAPI.RemoveCommands(component);

View file

@ -4,6 +4,9 @@ import buttondevteam.core.MainPlugin;
import lombok.experimental.var; import lombok.experimental.var;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
@ -25,7 +28,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
for (val method : command.getClass().getMethods()) { for (val method : command.getClass().getMethods()) {
if (!method.isAnnotationPresent(Subcommand.class)) continue; if (!method.isAnnotationPresent(Subcommand.class)) continue;
String pg = permGroup(command, method); String pg = permGroup(command, method);
if (pg == null) continue; if (pg.length() == 0) continue;
perm = "thorpe." + pg; perm = "thorpe." + pg;
if (Bukkit.getPluginManager().getPermission(perm) == null) //It may occur multiple times if (Bukkit.getPluginManager().getPermission(perm) == null) //It may occur multiple times
System.out.println("Adding perm " + perm + " with default: " System.out.println("Adding perm " + perm + " with default: "
@ -39,15 +42,26 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
@Override @Override
public boolean hasPermission(Command2MCSender sender, ICommand2MC command, Method method) { public boolean hasPermission(Command2MCSender sender, ICommand2MC command, Method method) {
if (sender.getSender() instanceof ConsoleCommandSender) return true; //Always allow the console
String pg; String pg;
String perm = modOnly(command) boolean p = true;
? "tbmc.admin" String[] perms = {
: (pg = permGroup(command, method)) != null //TODO: This way we can't grant specific perms if it has a perm group "thorpe.command." + command.getCommandPath().replace(' ', '.'),
? "thorpe." + pg (pg = permGroup(command, method)).length() > 0 ? "thorpe." + pg : null,
: "thorpe.command." + command.getCommandPath().replace(' ', '.'); modOnly(command) ? "tbmc.admin" : null
//noinspection deprecation };
System.out.println("Has permission " + perm + ": " + MainPlugin.permission.playerHas((String) null, sender.getSender().getName(), perm)); for (String perm : perms) {
return MainPlugin.permission.playerHas((String) null, sender.getSender().getName(), perm); if (perm != null) {
if (p) { //Use OfflinePlayer to avoid fetching player data
if (sender.getSender() instanceof Player)
p = MainPlugin.permission.playerHas(null, (OfflinePlayer) sender.getSender(), perm);
else
p = MainPlugin.permission.groupHas((String) null, MainPlugin.Instance.unconnPermGroup().get(), perm);
System.out.println("Has permission " + perm + ": " + p);
} else break; //If any of the permissions aren't granted then don't allow
}
}
return p;
} }
/** /**
@ -64,7 +78,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
* Returns true if this class or <u>any</u> of the superclasses are mod only. * Returns true if this class or <u>any</u> of the superclasses are mod only.
* *
* @param method The subcommand to check * @param method The subcommand to check
* @return The permission group for the subcommand or null * @return The permission group for the subcommand or empty string
*/ */
private String permGroup(ICommand2MC command, Method method) { private String permGroup(ICommand2MC command, Method method) {
//System.out.println("Perm group for command " + command.getClass().getSimpleName() + " and method " + method.getName()); //System.out.println("Perm group for command " + command.getClass().getSimpleName() + " and method " + method.getName());
@ -74,7 +88,7 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> {
return sc.permGroup(); return sc.permGroup();
} }
//System.out.println("Returning getAnnForValue(" + command.getClass().getSimpleName() + ", ...): " + getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, null)); //System.out.println("Returning getAnnForValue(" + command.getClass().getSimpleName() + ", ...): " + getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, null));
return getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, null); return getAnnForValue(command.getClass(), CommandClass.class, CommandClass::permGroup, "");
} }
/** /**