diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index ad470c64..152faa02 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -9,6 +9,7 @@ import com.sekwah.advancedportals.core.connector.commands.CommandRegister; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.module.AdvancedPortalsModule; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; @@ -19,11 +20,11 @@ import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; + import java.io.File; import java.util.Arrays; public class AdvancedPortalsCore { - public static final String version = "1.0.0"; private final InfoLogger infoLogger; private final DataStorage dataStorage; @@ -73,7 +74,7 @@ public AdvancedPortalsCore(String mcVersion, File dataStorageLoc, this.infoLogger = infoLogger; int[] mcVersionTemp; - infoLogger.info("Loading Advanced Portals Core v" + version + infoLogger.info("Loading Advanced Portals Core v" + BuildConstants.VERSION + " for MC: " + mcVersion); try { mcVersionTemp = Arrays.stream(mcVersion.split("\\.")) @@ -147,7 +148,7 @@ public void registerCommands() { } private void registerPortalCommand(CommandRegister commandRegister) { - this.portalCommand = new CommandWithSubCommands(this); + this.portalCommand = new CommandWithSubCommands(this, Permissions.PORTAL); this.portalCommand.registerSubCommand("version", new VersionSubCommand()); @@ -180,7 +181,7 @@ private void registerPortalCommand(CommandRegister commandRegister) { } private void registerDestinationCommand(CommandRegister commandRegister) { - this.destiCommand = new CommandWithSubCommands(this); + this.destiCommand = new CommandWithSubCommands(this, Permissions.DESTI); this.destiCommand.registerSubCommand("create", new CreateDestiSubCommand()); this.destiCommand.registerSubCommand("remove", diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index b21b059a..9414a2fa 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -8,7 +8,7 @@ import com.sekwah.advancedportals.core.data.BlockAxis; import com.sekwah.advancedportals.core.data.Direction; import com.sekwah.advancedportals.core.network.ServerDestiPacket; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; @@ -104,7 +104,7 @@ public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, if (player == null) { return !portalServices.inPortalRegionProtected(blockPos); } - if (!(PortalPermissions.BUILD.hasPermission(player) + if (!(Permissions.BUILD.hasPermission(player) || !portalServices.inPortalRegionProtected(blockPos))) { player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.nobuild")); @@ -122,7 +122,7 @@ public boolean blockBreak(PlayerContainer player, BlockLocation blockPos, public boolean blockPlace(PlayerContainer player, BlockLocation blockPos, String blockMaterial, String itemInHandMaterial, String itemInHandName) { - if (player != null && PortalPermissions.BUILD.hasPermission(player)) { + if (player != null && Permissions.BUILD.hasPermission(player)) { WorldContainer world = player.getWorld(); if (itemInHandName.equals("\u00A75Portal Block Placer")) { world.setBlock(blockPos, "NETHER_PORTAL"); @@ -180,8 +180,7 @@ public boolean playerInteractWithBlock(PlayerContainer player, BlockLocation blockLoc, boolean leftClick) { if (itemName != null - && (player.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(player)) + && Permissions.CREATE_PORTAL.hasPermission(player) && itemMaterialName.equalsIgnoreCase( this.configRepository.getSelectorMaterial()) && (!this.configRepository.getUseOnlySpecialAxe() @@ -192,7 +191,7 @@ public boolean playerInteractWithBlock(PlayerContainer player, } else if (itemName != null && leftClick && Objects.equals(itemMaterialName, "PURPLE_WOOL") && itemName.equals("\u00A75Portal Block Placer") - && PortalPermissions.BUILD.hasPermission(player)) { + && Permissions.BUILD.hasPermission(player)) { if (!Objects.equals(blockMaterialname, "NETHER_PORTAL")) { return false; } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java index 3ef2ba8b..a64215a6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandTemplate.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.core.commands; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; + import java.util.List; /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java index a26cdd42..614726d2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java @@ -2,8 +2,10 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.PermissionBuilder; import com.sekwah.advancedportals.core.registry.SubCommandRegistry; import com.sekwah.advancedportals.core.util.Lang; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -12,12 +14,14 @@ public class CommandWithSubCommands implements CommandTemplate { private final SubCommandRegistry subCommandRegistry; - private final int subCommandsPerPage = 7; + private final int subCommandsPerPage = 6; private final AdvancedPortalsCore pluginCore; + private final PermissionBuilder permission; - public CommandWithSubCommands(AdvancedPortalsCore advancedPortalsCore) { + public CommandWithSubCommands(AdvancedPortalsCore advancedPortalsCore, PermissionBuilder permission) { this.subCommandRegistry = new SubCommandRegistry(); this.pluginCore = advancedPortalsCore; + this.permission = permission; } public boolean registerSubCommand(String arg, SubCommand subCommand, @@ -53,6 +57,10 @@ public SubCommand getSubCommand(String arg) { @Override public void onCommand(CommandSenderContainer sender, String commandExecuted, String[] args) { + if(!permission.hasPermission(sender)) { + sender.sendMessage(Lang.getNegativePrefix() + Lang.translate("command.nopermission")); + return; + } if (args.length > 0) { if (args[0].equalsIgnoreCase("help")) { int helpPage = 1; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java index 233bb26f..e30c8a77 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/SubCommand.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.core.commands; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; + import java.util.List; public interface SubCommand { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java index 2c49b69b..f79a2227 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java @@ -5,6 +5,7 @@ import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java index 979e1c94..b84fabc4 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateDestiSubCommand.java @@ -5,13 +5,14 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.destination.Destination; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -85,7 +86,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); + return Permissions.CREATE_DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java index e1e90cd2..ae7a340a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ListDestiSubCommand.java @@ -3,8 +3,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; import java.util.stream.Collectors; @@ -23,7 +25,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.LIST_DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java index f2dbf7ee..124f13b2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/RemoveDestiSubCommand.java @@ -3,9 +3,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.Collections; import java.util.List; @@ -33,7 +34,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); + return Permissions.REMOVE_DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java index 8de82335..8a17fff6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/ShowDestiSubCommand.java @@ -7,12 +7,14 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.destination.Destination; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.services.PlayerDataServices; import com.sekwah.advancedportals.core.util.Debug; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.Lang; + import java.awt.*; import java.util.List; import java.util.Objects; @@ -66,7 +68,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.SHOW_DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java index 6ae1e3b7..246288f8 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/desti/TeleportDestiSubCommand.java @@ -3,9 +3,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.Collections; import java.util.List; @@ -35,7 +36,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.DESTI.hasPermission(sender); + return Permissions.TELEPORT_DESTI.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java index 9ecd7a41..95d1c306 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java @@ -4,7 +4,7 @@ import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedSubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.repository.ConfigRepository; @@ -12,10 +12,10 @@ import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.tags.NameTag; import com.sekwah.advancedportals.core.tags.TriggerBlockTag; -import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,9 +27,6 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { @Inject TagRegistry tagRegistry; - @Inject - InfoLogger infoLogger; - @Inject ConfigRepository config; @@ -106,8 +103,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.CREATE_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java index b0074181..e9408e04 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/DisableBeaconSubCommand.java @@ -3,9 +3,9 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; -import com.sekwah.advancedportals.core.util.TagReader; import java.util.List; @@ -34,7 +34,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.DISABLE_BEACON.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java index 7e54c788..e2931328 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndGatewayBlockSubCommand.java @@ -5,8 +5,9 @@ import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class EndGatewayBlockSubCommand implements SubCommand { @@ -31,8 +32,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.CREATE_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java index 873f6a00..63ad0107 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/EndPortalBlockSubCommand.java @@ -5,8 +5,9 @@ import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class EndPortalBlockSubCommand implements SubCommand { @@ -31,8 +32,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.CREATE_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java index b01aef32..fbd8b4bb 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/InfoPortalSubCommand.java @@ -3,6 +3,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; @@ -34,7 +35,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.PORTAL_INFO.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java index 22a0bf8e..b17599eb 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/LangUpdateSubCommand.java @@ -4,9 +4,10 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.util.Lang; + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -82,8 +83,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.LANG_UPDATE.hasPermission(sender); + return Permissions.LANG_UPDATE.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java index 15957417..54b0a4da 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ListPortalsSubCommand.java @@ -3,8 +3,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; import java.util.stream.Collectors; @@ -23,7 +25,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.LIST_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java index 4ca97d2b..474c4af1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/PortalBlockSubCommand.java @@ -5,8 +5,9 @@ import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class PortalBlockSubCommand implements SubCommand { @@ -34,8 +35,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.CREATE_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java index 2dbf5d28..a52b46ce 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadPortalSubCommand.java @@ -4,11 +4,12 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class ReloadPortalSubCommand implements SubCommand { @@ -36,7 +37,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() || PortalPermissions.RELOAD.hasPermission(sender); + return Permissions.RELOAD.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java index 38ca8aaf..83c38c0e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/RemovePortalSubCommand.java @@ -3,9 +3,10 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class RemovePortalSubCommand implements SubCommand { @@ -32,8 +33,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.REMOVE_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java index a21caf3a..e9b6a145 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/SelectorSubCommand.java @@ -5,9 +5,10 @@ import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.permissions.PortalPermissions; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class SelectorSubCommand implements SubCommand { @@ -42,8 +43,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return sender.isOp() - || PortalPermissions.CREATE_PORTAL.hasPermission(sender); + return Permissions.SELECTOR.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index 0bf296c9..5408f440 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -6,6 +6,7 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; @@ -15,6 +16,7 @@ import com.sekwah.advancedportals.core.util.Debug; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.Lang; + import java.awt.*; import java.util.List; import java.util.Objects; @@ -82,7 +84,7 @@ public void onCommand(CommandSenderContainer sender, String[] args) { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.SHOW_PORTAL.hasPermission(sender); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java index d3a12a5d..3f07e49e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/VersionSubCommand.java @@ -1,9 +1,10 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal; -import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.BuildConstants; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.util.Lang; + import java.util.List; public class VersionSubCommand implements SubCommand { @@ -11,7 +12,7 @@ public class VersionSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { sender.sendMessage(Lang.getPositivePrefix() + " Advanced Portals v" - + AdvancedPortalsCore.version); + + BuildConstants.VERSION); } @Override diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java index 937dc644..65bb976f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/CommandSenderContainer.java @@ -1,14 +1,10 @@ package com.sekwah.advancedportals.core.connector.containers; -public interface CommandSenderContainer { +public interface CommandSenderContainer extends HasPermission { void sendMessage(String message); - boolean isOp(); - /** - * @return null if there isnt a player e.g. the console + * @return null if there isn't a player e.g. the console */ PlayerContainer getPlayerContainer(); - - boolean hasPermission(String permission); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/HasPermission.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/HasPermission.java new file mode 100644 index 00000000..99a8bf1c --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/HasPermission.java @@ -0,0 +1,6 @@ +package com.sekwah.advancedportals.core.connector.containers; + +public interface HasPermission { + boolean isOp(); + boolean hasPermission(String permission); +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java index 2d5c67bc..f5170c64 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/PlayerContainer.java @@ -8,17 +8,13 @@ * Just a temporary container for whenever advanced portals needs to get data * from a player */ -public interface PlayerContainer extends EntityContainer { +public interface PlayerContainer extends EntityContainer, HasPermission { UUID getUUID(); void sendMessage(String message); void sendActionBar(String message); - boolean isOp(); - - boolean hasPermission(String permission); - /** * @param blockPos * @param material diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java index 97aacbd0..18787f42 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.core.connector.containers; import com.sekwah.advancedportals.core.tags.CommandTag; + import java.util.List; import java.util.UUID; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java index b9b2f7f9..46d6829f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/module/AdvancedPortalsModule.java @@ -1,6 +1,9 @@ package com.sekwah.advancedportals.core.module; -import com.google.inject.*; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Scopes; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.registry.TagRegistry; @@ -17,9 +20,10 @@ import com.sekwah.advancedportals.core.serializeddata.config.Config; import com.sekwah.advancedportals.core.serializeddata.config.ConfigProvider; import com.sekwah.advancedportals.core.util.InfoLogger; + +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; -import javax.annotation.Nonnull; public class AdvancedPortalsModule extends AbstractModule { private Injector injector; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PermissionBuilder.java b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PermissionBuilder.java new file mode 100644 index 00000000..cd0aeea2 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PermissionBuilder.java @@ -0,0 +1,122 @@ +package com.sekwah.advancedportals.core.permissions; + +import com.google.common.collect.ImmutableList; +import com.sekwah.advancedportals.core.connector.containers.HasPermission; + +import java.util.ArrayList; +import java.util.List; + +/** + * this will not currently build the permissions for the files, but maybe at + * some point. It'll just make it easier though. + */ +public class PermissionBuilder { + private final String permissionTag; + private final PermissionDefault permissionDefault; + private final PermissionBuilder parent; + private final List children = new ArrayList<>(); + private final List grantChildren = new ArrayList<>(); + private String description; + private boolean doNotExport = false; + + PermissionBuilder(String permissionTag) { + this.permissionTag = permissionTag; + this.parent = null; + this.permissionDefault = PermissionDefault.FALSE; + } + + PermissionBuilder(String permissionTag, PermissionBuilder parent) { + this.permissionTag = permissionTag; + this.parent = parent; + this.permissionDefault = parent.permissionDefault; + } + + PermissionBuilder(String permissionTag, PermissionBuilder parent, PermissionDefault permissionDefault) { + this.permissionTag = permissionTag; + this.parent = parent; + this.permissionDefault = permissionDefault; + } + + PermissionBuilder(String permissionTag, PermissionDefault permissionDefault) { + this.permissionTag = permissionTag; + this.parent = null; + this.permissionDefault = permissionDefault; + } + + public PermissionDefault getPermissionDefault() { + return permissionDefault; + } + + public PermissionBuilder createChild(String permissionTag) { + var child = new PermissionBuilder(permissionTag, this); + children.add(child); + + return child; + } + + public PermissionBuilder createChild(String permissionTag, PermissionDefault permissionDefault) { + var child = new PermissionBuilder(permissionTag, this, permissionDefault); + children.add(child); + + return child; + } + + public PermissionBuilder addGrantChild(PermissionBuilder child) { + grantChildren.add(child); + return this; + } + + public PermissionBuilder doNotExport() { + this.doNotExport = true; + return this; + } + + @Override + public String toString() { + if (parent != null) { + return parent + "." + permissionTag; + } else { + return permissionTag; + } + } + + public boolean hasPermission(HasPermission sender) { + if (Permissions.hasPermissionManager) { + return sender.hasPermission(this.toString()); + } + return switch (permissionDefault) { + case TRUE -> true; + case FALSE -> false; + case OP -> sender.isOp(); + case NOT_OP -> !sender.isOp(); + }; + } + + public List getChildren() { + return ImmutableList.copyOf(children); + } + + public List getGrantChildren() { + return ImmutableList.copyOf(grantChildren); + } + + public String getDescription() { + return description; + } + + public boolean isDoNotExport() { + return doNotExport; + } + + public PermissionBuilder description(String description) { + this.description = description; + return this; + } + + public enum PermissionDefault { + TRUE, + FALSE, + OP, + NOT_OP + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/permissions/Permissions.java b/core/src/main/java/com/sekwah/advancedportals/core/permissions/Permissions.java new file mode 100644 index 00000000..cc1b9a99 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/permissions/Permissions.java @@ -0,0 +1,108 @@ +package com.sekwah.advancedportals.core.permissions; + +public class Permissions { + + /** + * If true then a permission manager is being used and don't check for op + * for platforms like spigot this will always be true. + *

+ * This is to allow for negative permissions where a value may be defaulted to true. + */ + public static boolean hasPermissionManager = false; + + public static final PermissionBuilder ROOT = + new PermissionBuilder("advancedportals").doNotExport(); + + public static final PermissionBuilder BUILD = + ROOT.createChild("build", PermissionBuilder.PermissionDefault.OP).description("Allows you to build in the portal regions"); + + + public static final PermissionBuilder DESTI = + ROOT.createChild("desti", PermissionBuilder.PermissionDefault.TRUE).description("Allows you to use the destination command"); + + public static final PermissionBuilder CREATE_DESTI = + DESTI.createChild("create", PermissionBuilder.PermissionDefault.OP).description("Allows you to create destinations"); + + public static final PermissionBuilder TELEPORT_DESTI = + DESTI.createChild("teleport", PermissionBuilder.PermissionDefault.OP).description("Allows you to teleport to destinations"); + + public static final PermissionBuilder REMOVE_DESTI = + DESTI.createChild("remove", PermissionBuilder.PermissionDefault.OP).description("Allows you to remove destinations"); + + public static final PermissionBuilder LIST_DESTI = + DESTI.createChild("list", PermissionBuilder.PermissionDefault.OP).description("Allows you to list all destinations"); + + public static final PermissionBuilder SHOW_DESTI = + DESTI.createChild("show", PermissionBuilder.PermissionDefault.OP).description("Allows you to visualise the destination locations"); + + public static final PermissionBuilder PORTAL = + ROOT.createChild("portal", PermissionBuilder.PermissionDefault.TRUE).description("Allows you to use the portal command"); + + public static final PermissionBuilder CREATE_PORTAL = + PORTAL.createChild("create", PermissionBuilder.PermissionDefault.OP).description("Allows you to create portals"); + + public static final PermissionBuilder SELECTOR = + PORTAL.createChild("selector", PermissionBuilder.PermissionDefault.OP).description("Allows you to give yourself a portal selector"); + + public static final PermissionBuilder REMOVE_PORTAL = + PORTAL.createChild("remove", PermissionBuilder.PermissionDefault.OP).description("Allows you to remove portals"); + + public static final PermissionBuilder LIST_PORTAL = + PORTAL.createChild("list", PermissionBuilder.PermissionDefault.OP).description("Allows you to list all portals"); + + public static final PermissionBuilder LANG_UPDATE = + PORTAL.createChild("lang_update", PermissionBuilder.PermissionDefault.OP); + public static final PermissionBuilder RELOAD = + PORTAL.createChild("reload", PermissionBuilder.PermissionDefault.OP); + + public static final PermissionBuilder DISABLE_BEACON = + PORTAL.createChild("disable_beacon", PermissionBuilder.PermissionDefault.OP); + public static final PermissionBuilder IMPORT = + PORTAL.createChild("import", PermissionBuilder.PermissionDefault.OP); + + public static final PermissionBuilder SHOW_PORTAL = + PORTAL.createChild("show", PermissionBuilder.PermissionDefault.OP).description("Allows you to view the portal regions"); + + private static final PermissionBuilder CREATE_COMMAND_LEVEL = + CREATE_PORTAL.createChild("command_level").doNotExport(); + + public static final PermissionBuilder CREATE_COMMAND_OP = + CREATE_COMMAND_LEVEL.createChild("op").description("Allows you to increase the users level temporarily to op"); + + public static final PermissionBuilder CREATE_COMMAND_CONSOLE = + CREATE_COMMAND_LEVEL.createChild("console").description("Allows you to create portals which execute console commands"); + + public static final PermissionBuilder CREATE_COMMAND_PERMS = + CREATE_COMMAND_LEVEL.createChild("perms_wildcard").description("Allows you to increase the users level temporarily to have all perms"); + + public static final PermissionBuilder PORTAL_INFO = + PORTAL.createChild("info", PermissionBuilder.PermissionDefault.OP).description("Allows you to view portal information"); + + static { + // These are to add children which will not be used directly e.g. advancedportals.* + ROOT.createChild("*", PermissionBuilder.PermissionDefault.OP).description("Gives access to all portal commands") + .addGrantChild(CREATE_PORTAL) + .addGrantChild(CREATE_DESTI) + .addGrantChild(DESTI) + .addGrantChild(PORTAL) + .addGrantChild(TELEPORT_DESTI) + .addGrantChild(REMOVE_DESTI) + .addGrantChild(LIST_DESTI) + .addGrantChild(SHOW_DESTI) + .addGrantChild(SELECTOR) + .addGrantChild(REMOVE_PORTAL) + .addGrantChild(LIST_PORTAL) + .addGrantChild(LANG_UPDATE) + .addGrantChild(RELOAD) + .addGrantChild(DISABLE_BEACON) + .addGrantChild(IMPORT) + .addGrantChild(SHOW_PORTAL) + .addGrantChild(PORTAL_INFO) + .addGrantChild(BUILD); + + CREATE_COMMAND_LEVEL.createChild("*", PermissionBuilder.PermissionDefault.OP).description("Gives access to all command level raisers") + .addGrantChild(CREATE_COMMAND_OP) + .addGrantChild(CREATE_COMMAND_CONSOLE) + .addGrantChild(CREATE_COMMAND_PERMS); + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java b/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java deleted file mode 100644 index 9f885263..00000000 --- a/core/src/main/java/com/sekwah/advancedportals/core/permissions/PortalPermissions.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.sekwah.advancedportals.core.permissions; - -import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; -import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import java.util.List; - -public class PortalPermissions { - private static final PermissionBuilder PERMISSIONS = - new PermissionBuilder("advancedportals"); - - public static final PermissionBuilder BUILD = - PERMISSIONS.createChild("build"); - public static final PermissionBuilder DESTI = - PERMISSIONS.createChild("desti"); - public static final PermissionBuilder CREATE_PORTAL = - PERMISSIONS.createChild("createportal"); - public static final PermissionBuilder LANG_UPDATE = - PERMISSIONS.createChild("langupdate"); - public static final PermissionBuilder RELOAD = - PERMISSIONS.createChild("reload"); - - /** - * this will not currently build the permissions for the files, but maybe at - * some point. It'll just make it easier though. - */ - public static class PermissionBuilder { - private final String permissionTag; - - private final PermissionBuilder parent; - - private List[] children; - - PermissionBuilder(String permissionTag) { - this.permissionTag = permissionTag; - this.parent = null; - } - - PermissionBuilder(String permissionTag, PermissionBuilder parent) { - this.permissionTag = permissionTag; - this.parent = parent; - } - - PermissionBuilder createChild(String permissionTag) { - return new PermissionBuilder(permissionTag, this); - } - - @Override - public String toString() { - if (parent != null) { - return parent + "." + permissionTag; - } else { - return permissionTag; - } - } - - public boolean hasPermission(CommandSenderContainer player) { - return player.hasPermission(this.toString()); - } - - public boolean hasPermission(PlayerContainer player) { - return player.hasPermission(this.toString()); - } - } -} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java index 9ac4f8e6..3cd5b180 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/SubCommandRegistry.java @@ -3,6 +3,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.util.InfoLogger; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java index ca7eca72..1ea9231d 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/TagRegistry.java @@ -3,6 +3,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.warphandler.Tag; + import java.util.*; /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java b/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java index 07b0634a..463c980f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/registry/WarpEffectRegistry.java @@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.effect.WarpEffect; import com.sekwah.advancedportals.core.util.InfoLogger; + import java.util.HashMap; import java.util.Map; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index 8bbf8dc3..eb3c3ba6 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -5,6 +5,7 @@ import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig; import com.sekwah.advancedportals.core.serializeddata.config.Config; + import java.util.HashMap; @Singleton diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java index 28d29e33..bdaffa2c 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/DestinationRepositoryImpl.java @@ -5,9 +5,10 @@ import com.sekwah.advancedportals.core.repository.IDestinationRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.tags.NameTag; + +import javax.inject.Singleton; import java.util.ArrayList; import java.util.List; -import javax.inject.Singleton; @Singleton public class DestinationRepositoryImpl implements IDestinationRepository { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java index 2265017c..635b855b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PlayerDataRepositoryImpl.java @@ -4,6 +4,7 @@ import com.sekwah.advancedportals.core.repository.IPlayerDataRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.serializeddata.PlayerData; + import java.util.List; public class PlayerDataRepositoryImpl implements IPlayerDataRepository { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java index 13778ddf..b8f90632 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/PortalRepositoryImpl.java @@ -7,7 +7,9 @@ import com.sekwah.advancedportals.core.repository.IPortalRepository; import com.sekwah.advancedportals.core.serializeddata.DataStorage; import com.sekwah.advancedportals.core.tags.NameTag; -import java.util.*; + +import java.util.ArrayList; +import java.util.List; @Singleton public class PortalRepositoryImpl implements IPortalRepository { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java index 00c5be2d..9ed14752 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/DataStorage.java @@ -3,17 +3,18 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.util.InfoLogger; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.inspector.TagInspector; +import org.yaml.snakeyaml.nodes.Tag; + import java.io.*; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.inspector.TagInspector; -import org.yaml.snakeyaml.nodes.Tag; public class DataStorage { private final File dataFolder; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java index f4c51bc6..064b47ea 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/ReflectiveConstructor.java @@ -1,16 +1,19 @@ package com.sekwah.advancedportals.core.serializeddata; import com.sekwah.advancedportals.core.util.InfoLogger; -import java.lang.reflect.*; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.inject.Inject; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.nodes.*; import sun.misc.Unsafe; +import javax.inject.Inject; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class ReflectiveConstructor extends Constructor { private static final Unsafe unsafe = getUnsafe(); private final Class clazz; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java index b754a83f..487ece8b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/DestinationServices.java @@ -12,11 +12,12 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.Tag; + +import javax.inject.Singleton; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.inject.Singleton; @Singleton public class DestinationServices { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java index 3236ecda..541445b5 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/PlayerDataServices.java @@ -7,10 +7,11 @@ import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.PlayerData; import com.sekwah.advancedportals.core.util.Lang; + +import javax.inject.Singleton; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.inject.Singleton; @Singleton public final class PlayerDataServices { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java index 2ece276a..861feea4 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/services/PortalServices.java @@ -2,7 +2,6 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; -import com.sekwah.advancedportals.core.portal.ActivationResult; import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.registry.TagRegistry; import com.sekwah.advancedportals.core.repository.ConfigRepository; @@ -17,8 +16,8 @@ import com.sekwah.advancedportals.core.warphandler.Tag; import com.sekwah.advancedportals.core.warphandler.TriggerType; -import java.util.*; import javax.inject.Singleton; +import java.util.*; @Singleton public class PortalServices { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java index a320a59e..18a06189 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/CommandTag.java @@ -4,7 +4,7 @@ import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.network.ProxyCommandPacket; -import com.sekwah.advancedportals.core.network.ProxyTransferPacket; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.registry.TagTarget; import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.util.Lang; @@ -168,7 +168,7 @@ public boolean created(TagTarget target, PlayerContainer player, + Lang.translate("tag.command.op.disabled")); yield false; } - if (!player.hasPermission("advancedportals.createportal.commandlevel.op")) { + if (!Permissions.CREATE_COMMAND_OP.hasPermission(player)) { player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission", "OP")); yield false; @@ -181,7 +181,7 @@ public boolean created(TagTarget target, PlayerContainer player, + Lang.translate("tag.command.console.disabled")); yield false; } - if (!player.hasPermission("advancedportals.createportal.commandlevel.console")) { + if (!Permissions.CREATE_COMMAND_CONSOLE.hasPermission(player)) { player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission","Console")); yield false; @@ -194,7 +194,7 @@ public boolean created(TagTarget target, PlayerContainer player, + Lang.translate("tag.command.permswildcard.disabled")); yield false; } - if (!player.hasPermission("advancedportals.createportal.commandlevel.permswild")) { + if (!Permissions.CREATE_COMMAND_PERMS.hasPermission(player)) { player.sendMessage(Lang.getNegativePrefix() + Lang.translateInsertVariables("tag.command.nopermission", "*")); yield false; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java index 5d0d5315..cd0e32bf 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/DestiTag.java @@ -13,8 +13,6 @@ import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; -import javax.annotation.Nullable; -import java.util.Arrays; import java.util.List; import java.util.Random; @@ -84,7 +82,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player, Tag.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME, Tag.TagType.DESTINATION); if (activationHandler != null - && !activationHandler.preActivated(target, player, activeData, argData)) { + && !activationHandler.preActivated(target, player, activeData, destiTag.VALUES)) { return false; } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java index 5b38684b..7ca343d2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java @@ -8,8 +8,6 @@ import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; -import javax.annotation.Nullable; -import java.util.List; import java.util.Random; public class MessageTag implements Tag.Activation { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java index 7706d0af..e918887b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/NameTag.java @@ -5,7 +5,6 @@ import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.warphandler.Tag; -import javax.annotation.Nullable; import java.util.List; /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/PermissionTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/PermissionTag.java index af52a782..e8e025b1 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/PermissionTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/PermissionTag.java @@ -52,8 +52,17 @@ public String description() { @Override public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { - if (!player.hasPermission(argData[1])) { - player.sendMessage(Lang.translate("portal.error.nopermission")); + var permission = argData[0]; + if(permission.startsWith("!")) { + permission = permission.substring(1); + if(player.hasPermission(permission)) { + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.error.nopermission")); + return false; + } + return true; + } + else if (!player.hasPermission(argData[0])) { + player.sendMessage(Lang.getNegativePrefix() + Lang.translate("portal.error.nopermission")); return false; } return true; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java index f0004824..936db9fe 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/ProxyTag.java @@ -1,7 +1,5 @@ package com.sekwah.advancedportals.core.tags; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; import com.google.inject.Inject; import com.sekwah.advancedportals.core.ProxyMessages; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; @@ -13,7 +11,6 @@ import com.sekwah.advancedportals.core.warphandler.ActivationData; import com.sekwah.advancedportals.core.warphandler.Tag; -import javax.annotation.Nullable; import java.util.Random; public class ProxyTag implements Tag.Activation, Tag.OrderPriority, Tag.Split { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java b/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java index 63bb426f..1fa08403 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/Debug.java @@ -2,6 +2,7 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; + import java.awt.*; public class Debug { diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java b/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java index aeafe78f..a6b352dc 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/FriendlyDataOutput.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.handler.codec.EncoderException; + import java.nio.charset.StandardCharsets; /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java b/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java index 56ebd7de..71f324a2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/GameScheduler.java @@ -1,8 +1,8 @@ package com.sekwah.advancedportals.core.util; +import javax.inject.Singleton; import java.util.ArrayList; import java.util.Iterator; -import javax.inject.Singleton; /** * For all delayed and repeating tasks. diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java b/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java index e115e443..4ff1c573 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.serializeddata.DataStorage; + import java.io.IOException; import java.io.InputStream; import java.net.URL; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java index e8607e72..bfcb89ee 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/util/TagReader.java @@ -2,6 +2,7 @@ import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.serializeddata.DataTag; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java index 0e7d1171..835e16fe 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/warphandler/Tag.java @@ -2,8 +2,9 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.registry.TagTarget; -import java.util.List; + import javax.annotation.Nullable; +import java.util.List; /** * If a tag can be used for any of them then either make it cast the target or diff --git a/curse.gradle b/curse.gradle index 426f12d9..f3be7b22 100644 --- a/curse.gradle +++ b/curse.gradle @@ -1,14 +1,14 @@ +import com.google.gson.Gson import org.apache.commons.codec.Charsets import org.apache.http.HttpResponse import org.apache.http.client.HttpClient import org.apache.http.client.config.CookieSpecs import org.apache.http.client.config.RequestConfig +import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPost import org.apache.http.entity.ContentType import org.apache.http.entity.mime.MultipartEntityBuilder import org.apache.http.impl.client.HttpClientBuilder -import org.apache.http.client.methods.HttpGet -import com.google.gson.Gson buildscript { repositories { diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 35c536ae..0f63fb47 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -146,7 +146,7 @@ portal.error.takenname= The name given for the portal is already taken. portal.error.selection.differentworlds= Both the selected points need to be in the same world. portal.error.selection.missing= You need to select both points for the portal. portal.error.save= There was a problem saving the portal. -portal.error.nopermission=You don't have permission to use that portal. +portal.error.nopermission= You don't have permission to use that portal. portal.nobuild= You don't have permission to build here! @@ -176,6 +176,7 @@ command.lang.help=Update the translation file command.version.help=Returns the current version of the plugin command.subcommand.nopermission= Sorry but you don't have permission for that, please use &e/%1$s help &cif you would like a list of possible sub commands. +command.nopermission= Sorry but you don't have permission for that. items.selector.name=Portal Region Selector items.selector.pos=Select pos %1$s diff --git a/spigot/build.gradle b/spigot/build.gradle index e8f3d868..c3471820 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -31,3 +31,81 @@ jar { it.isDirectory() ? it : zipTree(it) } } + +// Code for generating extra data in plugins.yml +// This may be able to be simplified drastically, though the goal is to get this working for now +// as it has gone through a few iterations. +sourceSets { + permissionsGen { + java { + srcDirs = ['src/main/java'] + } + } +} + +configurations { + permissionsGenCompileClasspath.extendsFrom compileClasspath +} + +def compilePermissionsGen = tasks.register('compilePermissionsGen', JavaCompile) { + source = sourceSets.permissionsGen.allJava + classpath = configurations.permissionsGenCompileClasspath + destinationDirectory = file("$buildDir/classes/permissionsGen") +} + +def templateSource = file('src/main/templates') +def templateDest = layout.buildDirectory.dir('generated/resources/templates') + +def generatePermissionsYaml = tasks.register('generatePermissionsYaml') { + dependsOn compilePermissionsGen + + doLast { + println "Generating permissions.yml file" + + def classFiles = [] + classFiles.addAll(files("$buildDir/classes/permissionsGen", sourceSets.permissionsGen.runtimeClasspath) + .collect { it.toURI().toURL() }) + + classFiles.addAll(project(':core').sourceSets.main.output.classesDirs + .collect { it.toURI().toURL() }) + + def urls = classFiles.toArray(new URL[0]) + + def parentClassLoader = Thread.currentThread().contextClassLoader + def classLoader = new URLClassLoader(urls, parentClassLoader) + + def permissionsGeneratorClass = classLoader.loadClass('com.sekwah.advancedportals.spigot.PermissionsGeneratorSpigot') + def getPermissionsMethod = permissionsGeneratorClass.getMethod('getPermissions') + def permissionsYaml = getPermissionsMethod.invoke(null) + + def permissionsFile = file("$buildDir/generated/resources/permissions.yml") + permissionsFile.parentFile.mkdirs() + permissionsFile.text = permissionsYaml + + println "Permissions YAML generated at: $permissionsFile" + } +} + +def generateTemplates = tasks.register('generateTemplates', Copy) { task -> + dependsOn generatePermissionsYaml + + def props = [ + 'permissions': { -> file("$buildDir/generated/resources/permissions.yml").text }, + 'pluginVersion': { -> project.version } + ] + + task.inputs.properties(props) + task.from(templateSource) + task.into(templateDest) + task.expand(props) + + doFirst { + println "Running generateTemplates task" + } +} + +generateTemplates.configure { + outputs.upToDateWhen { false } +} + +sourceSets.main.resources.srcDir(generateTemplates.map { it.outputs }) diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java index 5d3c6522..9026006e 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/AdvancedPortalsPlugin.java @@ -11,7 +11,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.bukkit.plugin.java.JavaPlugin; public class AdvancedPortalsPlugin extends JavaPlugin { private AdvancedPortalsCore portalsCore; diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java index 2582a016..ec742786 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/Listeners.java @@ -18,6 +18,8 @@ import org.bukkit.event.player.*; import org.bukkit.event.world.ChunkLoadEvent; +import java.util.List; + /** * Some of these will be passed to the core listener to handle the events, * others it's easier to just check directly. diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/PermissionsGeneratorSpigot.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/PermissionsGeneratorSpigot.java new file mode 100644 index 00000000..d0d7b7d9 --- /dev/null +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/PermissionsGeneratorSpigot.java @@ -0,0 +1,42 @@ +package com.sekwah.advancedportals.spigot; + + +import com.sekwah.advancedportals.core.permissions.PermissionBuilder; +import com.sekwah.advancedportals.core.permissions.Permissions; + +public class PermissionsGeneratorSpigot { + + private PermissionsGeneratorSpigot() { + } + + public static String getPermissions() { + return toPermBlock(Permissions.ROOT); + } + + public static String toPermBlock(PermissionBuilder permission) { + StringBuilder builder = new StringBuilder(); + String indent = " "; + if(!permission.isDoNotExport()) { + builder.append(indent).append(permission).append(":\n"); + builder.append(indent).append(indent).append("default: "); + builder.append(permission.getPermissionDefault().toString().toLowerCase()); + builder.append("\n"); + if(permission.getDescription() != null) { + builder.append(indent).append(indent).append("description: "); + builder.append(permission.getDescription()).append("\n"); + } + var children = permission.getGrantChildren(); + if(!children.isEmpty()) { + builder.append(indent).append(indent).append("children:\n"); + for(PermissionBuilder child : children) { + builder.append(indent).append(indent).append(indent); + builder.append(child.toString()).append(": true").append("\n"); + } + } + } + for(PermissionBuilder child : permission.getChildren()) { + builder.append(toPermBlock(child)); + } + return builder.toString(); + } +} diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java index 982b55f5..0c9b996d 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/SpigotInfoLogger.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.spigot; import com.sekwah.advancedportals.core.util.InfoLogger; + import java.util.logging.Level; public class SpigotInfoLogger extends InfoLogger { diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java index 4a81a402..f9539101 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java @@ -3,6 +3,7 @@ import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; +import com.sekwah.advancedportals.core.permissions.Permissions; import com.sekwah.advancedportals.core.serializeddata.BlockLocation; import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; @@ -11,10 +12,11 @@ import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; import com.sekwah.advancedportals.spigot.commands.subcommands.portal.importer.ConfigAccessor; +import org.bukkit.configuration.ConfigurationSection; + import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.bukkit.configuration.ConfigurationSection; public class ImportPortalSubCommand implements SubCommand { @@ -185,7 +187,7 @@ public int getPortalCount() { @Override public boolean hasPermission(CommandSenderContainer sender) { - return true; + return Permissions.IMPORT.hasPermission(sender); } @Override diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/importer/ConfigAccessor.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/importer/ConfigAccessor.java index c4dce614..877cb916 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/importer/ConfigAccessor.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/importer/ConfigAccessor.java @@ -1,12 +1,13 @@ package com.sekwah.advancedportals.spigot.commands.subcommands.portal.importer; -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; + public class ConfigAccessor { private final String fileName; private final JavaPlugin plugin; diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java index c91cce07..7d3330aa 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/command/SpigotCommandHandler.java @@ -2,12 +2,13 @@ import com.sekwah.advancedportals.core.commands.CommandTemplate; import com.sekwah.advancedportals.spigot.connector.container.SpigotCommandSenderContainer; -import java.util.List; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import java.util.List; + public class SpigotCommandHandler implements CommandExecutor, TabCompleter { private final CommandTemplate commandExecutor; diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java index 9d4edda9..150223d7 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotPlayerContainer.java @@ -9,9 +9,6 @@ import com.sekwah.advancedportals.core.serializeddata.PlayerLocation; import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; import com.sekwah.advancedportals.spigot.reflection.MinecraftCustomPayload; -import java.util.Arrays; -import java.util.UUID; - import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -21,6 +18,9 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.Arrays; +import java.util.UUID; + /** * Just a temporary container for whenever advanced portals needs to get data * from a player diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java index da23403d..300f6f8b 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java @@ -6,16 +6,15 @@ import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; import com.sekwah.advancedportals.core.tags.CommandTag; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionAttachment; -import org.bukkit.plugin.messaging.PluginMessageListener; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; public class SpigotServerContainer implements ServerContainer { @Inject diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java index 3d37cd2d..06294e86 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/metrics/Metrics.java @@ -3,6 +3,14 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.ServicePriority; + +import javax.net.ssl.HttpsURLConnection; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -12,13 +20,6 @@ import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; -import javax.net.ssl.HttpsURLConnection; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.ServicePriority; /** * bStats collects some data for plugin authors. diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java index 87f627fc..ee836f65 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/reflection/MinecraftCustomPayload.java @@ -1,8 +1,9 @@ package com.sekwah.advancedportals.spigot.reflection; +import org.bukkit.entity.Player; + import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.bukkit.entity.Player; /** * Just a util class to force spigot to allow us to have fun with the diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java index a9b9a7b7..ede414f0 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/EnderWarpEffect.java @@ -2,8 +2,6 @@ import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.effect.WarpEffect; -import com.sekwah.advancedportals.core.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.serializeddata.WorldLocation; import com.sekwah.advancedportals.spigot.connector.container.SpigotPlayerContainer; import org.bukkit.Effect; diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java index d6534d22..abc80e00 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/warpeffects/SpigotWarpEffects.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.spigot.warpeffects; import com.sekwah.advancedportals.core.registry.WarpEffectRegistry; + import javax.inject.Inject; public class SpigotWarpEffects { diff --git a/spigot/src/main/templates/plugin.yml b/spigot/src/main/templates/plugin.yml new file mode 100644 index 00000000..d5399cdc --- /dev/null +++ b/spigot/src/main/templates/plugin.yml @@ -0,0 +1,17 @@ +main: com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin +name: AdvancedPortals +version: ${pluginVersion} +author: sekwah41 +description: An advanced portals plugin for bukkit. +api-version: 1.13 +commands: + portal: + description: The main command for the advanced portals + aliases: [portals, aportals, advancedportals] + usage: / + destination: + description: Can be used to access portal destinations. + aliases: [desti] + usage: / +permissions: +${permissions} \ No newline at end of file diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java index 0b6b649b..c6e80298 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/AdvancedPortalsVelocityPlugin.java @@ -12,11 +12,11 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; -import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ServerConnection; -import org.slf4j.Logger; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; +import org.slf4j.Logger; @Plugin(authors = {"sekwah41"} ,id = "advancedportals", name = "Advanced Portals", url = "https://www.spigotmc.org/resources/advanced-portals.14356/", diff --git a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java index 3717f5c7..806c805d 100644 --- a/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java +++ b/velocity/src/main/java/com/sekwah/advancedportals/velocity/connector/container/VelocityProxyPlayerContainer.java @@ -3,7 +3,6 @@ import com.sekwah.advancedportals.proxycore.connector.container.ProxyPlayerContainer; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; -import net.kyori.adventure.text.Component; public class VelocityProxyPlayerContainer implements ProxyPlayerContainer {