1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Not add permission for a world if we did it already

This commit is contained in:
Zrips 2021-11-26 17:46:49 +02:00
parent 17005f2823
commit 63a8abc749
2 changed files with 11 additions and 2 deletions

View File

@ -19,8 +19,10 @@
package com.gamingmesh.jobs;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -228,13 +230,17 @@ public class PermissionHandler {
// recalculate!
player.recalculatePermissions();
}
public static Set<String> worldsRegistered = new HashSet<String>();
public void registerPermissions() {
PluginManager pm = plugin.getServer().getPluginManager();
for (World world : plugin.getServer().getWorlds()) {
String worldName = world.getName().toLowerCase();
if (pm.getPermission("jobs.world." + worldName) == null)
if (pm.getPermission("jobs.world." + worldName) == null) {
pm.addPermission(new Permission("jobs.world." + worldName, PermissionDefault.TRUE));
worldsRegistered.add(worldName);
}
}
for (Job job : Jobs.getJobs()) {

View File

@ -67,6 +67,7 @@ import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.PermissionHandler;
import com.gamingmesh.jobs.Signs.SignTopType;
import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.Signs.jobsSign;
@ -359,8 +360,10 @@ public class JobsListener implements Listener {
public void onWorldLoad(WorldLoadEvent event) {
PluginManager pm = plugin.getServer().getPluginManager();
String name = event.getWorld().getName().toLowerCase();
if (pm.getPermission("jobs.world." + name) == null)
if (pm.getPermission("jobs.world." + name) == null && !PermissionHandler.worldsRegistered.contains(name)) {
pm.addPermission(new Permission("jobs.world." + name, PermissionDefault.TRUE));
PermissionHandler.worldsRegistered.add(name);
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)