Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
EconomyLite v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Flibio committed Aug 7, 2015
1 parent 98b3666 commit f30066a
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 6 deletions.
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>EconomyLite</groupId>
<artifactId>EconomyLite</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>
<name>EconomyLite</name>
<description>An economy plugin for Sponge</description>
Expand Down
15 changes: 14 additions & 1 deletion src/me/Flibio/EconomyLite/API/EconomyLiteAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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;
}

}
3 changes: 2 additions & 1 deletion src/me/Flibio/EconomyLite/Commands/BusinessLeaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
77 changes: 77 additions & 0 deletions src/me/Flibio/EconomyLite/Commands/BusinessOwnersCommand.java
Original file line number Diff line number Diff line change
@@ -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<String> rawBusiness = args.<String>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<String> 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();
}



}
5 changes: 5 additions & 0 deletions src/me/Flibio/EconomyLite/Events/BalanceChangeEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion src/me/Flibio/EconomyLite/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand All @@ -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");
}
Expand Down
6 changes: 5 additions & 1 deletion src/me/Flibio/EconomyLite/Utils/BusinessManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
31 changes: 30 additions & 1 deletion src/me/Flibio/EconomyLite/Utils/PlayerManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.Flibio.EconomyLite.Utils;

import java.util.UUID;
import java.util.concurrent.ExecutionException;

import me.Flibio.EconomyLite.Main;
Expand All @@ -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;
Expand Down Expand Up @@ -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<GameProfileResolver> 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
Expand Down
17 changes: 17 additions & 0 deletions src/me/Flibio/EconomyLite/Utils/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit f30066a

Please sign in to comment.