diff --git a/pom.xml b/pom.xml index ee76683..8b2150e 100644 --- a/pom.xml +++ b/pom.xml @@ -146,6 +146,10 @@ CodeMC https://repo.codemc.org/repository/maven-public + + jitpack.io + https://jitpack.io + @@ -197,6 +201,14 @@ 1.7 compile + + + + com.github.MilkBowl + VaultAPI + 1.7 + provided + \ No newline at end of file diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java index ce073a1..efaf4cf 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java @@ -13,7 +13,8 @@ public class Floor { private String world; private int y; private ArrayList doorBlocks = new ArrayList<>(); - private HashSet whitelist = new HashSet<>(); + private HashSet userWhitelist = new HashSet<>(); + private HashSet groupWhitelist = new HashSet<>(); public Floor(int y, String world) { this.y = y; @@ -47,7 +48,8 @@ public class Floor { "world='" + world + '\'' + ", y=" + y + ", doorBlocks=" + doorBlocks + - ", whitelist=" + whitelist + + ", userWhitelist=" + userWhitelist + + ", groupWhitelist=" + groupWhitelist + '}'; } } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java index bf05315..d6dfe81 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Commands/V10LiftCommand.java @@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Managers.VaultManager; import nl.SBDeveloper.V10Lift.Utils.ConfigUtil; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; @@ -535,8 +536,24 @@ public class V10LiftCommand implements CommandExecutor { } Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); - OfflinePlayer wp = Bukkit.getOfflinePlayer(args[2]); - UUID wpu = wp.getUniqueId(); + boolean isGroup = false; + String wgn = null; + UUID wpu = null; + if (args[2].startsWith("g:")) { + if (!V10LiftPlugin.isVaultEnabled()) { + sender.sendMessage(ChatColor.RED + "You can't add a group when Vault is not found."); + return true; + } + isGroup = true; + wgn = args[2].replace("g:", ""); + if (!VaultManager.isGroup(wgn)) { + sender.sendMessage(ChatColor.RED + "Group " + wgn + " not found!"); + return true; + } + } else { + OfflinePlayer wp = Bukkit.getOfflinePlayer(args[2]); + wpu = wp.getUniqueId(); + } String floor = null; if (args.length < 4) { @@ -563,18 +580,36 @@ public class V10LiftCommand implements CommandExecutor { Floor f = lift.getFloors().get(floor); if (args[1].equalsIgnoreCase("add")) { - if (f.getWhitelist().contains(wpu)) { - sender.sendMessage(ChatColor.RED + "Whitelist already contains this user!"); + if (isGroup) { + if (f.getGroupWhitelist().contains(wgn)) { + sender.sendMessage(ChatColor.RED + "Whitelist already contains this group!"); + } else { + f.getGroupWhitelist().add(wgn); + sender.sendMessage(ChatColor.GREEN + "Group added to whitelist!"); + } } else { - f.getWhitelist().add(wpu); - sender.sendMessage(ChatColor.GREEN + "User added to whitelist!"); + if (f.getUserWhitelist().contains(wpu)) { + sender.sendMessage(ChatColor.RED + "Whitelist already contains this user!"); + } else { + f.getUserWhitelist().add(wpu); + sender.sendMessage(ChatColor.GREEN + "User added to whitelist!"); + } } } else if (args[1].equalsIgnoreCase("del")) { - if (!f.getWhitelist().contains(wpu)) { - sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this user!"); + if (isGroup) { + if (!f.getGroupWhitelist().contains(wgn)) { + sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this group!"); + } else { + f.getGroupWhitelist().remove(wgn); + sender.sendMessage(ChatColor.GREEN + "Group removed from whitelist!"); + } } else { - f.getWhitelist().remove(wpu); - sender.sendMessage(ChatColor.GREEN + "User removed from whitelist!"); + if (!f.getUserWhitelist().contains(wpu)) { + sender.sendMessage(ChatColor.RED + "Whitelist doesn't contain this user!"); + } else { + f.getUserWhitelist().remove(wpu); + sender.sendMessage(ChatColor.GREEN + "User removed from whitelist!"); + } } } else { return helpCommand(sender); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java index f84e32a..5715b84 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java @@ -4,6 +4,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.Floor; import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Managers.VaultManager; import nl.SBDeveloper.V10Lift.Utils.ConfigUtil; import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; @@ -316,7 +317,9 @@ public class PlayerInteractListener implements Listener { Floor floor = lift.getFloors().get(f2); if (lift.getY() == floor.getY()) { sign.setLine(3, ChatColor.GREEN + f2); - } else if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { + } else if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { + sign.setLine(3, ChatColor.RED + f2); + } else if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) { sign.setLine(3, ChatColor.RED + f2); } else { sign.setLine(3, ChatColor.YELLOW + f2); @@ -329,7 +332,13 @@ public class PlayerInteractListener implements Listener { } Floor floor = lift.getFloors().get(f); - if (!floor.getWhitelist().isEmpty() && !floor.getWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { + if (!floor.getUserWhitelist().isEmpty() && !floor.getUserWhitelist().contains(p.getUniqueId()) && !p.hasPermission("v10lift.admin")) { + p.sendMessage(ChatColor.RED + "You can't go to that floor!"); + e.setCancelled(true); + return; + } + + if (!floor.getGroupWhitelist().isEmpty() && !VaultManager.userHasAnyGroup(p, floor.getGroupWhitelist()) && !p.hasPermission("v10lift.admin")) { p.sendMessage(ChatColor.RED + "You can't go to that floor!"); e.setCancelled(true); return; diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/VaultManager.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/VaultManager.java new file mode 100644 index 0000000..9105d76 --- /dev/null +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Managers/VaultManager.java @@ -0,0 +1,32 @@ +package nl.SBDeveloper.V10Lift.Managers; + +import net.milkbowl.vault.permission.Permission; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; + +import javax.annotation.Nonnull; +import java.util.Arrays; +import java.util.HashSet; + +public class VaultManager { + private static Permission perms = null; + + public static boolean setupPermissions() { + RegisteredServiceProvider rsp = V10LiftPlugin.getInstance().getServer().getServicesManager().getRegistration(Permission.class); + perms = rsp.getProvider(); + return perms != null; + } + + public static boolean isGroup(String groupName) { + return Arrays.asList(perms.getGroups()).contains(groupName); + } + + public static boolean userHasAnyGroup(Player player, @Nonnull HashSet whitelistSet) { + boolean found = false; + for (String group : whitelistSet) { + found = Arrays.asList(perms.getPlayerGroups(player)).contains(group); + } + return found; + } +} diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java index b4275d9..fe3b7a9 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/V10LiftPlugin.java @@ -10,6 +10,7 @@ import nl.SBDeveloper.V10Lift.Listeners.PlayerInteractListener; import nl.SBDeveloper.V10Lift.Listeners.SignChangeListener; import nl.SBDeveloper.V10Lift.Managers.DBManager; import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Managers.VaultManager; import nl.SBDevelopment.SBUtilities.Data.YamlFile; import nl.SBDevelopment.SBUtilities.PrivateManagers.UpdateManager; import nl.SBDevelopment.SBUtilities.SBUtilities; @@ -27,6 +28,7 @@ public class V10LiftPlugin extends JavaPlugin { private static YamlFile config; private static DBManager dbManager; private static V10LiftAPI api; + private static boolean vault = false; @Override public void onEnable() { @@ -50,6 +52,12 @@ public class V10LiftPlugin extends JavaPlugin { //Load the API api = new V10LiftAPI(); + //Load vault if found + if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { + vault = true; + VaultManager.setupPermissions(); + } + //Load the command Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setExecutor(new V10LiftCommand()); Objects.requireNonNull(getCommand("v10lift"), "Internal error! Command not found.").setTabCompleter(new V10LiftTabCompleter()); @@ -109,4 +117,8 @@ public class V10LiftPlugin extends JavaPlugin { public static V10LiftAPI getAPI() { return api; } + + public static boolean isVaultEnabled() { + return vault; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 83009e5..a1c06d2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,6 +3,7 @@ main: nl.SBDeveloper.V10Lift.V10LiftPlugin version: ${project.version} api-version: "1.13" author: SBDeveloper +softdepend: ["Vault"] commands: v10lift: description: The V10Lift Command \ No newline at end of file