Skip to content

Commit

Permalink
feat: re-implement and clean up permissions (#453)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Permissions have been reworked, if you use a permissions manager you may need to change a few of the permissions
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 57e27a8 commit 9030ff5
Show file tree
Hide file tree
Showing 75 changed files with 547 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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("\\."))
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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");
Expand Down Expand Up @@ -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()
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.commands;

import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
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;
import com.sekwah.advancedportals.core.serializeddata.DataTag;
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;
Expand All @@ -27,9 +27,6 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand {
@Inject
TagRegistry tagRegistry;

@Inject
InfoLogger infoLogger;

@Inject
ConfigRepository config;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9030ff5

Please sign in to comment.