Skip to content

Commit

Permalink
Added messages config
Browse files Browse the repository at this point in the history
  • Loading branch information
teitss committed May 28, 2017
1 parent 1a4b5b5 commit 9127279
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 11 deletions.
78 changes: 75 additions & 3 deletions src/main/java/com/teits/pixelmoney/ConfigPM.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;

import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.text.format.TextColors;

import com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon;

import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.loader.ConfigurationLoader;

Expand All @@ -14,6 +20,12 @@ public class ConfigPM {
public boolean levelbased;
public String operationType;
public BigDecimal amount;
public String logmessage;
public String reloadmessage;
public String turnonlogmessage;
public String turnofflogmessage;
public String tagcolor;
public String tagtext;

public CommentedConfigurationNode configInit(ConfigurationLoader<CommentedConfigurationNode> cm, CommentedConfigurationNode cn) {
try {
Expand All @@ -29,9 +41,27 @@ public void configSetup(Path filePath, ConfigurationLoader<CommentedConfiguratio
try {
Files.createFile(filePath);
confignode = configManager.createEmptyNode();
confignode.getNode("pixelmoney", "money").setValue(10).setComment("Amount of money to be rewarded/Number to be used in levelbased's mathematical operations");
confignode.getNode("pixelmoney", "levelbased", "enabled").setValue(false).setComment("Enable/Disable per pokemon's level reward");
confignode.getNode("pixelmoney", "levelbased", "operation-type").setValue("MULTIPLICATION").setComment("You can choose 'MULTIPLICATION', 'DIVISION', 'ADDITION' or 'SUBTRACTION'");
confignode.getNode("pixelmoney", "money").setValue(10)
.setComment("Amount of money to be rewarded/Number to be used in levelbased's mathematical operations");
confignode.getNode("pixelmoney", "levelbased", "enabled").setValue(false)
.setComment("Enable/Disable per pokemon's level reward");
confignode.getNode("pixelmoney", "levelbased", "operation-type").setValue("MULTIPLICATION")
.setComment("You can choose 'MULTIPLICATION', 'DIVISION', 'ADDITION' or 'SUBTRACTION'");
confignode.getNode("pixelmoney", "messages", "log-message")
.setValue("You've gained $%amount% for killing a(n) %pokemon%!")
.setComment("You can use Ampersanding Formatting(&1&n) and the placeholders %amount%, %pokemon%");
confignode.getNode("pixelmoney", "messages", "turnon-message")
.setValue("You've turned on notifications")
.setComment("You can use Ampersanding Formatting(&1&2)");
confignode.getNode("pixelmoney", "messages", "tag-color")
.setValue("WHITE")
.setComment("You can use AQUA, BLACK, BLUE, GOLD, GRAY, GREEN, RED, WHITE, YELLOW, LIGHT_PURPLE, DARK_AQUA, DARK_BLUE, DARK_GRAY, DARK_PURPLE, DARK_GREEN, DARK_RED");
confignode.getNode("pixelmoney", "messages", "turnoff-message")
.setValue("You've turned off notifications")
.setComment("You can use Ampersanding Formatting(&1&2)");
confignode.getNode("pixelmoney", "messages", "reload-message")
.setValue("Config reloaded!")
.setComment("You can use Ampersanding Formatting(&1&2)");
configManager.save(confignode);
}
catch (IOException ec){
Expand All @@ -40,9 +70,15 @@ public void configSetup(Path filePath, ConfigurationLoader<CommentedConfiguratio

}
public void configLoad(CommentedConfigurationNode cn) {
tagcolor = cn.getNode("pixelmoney", "messages", "tag-color").getString();
tagtext = getTagColor(tagcolor) + "[PixelMoney] ";
levelbased = cn.getNode("pixelmoney", "levelbased", "enabled").getBoolean();
operationType = cn.getNode("pixelmoney", "levelbased", "operation-type").getString();
money = cn.getNode("pixelmoney", "money").getInt();
logmessage = tagtext + cn.getNode("pixelmoney", "messages", "log-message").getString();
reloadmessage = tagtext + cn.getNode("pixelmoney", "messages", "reload-message").getString();
turnonlogmessage = tagtext + cn.getNode("pixelmoney", "messages", "turnon-message").getString();
turnofflogmessage = tagtext + cn.getNode("pixelmoney", "messages", "turnoff-message").getString();
}
public BigDecimal setAmount(EntityPixelmon poke) {
if(levelbased==true) {
Expand All @@ -60,4 +96,40 @@ else if(operationType.equals("SUBTRACTION"))
}
return null;
}
public String getTagColor(String color) {
if(color.equals("AQUA"))
return "&b";
else if(color.equals("BLACK"))
return "&0";
else if(color.equals("BLUE"))
return "&9";
else if(color.equals("GOLD"))
return "&6";
else if(color.equals("GRAY"))
return "&7";
else if(color.equals("GREEN"))
return "&a";
else if(color.equals("RED"))
return "&c";
else if(color.equals("WHITE"))
return "&f";
else if(color.equals("YELLOW"))
return "&e";
else if(color.equals("LIGHT_PURPLE"))
return "&d";
else if(color.equals("DARK_AQUA"))
return "&3";
else if(color.equals("DARK_BLUE"))
return "&1";
else if(color.equals("DARK_GRAY"))
return "&8";
else if(color.equals("DARK_PURPLE"))
return "&5";
else if(color.equals("DARK_GREEN"))
return "&2";
else if(color.equals("DARK_RED"))
return "&4";
else
return null;
}
}
8 changes: 5 additions & 3 deletions src/main/java/com/teits/pixelmoney/PixelMoney.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.economy.account.UniqueAccount;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.serializer.TextSerializers;

import com.google.inject.Inject;
import com.pixelmonmod.pixelmon.Pixelmon;
Expand All @@ -43,7 +43,7 @@
public class PixelMoney {

public static final String plName = "PixelMoney";
public static final String plVer = "1.0";
public static final String plVer = "1.1";
public static final String plAuthor = "Teits";

@Inject
Expand Down Expand Up @@ -143,7 +143,9 @@ public void onBeat(BeatWildPixelmonEvent event) {
if(toggle.contains(p.getUniqueId())) {
return ;
}else{
p.sendMessage(Text.of(TextColors.GREEN, "[PixelMoney] You've gained $" + config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN) + " for killing a(n) " + poke.getPokemonName() + "!"));
p.sendMessages(TextSerializers.FORMATTING_CODE.deserialize(config.logmessage
.replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString())
.replaceAll("%pokemon%", poke.getPokemonName())));
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.serializer.TextSerializers;

import com.teits.pixelmoney.PixelMoney;

Expand All @@ -20,7 +19,7 @@ public static void set(PixelMoney p) {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
instance.config.configLoad(instance.config.configInit(instance.getConfigManager(), instance.getConfigNode()));
src.sendMessage(Text.of(TextColors.GREEN, "[PixelMoney] Config reloaded!"));
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(instance.config.reloadmessage));
return CommandResult.success();
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.serializer.TextSerializers;

import com.teits.pixelmoney.PixelMoney;

Expand All @@ -22,11 +23,11 @@ public CommandResult execute(CommandSource src, CommandContext args) throws Comm
Player p = (Player) src;
if(PixelMoney.toggle.contains(p.getUniqueId())) {
PixelMoney.toggle.remove(p.getUniqueId());
p.sendMessage(Text.of(TextColors.GREEN, "[PixelMoney] You've turned on notifications"));
p.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(ReloadExecutor.instance.config.turnonlogmessage));
}
else {
PixelMoney.toggle.add(p.getUniqueId());
p.sendMessage(Text.of(TextColors.GREEN, "[PixelMoney] You've turned off notifications"));
p.sendMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ReloadExecutor.instance.config.turnofflogmessage)));
}
}
if(src instanceof ConsoleSource) {
Expand Down

0 comments on commit 9127279

Please sign in to comment.