mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-01-03 22:08:28 +00:00
Consolidate permissions default setup into single class
This commit is contained in:
parent
c12a031918
commit
9cda59511e
3 changed files with 59 additions and 49 deletions
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.commands.Commandhat;
|
||||
import com.earth2me.essentials.commands.EssentialsCommand;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
|
@ -28,6 +27,7 @@ import com.earth2me.essentials.items.CustomItemResolver;
|
|||
import com.earth2me.essentials.items.FlatItemDb;
|
||||
import com.earth2me.essentials.items.LegacyItemDb;
|
||||
import com.earth2me.essentials.metrics.MetricsWrapper;
|
||||
import com.earth2me.essentials.perm.PermissionsDefaults;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import com.earth2me.essentials.signs.SignBlockListener;
|
||||
|
@ -85,8 +85,6 @@ import org.bukkit.event.player.PlayerEvent;
|
|||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
@ -158,18 +156,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||
super(new JavaPluginLoader(server), new PluginDescriptionFile("Essentials", "", "com.earth2me.essentials.Essentials"), null, null);
|
||||
}
|
||||
|
||||
private static void addDefaultBackPermissionsToWorld(final World w) {
|
||||
final String permName = "essentials.back.into." + w.getName();
|
||||
|
||||
Permission p = Bukkit.getPluginManager().getPermission(permName);
|
||||
if (p == null) {
|
||||
p = new Permission(permName,
|
||||
"Allows access to /back when the destination location is within world " + w.getName(),
|
||||
PermissionDefault.TRUE);
|
||||
Bukkit.getPluginManager().addPermission(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISettings getSettings() {
|
||||
return settings;
|
||||
|
@ -362,17 +348,15 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
|
||||
|
||||
// Register hat permissions
|
||||
Commandhat.registerPermissionsIfNecessary(getServer().getPluginManager());
|
||||
|
||||
timer = new EssentialsTimer(this);
|
||||
scheduleSyncRepeatingTask(timer, 1000, 50);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegHandler");
|
||||
|
||||
for (final World w : Bukkit.getWorlds())
|
||||
addDefaultBackPermissionsToWorld(w);
|
||||
// Register /hat and /back default permissions
|
||||
PermissionsDefaults.registerAllBackDefaults();
|
||||
PermissionsDefaults.registerAllHatDefaults();
|
||||
|
||||
metrics = new MetricsWrapper(this, 858, true);
|
||||
|
||||
|
@ -1064,7 +1048,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
|||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onWorldLoad(final WorldLoadEvent event) {
|
||||
addDefaultBackPermissionsToWorld(event.getWorld());
|
||||
PermissionsDefaults.registerBackDefaultFor(event.getWorld());
|
||||
|
||||
ess.getJails().onReload();
|
||||
ess.getWarps().reloadConfig();
|
||||
|
|
|
@ -3,16 +3,12 @@ package com.earth2me.essentials.commands;
|
|||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -20,35 +16,14 @@ import java.util.List;
|
|||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandhat extends EssentialsCommand {
|
||||
/**
|
||||
* The prefix for hat prevention commands
|
||||
*/
|
||||
private static final String PERM_PREFIX = "essentials.hat.prevent-type.";
|
||||
|
||||
// The prefix for hat prevention commands
|
||||
public static final String PERM_PREFIX = "essentials.hat.prevent-type.";
|
||||
|
||||
public Commandhat() {
|
||||
super("hat");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register permissions used by this command.
|
||||
*
|
||||
* @param toRegister The plugin manager to register permissions in.
|
||||
*/
|
||||
public static void registerPermissionsIfNecessary(final PluginManager toRegister) {
|
||||
final Permission hatPerm = toRegister.getPermission(PERM_PREFIX + "*");
|
||||
if (hatPerm != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ImmutableMap.Builder<String, Boolean> children = ImmutableMap.builder();
|
||||
for (final Material mat : Material.values()) {
|
||||
final String matPerm = PERM_PREFIX + mat.name().toLowerCase();
|
||||
children.put(matPerm, true);
|
||||
toRegister.addPermission(new Permission(matPerm, "Prevent using " + mat + " as a type of hat.", PermissionDefault.FALSE));
|
||||
}
|
||||
toRegister.addPermission(new Permission(PERM_PREFIX + "*", "Prevent all types of hats", PermissionDefault.FALSE, children.build()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length == 0 || (!args[0].contains("rem") && !args[0].contains("off") && !args[0].equalsIgnoreCase("0"))) {
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
package com.earth2me.essentials.perm;
|
||||
|
||||
import com.earth2me.essentials.commands.Commandhat;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public final class PermissionsDefaults {
|
||||
|
||||
private PermissionsDefaults() {
|
||||
}
|
||||
|
||||
public static void registerAllBackDefaults() {
|
||||
for (final World world : Bukkit.getWorlds()) {
|
||||
registerBackDefaultFor(world);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerBackDefaultFor(final World w) {
|
||||
final String permName = "essentials.back.into." + w.getName();
|
||||
|
||||
Permission p = Bukkit.getPluginManager().getPermission(permName);
|
||||
if (p == null) {
|
||||
p = new Permission(permName,
|
||||
"Allows access to /back when the destination location is within world " + w.getName(),
|
||||
PermissionDefault.TRUE);
|
||||
Bukkit.getPluginManager().addPermission(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerAllHatDefaults() {
|
||||
final PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
|
||||
final Permission hatPerm = pluginManager.getPermission(Commandhat.PERM_PREFIX + "*");
|
||||
if (hatPerm != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ImmutableMap.Builder<String, Boolean> children = ImmutableMap.builder();
|
||||
for (final Material mat : Material.values()) {
|
||||
final String matPerm = Commandhat.PERM_PREFIX + mat.name().toLowerCase();
|
||||
children.put(matPerm, true);
|
||||
pluginManager.addPermission(new Permission(matPerm, "Prevent using " + mat + " as a type of hat.", PermissionDefault.FALSE));
|
||||
}
|
||||
pluginManager.addPermission(new Permission(Commandhat.PERM_PREFIX + "*", "Prevent all types of hats", PermissionDefault.FALSE, children.build()));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue