mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +00:00
added command to set config double to a certain value, added command to scale the exp (separately)
renamed multiplier property, to be more descriptive
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package dev.sheldan.abstracto.core.commands.config;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.commands.channels.ChannelsModuleInterface;
|
||||
import dev.sheldan.abstracto.core.config.AbstractoFeatures;
|
||||
import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SetNumber implements Command {
|
||||
|
||||
@Autowired
|
||||
private ConfigService configService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String key = (String) commandContext.getParameters().getParameters().get(0);
|
||||
Double value = (Double) commandContext.getParameters().getParameters().get(1);
|
||||
configService.setDoubleValue(key, commandContext.getGuild().getIdLong(), value);
|
||||
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter channelGroupName = Parameter.builder().name("key").type(String.class).description("The key to change.").build();
|
||||
Parameter channelToAdd = Parameter.builder().name("value").type(Double.class).description("The numeric value to use for the config.").build();
|
||||
List<Parameter> parameters = Arrays.asList(channelGroupName, channelToAdd);
|
||||
return CommandConfiguration.builder()
|
||||
.name("setNumber")
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.description("Used to change the config on this server.")
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeature() {
|
||||
return AbstractoFeatures.CORE;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.ConfigurationException;
|
||||
import dev.sheldan.abstracto.core.service.management.ConfigManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.AConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,4 +30,13 @@ public class ConfigServiceBean implements ConfigService{
|
||||
public void createDoubleValueIfNotExist(String name, Long serverId, Double value) {
|
||||
configManagementService.createIfNotExists(serverId, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDoubleValue(String name, Long serverId, Double value) {
|
||||
if(configManagementService.configExists(serverId, name)) {
|
||||
configManagementService.setDoubleValue(serverId, name, value);
|
||||
} else {
|
||||
throw new ConfigurationException(String.format("Key %s does not exist.", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,4 +86,16 @@ public class ConfigManagementServiceBean implements ConfigManagementService {
|
||||
return configRepository.findAConfigByServerIdAndName(serverId, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configExists(Long serverId, String name) {
|
||||
return loadConfig(serverId, name) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDoubleValue(Long serverId, String name, Double value) {
|
||||
AConfig config = loadConfig(serverId, name);
|
||||
config.setDoubleValue(value);
|
||||
configRepository.save(config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user