Skip to content

Commit

Permalink
wip: start work on permissions config
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Jun 22, 2024
1 parent 8a49794 commit 0d3b81d
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sekwah.advancedportals.core.repository;

import com.sekwah.advancedportals.core.serializeddata.DataStorage;
import com.sekwah.advancedportals.core.serializeddata.config.CommandPortalConfig;

public interface ConfigRepository {
boolean getUseOnlySpecialAxe();
Expand Down Expand Up @@ -32,4 +33,6 @@ public interface ConfigRepository {
boolean playFailSound();

void storeConfig();

CommandPortalConfig getCommandPortals();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.inject.Singleton;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
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;

Expand Down Expand Up @@ -95,6 +96,11 @@ public boolean playFailSound() {
return this.config.playFailSound;
}

@Override
public CommandPortalConfig getCommandPortals() {
return this.config.commandPortals;
}

@Override
public void storeConfig() {
this.dataStorage.storeFile(this.config, "config.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sekwah.advancedportals.core.serializeddata.config;

public class CommandPortalConfig {
public final boolean op = true;
public final boolean console = true;

public final boolean permsWildcard = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public class Config {
public double throwbackStrength = 0.7;

public boolean playFailSound = true;

public CommandPortalConfig commandPortals = new CommandPortalConfig();
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.sekwah.advancedportals.core.tags.activation;

import com.google.inject.Inject;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.registry.TagTarget;
import com.sekwah.advancedportals.core.repository.ConfigRepository;
import com.sekwah.advancedportals.core.util.Lang;
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;
import javax.annotation.Nullable;

public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {

@Inject
ConfigRepository configRepository;

public static String TAG_NAME = "command";

private final TagType[] tagTypes = new TagType[] {TagType.PORTAL};
Expand Down Expand Up @@ -94,30 +100,28 @@ public boolean activated(TagTarget target, PlayerContainer player,
@Override
public boolean created(TagTarget target, PlayerContainer player,
String[] argData) {
var commandPortals = configRepository.getCommandPortals();
if (argData != null) {
for (String command : argData) {
char executionCommand = command.charAt(0);
return switch (executionCommand) {
case '!' -> {
if (!player.hasPermission("advancedportals.createportal.commandlevel.op")) {
player.sendMessage(Lang.translate("tag.command.nopermission")
.replaceAll("@CommandLevel", "OP"));
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission", "OP"));
yield false;
}
yield true;
}
case '#' -> {
if (!player.hasPermission("advancedportals.createportal.commandlevel.console")) {
player.sendMessage(Lang.translate("tag.command.nopermission")
.replaceAll("@CommandLevel", "Console"));
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission","Console"));
yield false;
}
yield true;
}
case '^' -> {
if (!player.hasPermission("advancedportals.createportal.commandlevel.permswild")) {
player.sendMessage(Lang.translate("tag.command.nopermission")
.replaceAll("@CommandLevel", "*"));
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission", "*"));
yield false;
}
yield true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

public class CooldownTag implements Tag.Activation, Tag.Creation {
@Inject
transient PlayerDataServices playerDataServices;
PlayerDataServices playerDataServices;

@Inject
transient ConfigRepository configRepository;
ConfigRepository configRepository;

@Inject
private InfoLogger infoLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

public class PermissionTag implements Tag.Activation {
@Inject
transient PlayerDataServices playerDataServices;
PlayerDataServices playerDataServices;

@Inject
transient ConfigRepository configRepository;
ConfigRepository configRepository;

@Inject
private InfoLogger infoLogger;
Expand Down
3 changes: 2 additions & 1 deletion lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,5 @@ tag.triggerblock.description=Sets the trigger block/s of the portal. Comma separ
tag.command.description=Sets a command on the post activation of the portal. Comma separated or multi tag.

tag.cooldown.fail= The cooldown must be a number.
tag.command.nopermission= You do not have permission to create a command at @CommandLevel command level
tag.command.nopermission= You do not have permission to create a command at %1$s command level
tag.command.notenabled= Command portals of %1$s level are not enabled on this server.

0 comments on commit 0d3b81d

Please sign in to comment.