Implemented SavageFactions Warp and Perms system as requested. - Credits SavageLif3 & ProSavage

This commit is contained in:
Driftay 2019-08-05 08:05:22 -04:00
parent bc06c5ab4a
commit 8dc1e97098
28 changed files with 516 additions and 1098 deletions

View File

@ -81,6 +81,11 @@
</build>
<dependencies>
<dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId>
<version>0.5.8</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
@ -295,7 +300,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version>
<version>28.0-jre</version>
<scope>provided</scope>
<exclusions>
<exclusion>
@ -307,7 +312,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableMap;
import com.massivecraft.factions.integration.dynmap.DynmapStyle;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.DefaultPermissions;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
@ -330,8 +332,6 @@ public class Conf {
// faction-<factionId>
public static int defaultMaxVaults = 0;
public static boolean disableFlightOnFactionClaimChange = true;
public static boolean useCustomDefaultPermissions = true;
public static boolean usePermissionHints = false;
public static Backend backEnd = Backend.JSON;
@ -341,9 +341,6 @@ public class Conf {
public static transient char[] mapKeyChrs = "\\/#$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz?".toCharArray();
// Default Options - Is this even shown on the Conf.json?
public static HashMap<String, DefaultPermissions> defaultFactionPermissions = new HashMap<>();
//Cooldown for /f logout in seconds
public static long logoutCooldown = 30;
@ -352,10 +349,21 @@ public class Conf {
//public static int maxCustomRanks = 2; // Setting this to -1 will allow unlimited custom ranks
// -------------------------------------------- //
// Persistance
// -------------------------------------------- //
// ----------------------------------------- //
// Default Faction Permission Settings.
public static boolean useLockedPermissions = false;
public static boolean useCustomDefaultPermissions = true;
public static boolean usePermissionHints = false;
public static HashMap<String, DefaultPermissions> defaultFactionPermissions = new HashMap<>();
public static HashSet<PermissableAction> lockedPermissions = new HashSet<>();
private static transient Conf i = new Conf();
static {
lockedPermissions.add(PermissableAction.CHEST);
}
static {
baseCommandAliases.add("f");

View File

@ -221,7 +221,7 @@ public interface Faction extends EconomyParticipator {
Access getAccess(FPlayer player, PermissableAction permissableAction);
void setPermission(Permissable permissable, PermissableAction permissableAction, Access access);
boolean setPermission(Permissable permissable, PermissableAction permissableAction, Access access);
void resetPerms();

View File

@ -13,7 +13,7 @@ import com.massivecraft.factions.listeners.*;
import com.massivecraft.factions.shop.ShopClickPersistence;
import com.massivecraft.factions.shop.ShopConfig;
import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.Placeholder;
import com.massivecraft.factions.util.Placeholder;
import com.massivecraft.factions.util.*;
import com.massivecraft.factions.util.Particles.ReflectionUtils;
import com.massivecraft.factions.zcore.CommandVisibility;
@ -68,6 +68,7 @@ public class P extends MPlugin {
public CmdAutoHelp cmdAutoHelp;
public boolean mc17 = false;
public boolean mc18 = false;
public boolean mc112 = false;
public boolean mc113 = false;
public boolean mc114 = false;
public boolean useNonPacketParticles = false;
@ -150,6 +151,9 @@ public class P extends MPlugin {
P.p.log("Minecraft Version 1.8 found, Title Fadeouttime etc will not be configurable.");
mc18 = true;
break;
case 12:
mc112 = true;
break;
case 13:
P.p.log("Minecraft Version 1.13 found, New Items will be used.");
mc113 = true;
@ -280,6 +284,8 @@ public class P extends MPlugin {
return skriptAddon;
}
private void setupPlaceholderAPI() {
Plugin clip = getServer().getPluginManager().getPlugin("PlaceholderAPI");
if (clip != null && clip.isEnabled()) {

View File

@ -4,8 +4,8 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.FactionWarpsFrame;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.util.WarpGUI;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
@ -42,10 +42,7 @@ public class CmdFWarp extends FCommand {
if (args.size() == 0) {
WarpGUI warpGUI = new WarpGUI(fme);
warpGUI.build();
me.openInventory(warpGUI.getInventory());
new FactionWarpsFrame(fme.getFaction()).buildGUI(fme);
} else if (args.size() > 2) {
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else {
@ -61,9 +58,7 @@ public class CmdFWarp extends FCommand {
}
// Check transaction AFTER password check.
if (!transact(fme)) {
return;
}
if (!transact(fme)) return;
final FPlayer fPlayer = fme;
final UUID uuid = fme.getPlayer().getUniqueId();
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
@ -73,9 +68,7 @@ public class CmdFWarp extends FCommand {
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
}
}, this.p.getConfig().getLong("warmups.f-warp", 0));
} else {
fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
}
} else { fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName); }
}
}

View File

@ -6,8 +6,8 @@ import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.fperms.gui.PermissableActionGUI;
import com.massivecraft.factions.zcore.fperms.gui.PermissableRelationGUI;
import com.massivecraft.factions.zcore.fperms.gui.PermissableActionFrame;
import com.massivecraft.factions.zcore.fperms.gui.PermissableRelationFrame;
import com.massivecraft.factions.zcore.util.TL;
import java.util.Arrays;
@ -41,16 +41,10 @@ public class CmdPerm extends FCommand {
@Override
public void perform() {
if (args.size() == 0) {
PermissableRelationGUI gui = new PermissableRelationGUI(fme);
gui.build();
me.openInventory(gui.getInventory());
new PermissableRelationFrame(fme.getFaction()).buildGUI(fme);
return;
} else if (args.size() == 1 && getPermissable(argAsString(0)) != null) {
PermissableActionGUI gui = new PermissableActionGUI(fme, getPermissable(argAsString(0)));
gui.build();
me.openInventory(gui.getInventory());
new PermissableActionFrame(fme.getFaction()).buildGUI(fme, getPermissable(argAsString(0)));
return;
}
@ -103,7 +97,6 @@ public class CmdPerm extends FCommand {
fme.getFaction().setPermission(permissable, permissableAction, access);
}
}
fme.msg(TL.COMMAND_PERM_SET, argAsString(1), access.name(), argAsString(0));
P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), argAsString(1), access.name(), argAsString(0)) + " for faction " + fme.getTag());
}

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
@ -113,8 +114,8 @@ public class CmdTnt extends FCommand {
return;
}
for (int i = 0; i <= fullStacks - 1; i++) me.getPlayer().getInventory().addItem(new ItemStack(Material.TNT, 64));
if (remainderAmt != 0) me.getPlayer().getInventory().addItem(new ItemStack(Material.TNT, remainderAmt));
for (int i = 0; i <= fullStacks - 1; i++) me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0) me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
fme.getFaction().takeTnt(amount);
me.updateInventory();

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd.claim;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
@ -31,7 +32,10 @@ public class CmdClaimAt extends FCommand {
int x = argAsInt(1);
int z = argAsInt(2);
FLocation location = new FLocation(argAsString(0), x, z);
fme.attemptClaim(myFaction, location, true);
if (!((fme.getPlayer().getLocation().getX() + (x * 16)) > (fme.getPlayer().getLocation().getX() + (Conf.mapWidth * 16))) &&
!((fme.getPlayer().getLocation().getZ() + (z * 16)) > (fme.getPlayer().getLocation().getZ() + (Conf.mapHeight * 16)))) {
fme.attemptClaim(myFaction, location, true);
} else fme.msg(TL.COMMAND_CLAIM_DENIED);
}
@Override

View File

@ -16,6 +16,7 @@ public class CmdMoney extends FCommand {
public CmdMoney() {
super();
this.aliases.add("money");
this.aliases.add("bank");
//this.requiredArgs.add("");
//this.optionalArgs.put("","")

View File

@ -15,6 +15,7 @@ public class CmdMoneyBalance extends FCommand {
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "yours");
this.isMoneyCommand = true;
this.permission = Permission.MONEY_BALANCE.node;
this.setHelpShort(TL.COMMAND_MONEYBALANCE_SHORT.toString());

View File

@ -20,6 +20,8 @@ public class CmdMoneyDeposit extends FCommand {
this.requiredArgs.add("amount");
this.optionalArgs.put("faction", "yours");
this.isMoneyCommand = true;
this.permission = Permission.MONEY_DEPOSIT.node;

View File

@ -24,6 +24,8 @@ public class CmdMoneyTransferFf extends FCommand {
this.permission = Permission.MONEY_F2F.node;
this.isMoneyCommand = true;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -23,6 +23,7 @@ public class CmdMoneyTransferFp extends FCommand {
this.permission = Permission.MONEY_F2P.node;
this.isMoneyCommand = true;
senderMustBePlayer = false;
senderMustBeMember = false;

View File

@ -22,6 +22,7 @@ public class CmdMoneyTransferPf extends FCommand {
//this.optionalArgs.put("", "");
this.permission = Permission.MONEY_P2F.node;
this.isMoneyCommand = true;
senderMustBePlayer = false;

View File

@ -22,6 +22,7 @@ public class CmdMoneyWithdraw extends FCommand {
this.optionalArgs.put("faction", "yours");
this.permission = Permission.MONEY_WITHDRAW.node;
this.isMoneyCommand = true;
senderMustBePlayer = true;

View File

@ -47,6 +47,7 @@ public class ShopClickPersistence implements Listener {
if (e.getView().getTitle().equalsIgnoreCase(color(config.getString("F-Shop.GUI.Name")))) {
ItemStack item = e.getCurrentItem();
if(item == null) return;
String name = color(item.getItemMeta().getDisplayName());
e.setCancelled(true);
int t = e.getSlot();

View File

@ -0,0 +1,111 @@
package com.massivecraft.factions.util;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import com.massivecraft.factions.zcore.util.TL;
import java.util.Map;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import org.bukkit.configuration.ConfigurationSection;
public class FactionWarpsFrame {
private Gui gui;
private ConfigurationSection section;
public FactionWarpsFrame(final Faction f) {
this.section = P.p.getConfig().getConfigurationSection("fwarp-gui");
this.gui = new Gui(P.p, section.getInt("rows", 3), P.p.color(this.section.getString("name").replace("{faction}",f.getTag())));
}
public void buildGUI(final FPlayer fplayer) {
final PaginatedPane pane = new PaginatedPane(0, 0, 9, this.gui.getRows());
final List<GuiItem> GUIItems = new ArrayList<>();
final List<Integer> slots = section.getIntegerList("warp-slots");
int count = 0;
for (int x = 0; x <= gui.getRows() * 9 - 1; ++x) GUIItems.add(new GuiItem(buildDummyItem(), e -> e.setCancelled(true)));
slots.forEach(slot -> GUIItems.set(slot, new GuiItem(XMaterial.AIR.parseItem())));
for (final Map.Entry<String, LazyLocation> warp : fplayer.getFaction().getWarps().entrySet()) {
if (count > slots.size()) continue;
GUIItems.set(slots.get(count), new GuiItem(buildWarpAsset(warp, fplayer.getFaction()), e -> {
e.setCancelled(true);
fplayer.getPlayer().closeInventory();
if (!fplayer.getFaction().hasWarpPassword(warp.getKey())) {
if (transact(fplayer)) {
doWarmup(warp.getKey(), fplayer);
}
} else {
fplayer.setEnteringPassword(true, warp.getKey());
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED);
Bukkit.getScheduler().runTaskLater(P.p, () -> {
if (fplayer.isEnteringPassword()) {
fplayer.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fplayer.setEnteringPassword(false, "");
}
}, P.p.getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
}
}));
++count;
}
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fplayer.getPlayer());
}
private ItemStack buildWarpAsset(final Map.Entry<String, LazyLocation> warp, final Faction faction) {
final ConfigurationSection config = this.section.getConfigurationSection("warp-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
final ItemMeta meta = item.getItemMeta();
meta.setLore(P.p.colorList(P.p.replacePlaceholders(config.getStringList("Lore"), new Placeholder("{warp-protected}", faction.hasWarpPassword(warp.getKey()) ? "Enabled" : "Disabled"), new Placeholder("{warp-cost}", P.p.getConfig().getBoolean("warp-cost.enabled", false) ? Integer.toString(P.p.getConfig().getInt("warp-cost.warp", 5)) : "Disabled"))));
meta.setDisplayName(P.p.color(config.getString("Name").replace("{warp}", warp.getKey())));
item.setItemMeta(meta);
return item;
}
private ItemStack buildDummyItem() {
final ConfigurationSection config = this.section.getConfigurationSection("dummy-item");
final ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
final ItemMeta meta = item.getItemMeta();
meta.setLore(P.p.colorList(config.getStringList("Lore")));
meta.setDisplayName(P.p.color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
private void doWarmup(final String warp, FPlayer fme) {
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, () -> {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
}, P.p.getConfig().getLong("warmups.f-warp", 0));
}
private boolean transact(FPlayer player) {
if (!P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing()) return true;
double cost = P.p.getConfig().getDouble("warp-cost.warp", 5);
if (!Econ.shouldBeUsed() || cost == 0.0 || player.isAdminBypassing()) return true;
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && player.hasFaction()) {
return Econ.modifyMoney(player.getFaction(), -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
} else {
return Econ.modifyMoney(player, -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
}
}
}

View File

@ -0,0 +1,61 @@
package com.massivecraft.factions.util.Particles;
import com.massivecraft.factions.P;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
public enum Particles {
// Gotta use Strings or runtime errors on 1.8, the Particle class does not exist
CLOUD(ParticleEffect.CLOUD, "CLOUD"),
REDSTONE(ParticleEffect.REDSTONE, "REDSTONE"),
NOTE(ParticleEffect.NOTE, "NOTE");
private ParticleEffect sub18;
private String over19;
Particles(ParticleEffect sub18, String over19) {
this.sub18 = sub18;
this.over19 = over19;
}
public void displayAtLocation(Location location, int amt) {
if (P.p.useNonPacketParticles) {
// 1.9+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
} else {
sub18.display((float) 0, (float) 0, (float) 0, (float) 0, amt, location, 16);
}
}
public void displayAtLocation(Location location, int amt, ParticleEffect.OrdinaryColor color) {
if (P.p.useNonPacketParticles) {
// 1.9-1.11 & 1.13+ based servers will use the built in particleAPI instead of packet based.
// any particle amount higher than 0 made them go everywhere, and the offset at 0 was not working.
// So setting the amount to 0 spawns 1 in the precise location
// Gotta do this so colorable ones have their data :P
if (this == Particles.REDSTONE || this == Particles.CLOUD || this == Particles.NOTE) {
if (P.p.mc112) {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
} else {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0, new Particle.DustOptions(Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()), 1));
}
} else {
location.getWorld().spawnParticle(Particle.valueOf(over19), location, 0);
}
} else {
sub18.display(color, location, 16);
}
}
}

View File

@ -0,0 +1,22 @@
package com.massivecraft.factions.util;
public class Placeholder {
private String tag;
private String replace;
public Placeholder(String tag, String replace) {
this.tag = tag;
this.replace = replace;
}
public String getReplace() {
return replace;
}
public String getTag() {
return tag;
}
}

View File

@ -1,259 +0,0 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.logging.Level;
public class WarpGUI implements InventoryHolder, FactionGUI {
private final ConfigurationSection section;
int guiSize;
private Inventory warpGUI;
private FPlayer fme;
private HashMap<Integer, String> warpSlots = new HashMap<>();
private int maxWarps;
private List<Integer> dummySlots = new ArrayList<>();
public WarpGUI(FPlayer fme) {
this.fme = fme;
this.section = P.p.getConfig().getConfigurationSection("fwarp-gui");
}
@Override
public void build() {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f warp GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return;
}
// Build basic Inventory info
guiSize = section.getInt("rows", 3);
if (guiSize > 6) {
guiSize = 6;
P.p.log(Level.INFO, "Warp GUI size out of bounds, defaulting to 6");
}
guiSize *= 9;
String guiName = ChatColor.translateAlternateColorCodes('&', section.getString("name", "FactionPermissions"));
warpGUI = Bukkit.createInventory(this, guiSize, guiName);
maxWarps = P.p.getConfig().getInt("max-warps", 5);
Set<String> factionWarps = fme.getFaction().getWarps().keySet();
List<Integer> warpOpenSlots = section.getIntegerList("warp-slots");
buildDummyItems();
if (maxWarps != warpOpenSlots.size()) {
P.p.log(Level.SEVERE, "Invalid warp slots for GUI, Please use same value as max warps");
return;
}
int warpSlotIndex = 0;
for (String warp : factionWarps) {
warpSlots.put(warpOpenSlots.get(warpSlotIndex), warp);
warpSlotIndex++;
}
buildItems();
}
@Override
public Inventory getInventory() {
return warpGUI;
}
private void buildItems() {
for (Map.Entry<Integer, String> entry : warpSlots.entrySet()) {
warpGUI.setItem(entry.getKey(), buildItem(entry.getValue()));
}
}
@Override
public void onClick(int slot, ClickType action) {
if (warpSlots.containsKey(slot)) {
fme.getPlayer().closeInventory();
// All clear lets TP them or ask for password
String warp = warpSlots.get(slot);
if (!fme.getFaction().hasWarpPassword(warp)) {
if (transact(fme)) {
doWarmup(warp);
}
} else {
fme.setEnteringPassword(true, warp);
fme.msg(TL.COMMAND_FWARP_PASSWORD_REQUIRED);
Bukkit.getScheduler().runTaskLater(P.p, () -> {
if (fme.isEnteringPassword()) {
fme.msg(TL.COMMAND_FWARP_PASSWORD_TIMEOUT);
fme.setEnteringPassword(false, "");
}
}, P.p.getConfig().getInt("fwarp-gui.password-timeout", 5) * 20);
}
}
}
private void doWarmup(final String warp) {
WarmUpUtil.process(fme, WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warp, () -> {
Player player = Bukkit.getPlayer(fme.getPlayer().getUniqueId());
if (player != null) {
player.teleport(fme.getFaction().getWarp(warp).getLocation());
fme.msg(TL.COMMAND_FWARP_WARPED, warp);
}
}, P.p.getConfig().getLong("warmups.f-warp", 0));
}
private boolean transact(FPlayer player) {
if (!P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing()) {
return true;
}
double cost = P.p.getConfig().getDouble("warp-cost.warp", 5);
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) {
return true;
}
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.modifyMoney(fme.getFaction(), -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
} else {
return Econ.modifyMoney(fme, -cost, TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
}
}
private ItemStack buildItem(String warp) {
ConfigurationSection warpItemSection = section.getConfigurationSection("warp-item");
if (warpItemSection == null) {
P.p.log(Level.WARNING, "Attempted to build f warp GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
String displayName = replacePlaceholers(warpItemSection.getString("name"), warp, fme.getFaction());
List<String> lore = new ArrayList<>();
if (warpItemSection.getString("material") == null) {
return null;
}
Material material = XMaterial.matchXMaterial("material").parseMaterial();
if (material == null) {
material = Material.STONE;
}
ItemStack item = new ItemStack(material);
ItemMeta itemMeta = item.getItemMeta();
for (String loreLine : warpItemSection.getStringList("lore")) {
lore.add(replacePlaceholers(loreLine, warp, fme.getFaction()));
}
itemMeta.setDisplayName(displayName);
itemMeta.setLore(lore);
item.setItemMeta(itemMeta);
return item;
}
private String replacePlaceholers(String string, String warp, Faction faction) {
string = ChatColor.translateAlternateColorCodes('&', string);
string = string.replace("{warp}", warp);
string = string.replace("{warp-protected}", faction.hasWarpPassword(warp) ? "Enabled" : "Disabled");
string = string.replace("{warp-cost}", !P.p.getConfig().getBoolean("warp-cost.enabled", false) ? "Disabled" : Integer.toString(P.p.getConfig().getInt("warp-cost.warp", 5)));
return string;
}
private void buildDummyItems() {
for (String key : section.getConfigurationSection("dummy-slots").getKeys(false)) {
int dummyId;
try {
dummyId = Integer.parseInt(key);
} catch (NumberFormatException exception) {
P.p.log(Level.WARNING, "Invalid dummy item id: " + key.toUpperCase());
continue;
}
ItemStack dummyItem = buildDummyItem(dummyId);
if (dummyItem == null) {
continue;
}
List<Integer> dummyIdSlots = section.getIntegerList("dummy-slots." + key);
for (Integer slot : dummyIdSlots) {
if (slot + 1 > guiSize || slot < 0) {
P.p.log(Level.WARNING, "Invalid slot: " + slot + " for dummy item: " + key);
continue;
}
dummySlots.add(slot);
warpGUI.setItem(slot, dummyItem);
}
}
}
private ItemStack buildDummyItem(int id) {
final ConfigurationSection dummySection = section.getConfigurationSection("dummy-items." + id);
if (dummySection == null) {
P.p.log(Level.WARNING, "Attempted to build f warp GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
Material material = Material.matchMaterial(dummySection.getString("material", ""));
if (material == null) {
P.p.log(Level.WARNING, "Invalid material for dummy item: " + id);
return null;
}
ItemStack itemStack = new ItemStack(material);
DyeColor color;
try {
color = DyeColor.valueOf(dummySection.getString("color", ""));
} catch (Exception exception) {
color = null;
}
if (color != null) {
itemStack.setDurability(color.getWoolData());
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (!P.p.mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
List<String> lore = new ArrayList<>();
for (String loreLine : dummySection.getStringList("lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
}
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}

View File

@ -2,19 +2,15 @@ package com.massivecraft.factions.zcore.fperms;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.util.Placeholder;
import com.massivecraft.factions.util.XMaterial;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
public enum PermissableAction {
BAN("ban"),
@ -67,6 +63,8 @@ public enum PermissableAction {
return null;
}
public int getSlot() { return P.p.getConfig().getInt("fperm-gui.action.slots." + this.name.toLowerCase()); }
public static Map<PermissableAction, Access> fromDefaults(DefaultPermissions defaultPermissions) {
Map<PermissableAction, Access> defaultMap = new HashMap<>();
for (PermissableAction permissableAction : PermissableAction.values()) {
@ -89,93 +87,28 @@ public enum PermissableAction {
return name;
}
// Utility method to build items for F Perm GUI
public ItemStack buildItem(FPlayer fme, Permissable permissable) {
final ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.action");
public ItemStack buildAsset(FPlayer fme, Permissable perm) {
ConfigurationSection section = P.p.getConfig().getConfigurationSection("fperm-gui.action");
ItemStack item = XMaterial.matchXMaterial(section.getString("Materials." + this.name)).parseItem();
ItemMeta meta = item.getItemMeta();
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
meta.setDisplayName(P.p.color(section.getString("placeholder-item.name").replace("{action}", this.name)));
List<String> lore = section.getStringList("placeholder-item.lore");
String displayName = replacePlaceholders(section.getString("placeholder-item.name"), fme, permissable);
List<String> lore = new ArrayList<>();
if (section.getString("materials." + name().toLowerCase().replace('_', '-')) == null) return null;
Material material = XMaterial.matchXMaterial(section.getString("materials." + name().toLowerCase().replace('_', '-'))).parseMaterial();
Access access = fme.getFaction().getAccess(permissable, this);
if (access == null) access = Access.UNDEFINED;
ItemStack item = new ItemStack(material);
ItemMeta itemMeta = item.getItemMeta();
String accessValue = null;
switch (access) {
case ALLOW:
accessValue = "allow";
break;
case DENY:
accessValue = "deny";
break;
case UNDEFINED:
accessValue = "undefined";
break;
}
// If under the 1.13 version we will use the colorable option.
if (!P.p.mc113 && !P.p.mc114) {
//TODO see if it's working in other version than 1.13 and 1.14
DyeColor dyeColor = null;
try {
dyeColor = DyeColor.valueOf(section.getString("access." + access.name().toLowerCase()));
} catch (Exception exception) {
}
accessValue = "deny";
if (dyeColor != null) {
item.setDurability(dyeColor.getWoolData());
}
} else {
Material mat = XMaterial.CYAN_GLAZED_TERRACOTTA.parseMaterial();
switch (accessValue) {
case "deny": mat = XMaterial.RED_GLAZED_TERRACOTTA.parseMaterial(); break;
case "allow": mat = XMaterial.GREEN_GLAZED_TERRACOTTA.parseMaterial(); break;
case "undefined": mat = XMaterial.CYAN_GLAZED_TERRACOTTA.parseMaterial(); break;
}
item.setType(mat);
}
for (String loreLine : section.getStringList("placeholder-item.lore")) lore.add(replacePlaceholders(loreLine, fme, permissable));
if (!P.p.mc17) itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
itemMeta.setDisplayName(displayName);
itemMeta.setLore(lore);
item.setItemMeta(itemMeta);
lore = P.p.replacePlaceholders(lore,
new Placeholder("{action-access-color}", fme.getFaction().getPermissions().get(perm).get(this).getColor()),
new Placeholder("{action-access}", fme.getFaction().getPermissions().get(perm).get(this).getName()));
meta.setLore(P.p.colorList(lore));
item.setItemMeta(meta);
return item;
}
public String replacePlaceholders(String string, FPlayer fme, Permissable permissable) {
// Run Permissable placeholders
string = permissable.replacePlaceholders(string);
String actionName = name.substring(0, 1).toUpperCase() + name.substring(1);
string = string.replace("{action}", actionName);
Access access = fme.getFaction().getAccess(permissable, this);
if (access == null) {
access = Access.UNDEFINED;
public static PermissableAction fromSlot(int slot) {
for (PermissableAction action : PermissableAction.values()) {
if (action.getSlot() == slot) return action;
}
String actionAccess = access.getName();
string = string.replace("{action-access}", actionAccess);
string = string.replace("{action-access-color}", access.getColor().toString());
return string;
return null;
}
}
}

View File

@ -0,0 +1,105 @@
package com.massivecraft.factions.zcore.fperms.gui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class PermissableActionFrame {
private Gui gui;
private ConfigurationSection section;
public PermissableActionFrame(Faction f) {
section = P.p.getConfig().getConfigurationSection("fperm-gui.action");
gui = new Gui(P.p,
section.getInt("rows", 3),
P.p.color(P.p.getConfig().getString("fperm-gui.action.name").replace("{faction}", f.getTag())));
}
public void buildGUI(FPlayer fplayer, Permissable perm) {
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
List<GuiItem> GUIItems = new ArrayList<>();
ItemStack dumby = buildDummyItem();
// Fill background of GUI with dumbyitem & replace GUI assets after
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dumby, e -> e.setCancelled(true)));
for (PermissableAction action : PermissableAction.values()) {
if (action.getSlot() == -1) continue;
GUIItems.set(action.getSlot(), new GuiItem(action.buildAsset(fplayer, perm), e -> {
e.setCancelled(true);
if (PermissableAction.fromSlot(e.getSlot()) == action) {
Access access;
boolean success = false;
switch (e.getClick()) {
case LEFT:
access = Access.ALLOW;
success = fplayer.getFaction().setPermission(perm, action, access);
break;
case RIGHT:
access = Access.DENY;
success = fplayer.getFaction().setPermission(perm, action, access);
break;
case MIDDLE:
access = Access.UNDEFINED;
success = fplayer.getFaction().setPermission(perm, action, access);
break;
default:
return;
}
if (success) fplayer.msg(TL.COMMAND_PERM_SET, action.name(), access.name(), perm.name());
else fplayer.msg(TL.COMMAND_PERM_LOCKED);
P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), action.name(), access.name(), perm.name()) + " for faction " + fplayer.getTag());
// Closing and opening resets the cursor.
// fplayer.getPlayer().closeInventory();
buildGUI(fplayer, perm);
}
}));
}
GUIItems.set(P.p.getConfig().getInt("fperm-gui.action.slots.back"), new GuiItem(buildBackItem(), event -> {
event.setCancelled(true);
// Closing and opening resets the cursor.
// fplayer.getPlayer().closeInventory();
new PermissableRelationFrame(fplayer.getFaction()).buildGUI(fplayer);
}));
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fplayer.getPlayer());
}
private ItemStack buildDummyItem() {
ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
meta.setLore(P.p.colorList(config.getStringList("Lore")));
meta.setDisplayName(P.p.color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
private ItemStack buildBackItem() {
ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.back-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
meta.setLore(P.p.colorList(config.getStringList("Lore")));
meta.setDisplayName(P.p.color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
}

View File

@ -1,315 +0,0 @@
package com.massivecraft.factions.zcore.fperms.gui;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.logging.Level;
public class PermissableActionGUI implements InventoryHolder, FactionGUI {
private final ConfigurationSection section;
private Inventory actionGUI;
private FPlayer fme;
private int guiSize;
private Permissable permissable;
private HashMap<Integer, PermissableAction> actionSlots = new HashMap<>();
private HashMap<Integer, SpecialItem> specialSlots = new HashMap<>();
private ArrayList<Integer> usedDummySlots = new ArrayList<>();
public PermissableActionGUI(FPlayer fme, Permissable permissable) {
this.fme = fme;
this.permissable = permissable;
this.section = P.p.getConfig().getConfigurationSection("fperm-gui.action");
}
public void build() {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return;
}
guiSize = section.getInt("rows", 3);
if (guiSize > 6) {
guiSize = 6;
P.p.log(Level.INFO, "Action GUI size out of bounds, defaulting to 6");
}
guiSize *= 9;
String guiName = ChatColor.translateAlternateColorCodes('&', section.getString("name", "FactionPerms"));
actionGUI = Bukkit.createInventory(this, guiSize, guiName);
boolean disabled = false;
for (String key : section.getConfigurationSection("slots").getKeys(false)) {
int slot = section.getInt("slots." + key);
if (slot == -1) {
disabled = true;
continue;
}
if (slot + 1 > guiSize || slot < 0) {
P.p.log(Level.WARNING, "Invalid slot for: " + key.toUpperCase());
continue;
}
if (SpecialItem.isSpecial(key)) {
specialSlots.put(slot, SpecialItem.fromString(key));
continue;
}
PermissableAction permissableAction = PermissableAction.fromString(key.toUpperCase().replace('-', '_'));
if (permissableAction == null) {
P.p.log(Level.WARNING, "Invalid permissable action: " + key.toUpperCase());
continue;
}
actionSlots.put(section.getInt("slots." + key), permissableAction);
}
buildDummyItems();
if (actionSlots.values().toArray().length != PermissableAction.values().length) {
// Missing actions add them forcefully to the GUI and log error
Set<PermissableAction> missingActions = new HashSet<>(Arrays.asList(PermissableAction.values()));
missingActions.removeAll(actionSlots.values());
for (PermissableAction action : missingActions) {
if (disabled) {
break;
}
if (!usedDummySlots.isEmpty()) {
int slot = usedDummySlots.get(0);
actionSlots.put(slot, action);
} else {
int slot = actionGUI.firstEmpty();
if (slot != -1) {
actionSlots.put(slot, action);
}
}
P.p.log(Level.WARNING, "Missing action: " + action.name());
}
}
buildSpecialItems();
buildItems();
}
@Override
public Inventory getInventory() {
return actionGUI;
}
@Override
public void onClick(int slot, ClickType click) {
if (specialSlots.containsKey(slot)) {
if (specialSlots.get(slot) == SpecialItem.BACK) {
PermissableRelationGUI relationGUI = new PermissableRelationGUI(fme);
relationGUI.build();
fme.getPlayer().openInventory(relationGUI.getInventory());
}
return;
}
if (!actionSlots.containsKey(slot)) {
return;
}
PermissableAction action = actionSlots.get(slot);
Access access;
if (click == ClickType.LEFT) {
access = Access.ALLOW;
fme.getFaction().setPermission(permissable, action, access);
} else if (click == ClickType.RIGHT) {
access = Access.DENY;
fme.getFaction().setPermission(permissable, action, access);
} else if (click == ClickType.MIDDLE) {
access = Access.UNDEFINED;
fme.getFaction().setPermission(permissable, action, access);
} else {
return;
}
actionGUI.setItem(slot, action.buildItem(fme, permissable));
fme.msg(TL.COMMAND_PERM_SET, action.name(), access.name(), permissable.name());
P.p.log(String.format(TL.COMMAND_PERM_SET.toString(), action.name(), access.name(), permissable.name()) + " for faction " + fme.getTag());
}
private void buildItems() {
for (Map.Entry<Integer, PermissableAction> entry : actionSlots.entrySet()) {
PermissableAction permissableAction = entry.getValue();
ItemStack item = permissableAction.buildItem(fme, permissable);
if (item == null) {
P.p.log(Level.WARNING, "Invalid item for: " + permissableAction.toString().toUpperCase());
continue;
}
actionGUI.setItem(entry.getKey(), item);
}
}
private void buildSpecialItems() {
for (Map.Entry<Integer, SpecialItem> entry : specialSlots.entrySet()) {
actionGUI.setItem(entry.getKey(), getSpecialItem(entry.getValue()));
}
}
private ItemStack getSpecialItem(SpecialItem specialItem) {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
switch (specialItem) {
case RELATION:
return permissable.buildItem();
case BACK:
ConfigurationSection backButtonConfig = P.p.getConfig().getConfigurationSection("fperm-gui.back-item");
ItemStack backButton = new ItemStack(XMaterial.matchXMaterial(backButtonConfig.getString("material")).parseItem());
ItemMeta backButtonMeta = backButton.getItemMeta();
backButtonMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', backButtonConfig.getString("name")));
List<String> lore = new ArrayList<>();
for (String loreLine : backButtonConfig.getStringList("lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
}
backButtonMeta.setLore(lore);
if (!P.p.mc17) {
backButtonMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
backButton.setItemMeta(backButtonMeta);
return backButton;
default:
return null;
}
}
private void buildDummyItems() {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return;
}
for (String key : section.getConfigurationSection("dummy-items").getKeys(false)) {
int dummyId;
try {
dummyId = Integer.parseInt(key);
} catch (NumberFormatException exception) {
P.p.log(Level.WARNING, "Invalid dummy item id: " + key.toUpperCase());
continue;
}
ItemStack dummyItem = buildDummyItem(dummyId);
if (dummyItem == null) {
continue;
}
ItemMeta meta = dummyItem.getItemMeta();
if (!P.p.mc17) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
dummyItem.setItemMeta(meta);
List<Integer> dummySlots = section.getIntegerList("dummy-items." + key);
for (Integer slot : dummySlots) {
if (slot + 1 > guiSize || slot < 0) {
P.p.log(Level.WARNING, "Invalid slot: " + slot + " for dummy item: " + key);
continue;
}
usedDummySlots.add(slot);
actionGUI.setItem(slot, dummyItem);
}
}
}
private ItemStack buildDummyItem(int id) {
final ConfigurationSection dummySection = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-items." + id);
if (dummySection == null) {
P.p.log(Level.WARNING, "Attempted to build dummy items for F PERM GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
Material material = XMaterial.matchXMaterial(dummySection.getString("material", "")).parseMaterial();
if (material == null) {
P.p.log(Level.WARNING, "Invalid material for dummy item: " + id);
return null;
}
ItemStack itemStack = XMaterial.matchXMaterial(material).parseItem();
DyeColor color;
try {
color = DyeColor.valueOf(dummySection.getString("color", ""));
} catch (Exception exception) {
color = null;
}
if (color != null) {
itemStack.setDurability(color.getWoolData());
}
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
List<String> lore = new ArrayList<>();
for (String loreLine : dummySection.getStringList("lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
}
itemMeta.setLore(lore);
if (!P.p.mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public enum SpecialItem {
BACK,
RELATION;
static boolean isSpecial(String string) {
return fromString(string) != null;
}
static SpecialItem fromString(String string) {
for (SpecialItem specialItem : SpecialItem.values()) {
if (string.equalsIgnoreCase(specialItem.name())) {
return specialItem;
}
}
return null;
}
}
}

View File

@ -0,0 +1,80 @@
package com.massivecraft.factions.zcore.fperms.gui;
import com.github.stefvanschie.inventoryframework.Gui;
import com.github.stefvanschie.inventoryframework.GuiItem;
import com.github.stefvanschie.inventoryframework.pane.PaginatedPane;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.Permissable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
public class PermissableRelationFrame {
private Gui gui;
private ConfigurationSection section;
public PermissableRelationFrame(Faction f) {
section = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
gui = new Gui(P.p,
section.getInt("rows", 3),
P.p.color(P.p.getConfig().getString("fperm-gui.relation.name").replace("{faction}", f.getTag())));
}
public void buildGUI(FPlayer fplayer) {
PaginatedPane pane = new PaginatedPane(0, 0, 9, gui.getRows());
List<GuiItem> GUIItems = new ArrayList<>();
ItemStack dumby = buildDummyItem();
// Fill background of GUI with dumbyitem & replace GUI assets after
for (int x = 0; x <= (gui.getRows() * 9) - 1; x++) GUIItems.add(new GuiItem(dumby, e -> e.setCancelled(true)));
ConfigurationSection sec = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
for (String key : sec.getConfigurationSection("slots").getKeys(false)) {
GUIItems.set(sec.getInt("slots." + key), new GuiItem(buildAsset("fperm-gui.relation.materials." + key, key), e -> {
e.setCancelled(true);
// Closing and opening resets the cursor.
// e.getWhoClicked().closeInventory();
new PermissableActionFrame(fplayer.getFaction()).buildGUI(fplayer, getPermissable(key));
}));
}
pane.populateWithGuiItems(GUIItems);
gui.addPane(pane);
gui.update();
gui.show(fplayer.getPlayer());
}
private ItemStack buildAsset(String loc, String relation) {
ItemStack item = XMaterial.matchXMaterial(P.p.getConfig().getString(loc)).parseItem();
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(P.p.color(P.p.getConfig().getString("fperm-gui.relation.Placeholder-Item.Name").replace("{relation}", relation)));
item.setItemMeta(meta);
return item;
}
private ItemStack buildDummyItem() {
ConfigurationSection config = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-item");
ItemStack item = XMaterial.matchXMaterial(config.getString("Type")).parseItem();
ItemMeta meta = item.getItemMeta();
meta.setLore(P.p.colorList(config.getStringList("Lore")));
meta.setDisplayName(P.p.color(config.getString("Name")));
item.setItemMeta(meta);
return item;
}
private Permissable getPermissable(String name) {
if (Role.fromString(name.toUpperCase()) != null) {
return Role.fromString(name.toUpperCase());
} else if (Relation.fromString(name.toUpperCase()) != null) {
return Relation.fromString(name.toUpperCase());
} else {
return null;
}
}
}

View File

@ -1,209 +0,0 @@
package com.massivecraft.factions.zcore.fperms.gui;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.zcore.fperms.Permissable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
public class PermissableRelationGUI implements InventoryHolder, FactionGUI {
private final ConfigurationSection section;
private Inventory relationGUI;
private FPlayer fme;
private int guiSize;
private HashMap<Integer, Permissable> relationSlots = new HashMap<>();
public PermissableRelationGUI(FPlayer fme) {
this.fme = fme;
this.section = P.p.getConfig().getConfigurationSection("fperm-gui.relation");
}
public void build() {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return;
}
// Build basic Inventory info
guiSize = section.getInt("rows", 3);
if (guiSize > 5) {
guiSize = 5;
P.p.log(Level.INFO, "Relation GUI size out of bounds, defaulting to 5");
}
guiSize *= 9;
String guiName = ChatColor.translateAlternateColorCodes('&', section.getString("name", "FactionPermissions"));
relationGUI = Bukkit.createInventory(this, guiSize, guiName);
for (String key : section.getConfigurationSection("slots").getKeys(false)) {
int slot = section.getInt("slots." + key);
if (slot == -1) {
continue;
}
if (slot + 1 > guiSize && slot > 0) {
P.p.log(Level.WARNING, "Invalid slot of " + key.toUpperCase() + " in relation GUI skipping it");
continue;
}
if (getPermissable(key) == null) {
P.p.log(Level.WARNING, "Invalid permissable " + key.toUpperCase() + " skipping it");
continue;
}
relationSlots.put(slot, getPermissable(key));
}
buildDummyItems();
buildItems();
}
@Override
public Inventory getInventory() {
return relationGUI;
}
@Override
public void onClick(int slot, ClickType clickType) {
if (!relationSlots.containsKey(slot)) {
return;
}
PermissableActionGUI actionGUI = new PermissableActionGUI(fme, relationSlots.get(slot));
actionGUI.build();
fme.getPlayer().openInventory(actionGUI.getInventory());
}
private Permissable getPermissable(String name) {
if (Role.fromString(name.toUpperCase()) != null) {
return Role.fromString(name.toUpperCase());
} else if (Relation.fromString(name.toUpperCase()) != null) {
return Relation.fromString(name.toUpperCase());
} else {
return null;
}
}
private void buildItems() {
for (Map.Entry<Integer, Permissable> entry : relationSlots.entrySet()) {
Permissable permissable = entry.getValue();
ItemStack item = permissable.buildItem();
if (item == null) {
P.p.log(Level.WARNING, "Invalid material for " + permissable.toString().toUpperCase() + " skipping it");
continue;
}
relationGUI.setItem(entry.getKey(), item);
}
}
private void buildDummyItems() {
if (section == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return;
}
for (String key : section.getConfigurationSection("dummy-items").getKeys(false)) {
int dummyId;
try {
dummyId = Integer.parseInt(key);
} catch (NumberFormatException exception) {
P.p.log(Level.WARNING, "Invalid dummy item id: " + key.toUpperCase());
continue;
}
ItemStack dummyItem = buildDummyItem(dummyId);
if (dummyItem == null) {
continue;
}
ItemMeta meta = dummyItem.getItemMeta();
if (!P.p.mc17) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
dummyItem.setItemMeta(meta);
List<Integer> dummySlots = section.getIntegerList("dummy-items." + key);
for (Integer slot : dummySlots) {
if (slot + 1 > guiSize || slot < 0) {
P.p.log(Level.WARNING, "Invalid slot: " + slot + " for dummy item: " + key);
continue;
}
relationGUI.setItem(slot, dummyItem);
}
}
}
private ItemStack buildDummyItem(int id) {
final ConfigurationSection dummySection = P.p.getConfig().getConfigurationSection("fperm-gui.dummy-items." + id);
if (dummySection == null) {
P.p.log(Level.WARNING, "Attempted to build f perm GUI but config section not present.");
P.p.log(Level.WARNING, "Copy your config, allow the section to generate, then copy it back to your old config.");
return new ItemStack(Material.AIR);
}
Material material = Material.matchMaterial(dummySection.getString("material", ""));
if (material == null) {
P.p.log(Level.WARNING, "Invalid material for dummy item: " + id);
return null;
}
ItemStack itemStack = new ItemStack(material);
DyeColor color;
try {
color = DyeColor.valueOf(dummySection.getString("color", ""));
} catch (Exception exception) {
color = null;
}
if (color != null) {
itemStack.setDurability(color.getWoolData());
}
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dummySection.getString("name", " ")));
List<String> lore = new ArrayList<>();
for (String loreLine : dummySection.getStringList("lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreLine));
}
itemMeta.setLore(lore);
if (!P.p.mc17) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_ATTRIBUTES);
}
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}

View File

@ -680,13 +680,12 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return Access.UNDEFINED;
}
public void setPermission(Permissable permissable, PermissableAction permissableAction, Access access) {
public boolean setPermission(Permissable permissable, PermissableAction permissableAction, Access access) {
if (Conf.useLockedPermissions && Conf.lockedPermissions.contains(permissableAction)) return false;
Map<PermissableAction, Access> accessMap = permissions.get(permissable);
if (accessMap == null) {
accessMap = new HashMap<>();
}
if (accessMap == null) accessMap = new HashMap<>();
accessMap.put(permissableAction, access);
return true;
}
public void resetPerms() {

View File

@ -549,6 +549,7 @@ public enum TL {
COMMAND_PERM_INVALID_ACTION("&c&l[!]&7 Invalid action defined. Try something like &c'build'"),
COMMAND_PERM_SET("&c&l[!]&7 Set permission&c %1$s &7to &c%2$s &7for relation&c %3$s"),
COMMAND_PERM_TOP("RCT MEM OFF ALLY TRUCE NEUT ENEMY"),
COMMAND_PERM_LOCKED("&cThis permission has been locked by the server"),
COMMAND_POINTS_FAILURE("&c&l[!] &c{faction} does not exist."),
COMMAND_POINTS_SUCCESSFUL("&c&l[!] &7You have added &e%1$s &7points to &b%2$s&7. &b%2$s's &7New Point Balance: &e%3$s"),

View File

@ -415,7 +415,6 @@ fperm-gui:
name: 'Faction Permissions'
# Amount of inventory rows, No larger than 5
rows: 4
# These are the slots where the relations are going to be placed on the first GUI
# Note: Slots start at 0 and end at one less that GUI size
#Setting a slot to -1 will disable it
@ -438,56 +437,43 @@ fperm-gui:
ally: GOLD_AXE
enemy: DIAMOND_AXE
neutral: WOOD_AXE
# Dummy items using the Items lower down
dummy-items:
'0':
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 11
- 13
- 15
- 17
- 20
- 22
- 24
- 26
- 17
- 18
- 19
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
# This is the item that all relation items are based off of
# Replacing {relation} with relation name eg: Moderator, Ally
# also replaces {relation-color} with relation color eg: Enemy;RED
placeholder-item:
name: '&8[{relation-color}{relation}&8]'
lore:
-
Placeholder-Item:
Name: '&cClick to edit {relation} permissions!'
action:
name: 'Faction Permissions'
rows: 6
# If this field exists colorable materials will be updated
# https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/DyeColor.html
access:
allow: LIME
deny: RED
undefined: CYAN
Access-Colors:
Allow: '&a'
Deny: '&c'
Undefined: '&7'
Materials:
build: COBBLESTONE
destroy: DIAMOND_PICKAXE
frostwalk: ICE
painbuild: ARROW
door: IRON_DOOR
button: OAK_BUTTON
lever: LEVER
container: CHEST
invite: NETHER_STAR
kick: DIAMOND_SWORD
items: PAPER
sethome: HOPPER
withdraw: SUNFLOWER
territory: SIGN
access: EMERALD
promote: DIAMOND
setwarp: COMPASS
warp: ENDER_PEARL
ban: ANVIL
disband: BARRIER
fly: FEATHER
vault: END_PORTAL_FRAME
tntbank: BEACON
tntfill: TNT
chest: ENDER_CHEST
spawner: MOB_SPAWNER
home: ENDER_EYE
slots:
# Uses same format as above to inform the player of clicked relation
relation: 4
@ -496,15 +482,15 @@ fperm-gui:
# Start action slots
build: 10
destroy: 11
frost-walk: 12
pain-build: 13
frostwalk: 12
painbuild: 13
door: 14
button: 15
lever: 16
container: 19
invite: 20
kick: 21
item: 22
items: 22
sethome: 23
withdraw: 24
territory: 25
@ -521,90 +507,6 @@ fperm-gui:
chest: 42
spawner: 38
home: 49
# Material to show, if the material is colorable eg: Wool, Stained Clay it will update with it's access color
materials:
# This is important to change, depending on what you use. If you use clay, make it clay, if its glass make it glass.
default: STAINED_GLASS
# These below are for different actual permissions.
build: STAINED_GLASS
destroy: STAINED_GLASS
frost-walk: STAINED_GLASS
pain-build: STAINED_GLASS
door: STAINED_GLASS
button: STAINED_GLASS
lever: STAINED_GLASS
container: STAINED_GLASS
invite: STAINED_GLASS
kick: STAINED_GLASS
item: STAINED_GLASS
sethome: STAINED_GLASS
withdraw: STAINED_GLASS
territory: STAINED_GLASS
access: STAINED_GLASS
promote: STAINED_GLASS
setwarp: STAINED_GLASS
warp: STAINED_GLASS
ban: STAINED_GLASS
disband: STAINED_GLASS
fly: STAINED_GLASS
vault: STAINED_GLASS
tntbank: STAINED_GLASS
tntfill: STAINED_GLASS
chest: STAINED_GLASS
spawner: STAINED_GLASS
home: STAINED_GLASS
# Same dummy items format as above
dummy-items:
'0':
- 1
- 2
- 3
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 10
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
# {action} Action name eg: Setwarp, Kick
# {action-access} Access name eg: Allow, Deny
# {action-access-color} Access color eg: Allow;GREEN
@ -619,20 +521,16 @@ fperm-gui:
- '&7Middle click to &7&nUndefine&7.'
# Back item will be take you to the previous GUI
back-item:
name: '&c&l<- Back'
material: ARROW
Type: ARROW
Name: '&c&l<- Back'
lore:
- '&7Click to return to previous menu.'
# Dummy Items
dummy-items:
# Dummy Item id, used to set the slots above
'0':
material: STAINED_GLASS_PANE
# Color will only work on colorable materials
color: BLACK
name: ' '
lore:
-
dummy-item:
Type: BLACK_STAINED_GLASS_PANE
Name: ' '
Lore:
- ' '
############################################################
# +------------------------------------------------------+ #
@ -650,53 +548,24 @@ fwarp-gui:
- 13
- 14
- 15
dummy-slots:
'0':
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
warp-item:
material: EYE_OF_ENDER
name: "&e&l(!) &eFaction Warp: &6&n{warp}"
Type: EYE_OF_ENDER
Name: '&e&l(!) &eFaction Warp: &6&n{warp}'
# {warp-protected} Warp protection by password, Enabled & Disabled
# {warp-cost} Warp cost
lore:
- ""
- "&6&l * &ePassword: &7{warp-protected}"
- "&6&l * &eCost: &7{warp-cost}"
- ""
- "&c&lNote: &7You need pay to teleport to"
- "&7a faction warp. Unless it's &nDisabled&7."
Lore:
- ''
- '&6&l * &ePassword: &7{warp-protected}'
- '&6&l * &eCost: &7{warp-cost}'
- ''
- '&c&lNote: &7You need pay to teleport to'
- '&7a faction warp. Unless it''s &nDisabled&7.'
# Dummy Items
dummy-items:
# Dummy Item id, used to set the slots above
'0':
material: STAINED_GLASS_PANE
# Color will only work on colorable materials
color: BLACK
name: ' '
lore:
-
dummy-item:
Type: BLACK_STAINED_GLASS_PANE
Name: ' '
Lore:
- ' '
############################################################
# +------------------------------------------------------+ #
# | Faction Creation/Disband Broadcast | #