fix: portal command config reading

This commit is contained in:
Sekwah 2024-09-02 03:35:45 +01:00
parent fd2483c3af
commit 22cda5d2cc
6 changed files with 39 additions and 9 deletions

View File

@ -66,6 +66,9 @@ public class CoreListeners {
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);
}

View File

@ -37,4 +37,8 @@ public interface ConfigRepository {
boolean getDisablePhysicsEvents();
CommandPortalConfig getCommandPortals();
String getWarpSound();
String getWarpParticles();
}

View File

@ -85,6 +85,16 @@ public class ConfigRepositoryImpl implements ConfigRepository {
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;

View File

@ -193,6 +193,7 @@ public class ReflectiveConstructor<T> extends Constructor {
*/
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();

View File

@ -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;
}

View File

@ -49,12 +49,7 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
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) {
@ -101,10 +96,19 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
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;
@ -112,6 +116,10 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
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;
@ -119,6 +127,10 @@ public class CommandTag implements Tag.Activation, Tag.Split, Tag.Creation {
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;