WIP: DCustom Default Faction Permissions - No reliable

This commit is contained in:
SvenjaReißaus 2019-02-26 12:15:17 -05:00
parent 52c1966fb8
commit 39334070a7
No known key found for this signature in database
GPG Key ID: B14150951DBF6D29
8 changed files with 209 additions and 0 deletions

Binary file not shown.

View File

@ -3,6 +3,8 @@ package com.massivecraft.factions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.massivecraft.factions.integration.dynmap.DynmapStyle; import com.massivecraft.factions.integration.dynmap.DynmapStyle;
import com.massivecraft.factions.util.MultiversionMaterials; import com.massivecraft.factions.util.MultiversionMaterials;
import com.massivecraft.factions.zcore.fperms.DefaultPermissions;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -330,6 +332,15 @@ public class Conf {
public static int mapHeight = 17; public static int mapHeight = 17;
public static int mapWidth = 49; public static int mapWidth = 49;
public static transient char[] mapKeyChrs = "\\/#$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz?".toCharArray(); public static transient char[] mapKeyChrs = "\\/#$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz?".toCharArray();
// Default Options
public static boolean useCustomDefaultPermissions = false;
public static boolean usePermissionHints = false;
public static HashMap<String, DefaultPermissions> defaultFactionPermissions;
// Custom Ranks
//public static boolean enableCustomRanks = false; // We will disable it by default to avoid any migration error
//public static int maxCustomRanks = 2; // Setting this to -1 will allow unlimited custom ranks
// -------------------------------------------- // // -------------------------------------------- //
// Persistance // Persistance
// -------------------------------------------- // // -------------------------------------------- //
@ -430,6 +441,12 @@ public class Conf {
safeZoneNerfedCreatureTypes.add(EntityType.WITCH); safeZoneNerfedCreatureTypes.add(EntityType.WITCH);
safeZoneNerfedCreatureTypes.add(EntityType.WITHER); safeZoneNerfedCreatureTypes.add(EntityType.WITHER);
safeZoneNerfedCreatureTypes.add(EntityType.ZOMBIE); safeZoneNerfedCreatureTypes.add(EntityType.ZOMBIE);
// Is this called lazy load?
defaultFactionPermissions.put("LEADER", new DefaultPermissions(true));
defaultFactionPermissions.put("COLEADER", new DefaultPermissions(true));
defaultFactionPermissions.put("MODERATOR", new DefaultPermissions(true));
defaultFactionPermissions.put("MEMBER", new DefaultPermissions(false));
defaultFactionPermissions.put("RECRUIT", new DefaultPermissions(false));
} }
public static void load() { public static void load() {

View File

@ -203,6 +203,7 @@ public interface Faction extends EconomyParticipator {
void setPermission(Permissable permissable, PermissableAction permissableAction, Access access); void setPermission(Permissable permissable, PermissableAction permissableAction, Access access);
void resetPerms(); void resetPerms();
void setDefaultPerms();
void disband(Player disbander); void disband(Player disbander);

View File

@ -103,6 +103,11 @@ public class CmdCreate extends FCommand {
if (SavageFactions.plugin.getConfig().getBoolean("fpaypal.Enabled")) { if (SavageFactions.plugin.getConfig().getBoolean("fpaypal.Enabled")) {
this.fme.msg(TL.COMMAND_PAYPALSET_CREATED); this.fme.msg(TL.COMMAND_PAYPALSET_CREATED);
} }
if (Conf.useCustomDefaultPermissions) {
faction.setDefaultPerms();
if (Conf.usePermissionHints)
this.fme.msg(TL.COMMAND_HINT_PERMISSION);
}
} }
@Override @Override

View File

@ -0,0 +1,147 @@
package com.massivecraft.factions.zcore.fperms;
public class DefaultPermissions {
public DefaultPermissions() { }
public DefaultPermissions(boolean def) {
this.ban = def;
this.build = def;
this.destroy = def;
this.frostwalk = def;
this.painbuild = def;
this.door = def;
this.button = def;
this.lever = def;
this.container = def;
this.invite = def;
this.kick = def;
this.items = def;
this.sethome = def;
this.territory = def;
this.access = def;
this.home = def;
this.disband = def;
this.promote = def;
this.setwarp = def;
this.warp = def;
this.fly = def;
this.vault = def;
this.tntbank = def;
this.tntfill = def;
this.withdraw = def;
this.chest = def;
this.spawner = def;
}
public DefaultPermissions(boolean canBan,
boolean canBuild,
boolean canDestory,
boolean canFrostwalk,
boolean canPainbuild,
boolean canDoor,
boolean canButton,
boolean canLever,
boolean canContainer,
boolean canInvite,
boolean canKick,
boolean canItems,
boolean canSethome,
boolean canTerritory,
boolean canAccess,
boolean canHome,
boolean canDisband,
boolean canPromote,
boolean canSetwarp,
boolean canWarp,
boolean canFly,
boolean canVault,
boolean canTntbank,
boolean canTntfill,
boolean canWithdraw,
boolean canChest,
boolean canSpawners) {
this.ban = canBan;
this.build = canBuild;
this.destroy = canDestory;
this.frostwalk = canFrostwalk;
this.painbuild = canPainbuild;
this.door = canDoor;
this.button = canButton;
this.lever = canLever;
this.container = canContainer;
this.invite = canInvite;
this.kick = canKick;
this.items = canItems;
this.sethome = canSethome;
this.territory = canTerritory;
this.access = canAccess;
this.home = canHome;
this.disband = canDisband;
this.promote = canPromote;
this.setwarp = canSetwarp;
this.warp = canWarp;
this.fly = canFly;
this.vault = canVault;
this.tntbank = canTntbank;
this.tntfill = canTntfill;
this.withdraw = canWithdraw;
this.chest = canChest;
this.spawner = canSpawners;
}
public boolean ban;
public boolean build;
public boolean destroy;
public boolean frostwalk;
public boolean painbuild;
public boolean door;
public boolean button;
public boolean lever;
public boolean container;
public boolean invite;
public boolean kick;
public boolean items;
public boolean sethome;
public boolean territory;
public boolean access;
public boolean home;
public boolean disband;
public boolean promote;
public boolean setwarp;
public boolean warp;
public boolean fly;
public boolean vault;
public boolean tntbank;
public boolean tntfill;
public boolean withdraw;
public boolean chest;
public boolean spawner;
@Deprecated
public boolean getbyName(String name) {
if (name == "ban") return this.ban;
else if (name == "build") return this.build;
else if (name == "destroy") return this.destroy;
else if (name == "frostwalk") return this.frostwalk;
else if (name == "painbuild") return this.painbuild;
else if (name == "door") return this.door;
else if (name == "button") return this.button;
else if (name == "lever") return this.lever;
else if (name == "container") return this.container;
else if (name == "invite") return this.invite;
else if (name == "kick") return this.kick;
else if (name == "items") return this.items;
else if (name == "sethome") return this.sethome;
else if (name == "territory") return this.territory;
else if (name == "access") return this.access;
else if (name == "home") return this.disband;
else if (name == "disband") return this.disband;
else if (name == "promote") return this.promote;
else if (name == "setwarp") return this.setwarp;
else if (name == "warp") return this.warp;
else if (name == "fly") return this.fly;
else if (name == "vault") return this.vault;
else if (name == "tntbank") return this.tntbank;
else if (name == "tntfill") return this.tntfill;
else if (name == "withdraw") return this.withdraw;
else if (name == "chest") return this.chest;
else if (name == "spawner") return this.spawner;
else return false;
}
}

View File

@ -10,7 +10,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
public enum PermissableAction { public enum PermissableAction {
@ -171,4 +173,12 @@ public enum PermissableAction {
return string; return string;
} }
public static Map<PermissableAction, Access> fromDefaults(DefaultPermissions defaultPermissions) {
Map<PermissableAction, Access> defaultMap = new HashMap<>();
for (PermissableAction permissableAction : PermissableAction.values()) {
defaultMap.put(permissableAction, defaultPermissions.getbyName(permissableAction.name) ? Access.ALLOW : Access.DENY);
}
return defaultMap;
}
} }

View File

@ -671,6 +671,33 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
} }
} }
public void setDefaultPerms() {
if (!Conf.useCustomDefaultPermissions) return;
Map<PermissableAction, Access> defaultMap = new HashMap<>();
for (PermissableAction permissableAction : PermissableAction.values()) {
defaultMap.put(permissableAction, Access.UNDEFINED);
}
// Put the map in there for each relation.
for (Relation relation : Relation.values()) {
if (relation != Relation.MEMBER) {
if (!Conf.defaultFactionPermissions.containsKey(relation.nicename))
permissions.put(relation, new HashMap<>(defaultMap));
else
permissions.put(relation, PermissableAction.fromDefaults(Conf.defaultFactionPermissions.get(relation.nicename)));
}
}
// And each role.
for (Role role : Role.values()) {
if (role != Role.LEADER) {
if (!Conf.defaultFactionPermissions.containsKey(role.nicename))
permissions.put(role, new HashMap<>(defaultMap));
else
permissions.put(role, PermissableAction.fromDefaults(Conf.defaultFactionPermissions.get(role.nicename)));
}
}
}
/** /**
* Read only map of Permissions. * Read only map of Permissions.
* *

View File

@ -308,6 +308,8 @@ public enum TL {
COMMAND_FWARP_PASSWORD_REQUIRED("&c&l[!]&c Warp Password:"), COMMAND_FWARP_PASSWORD_REQUIRED("&c&l[!]&c Warp Password:"),
COMMAND_FWARP_PASSWORD_TIMEOUT("&c&l[!]&7 Warp password &ccanceled"), COMMAND_FWARP_PASSWORD_TIMEOUT("&c&l[!]&7 Warp password &ccanceled"),
COMMAND_HINT_PERMISSION("&aYou can manage your factions permissions using &7/f perms"),
COMMAND_HOME_DISABLED("&c&l[!]&7 Sorry, Faction homes are &cdisabled on this server."), COMMAND_HOME_DISABLED("&c&l[!]&7 Sorry, Faction homes are &cdisabled on this server."),
COMMAND_HOME_TELEPORTDISABLED("&c&l[!]&7 Sorry, the ability to &cteleport &7to Faction homes is &cdisabled &7on this server."), COMMAND_HOME_TELEPORTDISABLED("&c&l[!]&7 Sorry, the ability to &cteleport &7to Faction homes is &cdisabled &7on this server."),
COMMAND_HOME_NOHOME("&c&l[!]&7 Your faction does &cnot &7have a home. "), COMMAND_HOME_NOHOME("&c&l[!]&7 Your faction does &cnot &7have a home. "),