mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-26 23:45:23 +00:00
Heavy cleanup of all classes
ItemDb is not static anymore Essentials.getStatic() removed
This commit is contained in:
parent
25c9557c59
commit
a38fe6acd4
48 changed files with 330 additions and 294 deletions
|
@ -1,7 +1,7 @@
|
|||
package com.earth2me.essentials.api;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.EssentialsConf;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.io.File;
|
||||
|
@ -9,6 +9,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
* Instead of using this api directly, we recommend to use the register plugin:
|
||||
* http://bit.ly/RegisterMethod
|
||||
|
@ -19,10 +20,19 @@ public final class Economy
|
|||
{
|
||||
}
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private static IEssentials ess;
|
||||
|
||||
/**
|
||||
* @param aEss the ess to set
|
||||
*/
|
||||
public static void setEss(IEssentials aEss)
|
||||
{
|
||||
ess = aEss;
|
||||
}
|
||||
|
||||
private static void createNPCFile(String name)
|
||||
{
|
||||
File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
|
||||
File folder = new File(ess.getDataFolder(), "userdata");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdirs();
|
||||
|
@ -30,13 +40,13 @@ public final class Economy
|
|||
EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml"));
|
||||
npcConfig.load();
|
||||
npcConfig.setProperty("npc", true);
|
||||
npcConfig.setProperty("money", Essentials.getStatic().getSettings().getStartingBalance());
|
||||
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
||||
npcConfig.save();
|
||||
}
|
||||
|
||||
|
||||
private static void deleteNPC(String name)
|
||||
{
|
||||
File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
|
||||
File folder = new File(ess.getDataFolder(), "userdata");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdirs();
|
||||
|
@ -44,24 +54,26 @@ public final class Economy
|
|||
File config = new File(folder, Util.sanitizeFileName(name) + ".yml");
|
||||
EssentialsConf npcConfig = new EssentialsConf(config);
|
||||
npcConfig.load();
|
||||
if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false)) {
|
||||
if (!config.delete()) {
|
||||
if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false))
|
||||
{
|
||||
if (!config.delete())
|
||||
{
|
||||
logger.log(Level.WARNING, Util.format("deleteFileError", config));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static User getUserByName(String name)
|
||||
{
|
||||
User user;
|
||||
Player player = Essentials.getStatic().getServer().getPlayer(name);
|
||||
Player player = ess.getServer().getPlayer(name);
|
||||
if (player != null)
|
||||
{
|
||||
user = Essentials.getStatic().getUser(player);
|
||||
user = ess.getUser(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
user = Essentials.getStatic().getOfflineUser(name);
|
||||
user = ess.getOfflineUser(name);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
@ -75,7 +87,8 @@ public final class Economy
|
|||
public static double getMoney(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
return user.getMoney();
|
||||
|
@ -91,7 +104,8 @@ public final class Economy
|
|||
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan"))
|
||||
|
@ -113,7 +127,7 @@ public final class Economy
|
|||
double result = getMoney(name) + amount;
|
||||
setMoney(name, result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Substracts money from the balance of a user
|
||||
* @param name Name of the user
|
||||
|
@ -161,7 +175,7 @@ public final class Economy
|
|||
*/
|
||||
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException
|
||||
{
|
||||
setMoney(name, Essentials.getStatic().getSettings().getStartingBalance());
|
||||
setMoney(name, ess.getSettings().getStartingBalance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,18 +230,19 @@ public final class Economy
|
|||
*/
|
||||
public static String format(double amount)
|
||||
{
|
||||
return Util.formatCurrency(amount);
|
||||
return Util.formatCurrency(amount, ess);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a player exists to avoid the UserDoesNotExistException
|
||||
* @param name Name of the user
|
||||
* @return true, if the user exists
|
||||
*/
|
||||
public static boolean playerExists(String name) {
|
||||
public static boolean playerExists(String name)
|
||||
{
|
||||
return getUserByName(name) != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if a player is a npc
|
||||
* @param name Name of the player
|
||||
|
@ -237,12 +252,13 @@ public final class Economy
|
|||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
return user.isNPC();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates dummy files for a npc, if there is no player yet with that name.
|
||||
* @param name Name of the player
|
||||
|
@ -251,7 +267,8 @@ public final class Economy
|
|||
public static boolean createNPC(String name)
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
createNPCFile(name);
|
||||
return true;
|
||||
}
|
||||
|
@ -266,7 +283,8 @@ public final class Economy
|
|||
public static void removeNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
if (user == null) {
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
}
|
||||
deleteNPC(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue