Skip to content

Commit

Permalink
fix: portal command config reading
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent fd2483c commit 22cda5d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void playerMove(PlayerContainer player, PlayerLocation toLoc) {
public boolean blockBreak(PlayerContainer player, BlockLocation blockPos,
String blockMaterial, String itemInHandMaterial,
String itemInHandName) {
if (!configRepository.getPortalProtection())
return true;

if (player == null) {
return !portalServices.inPortalRegionProtected(blockPos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public interface ConfigRepository {
boolean getDisablePhysicsEvents();

CommandPortalConfig getCommandPortals();

String getWarpSound();

String getWarpParticles();
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public double getThrowbackStrength() {
return this.config.throwbackStrength;
}

@Override
public String getWarpSound() {
return this.config.warpSound;
}

@Override
public String getWarpParticles() {
return this.config.warpParticles;
}

@Override
public void loadConfig(DataStorage dataStorage) {
this.dataStorage = dataStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private Map<String, Object> mapMappingNode(Class<?> currentClass,
*/
private void setField(Object instance, Field field, Object value)
throws IllegalAccessException {

// Check for numeric type compatibility and cast if necessary
if (field.getType() == float.class &&value instanceof Double) {
value = ((Double) value).floatValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +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;
public boolean op = true;
public boolean console = true;
public boolean permsWildcard = true;
public boolean enabled = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ public boolean preActivated(TagTarget target, PlayerContainer player,
ActivationData activeData, String[] argData) {
return true;
}
// TODO: Check if its worth autocompleting an existing command in the
// command tag by
// grabbing all commands in the server

// TODO: Add a warning in console if op/* command is used and tell them to
// use console instead
@Override
public void postActivated(TagTarget target, PlayerContainer player,
ActivationData activationData, String[] argData) {
Expand Down Expand Up @@ -101,24 +96,41 @@ public boolean activated(TagTarget target, PlayerContainer player,
public boolean created(TagTarget target, PlayerContainer player,
String[] argData) {
if (argData != null) {
var commandPortals = configRepository.getCommandPortals();
if(!commandPortals.enabled) {
player.sendMessage(Lang.translate("tag.command.disabled"));
return false;
}
for (String command : argData) {
char executionCommand = command.charAt(0);
return switch (executionCommand) {
case '!' -> {
if (!commandPortals.op) {
player.sendMessage(Lang.translate("tag.command.op.disabled"));
yield false;
}
if (!player.hasPermission("advancedportals.createportal.commandlevel.op")) {
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission", "OP"));
yield false;
}
yield true;
}
case '#' -> {
if (!commandPortals.console) {
player.sendMessage(Lang.translate("tag.command.console.disabled"));
yield false;
}
if (!player.hasPermission("advancedportals.createportal.commandlevel.console")) {
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission","Console"));
yield false;
}
yield true;
}
case '^' -> {
if (!commandPortals.permsWildcard) {
player.sendMessage(Lang.translate("tag.command.permswildcard.disabled"));
yield false;
}
if (!player.hasPermission("advancedportals.createportal.commandlevel.permswild")) {
player.sendMessage(Lang.translateInsertVariables("tag.command.nopermission", "*"));
yield false;
Expand Down

0 comments on commit 22cda5d

Please sign in to comment.