diff --git a/pom.xml b/pom.xml
index f754c61..7a0736c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
4.0.0
EconomyLite
EconomyLite
- 1.0.0
+ 1.0.1
jar
EconomyLite
An economy plugin for Sponge
diff --git a/src/me/Flibio/EconomyLite/API/EconomyLiteAPI.java b/src/me/Flibio/EconomyLite/API/EconomyLiteAPI.java
index aa5be9e..811e64b 100644
--- a/src/me/Flibio/EconomyLite/API/EconomyLiteAPI.java
+++ b/src/me/Flibio/EconomyLite/API/EconomyLiteAPI.java
@@ -11,7 +11,11 @@ public class EconomyLiteAPI {
private PlayerManager playerAPI = new PlayerManager();
/**
- * EconomyLite's API
+ * EconomyLite's API.
+ *
+ * Methods will query a MySQL Database if the EconomyLite user has opted to save data to a database.
+ *
+ * If possible, you should run these methods in a seperate thread.
*/
public EconomyLiteAPI() {
if(!Main.optionEnabled("businesses")) {
@@ -26,5 +30,14 @@ public BusinessManager getBusinessAPI() {
public PlayerManager getPlayerAPI() {
return playerAPI;
}
+
+ /**
+ * Gets the version of EconomyLite currently running
+ * @return
+ * String of the version in format X.Y.Z
+ */
+ public String getVersion() {
+ return Main.access.version;
+ }
}
diff --git a/src/me/Flibio/EconomyLite/Commands/BusinessLeaveCommand.java b/src/me/Flibio/EconomyLite/Commands/BusinessLeaveCommand.java
index 5d053ba..8bd492d 100644
--- a/src/me/Flibio/EconomyLite/Commands/BusinessLeaveCommand.java
+++ b/src/me/Flibio/EconomyLite/Commands/BusinessLeaveCommand.java
@@ -41,12 +41,13 @@ public void run() {
String businessName = businessNameOptional.get();
//Check if the business already exists
if(businessManager.businessExists(businessName)) {
+ String correctName = businessManager.getCorrectBusinessName(businessName);
//Check if the player is an owner
if(businessManager.ownerExists(businessName, player.getUniqueId().toString())) {
//Check if the player is the only owner
if(businessManager.getBusinessOwners(businessName).size()==1) {
//Tell player that the business will be deleted
- player.sendMessage(textUtils.leaveOnlyOwner(businessName));
+ player.sendMessage(textUtils.leaveOnlyOwner(correctName));
businessManager.setConfirmationNeeded(businessName, false);
//Expire in 1 minute
Thread expireThread = new Thread(new Runnable(){
diff --git a/src/me/Flibio/EconomyLite/Commands/BusinessOwnersCommand.java b/src/me/Flibio/EconomyLite/Commands/BusinessOwnersCommand.java
new file mode 100644
index 0000000..658d13f
--- /dev/null
+++ b/src/me/Flibio/EconomyLite/Commands/BusinessOwnersCommand.java
@@ -0,0 +1,77 @@
+package me.Flibio.EconomyLite.Commands;
+
+import java.util.ArrayList;
+
+import me.Flibio.EconomyLite.Main;
+import me.Flibio.EconomyLite.Utils.BusinessManager;
+import me.Flibio.EconomyLite.Utils.PlayerManager;
+import me.Flibio.EconomyLite.Utils.TextUtils;
+
+import org.spongepowered.api.entity.player.Player;
+import org.spongepowered.api.service.scheduler.TaskBuilder;
+import org.spongepowered.api.text.format.TextColors;
+import org.spongepowered.api.util.command.CommandException;
+import org.spongepowered.api.util.command.CommandResult;
+import org.spongepowered.api.util.command.CommandSource;
+import org.spongepowered.api.util.command.args.CommandContext;
+import org.spongepowered.api.util.command.spec.CommandExecutor;
+
+import com.google.common.base.Optional;
+
+public class BusinessOwnersCommand implements CommandExecutor{
+
+ private TextUtils textUtils = new TextUtils();
+ private BusinessManager businessManager = new BusinessManager();
+ private PlayerManager playerManager = new PlayerManager();
+ private TaskBuilder taskBuilder = Main.access.game.getScheduler().getTaskBuilder();
+
+ @Override
+ public CommandResult execute(CommandSource source, CommandContext args)
+ throws CommandException {
+ //Run in a seperate thread
+ taskBuilder.execute(new Runnable() {
+ public void run() {
+ //Make sure the source is a player
+ if(!(source instanceof Player)) {
+ source.sendMessage(textUtils.basicText("You must be a player to view the owners of a business!", TextColors.RED));
+ return;
+ }
+
+ Player player = (Player) source;
+
+ Optional rawBusiness = args.getOne("business");
+ if(rawBusiness.isPresent()) {
+ //Parameter is present
+ String businessName = rawBusiness.get().trim();
+ String correctName = businessManager.getCorrectBusinessName(businessName);
+
+ //Check if the business exists
+ if(!businessManager.businessExists(businessName)) {
+ player.sendMessage(textUtils.basicText("That business doesn't exist!", TextColors.RED));
+ return;
+ }
+ //Check if the player is an owner
+ if(!businessManager.ownerExists(businessName, player.getUniqueId().toString())) {
+ player.sendMessage(textUtils.basicText("You don't have permission to view the owners of that business!", TextColors.RED));
+ return;
+ }
+ //Send the message:
+ ArrayList owners = businessManager.getBusinessOwners(businessName);
+ player.sendMessage(textUtils.ownersTitle(correctName));
+ for(String owner : owners) {
+ player.sendMessage(textUtils.owner(playerManager.getName(owner)));
+ }
+ } else {
+ //An error occured
+ player.sendMessage(textUtils.basicText("An internal error has occured!", TextColors.RED));
+ return;
+ }
+
+ }
+ }).async().submit(Main.access);
+ return CommandResult.success();
+ }
+
+
+
+}
diff --git a/src/me/Flibio/EconomyLite/Events/BalanceChangeEvent.java b/src/me/Flibio/EconomyLite/Events/BalanceChangeEvent.java
index ee54fa2..b670616 100644
--- a/src/me/Flibio/EconomyLite/Events/BalanceChangeEvent.java
+++ b/src/me/Flibio/EconomyLite/Events/BalanceChangeEvent.java
@@ -8,6 +8,11 @@ public class BalanceChangeEvent extends AbstractEvent implements Cancellable {
private boolean cancelled = false;
private String playerUUID;
+ /**
+ * Sponge event called when a player's balance changes
+ * @param playerUUID
+ * The UUID of the player whose balance changed
+ */
public BalanceChangeEvent(String playerUUID){
this.playerUUID = playerUUID;
}
diff --git a/src/me/Flibio/EconomyLite/Main.java b/src/me/Flibio/EconomyLite/Main.java
index 255acaf..8b36cf4 100644
--- a/src/me/Flibio/EconomyLite/Main.java
+++ b/src/me/Flibio/EconomyLite/Main.java
@@ -10,6 +10,7 @@
import me.Flibio.EconomyLite.Commands.BusinessInviteAcceptCommand;
import me.Flibio.EconomyLite.Commands.BusinessInviteCommand;
import me.Flibio.EconomyLite.Commands.BusinessLeaveCommand;
+import me.Flibio.EconomyLite.Commands.BusinessOwnersCommand;
import me.Flibio.EconomyLite.Commands.BusinessRegisterCommand;
import me.Flibio.EconomyLite.Commands.BusinessTransferCommand;
import me.Flibio.EconomyLite.Commands.PayCommand;
@@ -42,7 +43,7 @@
import com.google.common.base.Optional;
import com.google.inject.Inject;
-@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.0.0")
+@Plugin(id = "EconomyLite", name = "EconomyLite", version = "1.0.1")
public class Main {
@Inject
@@ -229,6 +230,13 @@ private void registerCommands() {
.arguments(GenericArguments.integer(Texts.of("amount")),GenericArguments.remainingJoinedStrings(Texts.of("business")))
.executor(new BusinessTransferCommand())
.build();
+ //Owners Child
+ CommandSpec businessOwnersCommand = CommandSpec.builder()
+ .description(Texts.of("View the owners of a business"))
+ .permission("econ.busines.owners")
+ .arguments(GenericArguments.remainingJoinedStrings(Texts.of("business")))
+ .executor(new BusinessOwnersCommand())
+ .build();
//Main Command
CommandSpec businessCommand = CommandSpec.builder()
.description(Texts.of("Business management commands"))
@@ -239,6 +247,7 @@ private void registerCommands() {
.child(businessInviteCommand, "invite", "inv")
.child(businessInviteAcceptCommand, "inviteAccept")
.child(businessTransferCommand, "transfer")
+ .child(businessOwnersCommand, "owners")
.build();
game.getCommandDispatcher().register(this, businessCommand, "business");
}
diff --git a/src/me/Flibio/EconomyLite/Utils/BusinessManager.java b/src/me/Flibio/EconomyLite/Utils/BusinessManager.java
index 41c0cb2..2b9f9dc 100644
--- a/src/me/Flibio/EconomyLite/Utils/BusinessManager.java
+++ b/src/me/Flibio/EconomyLite/Utils/BusinessManager.java
@@ -15,7 +15,11 @@ public class BusinessManager {
private FileManager fileManager;
/**
- * EconomyLite's Business API
+ * EconomyLite's Business API.
+ *
+ * Methods will query a MySQL Database if the EconomyLite user has opted to save data to a database.
+ *
+ * If possible, you should run these methods in a seperate thread.
*/
public BusinessManager() {
fileManager = new FileManager();
diff --git a/src/me/Flibio/EconomyLite/Utils/PlayerManager.java b/src/me/Flibio/EconomyLite/Utils/PlayerManager.java
index 2250807..a8fb4f9 100644
--- a/src/me/Flibio/EconomyLite/Utils/PlayerManager.java
+++ b/src/me/Flibio/EconomyLite/Utils/PlayerManager.java
@@ -1,5 +1,6 @@
package me.Flibio.EconomyLite.Utils;
+import java.util.UUID;
import java.util.concurrent.ExecutionException;
import me.Flibio.EconomyLite.Main;
@@ -21,7 +22,11 @@ public class PlayerManager {
private Game game;
/**
- * EconomyLite's Player API
+ * EconomyLite's Player API.
+ *
+ * Methods will query a MySQL Database if the EconomyLite user has opted to save data to a database.
+ *
+ * If possible, you should run these methods in a seperate thread.
*/
public PlayerManager() {
this.game = Main.access.game;
@@ -54,6 +59,30 @@ public String getUUID(String name) {
}
}
+ /**
+ * Looks up a player's name
+ * @param uuid
+ * UUID of the player whom to lookup
+ * @return
+ * Name of the corresponding player
+ */
+ public String getName(String uuid) {
+ Optional resolverOptional = game.getServiceManager().provide(GameProfileResolver.class);
+ if(resolverOptional.isPresent()) {
+ GameProfileResolver resolver = resolverOptional.get();
+ GameProfile profile;
+ try {
+ profile = resolver.get(UUID.fromString(uuid)).get();
+ } catch (InterruptedException | ExecutionException e) {
+ logger.error("Error getting player's name");
+ return "";
+ }
+ return profile.getName().toString();
+ } else {
+ return "";
+ }
+ }
+
/**
* Sets the balance of the given player to the given amount
* @param uuid
diff --git a/src/me/Flibio/EconomyLite/Utils/TextUtils.java b/src/me/Flibio/EconomyLite/Utils/TextUtils.java
index 8e8bb24..17e94e3 100644
--- a/src/me/Flibio/EconomyLite/Utils/TextUtils.java
+++ b/src/me/Flibio/EconomyLite/Utils/TextUtils.java
@@ -251,6 +251,23 @@ public Text transferSuccess(String businessName, int amount) {
return text;
}
+ public Text ownersTitle(String businessName) {
+ Text text = Texts.builder("EconomyLite » ").color(TextColors.GOLD).build();
+
+ text = text.builder().append(basicText("Owners of ",TextColors.YELLOW)).build();
+ text = text.builder().append(basicText(businessName+":",TextColors.GREEN)).build();
+
+ return text;
+ }
+
+ public Text owner(String owner) {
+ Text text = Texts.builder(" + ").color(TextColors.YELLOW).build();
+
+ text = text.builder().append(basicText(owner,TextColors.GREEN)).build();
+
+ return text;
+ }
+
public String getDownloadUrl(String jsonRelease) {
return jsonRelease.split("browser_download_url")[1].split("}",2)[0].replaceAll("\"", "").replaceFirst(":", "").trim();
}