Change MoneyMixinVault to use OfflinePlayer instead of name
This commit is contained in:
parent
bef59da1d8
commit
265ee919a6
@ -97,7 +97,7 @@ public class Money
|
||||
public static boolean exists(Object account)
|
||||
{
|
||||
if (disabled()) return false;
|
||||
return mixin.exists(accountId(account));
|
||||
return mixin.exists(accountId(account).toString());
|
||||
}
|
||||
|
||||
public static boolean create(Object account)
|
||||
|
@ -1,13 +1,14 @@
|
||||
package com.massivecraft.massivecore.money;
|
||||
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -114,7 +115,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
@Override
|
||||
public boolean exists(String accountId)
|
||||
{
|
||||
return this.getEconomy().hasAccount(accountId);
|
||||
return this.getEconomy().hasAccount(IdUtil.getOfflinePlayer(accountId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,14 +132,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
public double get(String accountId)
|
||||
{
|
||||
this.ensureExists(accountId);
|
||||
return this.getEconomy().getBalance(accountId);
|
||||
return this.getEconomy().getBalance(IdUtil.getOfflinePlayer(accountId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String accountId, double amount)
|
||||
{
|
||||
this.ensureExists(accountId);
|
||||
return this.getEconomy().has(accountId, amount);
|
||||
return this.getEconomy().has(IdUtil.getOfflinePlayer(accountId), amount);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -150,6 +151,9 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
{
|
||||
Economy economy = this.getEconomy();
|
||||
|
||||
OfflinePlayer offlinePlayerFrom = IdUtil.getOfflinePlayer(fromId);
|
||||
OfflinePlayer offlinePlayerTo = IdUtil.getOfflinePlayer(toId);
|
||||
|
||||
// Ensure positive direction
|
||||
if (amount < 0)
|
||||
{
|
||||
@ -166,7 +170,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
// Subtract From
|
||||
if (fromId != null)
|
||||
{
|
||||
if (!economy.withdrawPlayer(fromId, amount).transactionSuccess())
|
||||
if (!economy.withdrawPlayer(offlinePlayerFrom, amount).transactionSuccess())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -175,12 +179,12 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
// Add To
|
||||
if (toId != null)
|
||||
{
|
||||
if (!economy.depositPlayer(toId, amount).transactionSuccess())
|
||||
if (!economy.depositPlayer(offlinePlayerTo, amount).transactionSuccess())
|
||||
{
|
||||
if (fromId != null)
|
||||
{
|
||||
// Undo the withdraw
|
||||
economy.depositPlayer(fromId, amount);
|
||||
economy.depositPlayer(offlinePlayerFrom, amount);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -197,14 +201,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract
|
||||
{
|
||||
Economy economy = this.getEconomy();
|
||||
|
||||
if (economy.hasAccount(accountId)) return true;
|
||||
if (economy.hasAccount(IdUtil.getOfflinePlayer(accountId))) return true;
|
||||
|
||||
if (!economy.createPlayerAccount(accountId)) return false;
|
||||
if (!economy.createPlayerAccount(IdUtil.getOfflinePlayer(accountId))) return false;
|
||||
|
||||
if (MUtil.isValidPlayerName(accountId)) return true;
|
||||
if (MUtil.isUuid(accountId)) return true;
|
||||
|
||||
double balance = economy.getBalance(accountId);
|
||||
economy.withdrawPlayer(accountId, balance);
|
||||
double balance = economy.getBalance(IdUtil.getOfflinePlayer(accountId));
|
||||
economy.withdrawPlayer(IdUtil.getOfflinePlayer(accountId), balance);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.massivecraft.massivecore.mixin.MixinPlayed;
|
||||
import com.massivecraft.massivecore.store.SenderEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -753,6 +754,21 @@ public class IdUtil implements Listener, Runnable
|
||||
return null;
|
||||
}
|
||||
|
||||
public static OfflinePlayer getOfflinePlayer(Object senderObject)
|
||||
{
|
||||
// Null Return
|
||||
if (senderObject == null) return null;
|
||||
|
||||
// Already done
|
||||
if (senderObject instanceof OfflinePlayer) return (OfflinePlayer) senderObject;
|
||||
|
||||
//
|
||||
UUID uuid = getUuid(senderObject);
|
||||
if (uuid == null) return null;
|
||||
|
||||
return Bukkit.getOfflinePlayer(uuid);
|
||||
}
|
||||
|
||||
public static String getNameFromSender(CommandSender sender)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender) return CONSOLE_ID;
|
||||
|
@ -21,7 +21,6 @@ import com.massivecraft.massivecore.util.extractor.ExtractorPlayer;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorSender;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorSenderId;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorSenderName;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorWorld;
|
||||
import com.massivecraft.massivecore.util.extractor.ExtractorWorldName;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -1974,7 +1973,7 @@ public class MUtil
|
||||
|
||||
// The accountId extractor is used for the money mixin.
|
||||
// For now we act on the name instead of the ID since vault needs names.
|
||||
registerExtractor(String.class, "accountId", ExtractorSenderName.get());
|
||||
registerExtractor(UUID.class, "accountId", ExtractorSenderId.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEvent;
|
||||
import org.bukkit.event.vehicle.VehicleExitEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExtractorLogic
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user