diff --git a/nPermissions/.classpath b/nPermissions/.classpath
new file mode 100644
index 0000000..4818a81
--- /dev/null
+++ b/nPermissions/.classpath
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nPermissions/.project b/nPermissions/.project
new file mode 100644
index 0000000..41130d9
--- /dev/null
+++ b/nPermissions/.project
@@ -0,0 +1,17 @@
+
+
+ nPermissions
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/nPermissions/src/config.yml b/nPermissions/src/config.yml
new file mode 100644
index 0000000..3b25f94
--- /dev/null
+++ b/nPermissions/src/config.yml
@@ -0,0 +1,15 @@
+DATABASE:
+ MONGO:
+ HOST: "127.0.0.1"
+ PORT: 27017
+ AUTHENTICATION:
+ ENABLED: FALSE
+ DATABASE: "permissions"
+ USER: "user"
+ PASSWORD: "password"
+ REDIS:
+ HOST: "127.0.0.1"
+ PORT: 6379
+ AUTHENTICATION:
+ ENABLED: FALSE
+ PASSWORD: "password"
diff --git a/nPermissions/src/plugin.yml b/nPermissions/src/plugin.yml
new file mode 100644
index 0000000..0b4801e
--- /dev/null
+++ b/nPermissions/src/plugin.yml
@@ -0,0 +1,4 @@
+name: "Hydrogen"
+version: "${project.version}"
+author: "AMGeneral and Emilio"
+main: "us.centile.permissions.nPermissions"
\ No newline at end of file
diff --git a/nPermissions/src/ranks.yml b/nPermissions/src/ranks.yml
new file mode 100644
index 0000000..47cb419
--- /dev/null
+++ b/nPermissions/src/ranks.yml
@@ -0,0 +1,354 @@
+DEFAULT:
+ NAME: "Default"
+ PREFIX: "&f"
+ DEFAULT: TRUE
+ PERMISSIONS:
+ - chestcommands.open.ranks.yml
+ - deluxemenus.open
+ - crazyauctions.access
+ - crazyauctions.sell.10
+ - crazyauctions.sell
+ - pkm.kill.reward
+ - nte.noob
+ - -minecraft:me
+ - -bukkit:me
+ - -bukkit:?
+ - -essentials.sell
+ - -essentials.sellhand
+ - -essentials.sell.hand
+ - -essentials.mail
+ - -essentials.seen
+ - -essentials.back
+ - essentials.back
+ - essentials.balance
+ - essentials.balance.others
+ - backpack.use
+ - backpack.KeepOnDeath
+ - treasurechest.access.treasure
+ - essentials.balancetop
+ - essentials.build
+ - essentials.compass
+ - essentials.delhome
+ - essentials.geoip.show
+ - essentials.getpos
+ - essentials.help
+ - essentials.helpop
+ - essentials.home.others
+ - essentials.ignore
+ - essentials.info
+ - essentials.itemdb
+ - essentials.kit
+ - essentials.kits.bonus
+ - essentials.mail
+ - essentials.mail.send
+ - essentials.motd
+ - essentials.msg
+ - essentials.near
+ - essentials.pay
+ - essentials.ping
+ - essentials.protect
+ - essentials.r
+ - essentials.realname
+ - essentials.sell
+ - essentials.sethome.multiple.Default
+ - essentials.setxmpp
+ - essentials.signs.break.protection
+ - essentials.signs.break.trade
+ - essentials.signs.create.protection
+ - essentials.signs.create.trade
+ - essentials.signs.use.balance
+ - essentials.signs.use.buy
+ - essentials.signs.use.disposal
+ - essentials.signs.use.enchant
+ - essentials.signs.use.free
+ - essentials.signs.use.heal
+ - essentials.signs.use.info
+ - essentials.signs.use.kit
+ - essentials.signs.use.repair
+ - essentials.signs.use.sell
+ - essentials.signs.use.trade
+ - essentials.signs.use.warp
+ - essentials.spawn
+ - essentials.spawner
+ - essentials.suicide
+ - essentials.time
+ - essentials.tpa
+ - essentials.tpaccept
+ - essentials.tpahere
+ - essentials.tpdeny
+ - essentials.tps
+ - essentials.warp
+ - essentials.kit
+ - essentials.kits
+ - essentials.warp.*
+ - essentials.warp.list
+ - essentials.warps
+ - essentials.warps.*
+ - essentials.warps.list
+ - essentialsa.itemdb
+ - playervaults.amount.2
+ - playervaults.signs.bypass
+ - playervaults.signs.use
+ - playervaults.size.6
+ - skinsrestorer.playercmds
+ - essentials.kits.noob
+ - headdb.allow.buy
+ - headdb.category.*
+ - headdb.open
+ - playtime.check
+ - custom.help.use
+ - dailyspin.open
+ - auction.limit.5
+ - shopguiplus.shop
+ - shopguiplus.shops
+ - shopguiplus.shops.*
+ - shopguiplus.shops.blocks
+ - shopguiplus.shops.farming
+ - shopguiplus.shops.food
+ - shopguiplus.shops.minerals
+ - shopguiplus.shops.misc
+ - shopguiplus.shops.potions
+ - shopguiplus.shops.tools
+ - chestcommands.open.donate.yml
+ - chestcommands.open.kits.yml
+ - chestcommands.open.drewards.yml
+ - chestcommands.open.warps.yml
+ - dr.claim
+ - bk.join
+ - bk.book
+ - custom.help.use
+ - kitspreview
+ - trading.trade
+ - deluxemenus.*
+ - Friends.ExtraFriends
+ - Friends.Use
+ - Friends.*
+ - -nte.noob
+ - nte.newbie
+ - essentials.kits.newbie
+HELPER:
+ NAME: "Helper"
+ PREFIX: "&8(&6Helper&8) &6"
+ INHERITANCE:
+ - DEFAULT
+ PERMISSIONS:
+ - nocheatplus.notify
+ - nametag.group.helper
+ - essentials.god
+ - chatcontrol.commands.clear
+ - chatcontrol.commands.mute
+ - chatcontrol.bypass
+ - chatcontrol.notify.ad
+ - essentials.afk
+ - essentials.back
+ - essentials.afk.auto
+ - essentials.chat.ignoreexempt
+ - essentials.feed
+ - essentials.fly
+ - essentials.godmode
+ - essentials.helpop.receive
+ - essentials.kick
+ - essentials.kick.notify
+ - essentials.mute
+ - essentials.mute.notify
+ - essentials.socialspy
+ - essentials.tp
+ - essentials.tphere
+ - essentials.tpohere
+ - essentials.tpo
+ - essentials.enderchest
+ - essentials.enderchest.others
+ - essentials.vanish
+ - essentials.socialspy
+ - nte.helper
+MOD:
+ NAME: "Mod"
+ PREFIX: "&8(&dMod&8) &d"
+ INHERITANCE:
+ - DEFAULT
+ - HELPER
+ PERMISSIONS:
+ - nocheatplus.notify
+ - nametag.group.mod
+ - essentials.speed
+ - essentials.warps.*
+ - essentials.god
+ - worldedit.*
+ - chatcontrol.bypass.mute
+ - essentials.ban
+ - essentials.fly
+ - essentials.invsee
+ - essentials.mute.offline
+ - essentials.seen.banreason
+ - essentials.tp
+ - plotme.admin.bypassdeny
+ - bukkit.command.gamemode
+ - bukkit.command.kick
+ - -essentials.spawner.enderdragon
+ - essentials.afk.kickexempt
+ - essentials.ban
+ - essentials.ban.notify
+ - essentials.banip
+ - essentials.broadcast
+ - essentials.chat.url
+ - essentials.chat.magic
+ - essentials.clearinventory
+ - essentials.delwarp
+ - essentials.eco.loan
+ - essentials.exp.others
+ - essentials.ext
+ - essentials.fly
+ - essentials.getpos
+ - essentials.getpos.others
+ - essentials.helpop.recieve
+ - essentials.home.others
+ - essentials.invsee
+ - essentials.jails
+ - essentials.jump
+ - essentials.kick
+ - essentials.kick.notify
+ - essentials.kill
+ - essentials.kit.*
+ - essentials.msg.magic
+ - essentials.mute
+ - essentials.nick.color
+ - essentials.nick.others
+ - essentials.realname
+ - essentials.seen.banreason
+ - essentials.seen.extra
+ - essentials.setwarp
+ - essentials.signs.create.*
+ - essentials.signs.break.*
+ - essentials.spawner
+ - essentials.spawner.*
+ - essentials.thunder
+ - essentials.time
+ - essentials.time.set
+ - essentials.protect.alerts
+ - essentials.protect.admin
+ - essentials.protect.ownerinfo
+ - essentials.ptime
+ - essentials.ptime.others
+ - essentials.togglejail
+ - essentials.top
+ - essentials.tp
+ - essentials.tp.others
+ - essentials.tphere
+ - essentials.tppos
+ - essentials.tptoggle
+ - essentials.vanish
+ - essentials.warp.*
+ - essentials.weather
+ - essentials.whois
+ - essentials.workbench
+ - essentials.world
+ - essentials.world.*
+ - nte.mod
+SRMOD:
+ NAME: "SrMod"
+ PREFIX: "&8(&d&oSr Mod&8) &d"
+ INHERITANCE:
+ - DEFAULT
+ - MOD
+ - HELPER
+ PERMISSIONS:
+ - worldedit.*
+ - nocheatplus.notify
+ - nte.srmod
+ - essentials.invsee
+ - essentials.*
+ - essentials.ban
+ - essentials.feed
+ - essentials.fly
+ - essentials.gamemode
+ - essentials.god
+ - essentials.heal
+ - essentials.invsee.modify
+ - essentials.spawn
+ - essentials.tp
+ - playervaults.admin
+
+ADMIN:
+ NAME: "Admin"
+ PREFIX: "&8(&cAdmin&8) &c"
+ INHERITANCE:
+ - DEFAULT
+ - SRMOD
+ - MOD
+ - HELPER
+ PERMISSIONS:
+ - playervaults.*
+ - worldedit.*
+ - permissions.*
+ - essentials.*
+ - nte.admin
+SRADMIN:
+ NAME: "Sr Admin"
+ PREFIX: "&8(&c&oSr Admin&8) &c"
+ INHERITANCE:
+ - DEFAULT
+ - ADMIN
+ - SRMOD
+ - MOD
+ - HELPER
+ PERMISSIONS:
+ - pte.sradmin
+ - -nte.padmin
+ - -nte.owner
+ - -nte.manager
+ - '*'
+PADMIN:
+ NAME: "PlatAdmin"
+ PREFIX: "&8(&c&oPlat Admin&8) &c"
+ INHERITANCE:
+ - DEFAULT
+ - ADMIN
+ - SRMOD
+ - MOD
+ - HELPER
+ - SRADMIN
+ PERMISSIONS:
+ - nte.padmin
+ - -nte.owner
+ - -nte.manager
+ - '*'
+DEVELOPER:
+ NAME: "Developer"
+ PREFIX: "&7[&bDeveloper&7] &b"
+ INHERITANCE:
+ - DEFAULT
+ - SRADMIN
+ - ADMIN
+ - SRMOD
+ - MOD
+ - HELPER
+ PERMISSIONS:
+ - queue.priority.0
+MANAGER:
+ NAME: "Manager"
+ PREFIX: "&8(&4&oManager&8) &4"
+ INHERITANCE:
+ - DEFAULT
+ - SRADMIN
+ - ADMIN
+ - SRMOD
+ - MOD
+ - HELPER
+ PERMISSIONS:
+ - nte.manager
+ - -nte.owner
+ - '*'
+OWNER:
+ NAME: "Owner"
+ PREFIX: "&8(&4&oOwner&8) &4"
+ INHERITANCE:
+ - DEFAULT
+ - DEVELOPER
+ - SENIORADMIN
+ - ADMIN
+ - SENIORMOD
+ - MODERATOR
+ - HELPER
+ PERMISSIONS:
+ - '*'
+ - nte.owner
\ No newline at end of file
diff --git a/nPermissions/src/us/centile/permissions/grant/Grant.java b/nPermissions/src/us/centile/permissions/grant/Grant.java
new file mode 100644
index 0000000..bb39040
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/Grant.java
@@ -0,0 +1,86 @@
+package us.centile.permissions.grant;
+
+import us.centile.permissions.rank.*;
+import java.util.*;
+
+public class Grant
+{
+ private UUID issuer;
+ private UUID rankId;
+ private long dateAdded;
+ private long duration;
+ private String reason;
+ private boolean active;
+
+ public Grant(final UUID issuer, final Rank rank, final long dateAdded, final long duration, final String reason, final boolean active) {
+ this.issuer = issuer;
+ this.rankId = rank.getUuid();
+ this.dateAdded = dateAdded;
+ this.duration = duration;
+ this.reason = reason;
+ this.active = active;
+ }
+
+ public Rank getRank() {
+ Rank toReturn = Rank.getByUuid(this.rankId);
+ if (toReturn == null) {
+ this.active = false;
+ toReturn = new Rank(UUID.randomUUID(), new ArrayList(), new ArrayList(), new RankData("N/A"));
+ Rank.getRanks().remove(toReturn);
+ return toReturn;
+ }
+ return toReturn;
+ }
+
+ public boolean isExpired() {
+ return !this.active || System.currentTimeMillis() >= this.dateAdded + this.duration;
+ }
+
+ public UUID getIssuer() {
+ return this.issuer;
+ }
+
+ public void setIssuer(final UUID issuer) {
+ this.issuer = issuer;
+ }
+
+ public UUID getRankId() {
+ return this.rankId;
+ }
+
+ public void setRankId(final UUID rankId) {
+ this.rankId = rankId;
+ }
+
+ public long getDateAdded() {
+ return this.dateAdded;
+ }
+
+ public void setDateAdded(final long dateAdded) {
+ this.dateAdded = dateAdded;
+ }
+
+ public long getDuration() {
+ return this.duration;
+ }
+
+ public void setDuration(final long duration) {
+ this.duration = duration;
+ }
+
+ public String getReason() {
+ return this.reason;
+ }
+
+ public void setReason(final String reason) {
+ this.reason = reason;
+ }
+
+ public boolean isActive() {
+ return this.active;
+ }
+
+ public void setActive(final boolean active) {
+ this.active = active;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedure.java b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedure.java
new file mode 100644
index 0000000..96dc6d3
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedure.java
@@ -0,0 +1,77 @@
+package us.centile.permissions.grant.procedure;
+
+import us.centile.permissions.rank.*;
+import org.bukkit.inventory.*;
+import org.bukkit.*;
+import us.centile.permissions.util.*;
+import org.bukkit.entity.*;
+import java.util.*;
+
+public class GrantProcedure
+{
+ private static Set procedures;
+ private final GrantRecipient recipient;
+ private final UUID issuer;
+ private final GrantProcedureData data;
+
+ public GrantProcedure(final GrantRecipient recipient, final UUID issuer, final GrantProcedureData data) {
+ this.recipient = recipient;
+ this.issuer = issuer;
+ this.data = data;
+ GrantProcedure.procedures.add(this);
+ }
+
+ public Inventory getInventory() {
+ final int size = (int)Math.ceil(Rank.getRanks().size() / 9.0);
+ final Inventory inventory = Bukkit.createInventory((InventoryHolder)null, (size == 0) ? 9 : (size * 9), ChatColor.YELLOW + "" + ChatColor.BOLD + "Choose a Rank");
+ for (final Rank rank : Rank.getRanks()) {
+ if (rank.getData().isDefaultRank()) {
+ continue;
+ }
+ ChatColor color;
+ if (rank.getData().getPrefix().isEmpty()) {
+ color = ChatColor.WHITE;
+ }
+ else {
+ char code = 'f';
+ for (final String string : rank.getData().getPrefix().split("&")) {
+ if (!string.isEmpty() && ChatColor.getByChar(string.toCharArray()[0]) != null) {
+ code = string.toCharArray()[0];
+ }
+ }
+ color = ChatColor.getByChar(code);
+ }
+ inventory.addItem(new ItemStack[] { new ItemBuilder(Material.WOOL).durability(WoolUtil.convertChatColorToWoolData(color)).name(color + rank.getData().getName()).lore(Arrays.asList("&7&m------------------------------", "&9Click to grant &f" + this.getRecipient().getName() + "&9 the " + color + rank.getData().getName() + "&9 rank.", "&7&m------------------------------")).build() });
+ }
+ return inventory;
+ }
+
+ public static GrantProcedure getByPlayer(final Player player) {
+ for (final GrantProcedure grantProcedure : GrantProcedure.procedures) {
+ if (grantProcedure.getIssuer() != null && grantProcedure.getIssuer().equals(player.getUniqueId())) {
+ return grantProcedure;
+ }
+ }
+ return null;
+ }
+
+ public static Set getProcedures() {
+ return GrantProcedure.procedures;
+ }
+
+ public GrantRecipient getRecipient() {
+ return this.recipient;
+ }
+
+ public UUID getIssuer() {
+ return this.issuer;
+ }
+
+ public GrantProcedureData getData() {
+ return this.data;
+ }
+
+ static {
+ GrantProcedure.procedures = new HashSet();
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureData.java b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureData.java
new file mode 100644
index 0000000..2bd9c36
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureData.java
@@ -0,0 +1,56 @@
+package us.centile.permissions.grant.procedure;
+
+import us.centile.permissions.rank.*;
+
+public class GrantProcedureData
+{
+ private GrantProcedureStage stage;
+ private Rank rank;
+ private long created;
+ private long duration;
+ private String reason;
+
+ public GrantProcedureData() {
+ this.stage = GrantProcedureStage.RANK;
+ }
+
+ public GrantProcedureStage getStage() {
+ return this.stage;
+ }
+
+ public void setStage(final GrantProcedureStage stage) {
+ this.stage = stage;
+ }
+
+ public Rank getRank() {
+ return this.rank;
+ }
+
+ public void setRank(final Rank rank) {
+ this.rank = rank;
+ }
+
+ public long getCreated() {
+ return this.created;
+ }
+
+ public long getDuration() {
+ return this.duration;
+ }
+
+ public void setCreated(final long created) {
+ this.created = created;
+ }
+
+ public void setDuration(final long duration) {
+ this.duration = duration;
+ }
+
+ public String getReason() {
+ return this.reason;
+ }
+
+ public void setReason(final String reason) {
+ this.reason = reason;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureListeners.java b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureListeners.java
new file mode 100644
index 0000000..3cafe9c
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureListeners.java
@@ -0,0 +1,96 @@
+package us.centile.permissions.grant.procedure;
+
+import org.bukkit.entity.*;
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.inventory.*;
+import org.bukkit.event.*;
+import org.bukkit.event.player.*;
+import us.centile.permissions.util.*;
+import mkremins.fanciful.*;
+import org.bukkit.event.inventory.*;
+
+public class GrantProcedureListeners implements Listener
+{
+ @EventHandler
+ public void onInventoryClickEvent(final InventoryClickEvent event) {
+ final Player player = (Player)event.getWhoClicked();
+ final Inventory inventory = event.getInventory();
+ final ItemStack itemStack = event.getCurrentItem();
+ final GrantProcedure procedure = GrantProcedure.getByPlayer(player);
+ if (procedure != null && itemStack != null && itemStack.getType() != Material.AIR) {
+ event.setCancelled(true);
+ if (procedure.getData().getStage() == GrantProcedureStage.RANK && inventory.getTitle().equals(procedure.getInventory().getTitle()) && itemStack.getItemMeta().hasDisplayName()) {
+ final Rank rank = Rank.getByName(ChatColor.stripColor(itemStack.getItemMeta().getDisplayName()));
+ if (rank != null) {
+ procedure.getData().setRank(rank);
+ procedure.getData().setStage(GrantProcedureStage.DURATION);
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.YELLOW + "Please enter a duration in chat (use 'permanent' for permanent ranks).");
+ player.sendMessage(" ");
+ }
+ player.closeInventory();
+ }
+ }
+ }
+
+ @EventHandler
+ public void onAsyncPlayerChatEvent(final AsyncPlayerChatEvent event) {
+ final Player player = event.getPlayer();
+ final GrantProcedure procedure = GrantProcedure.getByPlayer(player);
+ if (procedure != null && (procedure.getData().getStage() == GrantProcedureStage.DURATION || procedure.getData().getStage() == GrantProcedureStage.REASON || procedure.getData().getStage() == GrantProcedureStage.CONFIRMATION)) {
+ event.setCancelled(true);
+ try {
+ if (event.getMessage().equalsIgnoreCase("cancel")) {
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.RED + "Grant procedure cancelled.");
+ player.sendMessage(" ");
+ GrantProcedure.getProcedures().remove(procedure);
+ return;
+ }
+ if (procedure.getData().getStage() == GrantProcedureStage.DURATION) {
+ if (event.getMessage().equalsIgnoreCase("permanent") || event.getMessage().equalsIgnoreCase("perm")) {
+ procedure.getData().setDuration(2147483647L);
+ }
+ else {
+ procedure.getData().setDuration(System.currentTimeMillis() - DateUtil.parseDateDiff(event.getMessage(), false));
+ }
+ procedure.getData().setStage(GrantProcedureStage.REASON);
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.YELLOW + "Duration successfully recorded.");
+ player.sendMessage(ChatColor.YELLOW + "Please enter a reason in chat.");
+ player.sendMessage(" ");
+ }
+ else {
+ procedure.getData().setReason(event.getMessage());
+ procedure.getData().setStage(GrantProcedureStage.CONFIRMATION);
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.YELLOW + "Reason successfully recorded.");
+ new FancyMessage(ChatColor.YELLOW + "Would you like to proceed with this grant?: ").then(ChatColor.GREEN + "" + ChatColor.BOLD + "YES").tooltip(ChatColor.GREEN + "Confirm this grant").command("/grant confirm").then(ChatColor.RED + " " + ChatColor.BOLD + "NO").command("/grant cancel").tooltip(ChatColor.RED + "Cancel this grant").send(player);
+ player.sendMessage(" ");
+ }
+ }
+ catch (Exception e) {
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.RED + "Please enter a valid duration or type 'cancel' to cancel.");
+ player.sendMessage(" ");
+ }
+ }
+ }
+
+ @EventHandler
+ public void onInventoryCloseEvent(final InventoryCloseEvent event) {
+ final Player player = (Player)event.getPlayer();
+ final Inventory inventory = event.getInventory();
+ final GrantProcedure procedure = GrantProcedure.getByPlayer(player);
+ if (procedure != null) {
+ final GrantProcedureStage stage = procedure.getData().getStage();
+ if (stage == GrantProcedureStage.RANK && inventory.getTitle().equals(procedure.getInventory().getTitle())) {
+ player.sendMessage(" ");
+ player.sendMessage(ChatColor.RED + "Grant procedure cancelled.");
+ player.sendMessage(" ");
+ GrantProcedure.getProcedures().remove(procedure);
+ }
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureStage.java b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureStage.java
new file mode 100644
index 0000000..52d9902
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/procedure/GrantProcedureStage.java
@@ -0,0 +1,9 @@
+package us.centile.permissions.grant.procedure;
+
+public enum GrantProcedureStage
+{
+ RANK,
+ DURATION,
+ REASON,
+ CONFIRMATION;
+}
diff --git a/nPermissions/src/us/centile/permissions/grant/procedure/GrantRecipient.java b/nPermissions/src/us/centile/permissions/grant/procedure/GrantRecipient.java
new file mode 100644
index 0000000..16b8dd7
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/grant/procedure/GrantRecipient.java
@@ -0,0 +1,22 @@
+package us.centile.permissions.grant.procedure;
+
+import java.util.*;
+
+public class GrantRecipient
+{
+ private final UUID uuid;
+ private final String name;
+
+ public GrantRecipient(final UUID uuid, final String name) {
+ this.uuid = uuid;
+ this.name = name;
+ }
+
+ public UUID getUuid() {
+ return this.uuid;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/jedis/JedisPublisher.java b/nPermissions/src/us/centile/permissions/jedis/JedisPublisher.java
new file mode 100644
index 0000000..4f32ff6
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/jedis/JedisPublisher.java
@@ -0,0 +1,29 @@
+package us.centile.permissions.jedis;
+
+import us.centile.permissions.*;
+import redis.clients.jedis.*;
+
+public class JedisPublisher
+{
+ private nPermissions main;
+
+ public JedisPublisher(final nPermissions main) {
+ this.main = main;
+ }
+
+ public void write(final String message) {
+ Jedis jedis = null;
+ try {
+ jedis = this.main.getPool().getResource();
+ if (this.main.getConfigFile().getBoolean("DATABASE.REDIS.AUTHENTICATION.ENABLED")) {
+ jedis.auth(this.main.getConfigFile().getString("DATABASE.REDIS.AUTHENTICATION.PASSWORD"));
+ }
+ jedis.publish("permissions", message);
+ }
+ finally {
+ if (jedis != null) {
+ jedis.close();
+ }
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/jedis/JedisSubscriber.java b/nPermissions/src/us/centile/permissions/jedis/JedisSubscriber.java
new file mode 100644
index 0000000..646c5ce
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/jedis/JedisSubscriber.java
@@ -0,0 +1,240 @@
+package us.centile.permissions.jedis;
+
+import redis.clients.jedis.*;
+import us.centile.permissions.*;
+import us.centile.permissions.profile.*;
+import org.bukkit.*;
+import us.centile.permissions.grant.*;
+import us.centile.permissions.util.*;
+import org.bukkit.entity.*;
+import us.centile.permissions.rank.*;
+import com.google.gson.*;
+import java.util.*;
+
+public class JedisSubscriber
+{
+ private JedisPubSub jedisPubSub;
+ private Jedis jedis;
+ private nPermissions main;
+
+ public JedisSubscriber(final nPermissions main) {
+ this.main = main;
+ this.jedis = new Jedis(main.getAddress(), main.getPort());
+ if (main.getConfigFile().getBoolean("DATABASE.REDIS.AUTHENTICATION.ENABLED")) {
+ this.jedis.auth(main.getConfigFile().getString("DATABASE.REDIS.AUTHENTICATION.PASSWORD"));
+ }
+ this.subscribe();
+ }
+
+ public void subscribe() {
+ this.jedisPubSub = this.get();
+ new Thread() {
+ @Override
+ public void run() {
+ JedisSubscriber.this.jedis.subscribe(JedisSubscriber.this.jedisPubSub, "permissions");
+ }
+ }.start();
+ }
+
+ private JedisPubSub get() {
+ return new JedisPubSub() {
+ @Override
+ public void onMessage(final String channel, final String message) {
+ if (channel.equalsIgnoreCase("permissions")) {
+ final JsonObject object = new JsonParser().parse(message).getAsJsonObject();
+ final JedisSubscriberAction action = JedisSubscriberAction.valueOf(object.get("action").getAsString());
+ final JsonObject payload = object.get("payload").getAsJsonObject();
+ if (action == JedisSubscriberAction.DELETE_PLAYER_PERMISSION) {
+ final Player player = Bukkit.getPlayer(UUID.fromString(payload.get("uuid").getAsString()));
+ if (player != null) {
+ final Profile profile = Profile.getByUuid(player.getUniqueId());
+ if (profile != null) {
+ final String permission = payload.get("permission").getAsString();
+ profile.getPermissions().remove(permission);
+ profile.setupAtatchment();
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.ADD_PLAYER_PERMISSION) {
+ final Player player = Bukkit.getPlayer(UUID.fromString(payload.get("uuid").getAsString()));
+ if (player != null) {
+ final Profile profile = Profile.getByUuid(player.getUniqueId());
+ if (profile != null) {
+ final String permission = payload.get("permission").getAsString();
+ profile.getPermissions().add(permission);
+ profile.setupAtatchment();
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.ADD_RANK_PERMISSION) {
+ Rank rank;
+ try {
+ rank = Rank.getByUuid(UUID.fromString(payload.get("rank").getAsString()));
+ }
+ catch (Exception ex) {
+ rank = Rank.getByName(payload.get("rank").getAsString());
+ if (rank == null) {
+ throw new IllegalArgumentException("Invalid rank parameter");
+ }
+ }
+ if (rank != null) {
+ final String permission2 = payload.get("permission").getAsString();
+ rank.getPermissions().add(permission2);
+ final Player player2 = Bukkit.getPlayer(payload.get("player").getAsString());
+ if (player2 != null) {
+ player2.sendMessage(ChatColor.GREEN + "Permission '" + permission2 + "' successfully added to rank named '" + rank.getData().getName() + "'.");
+ }
+ for (final Profile profile2 : Profile.getProfiles()) {
+ if (profile2.getActiveGrant().getRank().getUuid().equals(rank.getUuid())) {
+ profile2.setupAtatchment();
+ }
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.DELETE_RANK_PERMISSION) {
+ Rank rank;
+ try {
+ rank = Rank.getByUuid(UUID.fromString(payload.get("rank").getAsString()));
+ }
+ catch (Exception ex) {
+ rank = Rank.getByName(payload.get("rank").getAsString());
+ if (rank == null) {
+ throw new IllegalArgumentException("Invalid rank parameter");
+ }
+ }
+ if (rank != null) {
+ final String permission2 = payload.get("permission").getAsString();
+ rank.getPermissions().remove(permission2);
+ final Player player2 = Bukkit.getPlayer(payload.get("player").getAsString());
+ if (player2 != null) {
+ player2.sendMessage(ChatColor.GREEN + "Permission '" + permission2 + "' successfully removed from rank named '" + rank.getData().getName() + "'.");
+ }
+ for (final Profile profile2 : Profile.getProfiles()) {
+ if (profile2.getActiveGrant().getRank().getUuid().equals(rank.getUuid())) {
+ profile2.setupAtatchment();
+ }
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.DELETE_GRANT) {
+ final UUID uuid = UUID.fromString(payload.get("uuid").getAsString());
+ final Player player3 = Bukkit.getPlayer(uuid);
+ if (player3 != null) {
+ final Profile profile3 = Profile.getByUuid(player3.getUniqueId());
+ if (!profile3.getActiveGrant().getRank().getData().isDefaultRank()) {
+ profile3.getActiveGrant().setActive(false);
+ final Rank rank2 = Rank.getDefaultRank();
+ if (rank2 != null) {
+ player3.sendMessage(ChatColor.GREEN + "Your rank has been set to " + rank2.getData().getColorPrefix() + rank2.getData().getName() + ChatColor.GREEN + ".");
+ }
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.ADD_GRANT) {
+ final JsonObject grant = payload.get("grant").getAsJsonObject();
+ final UUID uuid2 = UUID.fromString(payload.get("uuid").getAsString());
+ final Player player2 = Bukkit.getPlayer(uuid2);
+ if (player2 != null) {
+ final Profile profile4 = Profile.getByUuid(player2.getUniqueId());
+ Rank rank3;
+ try {
+ rank3 = Rank.getByUuid(UUID.fromString(grant.get("rank").getAsString()));
+ }
+ catch (Exception ex2) {
+ rank3 = Rank.getByName(grant.get("rank").getAsString());
+ if (rank3 == null) {
+ throw new IllegalArgumentException("Invalid rank parameter");
+ }
+ }
+ if (rank3 != null) {
+ final UUID issuer = grant.has("issuer") ? UUID.fromString(grant.get("issuer").getAsString()) : null;
+ for (final Grant other : profile4.getGrants()) {
+ if (!other.getRank().getData().isDefaultRank() && !other.isExpired()) {
+ other.setActive(false);
+ }
+ }
+ final Grant newGrant = new Grant(issuer, rank3, grant.get("datedAdded").getAsLong(), grant.get("duration").getAsLong(), grant.get("reason").getAsString(), true);
+ profile4.getGrants().add(newGrant);
+ player2.sendMessage(ChatColor.GREEN + "Your rank has been set to " + newGrant.getRank().getData().getColorPrefix() + newGrant.getRank().getData().getName() + ChatColor.GREEN + ".");
+ }
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.IMPORT_RANKS) {
+ Rank.getRanks().clear();
+ final Iterator profileIterator = Profile.getProfiles().iterator();
+ while (profileIterator.hasNext()) {
+ final Profile profile = profileIterator.next();
+ final Player player2 = profile.getPlayer();
+ if (player2 != null && profile.getAttachment() != null) {
+ player2.removeAttachment(profile.getAttachment());
+ }
+ profileIterator.remove();
+ }
+ for (final Player online : PlayerUtility.getOnlinePlayers()) {
+ new Profile(online.getUniqueId(), new ArrayList(), new ArrayList());
+ }
+ final Player player3 = Bukkit.getPlayer(payload.get("player").getAsString());
+ if (player3 != null) {
+ player3.sendMessage(ChatColor.GREEN + "Ranks successfully imported!");
+ }
+ JedisSubscriber.this.main.getRankHandler().load();
+ return;
+ }
+ if (action == JedisSubscriberAction.ADD_RANK) {
+ final String name = payload.get("name").getAsString();
+ final Rank rank4 = new Rank(UUID.randomUUID(), new ArrayList(), new ArrayList(), new RankData(name));
+ final Player player2 = Bukkit.getPlayer(payload.get("player").getAsString());
+ if (player2 != null) {
+ player2.sendMessage(ChatColor.GREEN + "Rank named '" + rank4.getData().getName() + "' successfully created.");
+ }
+ return;
+ }
+ if (action == JedisSubscriberAction.DELETE_RANK) {
+ final Rank rank = Rank.getByName(payload.get("rank").getAsString());
+ if (rank != null) {
+ final Player player3 = Bukkit.getPlayer(payload.get("player").getAsString());
+ if (player3 != null) {
+ player3.sendMessage(ChatColor.GREEN + "Rank named '" + rank.getData().getName() + "' successfully deleted.");
+ }
+ Rank.getRanks().remove(rank);
+ }
+ }
+ if (action == JedisSubscriberAction.SET_RANK_PREFIX) {
+ final Rank rank = Rank.getByName(payload.get("rank").getAsString());
+ if (rank != null) {
+ final Player player3 = Bukkit.getPlayer(payload.get("player").getAsString());
+ rank.getData().setPrefix(payload.get("prefix").getAsString());
+ if (player3 != null) {
+ player3.sendMessage(ChatColor.GREEN + "Rank named '" + rank.getData().getName() + "' prefix successfully changed.");
+ }
+ }
+ }
+ if (action == JedisSubscriberAction.SET_RANK_SUFFIX) {
+ final Rank rank = Rank.getByName(payload.get("rank").getAsString());
+ if (rank != null) {
+ final Player player3 = Bukkit.getPlayer(payload.get("player").getAsString());
+ rank.getData().setSuffix(payload.get("suffix").getAsString());
+ if (player3 != null) {
+ player3.sendMessage(ChatColor.GREEN + "Rank named '" + rank.getData().getName() + "' suffix successfully changed.");
+ }
+ }
+ }
+ }
+ }
+ };
+ }
+
+ public JedisPubSub getJedisPubSub() {
+ return this.jedisPubSub;
+ }
+
+ public Jedis getJedis() {
+ return this.jedis;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/jedis/JedisSubscriberAction.java b/nPermissions/src/us/centile/permissions/jedis/JedisSubscriberAction.java
new file mode 100644
index 0000000..3cfc41d
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/jedis/JedisSubscriberAction.java
@@ -0,0 +1,16 @@
+package us.centile.permissions.jedis;
+
+public enum JedisSubscriberAction
+{
+ ADD_RANK,
+ DELETE_RANK,
+ SET_RANK_PREFIX,
+ SET_RANK_SUFFIX,
+ ADD_GRANT,
+ DELETE_GRANT,
+ IMPORT_RANKS,
+ ADD_RANK_PERMISSION,
+ DELETE_RANK_PERMISSION,
+ ADD_PLAYER_PERMISSION,
+ DELETE_PLAYER_PERMISSION;
+}
diff --git a/nPermissions/src/us/centile/permissions/nPermissions.java b/nPermissions/src/us/centile/permissions/nPermissions.java
new file mode 100644
index 0000000..01a8163
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/nPermissions.java
@@ -0,0 +1,139 @@
+package us.centile.permissions;
+
+import org.bukkit.plugin.java.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.file.*;
+import us.centile.permissions.rank.*;
+import redis.clients.jedis.*;
+import us.centile.permissions.jedis.*;
+import us.centile.permissions.util.database.*;
+import us.centile.permissions.util.*;
+import org.bukkit.entity.*;
+import us.centile.permissions.grant.*;
+import java.util.*;
+import org.bukkit.*;
+import us.centile.permissions.grant.procedure.*;
+import org.bukkit.event.*;
+import us.centile.permissions.profile.*;
+import org.bukkit.plugin.*;
+import us.centile.permissions.rank.command.*;
+import us.centile.permissions.profile.command.*;
+import us.centile.permissions.rank.command.grant.*;
+
+public class nPermissions extends JavaPlugin
+{
+ private static nPermissions instance;
+ private CommandFramework commandFramework;
+ private ConfigFile configFile;
+ private ConfigFile ranksFile;
+ private RankHandler rankHandler;
+ private String address;
+ private int port;
+ private JedisPool pool;
+ private JedisPublisher publisher;
+ private JedisSubscriber subscriber;
+ private PermissionsDatabase permissionsDatabase;
+
+ public void onEnable() {
+ this.setupJedis();
+ this.registerCommands();
+ this.registerListeners();
+ nPermissions.instance = this;
+ this.commandFramework = new CommandFramework(this);
+ this.configFile = new ConfigFile(this, "config");
+ this.ranksFile = new ConfigFile(this, "ranks");
+ this.permissionsDatabase = new PermissionsDatabase(this);
+ this.rankHandler = new RankHandler(this);
+ for (final Player online : PlayerUtility.getOnlinePlayers()) {
+ new Profile(online.getUniqueId(), new ArrayList(), new ArrayList()).asyncLoad();
+ }
+ }
+
+ public void onDisable() {
+ this.subscriber.getJedisPubSub().unsubscribe();
+ this.pool.destroy();
+ for (final Profile profile : Profile.getProfiles()) {
+ if (profile.getPlayer() != null) {
+ profile.getPlayer().removeAttachment(profile.getAttachment());
+ }
+ profile.save();
+ }
+ this.rankHandler.save();
+ this.permissionsDatabase.getClient().close();
+ }
+
+ private void registerListeners() {
+ final PluginManager pluginManager = Bukkit.getPluginManager();
+ pluginManager.registerEvents((Listener)new GrantProcedureListeners(), (Plugin)this);
+ pluginManager.registerEvents((Listener)new ProfileListeners(), (Plugin)this);
+ pluginManager.registerEvents((Listener)new GrantListeners(), (Plugin)this);
+ }
+
+ private void registerCommands() {
+ new RankCreateCommand();
+ new RankDeleteCommand();
+ new RankPrefixCommand();
+ new RankSuffixCommand();
+ new RankImportCommand();
+ new RankAddPermissionCommand();
+ new RankDeletePermissionCommand();
+ new RankListPermissionsCommand();
+ new ProfileAddPermissionCommand();
+ new ProfileDeletePermissionCommand();
+ new ProfileListPermissionsCommand();
+ new GrantCommand();
+ new GrantsCommand();
+ }
+
+ private void setupJedis() {
+ this.address = this.configFile.getString("DATABASE.REDIS.HOST");
+ this.port = this.configFile.getInt("DATABASE.REDIS.PORT");
+ this.pool = new JedisPool(this.address, this.port);
+ this.publisher = new JedisPublisher(this);
+ this.subscriber = new JedisSubscriber(this);
+ }
+
+ public static nPermissions getInstance() {
+ return nPermissions.instance;
+ }
+
+ public CommandFramework getCommandFramework() {
+ return this.commandFramework;
+ }
+
+ public ConfigFile getConfigFile() {
+ return this.configFile;
+ }
+
+ public ConfigFile getRanksFile() {
+ return this.ranksFile;
+ }
+
+ public RankHandler getRankHandler() {
+ return this.rankHandler;
+ }
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public int getPort() {
+ return this.port;
+ }
+
+ public JedisPool getPool() {
+ return this.pool;
+ }
+
+ public JedisPublisher getPublisher() {
+ return this.publisher;
+ }
+
+ public JedisSubscriber getSubscriber() {
+ return this.subscriber;
+ }
+
+ public PermissionsDatabase getPermissionsDatabase() {
+ return this.permissionsDatabase;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/profile/Profile.java b/nPermissions/src/us/centile/permissions/profile/Profile.java
new file mode 100644
index 0000000..635c319
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/profile/Profile.java
@@ -0,0 +1,293 @@
+package us.centile.permissions.profile;
+
+import us.centile.permissions.*;
+import us.centile.permissions.grant.*;
+import org.bukkit.entity.*;
+import org.bukkit.permissions.*;
+import org.bukkit.plugin.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.scheduler.*;
+import org.bson.*;
+import org.bukkit.*;
+import com.google.gson.*;
+import com.mongodb.client.model.*;
+import java.io.*;
+import org.json.simple.parser.*;
+import java.util.*;
+
+public class Profile
+{
+ private static Set profiles;
+ private static nPermissions main;
+ private final UUID uuid;
+ private final List permissions;
+ private final List grants;
+ private final Player player;
+ private String name;
+ private boolean loaded;
+ private PermissionAttachment attachment;
+
+ public Profile(final UUID uuid, final List permissions, final List grants) {
+ this.uuid = uuid;
+ this.permissions = permissions;
+ this.grants = grants;
+ this.player = Bukkit.getPlayer(uuid);
+ if (this.player != null) {
+ this.name = this.player.getName();
+ this.attachment = this.player.addAttachment((Plugin)Profile.main);
+ }
+ else {
+ final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
+ if (offlinePlayer != null) {
+ this.name = offlinePlayer.getName();
+ }
+ this.attachment = null;
+ }
+ Profile.profiles.add(this);
+ }
+
+ public Grant getActiveGrant() {
+ Grant toReturn = null;
+ for (final Grant grant : this.grants) {
+ if (grant.isActive() && !grant.getRank().getData().isDefaultRank()) {
+ toReturn = grant;
+ }
+ }
+ if (toReturn == null) {
+ toReturn = new Grant(null, Rank.getDefaultRank(), System.currentTimeMillis(), 2147483647L, "Default Rank", true);
+ }
+ return toReturn;
+ }
+
+ public void asyncLoad() {
+ new BukkitRunnable() {
+ public void run() {
+ Profile.this.load();
+ }
+ }.runTaskAsynchronously((Plugin)Profile.main);
+ }
+
+ public Profile load() {
+ final Document document = (Document)Profile.main.getPermissionsDatabase().getProfiles().find(Filters.eq("uuid", this.uuid.toString())).first();
+ if (document != null) {
+ for (final JsonElement element : new JsonParser().parse(document.getString("grants")).getAsJsonArray()) {
+ final JsonObject keyGrant = element.getAsJsonObject();
+ UUID issuer = null;
+ if (keyGrant.get("issuer") != null) {
+ issuer = UUID.fromString(keyGrant.get("issuer").getAsString());
+ }
+ final long dateAdded = keyGrant.get("dateAdded").getAsLong();
+ final long duration = keyGrant.get("duration").getAsLong();
+ final String reason = keyGrant.get("reason").getAsString();
+ final boolean active = keyGrant.get("active").getAsBoolean();
+ Rank rank;
+ try {
+ rank = Rank.getByUuid(UUID.fromString(keyGrant.get("rank").getAsString()));
+ }
+ catch (Exception ex) {
+ rank = Rank.getByName(keyGrant.get("rank").getAsString());
+ if (rank == null) {
+ throw new IllegalArgumentException("Invalid rank parameter");
+ }
+ }
+ if (rank != null) {
+ this.grants.add(new Grant(issuer, rank, dateAdded, duration, reason, active));
+ }
+ }
+ if (document.containsKey("recentName")) {
+ this.name = document.getString("recentName");
+ }
+ final List permissionsList = new ArrayList();
+ for (final String id : document.get("permissions").toString().replace("[", "").replace("]", "").replace(" ", "").split(",")) {
+ if (!id.isEmpty()) {
+ permissionsList.add(id);
+ }
+ }
+ this.permissions.addAll(permissionsList);
+ }
+ boolean hasDefaultRank = false;
+ final Iterator iterator = this.grants.iterator();
+ while (iterator.hasNext()) {
+ if (iterator.next().getRank().getData().isDefaultRank()) {
+ hasDefaultRank = true;
+ break;
+ }
+ }
+ if (!hasDefaultRank) {
+ this.grants.add(new Grant(null, Rank.getDefaultRank(), System.currentTimeMillis(), 2147483647L, "Default Rank", true));
+ }
+ this.loaded = true;
+ this.setupAtatchment();
+ return this;
+ }
+
+ public void setupAtatchment() {
+ if (this.attachment != null) {
+ final Player player = Bukkit.getPlayer(this.uuid);
+ if (player != null) {
+ final Grant grant = this.getActiveGrant();
+ if (!player.getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', grant.getRank().getData().getPrefix() + player.getName() + grant.getRank().getData().getSuffix()))) {
+ player.setDisplayName(ChatColor.translateAlternateColorCodes('&', grant.getRank().getData().getPrefix() + player.getName() + grant.getRank().getData().getSuffix()));
+ }
+ }
+ for (final String permission : this.attachment.getPermissions().keySet()) {
+ this.attachment.unsetPermission(permission);
+ }
+ for (final Grant grant2 : this.grants) {
+ if (grant2 == null) {
+ continue;
+ }
+ if (grant2.isExpired()) {
+ continue;
+ }
+ for (final String permission2 : grant2.getRank().getPermissions()) {
+ this.attachment.setPermission(permission2.replace("-", ""), !permission2.startsWith("-"));
+ }
+ for (final UUID uuid : grant2.getRank().getInheritance()) {
+ final Rank rank = Rank.getByUuid(uuid);
+ if (rank != null) {
+ for (final String permission3 : rank.getPermissions()) {
+ this.attachment.setPermission(permission3.replace("-", ""), !permission3.startsWith("-"));
+ }
+ }
+ }
+ }
+ for (final String permission4 : this.permissions) {
+ this.attachment.setPermission(permission4.replace("-", ""), !permission4.startsWith("-"));
+ }
+ if (player != null) {
+ player.recalculatePermissions();
+ }
+ }
+ else {
+ final Player player = Bukkit.getPlayer(this.uuid);
+ if (player != null) {
+ this.attachment = player.addAttachment((Plugin)Profile.main);
+ this.load();
+ }
+ }
+ }
+
+ public Profile remove() {
+ Profile.profiles.remove(this);
+ return this;
+ }
+
+ public Profile save() {
+ final Document profileDocument = new Document();
+ final JsonArray grantsDocument = new JsonArray();
+ profileDocument.put("uuid", (Object)this.uuid.toString());
+ if (this.name != null) {
+ profileDocument.put("recentName", (Object)this.name);
+ profileDocument.put("recentNameLowercase", (Object)this.name.toLowerCase());
+ }
+ for (final Grant grant : this.grants) {
+ final JsonObject grantDocument = new JsonObject();
+ if (grant.getRank() == null) {
+ continue;
+ }
+ if (grant.getRank().getData().isDefaultRank()) {
+ continue;
+ }
+ if (grant.getIssuer() != null) {
+ grantDocument.addProperty("issuer", grant.getIssuer().toString());
+ }
+ grantDocument.addProperty("dateAdded", grant.getDateAdded());
+ grantDocument.addProperty("duration", grant.getDuration());
+ grantDocument.addProperty("reason", grant.getReason());
+ grantDocument.addProperty("active", Boolean.valueOf(grant.isActive() && !grant.isExpired()));
+ grantDocument.addProperty("rank", grant.getRank().getUuid().toString());
+ grantDocument.addProperty("rankName", grant.getRank().getData().getName());
+ grantsDocument.add(grantDocument);
+ }
+ profileDocument.put("grants", (Object)grantsDocument.toString());
+ profileDocument.put("permissions", (Object)this.permissions);
+ Profile.main.getPermissionsDatabase().getProfiles().replaceOne(Filters.eq("uuid", this.uuid.toString()), profileDocument, new UpdateOptions().upsert(true));
+ return this;
+ }
+
+ public static Profile getByUuid(final UUID uuid) {
+ for (final Profile profile : Profile.profiles) {
+ if (profile.getUuid().equals(uuid)) {
+ return profile;
+ }
+ }
+ return getExternalByUuid(uuid);
+ }
+
+ private static Profile getExternalByUuid(final UUID uuid) {
+ final Profile profile = new Profile(uuid, new ArrayList(), new ArrayList()).load();
+ profile.remove();
+ return profile;
+ }
+
+ public static Profile getExternalByName(final String name) {
+ for (final Player player : Bukkit.getServer().getOnlinePlayers()) {
+ final Profile profile = getByUuid(player.getUniqueId());
+ if (profile != null && profile.getName() != null && profile.getName().equalsIgnoreCase(name)) {
+ return profile;
+ }
+ }
+ UUID uuid;
+ String realName;
+ try {
+ final Map.Entry data = Profile.main.getRankHandler().getExternalUuid(name);
+ uuid = data.getKey();
+ realName = data.getValue();
+ }
+ catch (IOException | ParseException ex2) {
+ return null;
+ }
+ final Profile profile2 = new Profile(uuid, new ArrayList(), new ArrayList()).load();
+ if (profile2.getName() == null || !profile2.getName().equals(realName)) {
+ profile2.setName(realName);
+ }
+ profile2.remove();
+ return profile2;
+ }
+
+ public static Set getProfiles() {
+ return Profile.profiles;
+ }
+
+ public UUID getUuid() {
+ return this.uuid;
+ }
+
+ public List getPermissions() {
+ return this.permissions;
+ }
+
+ public List getGrants() {
+ return this.grants;
+ }
+
+ public Player getPlayer() {
+ return this.player;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public boolean isLoaded() {
+ return this.loaded;
+ }
+
+ public void setLoaded(final boolean loaded) {
+ this.loaded = loaded;
+ }
+
+ public PermissionAttachment getAttachment() {
+ return this.attachment;
+ }
+
+ static {
+ Profile.profiles = new HashSet();
+ Profile.main = nPermissions.getInstance();
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/profile/ProfileListeners.java b/nPermissions/src/us/centile/permissions/profile/ProfileListeners.java
new file mode 100644
index 0000000..b9b8763
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/profile/ProfileListeners.java
@@ -0,0 +1,56 @@
+package us.centile.permissions.profile;
+
+import us.centile.permissions.grant.*;
+import java.util.*;
+import org.bukkit.event.player.*;
+
+import org.bukkit.*;
+import org.bukkit.entity.*;
+import org.bukkit.event.*;
+
+public class ProfileListeners implements Listener {
+ @EventHandler
+ public void onPlayerJoinEvent(final PlayerJoinEvent event) {
+ final Profile profile = new Profile(event.getPlayer().getUniqueId(), new ArrayList(),
+ new ArrayList());
+ profile.asyncLoad();
+ if (event.getPlayer().hasPermission("test.test")) {
+ event.getPlayer().sendMessage("lol");
+
+ }
+ }
+
+ @EventHandler
+ public void onPlayerJoin(PlayerLoginEvent event) {
+
+ final Profile profile = new Profile(event.getPlayer().getUniqueId(), new ArrayList(),
+ new ArrayList());
+
+ if (!profile.isLoaded()) {
+ profile.load();
+ }
+
+ profile.setupAtatchment();
+ }
+
+ @EventHandler
+ public void onPlayerQuitEvent(final PlayerQuitEvent event) {
+ final Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId());
+ if (profile != null) {
+ Profile.getProfiles().remove(profile);
+ profile.save();
+ }
+ }
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onCommandProcess(final PlayerCommandPreprocessEvent event) {
+ final Player player = event.getPlayer();
+ if (event.getMessage().toLowerCase().startsWith("//calc")
+ || event.getMessage().toLowerCase().startsWith("//eval")
+ || event.getMessage().toLowerCase().startsWith("//solve")) {
+ player.sendMessage(ChatColor.RED + "You don't have enough permissions.");
+ event.setCancelled(true);
+ }
+ }
+
+}
diff --git a/nPermissions/src/us/centile/permissions/profile/command/ProfileAddPermissionCommand.java b/nPermissions/src/us/centile/permissions/profile/command/ProfileAddPermissionCommand.java
new file mode 100644
index 0000000..18d8d6e
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/profile/command/ProfileAddPermissionCommand.java
@@ -0,0 +1,67 @@
+package us.centile.permissions.profile.command;
+
+import org.bukkit.*;
+import us.centile.permissions.profile.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import org.bukkit.command.*;
+import org.bukkit.entity.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class ProfileAddPermissionCommand extends BaseCommand
+{
+ @Command(name = "addpermission", aliases = { "addperm" }, permission = "permissions.player.addpermission", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "/addpermission ");
+ return;
+ }
+ final Player player = Bukkit.getPlayer(args[0]);
+ UUID uuid;
+ String name;
+ if (player != null) {
+ uuid = player.getUniqueId();
+ name = player.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid = recipient.getKey();
+ name = recipient.getValue();
+ }
+ catch (Exception e) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Profile profile = Profile.getByUuid(uuid);
+ if (profile == null) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ final String permission = args[1].toLowerCase();
+ if (profile.getPermissions().contains(permission)) {
+ sender.sendMessage(ChatColor.RED + "Player named '" + name + "' already has permission node '" + permission + "'.");
+ return;
+ }
+ profile.getPermissions().add(permission);
+ profile.setupAtatchment();
+ profile.save();
+ if (player == null) {
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.ADD_PLAYER_PERMISSION.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("player", sender.getName());
+ payload.addProperty("uuid", uuid.toString());
+ payload.addProperty("permission", permission);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+ sender.sendMessage(ChatColor.GREEN + "Permission '" + permission + "' successfully given to player named '" + name + "'.");
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/profile/command/ProfileDeletePermissionCommand.java b/nPermissions/src/us/centile/permissions/profile/command/ProfileDeletePermissionCommand.java
new file mode 100644
index 0000000..6df17b5
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/profile/command/ProfileDeletePermissionCommand.java
@@ -0,0 +1,67 @@
+package us.centile.permissions.profile.command;
+
+import org.bukkit.*;
+import us.centile.permissions.profile.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import org.bukkit.command.*;
+import org.bukkit.entity.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class ProfileDeletePermissionCommand extends BaseCommand
+{
+ @Command(name = "deletepermission", aliases = { "delperm", "removepermission", "removeperm" }, permission = "permissions.player.removepermission", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "/removepermission ");
+ return;
+ }
+ final Player player = Bukkit.getPlayer(args[0]);
+ UUID uuid;
+ String name;
+ if (player != null) {
+ uuid = player.getUniqueId();
+ name = player.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid = recipient.getKey();
+ name = recipient.getValue();
+ }
+ catch (Exception e) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Profile profile = Profile.getByUuid(uuid);
+ if (profile == null) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ final String permission = args[1].toLowerCase();
+ if (!profile.getPermissions().contains(permission)) {
+ sender.sendMessage(ChatColor.RED + "Player named '" + name + "' doesn't have permission node '" + permission + "'.");
+ return;
+ }
+ profile.getPermissions().remove(permission);
+ profile.setupAtatchment();
+ profile.save();
+ if (player == null) {
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.DELETE_PLAYER_PERMISSION.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("player", sender.getName());
+ payload.addProperty("uuid", uuid.toString());
+ payload.addProperty("permission", permission);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+ sender.sendMessage(ChatColor.GREEN + "Permission '" + permission + "' successfully removed from player named '" + name + "'.");
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/profile/command/ProfileListPermissionsCommand.java b/nPermissions/src/us/centile/permissions/profile/command/ProfileListPermissionsCommand.java
new file mode 100644
index 0000000..92fc3c2
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/profile/command/ProfileListPermissionsCommand.java
@@ -0,0 +1,78 @@
+package us.centile.permissions.profile.command;
+
+import org.bukkit.*;
+import us.centile.permissions.profile.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.command.*;
+import org.bukkit.entity.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class ProfileListPermissionsCommand extends BaseCommand
+{
+ @Command(name = "listpermissions", aliases = { "listperms" }, permission = "permissions.player.listpermissions", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "/listpermissions ");
+ return;
+ }
+ final Player player = Bukkit.getPlayer(args[0]);
+ UUID uuid;
+ String name;
+ if (player != null) {
+ uuid = player.getUniqueId();
+ name = player.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid = recipient.getKey();
+ name = recipient.getValue();
+ }
+ catch (Exception e) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Profile profile = Profile.getByUuid(uuid);
+ if (profile == null) {
+ sender.sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ sender.sendMessage(ChatColor.GREEN + "Listing permissions of " + ChatColor.translateAlternateColorCodes('&', profile.getActiveGrant().getRank().getData().getPrefix() + name + profile.getActiveGrant().getRank().getData().getSuffix()) + ChatColor.GREEN + ":");
+ if (!profile.getPermissions().isEmpty()) {
+ sender.sendMessage(ChatColor.GREEN + "Base permissions:");
+ for (final String permission : profile.getPermissions()) {
+ sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + permission);
+ }
+ }
+ final Rank rank = profile.getActiveGrant().getRank();
+ if (rank != null) {
+ int count = 0;
+ for (final String permission2 : rank.getPermissions()) {
+ if (count == 0) {
+ sender.sendMessage(ChatColor.GREEN + "Permissions inherited from " + rank.getData().getColorPrefix() + rank.getData().getName() + ChatColor.GREEN + ":");
+ }
+ ++count;
+ sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + permission2);
+ if (count > 0 && count == rank.getPermissions().size()) {
+ count = 0;
+ for (final UUID otherId : rank.getInheritance()) {
+ if (count == 0) {
+ sender.sendMessage(ChatColor.GREEN + "Also inherits permissions from the following ranks:");
+ }
+ ++count;
+ final Rank other = Rank.getByUuid(otherId);
+ if (other != null) {
+ sender.sendMessage(ChatColor.DARK_GRAY + " * " + other.getData().getColorPrefix() + other.getData().getName());
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/Rank.java b/nPermissions/src/us/centile/permissions/rank/Rank.java
new file mode 100644
index 0000000..3ff2614
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/Rank.java
@@ -0,0 +1,74 @@
+package us.centile.permissions.rank;
+
+import us.centile.permissions.*;
+import java.util.*;
+
+public class Rank
+{
+ private static List ranks;
+ private static nPermissions main;
+ private final UUID uuid;
+ private final List inheritance;
+ private final List permissions;
+ private final RankData data;
+
+ public Rank(final UUID uuid, final List inheritance, final List permissions, final RankData data) {
+ this.uuid = uuid;
+ this.inheritance = inheritance;
+ this.permissions = permissions;
+ this.data = data;
+ Rank.ranks.add(this);
+ }
+
+ public static Rank getDefaultRank() {
+ for (final Rank rank : Rank.ranks) {
+ if (rank.getData().isDefaultRank()) {
+ return rank;
+ }
+ }
+ return null;
+ }
+
+ public static Rank getByName(final String name) {
+ for (final Rank rank : Rank.ranks) {
+ if (rank.getData().getName().replace(" ", "").equalsIgnoreCase(name.replace(" ", ""))) {
+ return rank;
+ }
+ }
+ return null;
+ }
+
+ public static Rank getByUuid(final UUID uuid) {
+ for (final Rank rank : Rank.ranks) {
+ if (rank.getUuid().equals(uuid)) {
+ return rank;
+ }
+ }
+ return null;
+ }
+
+ public static List getRanks() {
+ return Rank.ranks;
+ }
+
+ public UUID getUuid() {
+ return this.uuid;
+ }
+
+ public List getInheritance() {
+ return this.inheritance;
+ }
+
+ public List getPermissions() {
+ return this.permissions;
+ }
+
+ public RankData getData() {
+ return this.data;
+ }
+
+ static {
+ Rank.ranks = new ArrayList();
+ Rank.main = nPermissions.getInstance();
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/RankData.java b/nPermissions/src/us/centile/permissions/rank/RankData.java
new file mode 100644
index 0000000..cc7fc79
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/RankData.java
@@ -0,0 +1,77 @@
+package us.centile.permissions.rank;
+
+import org.bukkit.*;
+
+public class RankData
+{
+ private String name;
+ private String prefix;
+ private String suffix;
+ private boolean defaultRank;
+
+ public RankData(final String name, final String prefix, final String suffix, final boolean defaultRank) {
+ this.name = name;
+ this.prefix = prefix;
+ this.suffix = suffix;
+ this.defaultRank = defaultRank;
+ }
+
+ public RankData(final String name) {
+ this(name, "&f", "&f", false);
+ }
+
+ public String getColorPrefix() {
+ if (this.prefix.isEmpty()) {
+ return "";
+ }
+ char code = 'f';
+ char magic = 'f';
+ int count = 0;
+ for (final String string : this.prefix.split("&")) {
+ if (!string.isEmpty() && ChatColor.getByChar(string.toCharArray()[0]) != null) {
+ if (count == 0) {
+ code = string.toCharArray()[0];
+ }
+ else {
+ magic = string.toCharArray()[0];
+ }
+ ++count;
+ }
+ }
+ final ChatColor color = ChatColor.getByChar(code);
+ final ChatColor magicColor = ChatColor.getByChar(magic);
+ return (count == 1) ? color.toString() : (color.toString() + magicColor.toString());
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getPrefix() {
+ return this.prefix;
+ }
+
+ public void setPrefix(final String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getSuffix() {
+ return this.suffix;
+ }
+
+ public void setSuffix(final String suffix) {
+ this.suffix = suffix;
+ }
+
+ public boolean isDefaultRank() {
+ return this.defaultRank;
+ }
+
+ public void setDefaultRank(final boolean defaultRank) {
+ this.defaultRank = defaultRank;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/RankHandler.java b/nPermissions/src/us/centile/permissions/rank/RankHandler.java
new file mode 100644
index 0000000..dfcd709
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/RankHandler.java
@@ -0,0 +1,162 @@
+package us.centile.permissions.rank;
+
+import us.centile.permissions.*;
+import java.text.*;
+import org.bukkit.scheduler.*;
+import us.centile.permissions.profile.*;
+import us.centile.permissions.grant.*;
+import org.bukkit.entity.*;
+import org.bukkit.plugin.*;
+import org.bukkit.inventory.*;
+import org.bukkit.*;
+import us.centile.permissions.util.*;
+import com.mongodb.*;
+import org.bson.*;
+import com.mongodb.client.model.*;
+import java.util.*;
+import org.json.simple.*;
+import java.net.*;
+import java.io.*;
+import org.json.simple.parser.*;
+import org.json.simple.parser.ParseException;
+
+public class RankHandler
+{
+ private final nPermissions main;
+ private static final SimpleDateFormat DATE_FORMAT;
+
+ public RankHandler(final nPermissions main) {
+ this.main = main;
+ this.load();
+ new BukkitRunnable() {
+ public void run() {
+ for (final Profile profile : Profile.getProfiles()) {
+ for (final Grant grant : profile.getGrants()) {
+ if (grant.isExpired() && grant.isActive()) {
+ grant.setActive(false);
+ profile.setupAtatchment();
+ final Player player = Bukkit.getPlayer(profile.getUuid());
+ if (player == null) {
+ continue;
+ }
+ player.sendMessage(ChatColor.GREEN + "Your rank has been set to " + profile.getActiveGrant().getRank().getData().getColorPrefix() + profile.getActiveGrant().getRank().getData().getName() + ChatColor.GREEN + ".");
+ }
+ }
+ }
+ }
+ }.runTaskTimer((Plugin)main, 20L, 20L);
+ }
+
+ public Inventory getGrantsInventory(final Profile profile, final String name, final int page) {
+ int total = (int)Math.ceil(profile.getGrants().size() / 9.0);
+ if (total == 0) {
+ total = 1;
+ }
+ final Inventory inventory = Bukkit.createInventory((InventoryHolder)null, 18, ChatColor.RED + "Grants - " + page + "/" + total);
+ inventory.setItem(0, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Previous Page").build());
+ inventory.setItem(8, new ItemBuilder(Material.CARPET).durability(7).name(ChatColor.RED + "Next Page").build());
+ inventory.setItem(4, new ItemBuilder(Material.PAPER).name(ChatColor.RED + "Page " + page + "/" + ((total == 0) ? 1 : total)).lore(Arrays.asList(ChatColor.YELLOW + "Player: " + ChatColor.RED + name)).build());
+ final ArrayList toLoop = new ArrayList(profile.getGrants());
+ Collections.reverse(toLoop);
+ final Iterator iterator = toLoop.iterator();
+ while (iterator.hasNext()) {
+ final Grant grant = iterator.next();
+ if (grant.getRank().getData().isDefaultRank()) {
+ iterator.remove();
+ }
+ }
+ for (final Grant grant2 : toLoop) {
+ if (toLoop.indexOf(grant2) >= page * 9 - 9 && toLoop.indexOf(grant2) < page * 9) {
+ String end = "";
+ if (grant2.getDuration() != 2147483647L) {
+ if (grant2.isExpired()) {
+ end = "Expired";
+ }
+ else {
+ final Calendar from = Calendar.getInstance();
+ final Calendar to = Calendar.getInstance();
+ from.setTime(new Date(System.currentTimeMillis()));
+ to.setTime(new Date(grant2.getDateAdded() + grant2.getDuration()));
+ end = DateUtil.formatDateDiff(from, to);
+ }
+ }
+ String issuerName;
+ if (grant2.getIssuer() == null) {
+ issuerName = "Console";
+ }
+ else {
+ issuerName = Profile.getByUuid(grant2.getIssuer()).getName();
+ }
+ inventory.setItem(9 + toLoop.indexOf(grant2) % 9, new ItemBuilder(Material.WOOL).durability((grant2.isActive() && !grant2.isExpired()) ? 5 : 14).name(ChatColor.YELLOW + RankHandler.DATE_FORMAT.format(new Date(grant2.getDateAdded()))).lore(Arrays.asList("&7&m------------------------------", "&eBy: &c" + issuerName, "&eReason: &c" + grant2.getReason(), "&eRank: &c" + grant2.getRank().getData().getName(), "&7&m------------------------------", (grant2.getDuration() == 2147483647L) ? "&eThis is a permanent grant." : ("&eExpires in: &c" + end), "&7&m------------------------------")).build());
+ }
+ }
+ return inventory;
+ }
+
+ public void load() {
+ final Block printDocumentBlock = new Block() {
+ @Override
+ public void apply(final Document document) {
+ final RankData rankData = new RankData(document.getString("name"));
+ rankData.setPrefix(document.getString("prefix"));
+ rankData.setSuffix(document.getString("suffix"));
+ rankData.setDefaultRank(document.getBoolean("default"));
+ final Object inheritance = document.get("inheritance");
+ final Object permissions = document.get("permissions");
+ final List inheritanceList = new ArrayList();
+ for (final String id : inheritance.toString().replace("[", "").replace("]", "").replace(" ", "").split(",")) {
+ if (!id.isEmpty()) {
+ inheritanceList.add(UUID.fromString(id));
+ }
+ }
+ final List permissionsList = new ArrayList();
+ for (final String id2 : permissions.toString().replace("[", "").replace("]", "").replace(" ", "").split(",")) {
+ if (!id2.isEmpty()) {
+ permissionsList.add(id2);
+ }
+ }
+ new Rank(UUID.fromString(document.getString("uuid")), inheritanceList, permissionsList, rankData);
+ }
+ };
+ this.main.getPermissionsDatabase().getRanks().find().forEach(printDocumentBlock);
+ }
+
+ public void save() {
+ for (final Rank rank : Rank.getRanks()) {
+ final Document document = new Document();
+ document.put("uuid", (Object)rank.getUuid().toString());
+ final List inheritance = new ArrayList();
+ for (final UUID uuid : rank.getInheritance()) {
+ inheritance.add(uuid.toString());
+ }
+ document.put("inheritance", (Object)inheritance);
+ document.put("permissions", (Object)rank.getPermissions());
+ document.put("name", (Object)rank.getData().getName());
+ document.put("prefix", (Object)rank.getData().getPrefix());
+ document.put("suffix", (Object)rank.getData().getSuffix());
+ document.put("default", (Object)rank.getData().isDefaultRank());
+ this.main.getPermissionsDatabase().getRanks().replaceOne(Filters.eq("uuid", rank.getUuid().toString()), document, new UpdateOptions().upsert(true));
+ }
+ }
+
+ public Map.Entry getExternalUuid(String name) throws IOException, ParseException {
+ final Document document = (Document)nPermissions.getInstance().getPermissionsDatabase().getProfiles().find(Filters.eq("recentName", name)).first();
+ if (document != null && document.containsKey("recentName")) {
+ return new AbstractMap.SimpleEntry(UUID.fromString(document.getString("uuid")), document.getString("recentName"));
+ }
+ final URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
+ final URLConnection conn = url.openConnection();
+ conn.setDoOutput(true);
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ final JSONParser parser = new JSONParser();
+ final JSONObject obj = (JSONObject)parser.parse(reader.readLine());
+ final UUID uuid = UUID.fromString(String.valueOf(obj.get((Object)"id")).replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
+ name = String.valueOf(obj.get((Object)"name"));
+ reader.close();
+ return new AbstractMap.SimpleEntry(uuid, name);
+ }
+
+ static {
+ DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankAddPermissionCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankAddPermissionCommand.java
new file mode 100644
index 0000000..ce7f5f2
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankAddPermissionCommand.java
@@ -0,0 +1,41 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import org.bukkit.command.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class RankAddPermissionCommand extends BaseCommand
+{
+ @Command(name = "rank.addpermission", aliases = { "rank.addperm" }, permission = "permissions.rank.addpermission", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "/rank addpermission ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ sender.sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ final String permission = args[1].toLowerCase();
+ if (rank.getPermissions().contains(permission)) {
+ sender.sendMessage(ChatColor.RED + "Rank named '" + rank.getData().getName() + "' already has permission node '" + permission + "'.");
+ return;
+ }
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.ADD_RANK_PERMISSION.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("player", sender.getName());
+ payload.addProperty("rank", rank.getUuid().toString());
+ payload.addProperty("permission", permission);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankCreateCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankCreateCommand.java
new file mode 100644
index 0000000..6e7e397
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankCreateCommand.java
@@ -0,0 +1,32 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.util.command.*;
+
+public class RankCreateCommand extends BaseCommand
+{
+ @Command(name = "rank.create", aliases = { "createrank" }, permission = "permissions.rank.create", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (args.length == 0) {
+ command.getSender().sendMessage(ChatColor.RED + "/rank create ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank != null) {
+ command.getSender().sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' already exists!");
+ return;
+ }
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.ADD_RANK.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("name", args[0]);
+ payload.addProperty("player", command.getSender().getName());
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankDeleteCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankDeleteCommand.java
new file mode 100644
index 0000000..216bc39
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankDeleteCommand.java
@@ -0,0 +1,32 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.util.command.*;
+
+public class RankDeleteCommand extends BaseCommand
+{
+ @Command(name = "rank.delete", aliases = { "deleterank" }, permission = "permissions.rank.delete", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (args.length == 0) {
+ command.getSender().sendMessage(ChatColor.RED + "/rank delete ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ command.getSender().sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.DELETE_RANK.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("rank", rank.getData().getName());
+ payload.addProperty("player", command.getSender().getName());
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankDeletePermissionCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankDeletePermissionCommand.java
new file mode 100644
index 0000000..df7cff4
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankDeletePermissionCommand.java
@@ -0,0 +1,41 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import org.bukkit.command.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class RankDeletePermissionCommand extends BaseCommand
+{
+ @Command(name = "rank.deletepermission", aliases = { "rank.delperm", "rank.deleteperm", "rank.delpermission" }, permission = "permissions.rank.deletepermission", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 2) {
+ sender.sendMessage(ChatColor.RED + "/rank deletepermission ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ sender.sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ final String permission = args[1].toLowerCase();
+ if (!rank.getPermissions().contains(permission)) {
+ sender.sendMessage(ChatColor.RED + "Rank named '" + rank.getData().getName() + "' doesn't have permission node '" + permission + "'.");
+ return;
+ }
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.DELETE_RANK_PERMISSION.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("player", sender.getName());
+ payload.addProperty("rank", rank.getUuid().toString());
+ payload.addProperty("permission", permission);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankImportCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankImportCommand.java
new file mode 100644
index 0000000..b21349e
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankImportCommand.java
@@ -0,0 +1,65 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import mkremins.fanciful.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.scheduler.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import org.bukkit.plugin.*;
+import us.centile.permissions.util.file.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+
+public class RankImportCommand extends BaseCommand
+{
+ @Command(name = "rank.import", aliases = { "importranks" }, permission = "permissions.rank.import", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (args.length == 0) {
+ new FancyMessage(ChatColor.YELLOW + "Please confirm this action: ").then(ChatColor.GREEN + "" + ChatColor.BOLD + "CONFIRM").tooltip(ChatColor.GREEN + "Click to confirm").command("/rank import confirm").send(command.getSender());
+ }
+ else if (args[0].equalsIgnoreCase("confirm")) {
+ Rank.getRanks().clear();
+ this.main.getPermissionsDatabase().getProfiles().drop();
+ this.main.getPermissionsDatabase().getRanks().drop();
+ final ConfigFile config = this.main.getRanksFile();
+ for (final String key : config.getConfiguration().getKeys(false)) {
+ final String name = config.getString(key + ".NAME");
+ final String prefix = config.getString(key + ".PREFIX", "&f", false);
+ final String suffix = config.getString(key + ".SUFFIX", "&f", false);
+ final boolean defaultRank = config.getBoolean(key + ".DEFAULT");
+ final List permissions = config.getStringListOrDefault(key + ".PERMISSIONS", new ArrayList());
+ final RankData data = new RankData(name);
+ data.setPrefix(prefix);
+ data.setSuffix(suffix);
+ data.setDefaultRank(defaultRank);
+ new Rank(UUID.randomUUID(), new ArrayList(), permissions, data);
+ }
+ for (final String key : config.getConfiguration().getKeys(false)) {
+ final Rank rank = Rank.getByName(config.getString(key + ".NAME"));
+ if (rank != null) {
+ for (final String name2 : config.getStringListOrDefault(key + ".INHERITANCE", new ArrayList())) {
+ final Rank other = Rank.getByName(config.getString(name2 + ".NAME"));
+ if (other != null) {
+ rank.getInheritance().add(other.getUuid());
+ }
+ }
+ }
+ }
+ this.main.getRankHandler().save();
+ command.getSender().sendMessage(ChatColor.GREEN + "Processing request..");
+ new BukkitRunnable() {
+ public void run() {
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.IMPORT_RANKS.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("player", command.getSender().getName());
+ object.add("payload", payload);
+ RankImportCommand.this.main.getPublisher().write(object.toString());
+ }
+ }.runTaskLater((Plugin)this.main, 40L);
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankListPermissionsCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankListPermissionsCommand.java
new file mode 100644
index 0000000..83c0b29
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankListPermissionsCommand.java
@@ -0,0 +1,47 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.command.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class RankListPermissionsCommand extends BaseCommand
+{
+ @Command(name = "rank.listpermissions", aliases = { "rank.listperms" }, permission = "permissions.rank.listpermissions", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final CommandSender sender = command.getSender();
+ final String[] args = command.getArgs();
+ if (args.length != 1) {
+ sender.sendMessage(ChatColor.RED + "/rank listpermissions ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ sender.sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ sender.sendMessage(ChatColor.GREEN + "Listing permissions of " + rank.getData().getColorPrefix() + rank.getData().getName() + ChatColor.GREEN + ":");
+ sender.sendMessage(ChatColor.GREEN + "Base permissions:");
+ for (final String permission : rank.getPermissions()) {
+ sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + permission);
+ }
+ for (final UUID inheritance : rank.getInheritance()) {
+ final Rank other = Rank.getByUuid(inheritance);
+ if (other != null) {
+ int count = 0;
+ for (final String permission2 : other.getPermissions()) {
+ if (!rank.getPermissions().contains(permission2)) {
+ if (count == 0) {
+ sender.sendMessage(ChatColor.GREEN + "Permissions inherited from " + other.getData().getColorPrefix() + other.getData().getName() + ChatColor.GREEN + ":");
+ }
+ ++count;
+ sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + permission2);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankPrefixCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankPrefixCommand.java
new file mode 100644
index 0000000..e82718a
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankPrefixCommand.java
@@ -0,0 +1,38 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.util.command.*;
+
+public class RankPrefixCommand extends BaseCommand
+{
+ @Command(name = "rank.prefix", aliases = { "rank.setprefix", "setprefix" }, permission = "permissions.rank.prefix", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (args.length <= 1) {
+ command.getSender().sendMessage(ChatColor.RED + "/rank setprefix ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ command.getSender().sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 1; i < args.length; ++i) {
+ sb.append(command.getArgs()[i]).append(" ");
+ }
+ final String prefix = sb.toString().trim().replace("\"", "");
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.SET_RANK_PREFIX.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("rank", rank.getData().getName());
+ payload.addProperty("player", command.getSender().getName());
+ payload.addProperty("prefix", prefix);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/RankSuffixCommand.java b/nPermissions/src/us/centile/permissions/rank/command/RankSuffixCommand.java
new file mode 100644
index 0000000..03f5d33
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/RankSuffixCommand.java
@@ -0,0 +1,38 @@
+package us.centile.permissions.rank.command;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.util.command.*;
+
+public class RankSuffixCommand extends BaseCommand
+{
+ @Command(name = "rank.suffix", aliases = { "rank.setsuffix", "setsuffix" }, permission = "permissions.rank.suffix", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (args.length <= 1) {
+ command.getSender().sendMessage(ChatColor.RED + "/rank setsuffix ");
+ return;
+ }
+ final Rank rank = Rank.getByName(args[0]);
+ if (rank == null) {
+ command.getSender().sendMessage(ChatColor.RED + "Rank named '" + args[0] + "' not found.");
+ return;
+ }
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 1; i < args.length; ++i) {
+ sb.append(command.getArgs()[i]).append(" ");
+ }
+ final String suffix = sb.toString().trim().replace("\"", "");
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.SET_RANK_SUFFIX.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("rank", rank.getData().getName());
+ payload.addProperty("player", command.getSender().getName());
+ payload.addProperty("suffix", suffix);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/grant/GrantCommand.java b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantCommand.java
new file mode 100644
index 0000000..a9e192d
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantCommand.java
@@ -0,0 +1,203 @@
+package us.centile.permissions.rank.command.grant;
+
+import org.bukkit.*;
+import us.centile.permissions.rank.*;
+import us.centile.permissions.util.*;
+import us.centile.permissions.profile.*;
+import us.centile.permissions.grant.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.grant.procedure.*;
+import org.bukkit.command.*;
+import org.bukkit.entity.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+import us.centile.permissions.util.command.Command;
+
+public class GrantCommand extends BaseCommand
+{
+ @Command(name = "grant", permission = "permissions.rank.grant", inGameOnly = false)
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ if (command.getSender() instanceof ConsoleCommandSender) {
+ final CommandSender sender = command.getSender();
+ if (args.length < 4) {
+ command.getSender().sendMessage(ChatColor.RED + "/grant ");
+ return;
+ }
+ final Player player = Bukkit.getPlayer(args[0]);
+ UUID uuid;
+ String name;
+ if (player != null) {
+ uuid = player.getUniqueId();
+ name = player.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid = recipient.getKey();
+ name = recipient.getValue();
+ }
+ catch (Exception e) {
+ command.getSender().sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Rank rank = Rank.getByName(args[1]);
+ if (rank == null) {
+ sender.sendMessage(ChatColor.RED + "Failed to find rank.");
+ return;
+ }
+ long duration;
+ if (args[2].equalsIgnoreCase("perm") || args[2].equalsIgnoreCase("permanent")) {
+ duration = 2147483647L;
+ }
+ else {
+ try {
+ duration = System.currentTimeMillis() - DateUtil.parseDateDiff(args[2], false);
+ }
+ catch (Exception e2) {
+ sender.sendMessage(ChatColor.RED + "Invalid duration.");
+ return;
+ }
+ }
+ final StringBuilder sb = new StringBuilder();
+ for (int i = 3; i < args.length; ++i) {
+ sb.append(command.getArgs()[i]).append(" ");
+ }
+ final String reason = sb.toString().trim();
+ final Profile profile = Profile.getByUuid(uuid);
+ if (profile != null) {
+ if (profile.getActiveGrant().getRank() == rank) {
+ sender.sendMessage(ChatColor.RED + "User has that grant already.");
+ return;
+ }
+ if (profile.getName() == null || !profile.getName().equals(name)) {
+ profile.setName(name);
+ profile.save();
+ }
+ for (final Grant grant : profile.getGrants()) {
+ if (!grant.getRank().getData().isDefaultRank() && !grant.isExpired()) {
+ grant.setActive(false);
+ }
+ }
+ final Grant newGrant = new Grant(null, rank, System.currentTimeMillis(), duration, reason, true);
+ profile.getGrants().add(newGrant);
+ profile.setupAtatchment();
+ profile.save();
+ if (player == null) {
+ Profile.getProfiles().remove(profile);
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.ADD_GRANT.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("uuid", profile.getUuid().toString());
+ final JsonObject grant2 = new JsonObject();
+ grant2.addProperty("rank", rank.getUuid().toString());
+ grant2.addProperty("datedAdded", System.currentTimeMillis());
+ grant2.addProperty("duration", duration);
+ grant2.addProperty("reason", reason);
+ payload.add("grant", grant2);
+ object.add("payload", payload);
+ this.main.getPublisher().write(object.toString());
+ }
+ else {
+ player.sendMessage(ChatColor.GREEN + "Your rank has been set to " + newGrant.getRank().getData().getColorPrefix() + newGrant.getRank().getData().getName() + ChatColor.GREEN + ".");
+ }
+ }
+ sender.sendMessage(ChatColor.GREEN + "Grant successfully created.");
+ }
+ else {
+ final Player sender2 = command.getPlayer();
+ if (args.length == 0) {
+ command.getSender().sendMessage(ChatColor.RED + "/grant ");
+ return;
+ }
+ final GrantProcedure procedure = GrantProcedure.getByPlayer(sender2);
+ if (procedure != null) {
+ if (args[0].equalsIgnoreCase("cancel")) {
+ sender2.sendMessage(" ");
+ sender2.sendMessage(ChatColor.RED + "Grant procedure cancelled.");
+ sender2.sendMessage(" ");
+ GrantProcedure.getProcedures().remove(procedure);
+ }
+ else if (args[0].equalsIgnoreCase("confirm")) {
+ GrantProcedure.getProcedures().remove(procedure);
+ procedure.getData().setCreated(System.currentTimeMillis());
+ sender2.sendMessage(" ");
+ sender2.sendMessage(ChatColor.YELLOW + "Grant successfully created.");
+ sender2.sendMessage(" ");
+ final Profile profile2 = Profile.getByUuid(procedure.getRecipient().getUuid());
+ if (profile2 != null) {
+ final Player player2 = Bukkit.getPlayer(profile2.getUuid());
+ if (profile2.getName() == null || !profile2.getName().equals(procedure.getRecipient().getName())) {
+ profile2.setName(procedure.getRecipient().getName());
+ }
+ for (final Grant grant3 : profile2.getGrants()) {
+ if (!grant3.getRank().getData().isDefaultRank() && !grant3.isExpired()) {
+ grant3.setActive(false);
+ }
+ }
+ final Grant newGrant2 = new Grant(sender2.getUniqueId(), procedure.getData().getRank(), procedure.getData().getCreated(), procedure.getData().getDuration(), procedure.getData().getReason(), true);
+ profile2.getGrants().add(newGrant2);
+ profile2.setupAtatchment();
+ profile2.save();
+ if (player2 == null) {
+ Profile.getProfiles().remove(profile2);
+ final JsonObject object2 = new JsonObject();
+ object2.addProperty("action", JedisSubscriberAction.ADD_GRANT.name());
+ final JsonObject payload2 = new JsonObject();
+ payload2.addProperty("uuid", profile2.getUuid().toString());
+ final JsonObject grant4 = new JsonObject();
+ grant4.addProperty("issuer", sender2.getUniqueId().toString());
+ grant4.addProperty("rank", procedure.getData().getRank().getUuid().toString());
+ grant4.addProperty("datedAdded", procedure.getData().getCreated());
+ grant4.addProperty("duration", procedure.getData().getDuration());
+ grant4.addProperty("reason", procedure.getData().getReason());
+ payload2.add("grant", grant4);
+ object2.add("payload", payload2);
+ this.main.getPublisher().write(object2.toString());
+ }
+ else {
+ player2.sendMessage(ChatColor.GREEN + "Your rank has been set to " + newGrant2.getRank().getData().getColorPrefix() + newGrant2.getRank().getData().getName() + ChatColor.GREEN + ".");
+ }
+ }
+ }
+ else {
+ sender2.sendMessage(" ");
+ sender2.sendMessage(ChatColor.RED + "You're already in a grant procedure.");
+ sender2.sendMessage(ChatColor.RED + "Please enter a valid duration or type 'cancel' to cancel.");
+ sender2.sendMessage(" ");
+ }
+ return;
+ }
+ if (args[0].equalsIgnoreCase("confirm") || args[0].equalsIgnoreCase("cancel")) {
+ return;
+ }
+ final Player player3 = Bukkit.getPlayer(args[0]);
+ UUID uuid2;
+ String name2;
+ if (player3 != null) {
+ uuid2 = player3.getUniqueId();
+ name2 = player3.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient2 = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid2 = recipient2.getKey();
+ name2 = recipient2.getValue();
+ }
+ catch (Exception e3) {
+ command.getSender().sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Profile profile3 = Profile.getByUuid(uuid2);
+ if (profile3.getName() == null || !profile3.getName().equals(name2)) {
+ profile3.setName(name2);
+ profile3.save();
+ }
+ sender2.openInventory(new GrantProcedure(new GrantRecipient(uuid2, name2), sender2.getUniqueId(), new GrantProcedureData()).getInventory());
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/grant/GrantListeners.java b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantListeners.java
new file mode 100644
index 0000000..d5aa1b3
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantListeners.java
@@ -0,0 +1,92 @@
+package us.centile.permissions.rank.command.grant;
+
+import us.centile.permissions.*;
+import org.bukkit.event.player.*;
+import us.centile.permissions.profile.*;
+import org.bukkit.entity.*;
+import us.centile.permissions.grant.*;
+import org.bukkit.event.*;
+import org.bukkit.event.inventory.*;
+import org.bukkit.*;
+import us.centile.permissions.jedis.*;
+import com.google.gson.*;
+import us.centile.permissions.rank.*;
+import org.bukkit.inventory.*;
+
+public class GrantListeners implements Listener
+{
+ private static nPermissions main;
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onAsyncPlayerChatEvent(final AsyncPlayerChatEvent event) {
+ final Player player = event.getPlayer();
+ final Profile profile = Profile.getByUuid(player.getUniqueId());
+ event.setFormat("%1$s: %2$s");
+ player.setDisplayName(player.getName());
+ if (profile != null) {
+ final Grant grant = profile.getActiveGrant();
+ if (!player.getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', grant.getRank().getData().getPrefix() + player.getName() + grant.getRank().getData().getSuffix()))) {
+ player.setDisplayName(ChatColor.translateAlternateColorCodes('&', grant.getRank().getData().getPrefix() + player.getName() + grant.getRank().getData().getSuffix()));
+ }
+ }
+ }
+
+ @EventHandler
+ public void onInventoryClickEvent(final InventoryClickEvent event) {
+ final Player player = (Player)event.getWhoClicked();
+ final ItemStack itemStack = event.getCurrentItem();
+ if (itemStack != null && itemStack.getType() != Material.AIR) {
+ final String title = event.getInventory().getTitle();
+ final String displayName = itemStack.getItemMeta().getDisplayName();
+ if (title.contains(ChatColor.RED + "Grants") && player.hasPermission("permissions.rank.view")) {
+ event.setCancelled(true);
+ final int page = Integer.parseInt(title.substring(title.lastIndexOf("/") - 1, title.lastIndexOf("/")));
+ final int total = Integer.parseInt(title.substring(title.lastIndexOf("/") + 1, title.lastIndexOf("/") + 2));
+ final String playerName = ChatColor.stripColor(event.getInventory().getItem(4).getItemMeta().getLore().get(0).substring(event.getInventory().getItem(4).getItemMeta().getLore().get(0).indexOf(" "), event.getInventory().getItem(4).getItemMeta().getLore().get(0).length())).trim();
+ final Profile profile = Profile.getExternalByName(playerName);
+ if (event.getRawSlot() == 9 && profile != null && itemStack.getDurability() == 5) {
+ final Grant activeGrant = profile.getActiveGrant();
+ activeGrant.setActive(false);
+ profile.save();
+ final Player profilePlayer = Bukkit.getPlayer(profile.getUuid());
+ if (profilePlayer == null) {
+ final JsonObject object = new JsonObject();
+ object.addProperty("action", JedisSubscriberAction.DELETE_GRANT.name());
+ final JsonObject payload = new JsonObject();
+ payload.addProperty("uuid", profile.getUuid().toString());
+ object.add("payload", payload);
+ GrantListeners.main.getPublisher().write(object.toString());
+ }
+ else {
+ final Rank rank = Rank.getDefaultRank();
+ if (rank != null) {
+ profilePlayer.sendMessage(ChatColor.GREEN + "Your rank has been set to " + rank.getData().getColorPrefix() + rank.getData().getName() + ChatColor.GREEN + ".");
+ profile.setupAtatchment();
+ }
+ }
+ player.closeInventory();
+ player.sendMessage(ChatColor.RED + "Grant successfully disabled.");
+ return;
+ }
+ if (displayName.contains("Next Page")) {
+ if (page + 1 > total) {
+ player.sendMessage(ChatColor.RED + "There are no more pages.");
+ return;
+ }
+ player.openInventory(GrantListeners.main.getRankHandler().getGrantsInventory(profile, playerName, page + 1));
+ }
+ else if (displayName.contains("Previous Page")) {
+ if (page == 1) {
+ player.sendMessage(ChatColor.RED + "You're on the first page.");
+ return;
+ }
+ player.openInventory(GrantListeners.main.getRankHandler().getGrantsInventory(profile, playerName, page - 1));
+ }
+ }
+ }
+ }
+
+ static {
+ GrantListeners.main = nPermissions.getInstance();
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/rank/command/grant/GrantsCommand.java b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantsCommand.java
new file mode 100644
index 0000000..791be4e
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/rank/command/grant/GrantsCommand.java
@@ -0,0 +1,48 @@
+package us.centile.permissions.rank.command.grant;
+
+import org.bukkit.*;
+import us.centile.permissions.profile.*;
+import org.bukkit.entity.*;
+import java.util.*;
+import us.centile.permissions.util.command.*;
+
+public class GrantsCommand extends BaseCommand
+{
+ @Command(name = "rankhistory", aliases = { "rankhistory.view" }, permission = "permissions.rank.view")
+ @Override
+ public void onCommand(final CommandArgs command) {
+ final String[] args = command.getArgs();
+ final Player sender = command.getPlayer();
+ if (args.length == 0) {
+ command.getSender().sendMessage(ChatColor.RED + "/rankhistory ");
+ return;
+ }
+ final Player player = Bukkit.getPlayer(args[0]);
+ UUID uuid;
+ String name;
+ if (player != null) {
+ uuid = player.getUniqueId();
+ name = player.getName();
+ }
+ else {
+ try {
+ final Map.Entry recipient = this.main.getRankHandler().getExternalUuid(args[0]);
+ uuid = recipient.getKey();
+ name = recipient.getValue();
+ }
+ catch (Exception e) {
+ command.getSender().sendMessage(ChatColor.RED + "Failed to find player.");
+ return;
+ }
+ }
+ final Profile profile = Profile.getByUuid(uuid);
+ if (profile != null) {
+ if (profile.getName() == null || !profile.getName().equals(name)) {
+ profile.setName(name);
+ profile.save();
+ }
+ sender.sendMessage(ChatColor.YELLOW + "Displaying the grants of " + name + ".");
+ sender.openInventory(this.main.getRankHandler().getGrantsInventory(profile, name, 1));
+ }
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/DateUtil.java b/nPermissions/src/us/centile/permissions/util/DateUtil.java
new file mode 100644
index 0000000..d2025b9
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/DateUtil.java
@@ -0,0 +1,206 @@
+package us.centile.permissions.util;
+
+import java.util.regex.*;
+import java.util.*;
+import java.math.*;
+import java.text.*;
+import java.io.*;
+
+public class DateUtil
+{
+ private static Pattern timePattern;
+
+ public static String removeTimePattern(final String input) {
+ return DateUtil.timePattern.matcher(input).replaceFirst("").trim();
+ }
+
+ public static long parseDateDiff(final String time, final boolean future) throws Exception {
+ final Matcher m = DateUtil.timePattern.matcher(time);
+ int years = 0;
+ int months = 0;
+ int weeks = 0;
+ int days = 0;
+ int hours = 0;
+ int minutes = 0;
+ int seconds = 0;
+ boolean found = false;
+ while (m.find()) {
+ if (m.group() != null && !m.group().isEmpty()) {
+ for (int c = 0; c < m.groupCount(); ++c) {
+ if (m.group(c) != null && !m.group(c).isEmpty()) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ continue;
+ }
+ if (m.group(1) != null && !m.group(1).isEmpty()) {
+ years = Integer.parseInt(m.group(1));
+ }
+ if (m.group(2) != null && !m.group(2).isEmpty()) {
+ months = Integer.parseInt(m.group(2));
+ }
+ if (m.group(3) != null && !m.group(3).isEmpty()) {
+ weeks = Integer.parseInt(m.group(3));
+ }
+ if (m.group(4) != null && !m.group(4).isEmpty()) {
+ days = Integer.parseInt(m.group(4));
+ }
+ if (m.group(5) != null && !m.group(5).isEmpty()) {
+ hours = Integer.parseInt(m.group(5));
+ }
+ if (m.group(6) != null && !m.group(6).isEmpty()) {
+ minutes = Integer.parseInt(m.group(6));
+ }
+ if (m.group(7) != null && !m.group(7).isEmpty()) {
+ seconds = Integer.parseInt(m.group(7));
+ break;
+ }
+ break;
+ }
+ }
+ if (!found) {
+ throw new Exception("Illegal Date");
+ }
+ final GregorianCalendar var13 = new GregorianCalendar();
+ if (years > 0) {
+ var13.add(1, years * (future ? 1 : -1));
+ }
+ if (months > 0) {
+ var13.add(2, months * (future ? 1 : -1));
+ }
+ if (weeks > 0) {
+ var13.add(3, weeks * (future ? 1 : -1));
+ }
+ if (days > 0) {
+ var13.add(5, days * (future ? 1 : -1));
+ }
+ if (hours > 0) {
+ var13.add(11, hours * (future ? 1 : -1));
+ }
+ if (minutes > 0) {
+ var13.add(12, minutes * (future ? 1 : -1));
+ }
+ if (seconds > 0) {
+ var13.add(13, seconds * (future ? 1 : -1));
+ }
+ final GregorianCalendar max = new GregorianCalendar();
+ max.add(1, 10);
+ return var13.after(max) ? max.getTimeInMillis() : var13.getTimeInMillis();
+ }
+
+ static int dateDiff(final int type, final Calendar fromDate, final Calendar toDate, final boolean future) {
+ int diff = 0;
+ long savedDate = fromDate.getTimeInMillis();
+ while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate))) {
+ savedDate = fromDate.getTimeInMillis();
+ fromDate.add(type, future ? 1 : -1);
+ ++diff;
+ }
+ --diff;
+ fromDate.setTimeInMillis(savedDate);
+ return diff;
+ }
+
+ public static String formatDateDiff(final long date) {
+ final GregorianCalendar c = new GregorianCalendar();
+ c.setTimeInMillis(date);
+ final GregorianCalendar now = new GregorianCalendar();
+ return formatDateDiff(now, c);
+ }
+
+ public static String formatDateDiff(final Calendar fromDate, final Calendar toDate) {
+ boolean future = false;
+ if (toDate.equals(fromDate)) {
+ return "now";
+ }
+ if (toDate.after(fromDate)) {
+ future = true;
+ }
+ final StringBuilder sb = new StringBuilder();
+ final int[] types = { 1, 2, 5, 11, 12, 13 };
+ final String[] names = { "year", "years", "month", "months", "day", "days", "hour", "hours", "minute", "minutes", "second", "seconds" };
+ for (int accuracy = 0, i = 0; i < types.length && accuracy <= 2; ++i) {
+ final int diff = dateDiff(types[i], fromDate, toDate, future);
+ if (diff > 0) {
+ ++accuracy;
+ sb.append(" ").append(diff).append(" ").append(names[i * 2 + ((diff > 1) ? 1 : 0)]);
+ }
+ }
+ return (sb.length() == 0) ? "now" : sb.toString().trim();
+ }
+
+ public static String formatSimplifiedDateDiff(final long date) {
+ final GregorianCalendar c = new GregorianCalendar();
+ c.setTimeInMillis(date);
+ final GregorianCalendar now = new GregorianCalendar();
+ return formatSimplifiedDateDiff(now, c);
+ }
+
+ public static String formatSimplifiedDateDiff(final Calendar fromDate, final Calendar toDate) {
+ boolean future = false;
+ if (toDate.equals(fromDate)) {
+ return "now";
+ }
+ if (toDate.after(fromDate)) {
+ future = true;
+ }
+ final StringBuilder sb = new StringBuilder();
+ final int[] types = { 1, 2, 5, 11, 12, 13 };
+ final String[] names = { "y", "y", "m", "m", "d", "d", "h", "h", "m", "m", "s", "s" };
+ for (int accuracy = 0, i = 0; i < types.length && accuracy <= 2; ++i) {
+ final int diff = dateDiff(types[i], fromDate, toDate, future);
+ if (diff > 0) {
+ ++accuracy;
+ sb.append(" ").append(diff).append("").append(names[i * 2 + ((diff > 1) ? 1 : 0)]);
+ }
+ }
+ return (sb.length() == 0) ? "now" : sb.toString().trim();
+ }
+
+ public static String readableTime(final long time) {
+ final short SECOND = 1000;
+ final int MINUTE = 60 * SECOND;
+ final int HOUR = 60 * MINUTE;
+ final int DAY = 24 * HOUR;
+ long ms = time;
+ final StringBuilder text = new StringBuilder("");
+ if (time > DAY) {
+ text.append(time / DAY).append(" days ");
+ ms = time % DAY;
+ }
+ if (ms > HOUR) {
+ text.append(ms / HOUR).append(" hours ");
+ ms %= HOUR;
+ }
+ if (ms > MINUTE) {
+ text.append(ms / MINUTE).append(" minutes ");
+ ms %= MINUTE;
+ }
+ if (ms > SECOND) {
+ text.append(ms / SECOND).append(" seconds ");
+ final long n = ms % SECOND;
+ }
+ return text.toString();
+ }
+
+ public static String readableTime(BigDecimal time) {
+ final String text = "";
+ if (time.doubleValue() <= 60.0) {
+ time = time.add(BigDecimal.valueOf(0.1));
+ return text + " " + time + "s";
+ }
+ if (time.doubleValue() <= 3600.0) {
+ final int minutes = time.intValue() / 60;
+ final int seconds = time.intValue() % 60;
+ final DecimalFormat formatter = new DecimalFormat("00");
+ return text + " " + formatter.format(minutes) + ":" + formatter.format(seconds) + "m";
+ }
+ return null;
+ }
+
+ static {
+ DateUtil.timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?(?:([0-9]+)\\s*(?:s[a-z]*)?)?", 2);
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/ItemBuilder.java b/nPermissions/src/us/centile/permissions/util/ItemBuilder.java
new file mode 100644
index 0000000..e5fb6f4
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/ItemBuilder.java
@@ -0,0 +1,110 @@
+package us.centile.permissions.util;
+
+import org.bukkit.event.*;
+import org.bukkit.inventory.*;
+import java.util.*;
+import org.bukkit.material.*;
+import org.bukkit.enchantments.*;
+import org.bukkit.*;
+import org.bukkit.inventory.meta.*;
+
+public class ItemBuilder implements Listener
+{
+ private final ItemStack is;
+
+ public ItemBuilder(final Material mat) {
+ this.is = new ItemStack(mat);
+ }
+
+ public ItemBuilder(final ItemStack is) {
+ this.is = is;
+ }
+
+ public ItemBuilder amount(final int amount) {
+ this.is.setAmount(amount);
+ return this;
+ }
+
+ public ItemBuilder name(final String name) {
+ final ItemMeta meta = this.is.getItemMeta();
+ meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
+ this.is.setItemMeta(meta);
+ return this;
+ }
+
+ public ItemBuilder lore(final String name) {
+ final ItemMeta meta = this.is.getItemMeta();
+ List lore = (List)meta.getLore();
+ if (lore == null) {
+ lore = new ArrayList();
+ }
+ lore.add(name);
+ meta.setLore((List)lore);
+ this.is.setItemMeta(meta);
+ return this;
+ }
+
+ public ItemBuilder lore(final List lore) {
+ final List toSet = new ArrayList();
+ final ItemMeta meta = this.is.getItemMeta();
+ for (final String string : lore) {
+ toSet.add(ChatColor.translateAlternateColorCodes('&', string));
+ }
+ meta.setLore((List)toSet);
+ this.is.setItemMeta(meta);
+ return this;
+ }
+
+ public ItemBuilder durability(final int durability) {
+ this.is.setDurability((short)durability);
+ return this;
+ }
+
+ public ItemBuilder data(final int data) {
+ this.is.setData(new MaterialData(this.is.getType(), (byte)data));
+ return this;
+ }
+
+ public ItemBuilder enchantment(final Enchantment enchantment, final int level) {
+ this.is.addUnsafeEnchantment(enchantment, level);
+ return this;
+ }
+
+ public ItemBuilder enchantment(final Enchantment enchantment) {
+ this.is.addUnsafeEnchantment(enchantment, 1);
+ return this;
+ }
+
+ public ItemBuilder type(final Material material) {
+ this.is.setType(material);
+ return this;
+ }
+
+ public ItemBuilder clearLore() {
+ final ItemMeta meta = this.is.getItemMeta();
+ meta.setLore((List)new ArrayList());
+ this.is.setItemMeta(meta);
+ return this;
+ }
+
+ public ItemBuilder clearEnchantments() {
+ for (final Enchantment e : this.is.getEnchantments().keySet()) {
+ this.is.removeEnchantment(e);
+ }
+ return this;
+ }
+
+ public ItemBuilder color(final Color color) {
+ if (this.is.getType() == Material.LEATHER_BOOTS || this.is.getType() == Material.LEATHER_CHESTPLATE || this.is.getType() == Material.LEATHER_HELMET || this.is.getType() == Material.LEATHER_LEGGINGS) {
+ final LeatherArmorMeta meta = (LeatherArmorMeta)this.is.getItemMeta();
+ meta.setColor(color);
+ this.is.setItemMeta((ItemMeta)meta);
+ return this;
+ }
+ throw new IllegalArgumentException("color() only applicable for leather armor!");
+ }
+
+ public ItemStack build() {
+ return this.is;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/PlayerUtility.java b/nPermissions/src/us/centile/permissions/util/PlayerUtility.java
new file mode 100644
index 0000000..a930ea2
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/PlayerUtility.java
@@ -0,0 +1,24 @@
+package us.centile.permissions.util;
+
+import org.bukkit.entity.*;
+import java.util.*;
+import org.bukkit.*;
+
+public class PlayerUtility
+{
+ public static Set getConvertedUuidSet(final Set uuids) {
+ final Set toReturn = new HashSet();
+ for (final UUID uuid : uuids) {
+ toReturn.add(uuid.toString());
+ }
+ return toReturn;
+ }
+
+ public static List getOnlinePlayers() {
+ final ArrayList ret = new ArrayList();
+ for (final Player player : Bukkit.getServer().getOnlinePlayers()) {
+ ret.add(player);
+ }
+ return ret;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/WoolUtil.java b/nPermissions/src/us/centile/permissions/util/WoolUtil.java
new file mode 100644
index 0000000..439c6ff
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/WoolUtil.java
@@ -0,0 +1,20 @@
+package us.centile.permissions.util;
+
+import org.bukkit.*;
+import java.util.*;
+
+public class WoolUtil
+{
+ private static final ArrayList woolColors;
+
+ public static int convertChatColorToWoolData(ChatColor color) {
+ if (color == ChatColor.DARK_RED) {
+ color = ChatColor.RED;
+ }
+ return WoolUtil.woolColors.indexOf(color);
+ }
+
+ static {
+ woolColors = new ArrayList(Arrays.asList(ChatColor.WHITE, ChatColor.GOLD, ChatColor.LIGHT_PURPLE, ChatColor.AQUA, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.LIGHT_PURPLE, ChatColor.DARK_GRAY, ChatColor.GRAY, ChatColor.DARK_AQUA, ChatColor.DARK_PURPLE, ChatColor.BLUE, ChatColor.BLACK, ChatColor.DARK_GREEN, ChatColor.RED, ChatColor.BLACK));
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/BaseCommand.java b/nPermissions/src/us/centile/permissions/util/command/BaseCommand.java
new file mode 100644
index 0000000..f541048
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/BaseCommand.java
@@ -0,0 +1,18 @@
+package us.centile.permissions.util.command;
+
+import us.centile.permissions.*;
+import us.centile.permissions.util.file.*;
+
+public abstract class BaseCommand
+{
+ public nPermissions main;
+ public ConfigFile configFile;
+
+ public BaseCommand() {
+ this.main = nPermissions.getInstance();
+ this.configFile = this.main.getConfigFile();
+ this.main.getCommandFramework().registerCommands(this);
+ }
+
+ public abstract void onCommand(final CommandArgs p0);
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/BukkitCommand.java b/nPermissions/src/us/centile/permissions/util/command/BukkitCommand.java
new file mode 100644
index 0000000..538f094
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/BukkitCommand.java
@@ -0,0 +1,86 @@
+package us.centile.permissions.util.command;
+
+import java.util.List;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandException;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+import org.bukkit.plugin.Plugin;
+
+public class BukkitCommand extends Command {
+ private final Plugin owningPlugin;
+ private CommandExecutor executor;
+ protected BukkitCompleter completer;
+
+ protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
+ super(label);
+ this.executor = executor;
+ this.owningPlugin = owner;
+ this.usageMessage = "";
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String commandLabel,
+ String[] args) {
+ boolean success = false;
+ if (!this.owningPlugin.isEnabled()) {
+ return false;
+ }
+ if (!this.testPermission(sender)) {
+ return true;
+ }
+ try {
+ success = this.executor.onCommand(sender, this, commandLabel, args);
+ } catch (Throwable ex) {
+ throw new CommandException(
+ "Unhandled exception executing command '" + commandLabel
+ + "' in plugin "
+ + this.owningPlugin.getDescription().getFullName(),
+ ex);
+ }
+ if (!success && this.usageMessage.length() > 0) {
+ for (String line : this.usageMessage.replace("",
+ commandLabel).split("\n")) {
+ sender.sendMessage(line);
+ }
+ }
+ return success;
+ }
+
+ @Override
+ public List tabComplete(CommandSender sender, String alias,
+ String[] args) throws CommandException, IllegalArgumentException {
+ Validate.notNull(sender, "Sender cannot be null");
+ Validate.notNull(args, "Arguments cannot be null");
+ Validate.notNull(alias, "Alias cannot be null");
+ List completions = null;
+ try {
+ if (this.completer != null) {
+ completions = this.completer.onTabComplete(sender, this, alias,
+ args);
+ }
+ if (completions == null && this.executor instanceof TabCompleter) {
+ completions = ((TabCompleter) (this.executor))
+ .onTabComplete(sender, this, alias, args);
+ }
+ } catch (Throwable ex) {
+ StringBuilder message = new StringBuilder();
+ message.append(
+ "Unhandled exception during tab completion for command '/")
+ .append(alias).append(' ');
+ for (String arg : args) {
+ message.append(arg).append(' ');
+ }
+ message.deleteCharAt(message.length() - 1).append("' in plugin ")
+ .append(this.owningPlugin.getDescription().getFullName());
+ throw new CommandException(message.toString(), ex);
+ }
+ if (completions == null) {
+ return super.tabComplete(sender, alias, args);
+ }
+ return completions;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/BukkitCompleter.java b/nPermissions/src/us/centile/permissions/util/command/BukkitCompleter.java
new file mode 100644
index 0000000..8688923
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/BukkitCompleter.java
@@ -0,0 +1,55 @@
+package us.centile.permissions.util.command;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.TabCompleter;
+
+public class BukkitCompleter implements TabCompleter {
+ private Map> completers = new HashMap>();
+
+ public void addCompleter(String label, Method m, Object obj) {
+ this.completers.put(label, new AbstractMap.SimpleEntry(
+ m, obj));
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ public List onTabComplete(CommandSender sender, Command command,
+ String label, String[] args) {
+ for (int i = args.length; i >= 0; --i) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(label.toLowerCase());
+ for (int x = 0; x < i; ++x) {
+ if (args[x].equals("") || args[x].equals(" "))
+ continue;
+ buffer.append("." + args[x].toLowerCase());
+ }
+ String cmdLabel = buffer.toString();
+ if (!this.completers.containsKey(cmdLabel))
+ continue;
+ Map.Entry entry = this.completers.get(cmdLabel);
+ try {
+ return (List) entry.getKey().invoke(
+ entry.getValue(),
+ new CommandArgs(sender, command, label, args, cmdLabel
+ .split("\\.").length - 1));
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ continue;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ continue;
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/Command.java b/nPermissions/src/us/centile/permissions/util/command/Command.java
new file mode 100644
index 0000000..e2e452e
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/Command.java
@@ -0,0 +1,24 @@
+package us.centile.permissions.util.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(value = { ElementType.METHOD })
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface Command {
+ public String name();
+
+ public String permission() default "";
+
+ public String[] aliases() default {};
+
+ public String description() default "";
+
+ public String usage() default "";
+
+ public boolean inGameOnly() default true;
+
+ public boolean isAdminOnly() default false;
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/CommandArgs.java b/nPermissions/src/us/centile/permissions/util/command/CommandArgs.java
new file mode 100644
index 0000000..a7372f5
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/CommandArgs.java
@@ -0,0 +1,65 @@
+package us.centile.permissions.util.command;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class CommandArgs {
+ private CommandSender sender;
+ private Command command;
+ private String label;
+ private String[] args;
+
+ protected CommandArgs(CommandSender sender, Command command, String label,
+ String[] args, int subCommand) {
+ String[] modArgs = new String[args.length - subCommand];
+ for (int i = 0; i < args.length - subCommand; ++i) {
+ modArgs[i] = args[i + subCommand];
+ }
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(label);
+ for (int x = 0; x < subCommand; ++x) {
+ buffer.append("." + args[x]);
+ }
+ String cmdLabel = buffer.toString();
+ this.sender = sender;
+ this.command = command;
+ this.label = cmdLabel;
+ this.args = modArgs;
+ }
+
+ public CommandSender getSender() {
+ return this.sender;
+ }
+
+ public Command getCommand() {
+ return this.command;
+ }
+
+ public String getLabel() {
+ return this.label;
+ }
+
+ public String[] getArgs() {
+ return this.args;
+ }
+
+ public String getArgs(int index) {
+ return this.args[index];
+ }
+
+ public int length() {
+ return this.args.length;
+ }
+
+ public boolean isPlayer() {
+ return this.sender instanceof Player;
+ }
+
+ public Player getPlayer() {
+ if (this.sender instanceof Player) {
+ return (Player) this.sender;
+ }
+ return null;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/CommandFramework.java b/nPermissions/src/us/centile/permissions/util/command/CommandFramework.java
new file mode 100644
index 0000000..cf885d4
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/CommandFramework.java
@@ -0,0 +1,239 @@
+package us.centile.permissions.util.command;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandMap;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.PluginCommand;
+import org.bukkit.entity.Player;
+import org.bukkit.help.GenericCommandHelpTopic;
+import org.bukkit.help.HelpTopic;
+import org.bukkit.help.HelpTopicComparator;
+import org.bukkit.help.IndexHelpTopic;
+import org.bukkit.plugin.SimplePluginManager;
+
+
+import us.centile.permissions.nPermissions;
+
+public class CommandFramework implements CommandExecutor {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private Map> commandMap = new HashMap();
+ private CommandMap map;
+ private nPermissions plugin;
+
+ public CommandFramework(nPermissions plugin) {
+ this.plugin = plugin;
+ if ((plugin.getServer().getPluginManager() instanceof SimplePluginManager)) {
+ SimplePluginManager manager = (SimplePluginManager) plugin
+ .getServer().getPluginManager();
+ try {
+ Field field = SimplePluginManager.class
+ .getDeclaredField("commandMap");
+ field.setAccessible(true);
+ this.map = ((CommandMap) field.get(manager));
+ } catch (IllegalArgumentException | SecurityException
+ | NoSuchFieldException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender,
+ org.bukkit.command.Command cmd, String label, String[] args) {
+ return handleCommand(sender, cmd, label, args);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public boolean handleCommand(CommandSender sender,
+ org.bukkit.command.Command cmd, String label, String[] args) {
+ for (int i = args.length; i >= 0; i--) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(label.toLowerCase());
+ for (int x = 0; x < i; x++) {
+ buffer.append("." + args[x].toLowerCase());
+ }
+ String cmdLabel = buffer.toString();
+ if (this.commandMap.containsKey(cmdLabel)) {
+ Method method = (Method) ((Map.Entry) this.commandMap
+ .get(cmdLabel)).getKey();
+ Object methodObject = ((Map.Entry) this.commandMap
+ .get(cmdLabel)).getValue();
+ Command command = method.getAnnotation(Command.class);
+ if ((command.isAdminOnly())
+ && (!sender.hasPermission("admin.permission"))) {
+ sender.sendMessage(ChatColor.RED + "No permission!");
+ return true;
+ }
+ if ((!command.permission().equals(""))
+ && (!sender.hasPermission(command.permission()))) {
+ sender.sendMessage(ChatColor.RED
+ + "Not enough permissions to execute this command!");
+ return true;
+ }
+ if ((command.inGameOnly()) && (!(sender instanceof Player))) {
+ sender.sendMessage(ChatColor.RED
+ + "This command is only performable in game.");
+ return true;
+ }
+ try {
+ method.invoke(methodObject, new Object[] { new CommandArgs(
+ sender, cmd, label, args,
+ cmdLabel.split("\\.").length - 1) });
+ } catch (IllegalArgumentException | IllegalAccessException
+ | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ return true;
+ }
+ }
+ defaultCommand(new CommandArgs(sender, cmd, label, args, 0));
+ return true;
+ }
+
+ public void registerCommands(Object obj) {
+ for (Method m : obj.getClass().getMethods()) {
+ if (m.getAnnotation(Command.class) != null) {
+ Command command = m.getAnnotation(Command.class);
+ if ((m.getParameterTypes().length > 1)
+ || (m.getParameterTypes()[0] != CommandArgs.class)) {
+ System.out.println("Unable to register command "
+ + m.getName() + ". Unexpected method arguments");
+ } else {
+ registerCommand(command, command.name(), m, obj);
+ for (String alias : command.aliases()) {
+ registerCommand(command, alias, m, obj);
+ }
+ }
+ } else if (m.getAnnotation(Completer.class) != null) {
+ Completer comp = m.getAnnotation(Completer.class);
+ if ((m.getParameterTypes().length > 1)
+ || (m.getParameterTypes().length == 0)
+ || (m.getParameterTypes()[0] != CommandArgs.class)) {
+ System.out.println("Unable to register tab completer "
+ + m.getName() + ". Unexpected method arguments");
+ } else if (m.getReturnType() != List.class) {
+ System.out.println("Unable to register tab completer "
+ + m.getName() + ". Unexpected return type");
+ } else {
+ registerCompleter(comp.name(), m, obj);
+ for (String alias : comp.aliases()) {
+ registerCompleter(alias, m, obj);
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void registerHelp() {
+ Set help = new TreeSet(
+ HelpTopicComparator.helpTopicComparatorInstance());
+ for (String s : this.commandMap.keySet()) {
+ if (!s.contains(".")) {
+ org.bukkit.command.Command cmd = this.map.getCommand(s);
+ HelpTopic topic = new GenericCommandHelpTopic(cmd);
+ help.add(topic);
+ }
+ }
+ IndexHelpTopic topic = new IndexHelpTopic(this.plugin.getName(),
+ "All commands for " + this.plugin.getName(), null, help,
+ "Below is a list of all " + this.plugin.getName()
+ + " commands:");
+ Bukkit.getServer().getHelpMap().addTopic(topic);
+ }
+
+ public void unregisterCommands(Object obj) {
+ for (Method m : obj.getClass().getMethods()) {
+ if (m.getAnnotation(Command.class) != null) {
+ Command command = m.getAnnotation(Command.class);
+ this.commandMap.remove(command.name().toLowerCase());
+ this.commandMap.remove(this.plugin.getName() + ":"
+ + command.name().toLowerCase());
+ this.map.getCommand(command.name().toLowerCase()).unregister(
+ this.map);
+ }
+ }
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public void registerCommand(Command command, String label, Method m,
+ Object obj) {
+ this.commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry(m,
+ obj));
+ this.commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(),
+ new AbstractMap.SimpleEntry(m, obj));
+ String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
+ if (this.map.getCommand(cmdLabel) == null) {
+ org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this,
+ this.plugin);
+ this.map.register(this.plugin.getName(), cmd);
+ }
+ if ((!command.description().equalsIgnoreCase(""))
+ && (cmdLabel == label)) {
+ this.map.getCommand(cmdLabel).setDescription(command.description());
+ }
+ if ((!command.usage().equalsIgnoreCase("")) && (cmdLabel == label)) {
+ this.map.getCommand(cmdLabel).setUsage(command.usage());
+ }
+ }
+
+ public void registerCompleter(String label, Method m, Object obj) {
+ String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
+ if (this.map.getCommand(cmdLabel) == null) {
+ org.bukkit.command.Command command = new BukkitCommand(cmdLabel,
+ this, this.plugin);
+ this.map.register(this.plugin.getName(), command);
+ }
+ if ((this.map.getCommand(cmdLabel) instanceof BukkitCommand)) {
+ BukkitCommand command = (BukkitCommand) this.map
+ .getCommand(cmdLabel);
+ if (command.completer == null) {
+ command.completer = new BukkitCompleter();
+ }
+ command.completer.addCompleter(label, m, obj);
+ } else if ((this.map.getCommand(cmdLabel) instanceof PluginCommand)) {
+ try {
+ Object command = this.map.getCommand(cmdLabel);
+ Field field = command.getClass().getDeclaredField("completer");
+ field.setAccessible(true);
+ if (field.get(command) == null) {
+ BukkitCompleter completer = new BukkitCompleter();
+ completer.addCompleter(label, m, obj);
+ field.set(command, completer);
+ } else if ((field.get(command) instanceof BukkitCompleter)) {
+ BukkitCompleter completer = (BukkitCompleter) field
+ .get(command);
+ completer.addCompleter(label, m, obj);
+ } else {
+ System.out
+ .println("Unable to register tab completer "
+ + m.getName()
+ + ". A tab completer is already registered for that command!");
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private void defaultCommand(CommandArgs args) {
+ args.getSender()
+ .sendMessage(
+ ChatColor.YELLOW
+ + args.getLabel()
+ + ChatColor.BLUE
+ + " does not have a base command, please report this in teamspeak!");
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/command/Completer.java b/nPermissions/src/us/centile/permissions/util/command/Completer.java
new file mode 100644
index 0000000..20abcb8
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/command/Completer.java
@@ -0,0 +1,14 @@
+package us.centile.permissions.util.command;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(value = { ElementType.METHOD })
+@Retention(value = RetentionPolicy.RUNTIME)
+public @interface Completer {
+ public String name();
+
+ public String[] aliases() default {};
+}
diff --git a/nPermissions/src/us/centile/permissions/util/database/PermissionsDatabase.java b/nPermissions/src/us/centile/permissions/util/database/PermissionsDatabase.java
new file mode 100644
index 0000000..9f9c715
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/database/PermissionsDatabase.java
@@ -0,0 +1,73 @@
+package us.centile.permissions.util.database;
+
+import com.mongodb.client.*;
+import us.centile.permissions.*;
+import com.mongodb.*;
+import com.mongodb.MongoClient;
+
+import java.util.*;
+import java.security.cert.*;
+import java.security.*;
+import javax.net.ssl.*;
+
+public class PermissionsDatabase
+{
+ private MongoClient client;
+ private MongoDatabase database;
+ private MongoCollection ranks;
+ private MongoCollection profiles;
+
+ public PermissionsDatabase(final nPermissions main) {
+ if (main.getConfigFile().getBoolean("DATABASE.MONGO.AUTHENTICATION.ENABLED")) {
+ this.client = new MongoClient(new ServerAddress(main.getConfigFile().getString("DATABASE.MONGO.HOST"), main.getConfigFile().getInt("DATABASE.MONGO.PORT")), Arrays.asList(MongoCredential.createCredential(main.getConfigFile().getString("DATABASE.MONGO.AUTHENTICATION.USER"), main.getConfigFile().getString("DATABASE.MONGO.AUTHENTICATION.DATABASE"), main.getConfigFile().getString("DATABASE.MONGO.AUTHENTICATION.PASSWORD").toCharArray())));
+ }
+ else {
+ this.client = new MongoClient(new ServerAddress(main.getConfigFile().getString("DATABASE.MONGO.HOST"), main.getConfigFile().getInt("DATABASE.MONGO.PORT")));
+ }
+ this.database = this.client.getDatabase("permissions");
+ this.ranks = this.database.getCollection("ranks");
+ this.profiles = this.database.getCollection("profiles");
+ }
+
+ private SSLSocketFactory validateCert(final String hostIP) {
+ HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> hostname.equals(hostIP));
+ final TrustManager[] trustAllCerts = { new X509TrustManager() {
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ @Override
+ public void checkServerTrusted(final X509Certificate[] arg0, final String arg1) throws CertificateException {
+ }
+
+ @Override
+ public void checkClientTrusted(final X509Certificate[] arg0, final String arg1) throws CertificateException {
+ }
+ } };
+ try {
+ final SSLContext sc = SSLContext.getInstance("TLS");
+ sc.init(null, trustAllCerts, null);
+ return sc.getSocketFactory();
+ }
+ catch (GeneralSecurityException ex) {
+ return null;
+ }
+ }
+
+ public MongoClient getClient() {
+ return this.client;
+ }
+
+ public MongoDatabase getDatabase() {
+ return this.database;
+ }
+
+ public MongoCollection getRanks() {
+ return this.ranks;
+ }
+
+ public MongoCollection getProfiles() {
+ return this.profiles;
+ }
+}
diff --git a/nPermissions/src/us/centile/permissions/util/file/ConfigFile.java b/nPermissions/src/us/centile/permissions/util/file/ConfigFile.java
new file mode 100644
index 0000000..615f9e3
--- /dev/null
+++ b/nPermissions/src/us/centile/permissions/util/file/ConfigFile.java
@@ -0,0 +1,100 @@
+package us.centile.permissions.util.file;
+
+import java.io.*;
+import org.bukkit.configuration.file.*;
+import org.bukkit.plugin.java.*;
+import org.bukkit.*;
+import java.util.*;
+
+public class ConfigFile
+{
+ private File file;
+ private YamlConfiguration configuration;
+
+ public ConfigFile(final JavaPlugin plugin, final String name) {
+ this.file = new File(plugin.getDataFolder(), name + ".yml");
+ if (!this.file.getParentFile().exists()) {
+ this.file.getParentFile().mkdir();
+ }
+ plugin.saveResource(name + ".yml", false);
+ this.configuration = YamlConfiguration.loadConfiguration(this.file);
+ }
+
+ public double getDouble(final String path) {
+ if (this.configuration.contains(path)) {
+ return this.configuration.getDouble(path);
+ }
+ return 0.0;
+ }
+
+ public int getInt(final String path) {
+ if (this.configuration.contains(path)) {
+ return this.configuration.getInt(path);
+ }
+ return 0;
+ }
+
+ public boolean getBoolean(final String path) {
+ return this.configuration.contains(path) && this.configuration.getBoolean(path);
+ }
+
+ public String getString(final String path) {
+ if (this.configuration.contains(path)) {
+ return ChatColor.translateAlternateColorCodes('&', this.configuration.getString(path));
+ }
+ return "ERROR: STRING NOT FOUND";
+ }
+
+ public String getString(final String path, final String callback, final boolean colorize) {
+ if (!this.configuration.contains(path)) {
+ return callback;
+ }
+ if (colorize) {
+ return ChatColor.translateAlternateColorCodes('&', this.configuration.getString(path));
+ }
+ return this.configuration.getString(path);
+ }
+
+ public List getReversedStringList(final String path) {
+ final List list = this.getStringList(path);
+ if (list != null) {
+ final int size = list.size();
+ final List toReturn = new ArrayList();
+ for (int i = size - 1; i >= 0; --i) {
+ toReturn.add(list.get(i));
+ }
+ return toReturn;
+ }
+ return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
+ }
+
+ public List getStringList(final String path) {
+ if (this.configuration.contains(path)) {
+ final ArrayList strings = new ArrayList();
+ for (final String string : this.configuration.getStringList(path)) {
+ strings.add(ChatColor.translateAlternateColorCodes('&', string));
+ }
+ return strings;
+ }
+ return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
+ }
+
+ public List getStringListOrDefault(final String path, final List toReturn) {
+ if (this.configuration.contains(path)) {
+ final ArrayList strings = new ArrayList();
+ for (final String string : this.configuration.getStringList(path)) {
+ strings.add(ChatColor.translateAlternateColorCodes('&', string));
+ }
+ return strings;
+ }
+ return toReturn;
+ }
+
+ public File getFile() {
+ return this.file;
+ }
+
+ public YamlConfiguration getConfiguration() {
+ return this.configuration;
+ }
+}