mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-22 02:08:34 +01:00
Add Sign Edit permission, imporove permissions to be able to specify default values
This commit is contained in:
parent
17eb186d2b
commit
6e92c7fec9
@ -12,17 +12,37 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BasicPermission {
|
||||
private final String name;
|
||||
private final XMaterial icon;
|
||||
private final PermissionType type;
|
||||
|
||||
//It used to write the permission's value
|
||||
//to the global settings.yml which will be defaulted on all islands
|
||||
private final Map<IslandRole, Boolean> defaultValues;
|
||||
|
||||
protected BasicPermission(@Nonnull String name, @Nonnull XMaterial icon, @Nonnull PermissionType type) {
|
||||
this(name, icon, type, new HashMap<>());
|
||||
}
|
||||
|
||||
protected BasicPermission(@Nonnull String name, @Nonnull XMaterial icon, @Nonnull PermissionType type, Map<IslandRole, Boolean> defaultValues) {
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
this.type = type;
|
||||
if (defaultValues.isEmpty()) {
|
||||
this.defaultValues = new HashMap<>();
|
||||
this.defaultValues.put(IslandRole.VISITOR, false);
|
||||
this.defaultValues.put(IslandRole.MEMBER, true);
|
||||
this.defaultValues.put(IslandRole.OPERATOR, true);
|
||||
this.defaultValues.put(IslandRole.COOP, true);
|
||||
this.defaultValues.put(IslandRole.OWNER, true);
|
||||
} else {
|
||||
this.defaultValues = defaultValues;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getItem(Island island, IslandRole role) {
|
||||
@ -72,4 +92,8 @@ public abstract class BasicPermission {
|
||||
public PermissionType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Map<IslandRole, Boolean> getDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.craftaro.skyblock.permission;
|
||||
|
||||
import com.craftaro.skyblock.island.IslandRole;
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
@ -34,11 +35,17 @@ import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ListeningPermission extends BasicPermission {
|
||||
protected ListeningPermission(String name, XMaterial icon, PermissionType type) {
|
||||
super(name, icon, type);
|
||||
}
|
||||
|
||||
protected ListeningPermission(String name, XMaterial icon, PermissionType type, Map<IslandRole, Boolean> defaultValues) {
|
||||
super(name, icon, type, defaultValues);
|
||||
}
|
||||
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.craftaro.skyblock.permission;
|
||||
|
||||
import com.craftaro.core.compatibility.ServerVersion;
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
import com.craftaro.skyblock.config.FileManager;
|
||||
import com.craftaro.skyblock.island.Island;
|
||||
@ -141,6 +142,10 @@ public class PermissionManager {
|
||||
registerPermission(new HungerPermission(plugin));
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_20)) {
|
||||
registerPermission(new SignEditPermission(plugin));
|
||||
}
|
||||
|
||||
this.registeredHandlers = this.registeredHandlers.stream()
|
||||
.sorted(Comparator.comparingInt(h -> h.getHandler().getAnnotation(PermissionHandler.class).priority().ordinal()))
|
||||
.collect(Collectors.toList());
|
||||
@ -153,13 +158,16 @@ public class PermissionManager {
|
||||
switch (permission.getType()) {
|
||||
case GENERIC:
|
||||
if (settingsConfigLoad.getString("Settings.Visitor." + permission.getName()) == null) {
|
||||
settingsConfigLoad.set("Settings.Visitor." + permission.getName(), true);
|
||||
settingsConfigLoad.set("Settings.Visitor." + permission.getName(), permission.getDefaultValues().get(IslandRole.VISITOR));
|
||||
if (permission.getName().equals("EditSign")) {
|
||||
System.err.println("Default EditSign Visitor permission set to: " + permission.getDefaultValues().get(IslandRole.VISITOR));
|
||||
}
|
||||
}
|
||||
if (settingsConfigLoad.getString("Settings.Member." + permission.getName()) == null) {
|
||||
settingsConfigLoad.set("Settings.Member." + permission.getName(), true);
|
||||
settingsConfigLoad.set("Settings.Member." + permission.getName(), permission.getDefaultValues().get(IslandRole.MEMBER));
|
||||
}
|
||||
if (settingsConfigLoad.getString("Settings.Coop." + permission.getName()) == null) {
|
||||
settingsConfigLoad.set("Settings.Coop." + permission.getName(), true);
|
||||
settingsConfigLoad.set("Settings.Coop." + permission.getName(), permission.getDefaultValues().get(IslandRole.COOP));
|
||||
}
|
||||
break;
|
||||
case OPERATOR:
|
||||
|
@ -0,0 +1,42 @@
|
||||
package com.craftaro.skyblock.permission.permissions.listening;
|
||||
|
||||
import com.craftaro.skyblock.SkyBlock;
|
||||
import com.craftaro.skyblock.island.IslandRole;
|
||||
import com.craftaro.skyblock.permission.ListeningPermission;
|
||||
import com.craftaro.skyblock.permission.PermissionHandler;
|
||||
import com.craftaro.skyblock.permission.PermissionType;
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SignEditPermission extends ListeningPermission {
|
||||
|
||||
private final SkyBlock plugin;
|
||||
|
||||
public SignEditPermission(SkyBlock plugin) {
|
||||
super("EditSign", XMaterial.OAK_SIGN, PermissionType.GENERIC, new HashMap<IslandRole, Boolean>() {{
|
||||
put(IslandRole.VISITOR, false);
|
||||
put(IslandRole.MEMBER, true);
|
||||
put(IslandRole.OPERATOR, true);
|
||||
put(IslandRole.COOP, true);
|
||||
put(IslandRole.OWNER, true);
|
||||
}});
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@PermissionHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (event.getClickedBlock().getType().name().contains("SIGN")) {
|
||||
cancelAndMessage(event, player, this.plugin, this.plugin.getMessageManager());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user