Skip to content

Commit

Permalink
0.2 update
Browse files Browse the repository at this point in the history
Reloading, a config, basically changed the whole command structure.
  • Loading branch information
Xenoyia committed Apr 26, 2017
1 parent 5892c70 commit 3f6a25b
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/Lukas X. Valentine/Downloads/forge-1.10.2-12.18.3.2281-universal.jar"/>
<classpathentry kind="lib" path="C:/Users/Lukas X. Valentine/Downloads/server.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xpgaming</groupId>
<artifactId>xPBottles</artifactId>
<version>0.1</version>
<version>0.2</version>
<name>xPBottles</name>
<repositories>
<repository>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/xpgaming/xPBottles/Bottle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.xpgaming.xPBottles;

import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.entity.GameModeData;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.entity.Hotbar;
import org.spongepowered.api.item.inventory.type.GridInventory;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;

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

public class Bottle implements CommandExecutor {

public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if(src instanceof Player) {
Player player = (Player) src;
player.sendMessage(Text.of("§f[§bxP//§f] §b§l-- COMMANDS --"));
if(player.hasPermission("xpgaming.bottles.use")) {
player.sendMessage(Text.of(" §7> §b/bottle confirm §7- Convert your XP into bottles!"));
}
if(player.hasPermission("xpgaming.bottles.reload")) {
player.sendMessage(Text.of(" §7> §b/bottle reload §7- Reload plugin configuration!"));
}
} else {
src.sendMessage(Text.of("§f[§bxP//§f] §b§l-- COMMANDS --"));
src.sendMessage(Text.of(" §7> §b/bottle confirm §7- Convert your XP into bottles!"));
src.sendMessage(Text.of(" §7> §b/bottle reload §7- Reload plugin configuration!"));
}
return CommandResult.success();
}

}
17 changes: 13 additions & 4 deletions src/main/java/com/xpgaming/xPBottles/BottleXP.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.xpgaming.xPBottles;

import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
Expand Down Expand Up @@ -30,22 +33,28 @@
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;

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

public class BottleXP implements CommandExecutor {

public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if(src instanceof Player) {
Player player = (Player) src;
if(player.gameMode().get() == GameModes.SURVIVAL) {
int totalEXP = player.get(Keys.TOTAL_EXPERIENCE).orElseGet(() -> 0);
if(totalEXP >= 11) {
int currentLevel = player.get(Keys.EXPERIENCE_LEVEL).orElseGet(() -> 0);
int minLevels = Config.getInstance().getConfig().getNode("bottles", "min_level").getInt();
if(currentLevel >= minLevels) {
double bottlesNeeded = Math.ceil(totalEXP / 11);
createBottles(bottlesNeeded, player);
if(bottlesNeeded == 1) {
player.sendMessage(Text.of("§f[§axP//§f] §aSuccessfully exchanged your EXP for §2" + (int)bottlesNeeded + "§a bottle!"));
} else player.sendMessage(Text.of("§f[§axP//§f] §aSuccessfully exchanged your EXP for §2" + (int)bottlesNeeded + "§a bottles!"));
player.sendMessage(Text.of("§f[§axP//§f] §aSuccessfully exchanged your XP for §2" + (int)bottlesNeeded + "§a bottle!"));
} else player.sendMessage(Text.of("§f[§axP//§f] §aSuccessfully exchanged your XP for §2" + (int)bottlesNeeded + "§a bottles!"));
player.offer(Keys.TOTAL_EXPERIENCE, 0);
} else {
player.sendMessage(Text.of("§f[§cxP//§f] §cYou need at least 11 XP to convert to bottles!"));
player.sendMessage(Text.of("§f[§cxP//§f] §cYou need at least " + minLevels + " levels to convert to bottles!"));
}
return CommandResult.success();
} else {
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/xpgaming/xPBottles/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.xpgaming.xPBottles;

import java.io.File;
import java.io.IOException;

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

public class Config {
private static Config instance = new Config();

public static Config getInstance() {
return instance;
}

private ConfigurationLoader<CommentedConfigurationNode> configLoader;
private CommentedConfigurationNode config;
private File configFile;

public void configCreate() {
try {
configFile.createNewFile();
configLoad();
CommentedConfigurationNode bottles = config.getNode("bottles").setComment("xP// Bottles coded by Xenoyia! Check out mc.xpgaming.com!");
bottles.getNode("min_level").setComment("Do not set this to lower than 2, it's hardcoded to not give half a bottle.").setValue("30");
configSave();
} catch (IOException e) {
e.printStackTrace();
}
}

public void setup(File configFile, ConfigurationLoader<CommentedConfigurationNode> configLoader) {
this.configLoader = configLoader;
this.configFile = configFile;
if (!configFile.exists()) {
configCreate();
} else
configLoad();
}

public CommentedConfigurationNode getConfig() {
return config;
}

public void configLoad() {
if (!configFile.exists()) {
configCreate();
} else
try {
config = configLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
}

public void configSave() {
try {
configLoader.save(config);
} catch (IOException e) {
e.printStackTrace();
}
}

public void saveAndLoadConfig() {
configSave();
configLoad();
}
}
52 changes: 39 additions & 13 deletions src/main/java/com/xpgaming/xPBottles/Main.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
package com.xpgaming.xPBottles;

import java.util.logging.Logger;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.inject.Inject;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.loader.ConfigurationLoader;

@Plugin(id = "xpbottles", name = "xP// Bottles", version = "0.1")
@Plugin(id = "xpbottles", name = "xP// Bottles", version = "0.2")
public class Main {
private Logger logger;

CommandSpec Commands = CommandSpec.builder()

CommandSpec confirm = CommandSpec.builder()
.description(Text.of("Bottle 30 levels of XP!"))
.permission("xpgaming.bottles.use")
.executor(new BottleXP())
.build();

CommandSpec reload = CommandSpec.builder()
.description(Text.of("Reload config!"))
.permission("xpgaming.bottles.reload")
.executor(new Reload())
.build();

CommandSpec bottle = CommandSpec.builder()
.description(Text.of("Bottle XP!"))
.permission("xpgaming.bottles")
.child(confirm, "confirm", "c", "yes")
.child(reload, "reload", "r")
.executor(new Bottle())
.build();

@Inject
public Main(Logger logger) {
this.logger = logger;
}
@DefaultConfig(sharedRoot = true)
private File configFile;

public Logger Log() {
return logger;
@Inject
@DefaultConfig(sharedRoot = true)
ConfigurationLoader<CommentedConfigurationNode> configLoader;

@Listener
public void onGameInitialization(GameInitializationEvent event) {
Config.getInstance().setup(configFile, configLoader);
}

@Listener
public void onPreInitializationEvent(GameInitializationEvent event) {
Sponge.getCommandManager().register(this, Commands, "bottlexp", "xpbottle", "bottle");
Sponge.getCommandManager().register(this, bottle, "bottle", "xpbottle", "bottlexp", "xptobottle", "bxp");
}

@Listener
public void onServerStart(GameStartedServerEvent event) {
Log().info("[xP//] xPBottles has loaded: v0.1");
System.out.println("[xP// Bottles] Loaded v0.2!");
}


Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/xpgaming/xPBottles/Reload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.xpgaming.xPBottles;

import java.net.URL;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.spec.CommandExecutor;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.manipulator.mutable.entity.GameModeData;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.entity.living.player.gamemode.GameModes;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.entity.Hotbar;
import org.spongepowered.api.item.inventory.type.GridInventory;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;

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

public class Reload implements CommandExecutor {
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Config.getInstance().configLoad();
if(src instanceof Player) {
Player player = (Player) src;
player.sendMessage(Text.of("§f[§bxP//§f] §bSuccessfully reloaded xP// Bottles!"));
} else {
src.sendMessage(Text.of("§f[§bxP//§f] §bSuccessfully reloaded xP// Bottles!"));
}
return CommandResult.success();
}

}
1 change: 1 addition & 0 deletions src/main/resources/xpbottles.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcde

0 comments on commit 3f6a25b

Please sign in to comment.