Skip to content

Commit

Permalink
Reupload some things
Browse files Browse the repository at this point in the history
  • Loading branch information
teitss committed Aug 14, 2017
1 parent cffba1a commit 591e484
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 99 deletions.
173 changes: 86 additions & 87 deletions src/main/java/com/teits/pixelmoney/PixelMoney.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommentedConfigurationNode> configManager = HoconConfigurationLoader.builder().setPath(filePath).build();

private CommentedConfigurationNode configNode;
public static List<UUID> toggle = new ArrayList<>();
EconomyService economyService;
Pixelmon Pixelmon;
public EntityPixelmon poke;
public ConfigPM config = new ConfigPM();
public PixelMoney instance;
public static PixelMoney instance;

public ConfigurationLoader<CommentedConfigurationNode> 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);
}
Expand All @@ -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"))
Expand All @@ -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) {
Expand All @@ -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()))));
}
}
}
}
}
}
Expand All @@ -195,41 +194,41 @@ public void defeatWild(BeatWildPixelmonEvent event) {
if(p.hasPermission("teits.pixelmoney.enable")) {
Optional<UniqueAccount> 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())));
}
}
}
}
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/teits/pixelmoney/exec/ReloadExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 2 additions & 4 deletions src/main/java/com/teits/pixelmoney/exec/ToggleExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Empty file removed test.txt
Empty file.

0 comments on commit 591e484

Please sign in to comment.