From 591e484c2b38bea7d24dabda5db3493b6dfb671e Mon Sep 17 00:00:00 2001 From: superteits Date: Mon, 14 Aug 2017 19:14:05 -0300 Subject: [PATCH] Reupload some things --- .../java/com/teits/pixelmoney/PixelMoney.java | 173 +++++++++--------- .../teits/pixelmoney/exec/ReloadExecutor.java | 10 +- .../teits/pixelmoney/exec/ToggleExecutor.java | 6 +- test.txt | 0 4 files changed, 90 insertions(+), 99 deletions(-) delete mode 100644 test.txt diff --git a/src/main/java/com/teits/pixelmoney/PixelMoney.java b/src/main/java/com/teits/pixelmoney/PixelMoney.java index 1867934..6424a0a 100644 --- a/src/main/java/com/teits/pixelmoney/PixelMoney.java +++ b/src/main/java/com/teits/pixelmoney/PixelMoney.java @@ -43,52 +43,51 @@ @Plugin ( name = PixelMoney.plName, id = "pixelmoney", version = PixelMoney.plVer, authors = PixelMoney.plAuthor, dependencies = {@Dependency(id = "pixelmon")}) public class PixelMoney { - + public static final String plName = "PixelMoney"; - public static final String plVer = "2.0"; + public static final String plVer = "2.0.0"; public static final String plAuthor = "Teits"; - + public static final String plDesc = "Adds configurable money rewards for defeating Pokémon and NPC trainers."; @Inject Logger logger; - + @Inject @DefaultConfig(sharedRoot = true) public Path defaultConfig; - + @Inject @DefaultConfig(sharedRoot = true) private Path filePath = Paths.get(defaultConfig + "/pixelmoney.conf"); - + @Inject @DefaultConfig(sharedRoot = true) private ConfigurationLoader configManager = HoconConfigurationLoader.builder().setPath(filePath).build(); - + private CommentedConfigurationNode configNode; public static List toggle = new ArrayList<>(); EconomyService economyService; - Pixelmon Pixelmon; public EntityPixelmon poke; public ConfigPM config = new ConfigPM(); - public PixelMoney instance; - + public static PixelMoney instance; + public ConfigurationLoader getConfigManager() { return configManager; } public CommentedConfigurationNode getConfigNode() { return configNode; } - + @Listener public void onServerStart(GameInitializationEvent e){ + instance = this; - ReloadExecutor.set(this); logger.info(plName + " " + plVer + " by " + plAuthor); - + if(Files.exists(filePath)) { logger.info("Checking for config updates"); config.checkVer(config.configInit(configManager, configNode)); if(config.configver == 1) { - logger.info("An update has found"); + logger.info("An update was found"); /*try { Files.delete(filePath); } @@ -111,11 +110,11 @@ public void onServerStart(GameInitializationEvent e){ logger.info("Loading config file"); config.configLoad(config.configInit(configManager, configNode)); } - + Pixelmon.EVENT_BUS.register(this); - + logger.info("Registering commands"); - + CommandSpec toggle = CommandSpec.builder() .permission("teits.pixelmoney.command.toggle") .description(Text.of("Toggle the money log messages")) @@ -132,18 +131,18 @@ public void onServerStart(GameInitializationEvent e){ .child(reload, "reload") .child(toggle, "togglemsg") .build(); - + Sponge.getCommandManager().register(this, main, "pixelmoney", "pm"); - + logger.info("Successfully initializated!"); logger.info("Thank you for using " + plName); } - + @Listener public void onChangeServiceProvider(ChangeServiceProviderEvent event) { - if (event.getService().equals(EconomyService.class)) { - economyService = (EconomyService) event.getNewProviderRegistration().getProvider(); - } + if (event.getService().equals(EconomyService.class)) { + economyService = (EconomyService) event.getNewProviderRegistration().getProvider(); + } } @SubscribeEvent public void defeatNPC(BeatTrainerEvent event) { @@ -154,36 +153,36 @@ public void defeatNPC(BeatTrainerEvent event) { if(uOpt.isPresent()) { UniqueAccount acc = uOpt.get(); if(event.trainer.getBossMode().equals(EnumBossMode.NotBoss)) { - config.setAmountNormalNPC(event.trainer, p); - if(config.setAmountNormalNPC(event.trainer, p)==null){ - System.out.println("You have a problem in your config file"); - }else{ - acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); - if(toggle.contains(p.getUniqueId())) { - return ; - }else{ - p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage - .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) - .replaceAll("%pokemon%", event.trainer.getName(event.trainer.getName())))); - } - } - } + config.setAmountNormalNPC(event.trainer, p); + if(config.setAmountNormalNPC(event.trainer, p)==null){ + System.out.println("You have a problem in your config file"); + }else{ + acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); + if(toggle.contains(p.getUniqueId())) { + return ; + }else{ + p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage + .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) + .replaceAll("%pokemon%", event.trainer.getName(event.trainer.getName())))); + } + } + } else { - config.setAmountBossNPC(event.trainer, p); - if(config.setAmountBossNPC(event.trainer, p)==null) - System.out.println("You have a problem in your config file"); - else { - acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); - if(toggle.contains(p.getUniqueId())) { - return ; - } - else { - p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage - .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) - .replaceAll("%pokemon%", event.trainer.getName(event.trainer.getName())))); - } - } - } + config.setAmountBossNPC(event.trainer, p); + if(config.setAmountBossNPC(event.trainer, p)==null) + System.out.println("You have a problem in your config file"); + else { + acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); + if(toggle.contains(p.getUniqueId())) { + return ; + } + else { + p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage + .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) + .replaceAll("%pokemon%", event.trainer.getName(event.trainer.getName())))); + } + } + } } } } @@ -195,41 +194,41 @@ public void defeatWild(BeatWildPixelmonEvent event) { if(p.hasPermission("teits.pixelmoney.enable")) { Optional uOpt = economyService.getOrCreateAccount(p.getUniqueId()); if (uOpt.isPresent()) { - UniqueAccount acc = uOpt.get(); - for (PixelmonWrapper wrapper : event.wpp.allPokemon) { - poke = wrapper.pokemon; - if(poke.isBossPokemon() == true) { - config.setAmountBossWild(poke, p); - if(config.setAmountBossWild(poke, p)==null) - System.out.println("You have a problem in your config file"); - else { - acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); - if(toggle.contains(p.getUniqueId())) { - return ; - }else{ - p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage - .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) - .replaceAll("%pokemon%", wrapper.getPokemonName()))); - } - } - - } - else { - config.setAmountNormalWild(wrapper, p); - if(config.setAmountNormalWild(wrapper, p)==null){ - System.out.println("You have a problem in your config file"); - }else{ - acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); - if(toggle.contains(p.getUniqueId())) { - return ; - }else{ - p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage - .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) - .replaceAll("%pokemon%", wrapper.getPokemonName()))); - } - } - } - } + UniqueAccount acc = uOpt.get(); + for (PixelmonWrapper wrapper : event.wpp.allPokemon) { + poke = wrapper.pokemon; + if(poke.isBossPokemon() == true) { + config.setAmountBossWild(poke, p); + if(config.setAmountBossWild(poke, p)==null) + System.out.println("You have a problem in your config file"); + else { + acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); + if(toggle.contains(p.getUniqueId())) { + return ; + }else{ + p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage + .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) + .replaceAll("%pokemon%", wrapper.getPokemonName()))); + } + } + + } + else { + config.setAmountNormalWild(wrapper, p); + if(config.setAmountNormalWild(wrapper, p)==null){ + System.out.println("You have a problem in your config file"); + }else{ + acc.deposit(economyService.getDefaultCurrency(), config.amount, Cause.source(this).build()); + if(toggle.contains(p.getUniqueId())) { + return ; + }else{ + p.sendMessages(config.getChatType(config.chattype), TextSerializers.FORMATTING_CODE.deserialize(config.logmessage + .replaceAll("%amount%", config.amount.setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()) + .replaceAll("%pokemon%", wrapper.getPokemonName()))); + } + } + } + } } } } diff --git a/src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java b/src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java index ec10e19..e1827a2 100644 --- a/src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java +++ b/src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java @@ -10,16 +10,10 @@ import com.teits.pixelmoney.PixelMoney; public class ReloadExecutor implements CommandExecutor { - - static PixelMoney instance; - public static void set(PixelMoney p) { - instance = p; - } - @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { - instance.config.configLoad(instance.config.configInit(instance.getConfigManager(), instance.getConfigNode())); - src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(instance.config.reloadmessage)); + PixelMoney.instance.config.configLoad(PixelMoney.instance.config.configInit(PixelMoney.instance.getConfigManager(), PixelMoney.instance.getConfigNode())); + src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(PixelMoney.instance.config.reloadmessage)); return CommandResult.success(); } } diff --git a/src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java b/src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java index b91e7e8..d5ca1a6 100644 --- a/src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java +++ b/src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java @@ -15,19 +15,17 @@ import com.teits.pixelmoney.PixelMoney; public class ToggleExecutor implements CommandExecutor { - - @Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { if(src instanceof Player) { Player p = (Player) src; if(PixelMoney.toggle.contains(p.getUniqueId())) { PixelMoney.toggle.remove(p.getUniqueId()); - p.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(ReloadExecutor.instance.config.turnonlogmessage)); + p.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(PixelMoney.instance.config.turnonlogmessage)); } else { PixelMoney.toggle.add(p.getUniqueId()); - p.sendMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ReloadExecutor.instance.config.turnofflogmessage))); + p.sendMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(PixelMoney.instance.config.turnofflogmessage))); } } if(src instanceof ConsoleSource) { diff --git a/test.txt b/test.txt deleted file mode 100644 index e69de29..0000000