mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-18 04:50:38 +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.experience.commands;
|
||||||
|
|
||||||
|
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||||
|
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||||
|
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.service.ConfigService;
|
||||||
|
import dev.sheldan.abstracto.experience.config.ExperienceFeatures;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ExpScale extends AbstractConditionableCommand {
|
||||||
|
|
||||||
|
public static final String EXP_MULTIPLIER_KEY = "expMultiplier";
|
||||||
|
@Autowired
|
||||||
|
private ConfigService configService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandResult execute(CommandContext commandContext) {
|
||||||
|
Double scale = (Double) commandContext.getParameters().getParameters().get(0);
|
||||||
|
configService.setDoubleValue(EXP_MULTIPLIER_KEY, commandContext.getGuild().getIdLong(), scale);
|
||||||
|
return CommandResult.fromSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandConfiguration getConfiguration() {
|
||||||
|
List<Parameter> parameters = new ArrayList<>();
|
||||||
|
parameters.add(Parameter.builder().name("scale").type(Double.class).build());
|
||||||
|
HelpInfo helpInfo = HelpInfo.builder().longHelp("The new scale of experience on this server.").usage("expScale").build();
|
||||||
|
return CommandConfiguration.builder()
|
||||||
|
.name("expScale")
|
||||||
|
.module(ExperienceModule.EXPERIENCE)
|
||||||
|
.description("Sets the experience scale of this server to this value.")
|
||||||
|
.causesReaction(true)
|
||||||
|
.parameters(parameters)
|
||||||
|
.help(helpInfo)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFeature() {
|
||||||
|
return ExperienceFeatures.EXPERIENCE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,6 @@ import org.springframework.stereotype.Component;
|
|||||||
public class ExperienceConfig {
|
public class ExperienceConfig {
|
||||||
private Integer minExp;
|
private Integer minExp;
|
||||||
private Integer maxExp;
|
private Integer maxExp;
|
||||||
private Integer multiplier;
|
private Integer expMultiplier;
|
||||||
private Integer maxLvl;
|
private Integer maxLvl;
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,6 @@ public class ExperienceConfigListener implements ServerConfigListener {
|
|||||||
log.info("Setting up experience for {}", server.getId());
|
log.info("Setting up experience for {}", server.getId());
|
||||||
service.createDoubleValueIfNotExist("minExp", server.getId(), experienceConfig.getMinExp().doubleValue());
|
service.createDoubleValueIfNotExist("minExp", server.getId(), experienceConfig.getMinExp().doubleValue());
|
||||||
service.createDoubleValueIfNotExist("maxExp", server.getId(), experienceConfig.getMaxExp().doubleValue());
|
service.createDoubleValueIfNotExist("maxExp", server.getId(), experienceConfig.getMaxExp().doubleValue());
|
||||||
service.createDoubleValueIfNotExist("multiplier", server.getId(), experienceConfig.getMultiplier().doubleValue());
|
service.createDoubleValueIfNotExist("expMultiplier", server.getId(), experienceConfig.getExpMultiplier().doubleValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class ExperienceTrackerServiceBean implements ExperienceTrackerService {
|
|||||||
log.debug("Handling experience for server {}", serverExp.getId());
|
log.debug("Handling experience for server {}", serverExp.getId());
|
||||||
int minExp = configService.getDoubleValue("minExp", serverExp.getId()).intValue();
|
int minExp = configService.getDoubleValue("minExp", serverExp.getId()).intValue();
|
||||||
int maxExp = configService.getDoubleValue("maxExp", serverExp.getId()).intValue();
|
int maxExp = configService.getDoubleValue("maxExp", serverExp.getId()).intValue();
|
||||||
Integer multiplier = configService.getDoubleValue("multiplier", serverExp.getId()).intValue();
|
Integer multiplier = configService.getDoubleValue("expMultiplier", serverExp.getId()).intValue();
|
||||||
PrimitiveIterator.OfInt iterator = new Random().ints(serverExp.getUsers().size(), minExp, maxExp + 1).iterator();
|
PrimitiveIterator.OfInt iterator = new Random().ints(serverExp.getUsers().size(), minExp, maxExp + 1).iterator();
|
||||||
List<AExperienceLevel> levels = experienceLevelManagementService.getLevelConfig();
|
List<AExperienceLevel> levels = experienceLevelManagementService.getLevelConfig();
|
||||||
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRoleForServer(serverExp);
|
List<AExperienceRole> roles = experienceRoleManagementService.getExperienceRoleForServer(serverExp);
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ abstracto.features.experience=true
|
|||||||
|
|
||||||
abstracto.experience.minExp=10
|
abstracto.experience.minExp=10
|
||||||
abstracto.experience.maxExp=25
|
abstracto.experience.maxExp=25
|
||||||
abstracto.experience.multiplier=1
|
abstracto.experience.expMultiplier=1
|
||||||
abstracto.experience.maxLvl=200
|
abstracto.experience.maxLvl=200
|
||||||
@@ -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;
|
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.service.management.ConfigManagementService;
|
||||||
import dev.sheldan.abstracto.core.models.database.AConfig;
|
import dev.sheldan.abstracto.core.models.database.AConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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) {
|
public void createDoubleValueIfNotExist(String name, Long serverId, Double value) {
|
||||||
configManagementService.createIfNotExists(serverId, name, 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);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package dev.sheldan.abstracto.core.exception;
|
package dev.sheldan.abstracto.core.exception;
|
||||||
|
|
||||||
public class ConfigurationException extends Exception {
|
public class ConfigurationException extends AbstractoRunTimeException {
|
||||||
public ConfigurationException(String message) {
|
public ConfigurationException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ public interface ConfigService {
|
|||||||
Double getDoubleValue(String name, Long serverId);
|
Double getDoubleValue(String name, Long serverId);
|
||||||
Double getDoubleValue(String name, Long serverId, Double defaultValue);
|
Double getDoubleValue(String name, Long serverId, Double defaultValue);
|
||||||
void createDoubleValueIfNotExist(String name, Long serverId, Double value);
|
void createDoubleValueIfNotExist(String name, Long serverId, Double value);
|
||||||
|
void setDoubleValue(String name, Long serverId, Double value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ public interface ConfigManagementService {
|
|||||||
AConfig createIfNotExists(Long serverId, String name, String value);
|
AConfig createIfNotExists(Long serverId, String name, String value);
|
||||||
AConfig createIfNotExists(Long serverId, String name, Double value);
|
AConfig createIfNotExists(Long serverId, String name, Double value);
|
||||||
AConfig loadConfig(Long serverId, String name);
|
AConfig loadConfig(Long serverId, String name);
|
||||||
|
boolean configExists(Long serverId, String name);
|
||||||
|
void setDoubleValue(Long serverId, String name, Double value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user