Skip to content

Commit

Permalink
Few suggestions
Browse files Browse the repository at this point in the history
- Success message on transferring crypto between players
- Allowing players access to /cm balance <name> so they can compare their balance to others
- Check for resource file update
  • Loading branch information
Evirth committed Apr 1, 2018
1 parent af9b780 commit e4770e7
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public void transfer(String crypto, String amount, String toPlayer) {

this.changeBalance(coin, -amountOfCrypto);
this.printBalance();
this.player.sendMessage(String.format(CryptoMarket.resourceManager.getResource("TransferSuccess"), amountOfCrypto, coin.getSymbol(), coin.getPriceUSD() * amountOfCrypto, amountOfDiamonds, p2.name));

double amountOfNewCoin = amountOfCrypto - (amountOfCrypto * CryptoMarket.config.getFee());
int amountOfNewDiamonds = CoinHelper.calculateAmountOfDiamondsFromCoins(coin.getPriceUSD(), amountOfNewCoin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
public final class Permissions {
public static String CRYPTOMARKET_PLAYER = "cryptomarket.player";
public static String CRYPTOMARKET_ADMIN = "cryptomarket.admin";
public static String CRYPTOMARKET_BALANCE_OTHERS = "cryptomarket.balance.others";
public static String CRYPTOMARKET_HISTORY_OTHERS = "cryptomarket.history.others";
public static String CRYPTOMARKET_STATS_OTHERS = "cryptomarket.stats.others";
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public boolean execute(CommandSender commandSender, String[] strings) {
return true;
}

boolean isAdmin = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN);
if (strings.length == 2 && !isAdmin) {
boolean extendedPermission = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN) || commandSender.hasPermission(Permissions.CRYPTOMARKET_BALANCE_OTHERS);
if (strings.length == 2 && !extendedPermission) {
commandSender.sendMessage(CryptoMarket.resourceManager.getResource("MissingPermission"));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public boolean execute(CommandSender commandSender, String[] strings) {
return true;
}

boolean isAdmin = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN);
OfflinePlayer o = null;
if (strings.length > 1) {
o = Arrays.stream(Bukkit.getOfflinePlayers()).filter(f -> f.getName().equalsIgnoreCase(strings[1])).findFirst().orElse(null);
Expand All @@ -48,7 +47,8 @@ public boolean execute(CommandSender commandSender, String[] strings) {
return true;
}

if (strings.length > 1 && !isAdmin && o != null) {
boolean extendedPersmission = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN) || commandSender.hasPermission(Permissions.CRYPTOMARKET_HISTORY_OTHERS);
if (strings.length > 1 && !extendedPersmission && o != null) {
commandSender.sendMessage(CryptoMarket.resourceManager.getResource("MissingPermission"));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public boolean execute(CommandSender commandSender, String[] strings) {
return true;
}

boolean isAdmin = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN);
if (strings.length == 2 && !isAdmin) {
boolean extendedPersmission = commandSender.hasPermission(Permissions.CRYPTOMARKET_ADMIN) || commandSender.hasPermission(Permissions.CRYPTOMARKET_STATS_OTHERS);
if (strings.length == 2 && !extendedPersmission) {
commandSender.sendMessage(CryptoMarket.resourceManager.getResource("MissingPermission"));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package main.java.pl.csrv.divinecraft.evirth.cryptomarket.resources;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import main.java.pl.csrv.divinecraft.evirth.cryptomarket.CryptoMarket;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ResourceManager {
private Plugin plugin;
private File resourceFile;
Expand All @@ -35,8 +33,22 @@ public ResourceManager(Plugin plugin) {
try {
for (String s : lang) {
String file = String.format("messages_%s.yml", s);
if (!new File(Paths.get(this.resourcePath, file).toString()).exists())
File f = new File(Paths.get(this.resourcePath, file).toString());
if (!f.exists()) {
this.exportResource(file);
} else {
BufferedReader br = new BufferedReader(new InputStreamReader(ResourceManager.class.getResourceAsStream(file)));
long resourceFileLines = br.lines().count();
long currentFileLines = Files.lines(Paths.get(f.getPath())).count();

if (currentFileLines != resourceFileLines) {
File fbak = new File(Paths.get(this.resourcePath, file + ".old").toString());
if (f.renameTo(fbak)) {
this.exportResource(file);
this.plugin.getLogger().info(String.format("Resource file '%s' has been updated.", file));
}
}
}
}
} catch (Exception e) {
this.plugin.getLogger().warning("Cannot generate default resource messages.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PlayerDoesntHaveCoin: "&5%s&f doesn't have any &6%s&f coin."
PlayerDoesntHaveThatManyCoins: "&5%s&f doesn't have that many &6%s&f coins."
PlayerNotFound: "Could not find the Player '&5%s&f'."
Stats: "You've deposited &c%d&f and withdrawn &a%d&f &bDiamond(s)&f.\nFinal balance: "
TransferSuccess: "You have successfully transferred &6%.8f %s&f (&6$%.2f&f - &b%d Diamods(s)&f) to player &5%s&f!"
Usage: "Usage"
WithdrawAll: "You have withdrawn &b%d Diamond(s)&f."

Expand Down
15 changes: 14 additions & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ permission:
description: Gives access to player's CryptoMarket commands

cryptomarket.admin:
description: Gives access to admin's CryptoMarket commands
description: Gives access to admin's CryptoMarket commands
children:
cryptomarket.balance.others: true
cryptomarket.history.others: true
cryptomarket.stats.others: true

cryptomarket.balance.others:
description: Gives access to '/cm balance <player>' command

cryptomarket.history.others:
description: Gives access to '/cm history <player>' command

cryptomarket.stats.others:
description: Gives access to '/cm stats <player>' command

0 comments on commit e4770e7

Please sign in to comment.