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)
 | 
						public static boolean exists(Object account)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (disabled()) return false;
 | 
							if (disabled()) return false;
 | 
				
			||||||
		return mixin.exists(accountId(account));
 | 
							return mixin.exists(accountId(account).toString());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static boolean create(Object account)
 | 
						public static boolean create(Object account)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,14 @@
 | 
				
			|||||||
package com.massivecraft.massivecore.money;
 | 
					package com.massivecraft.massivecore.money;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.util.IdUtil;
 | 
				
			||||||
import com.massivecraft.massivecore.util.MUtil;
 | 
					import com.massivecraft.massivecore.util.MUtil;
 | 
				
			||||||
import net.milkbowl.vault.economy.Economy;
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.plugin.RegisteredServiceProvider;
 | 
					import org.bukkit.plugin.RegisteredServiceProvider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Collection;
 | 
					import java.util.Collection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@SuppressWarnings("deprecation")
 | 
					 | 
				
			||||||
public class MoneyMixinVault extends MoneyMixinAbstract
 | 
					public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@ -114,7 +115,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public boolean exists(String accountId)
 | 
						public boolean exists(String accountId)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return this.getEconomy().hasAccount(accountId);
 | 
							return this.getEconomy().hasAccount(IdUtil.getOfflinePlayer(accountId));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
@ -131,14 +132,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
	public double get(String accountId)
 | 
						public double get(String accountId)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		this.ensureExists(accountId);
 | 
							this.ensureExists(accountId);
 | 
				
			||||||
		return this.getEconomy().getBalance(accountId);
 | 
							return this.getEconomy().getBalance(IdUtil.getOfflinePlayer(accountId));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public boolean has(String accountId, double amount)
 | 
						public boolean has(String accountId, double amount)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		this.ensureExists(accountId);
 | 
							this.ensureExists(accountId);
 | 
				
			||||||
		return this.getEconomy().has(accountId, amount);
 | 
							return this.getEconomy().has(IdUtil.getOfflinePlayer(accountId), amount);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@ -149,7 +150,10 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
	public boolean move(String fromId, String toId, String byId, double amount, Collection<String> categories, Object message)
 | 
						public boolean move(String fromId, String toId, String byId, double amount, Collection<String> categories, Object message)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		Economy economy = this.getEconomy();
 | 
							Economy economy = this.getEconomy();
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
 | 
							OfflinePlayer offlinePlayerFrom = IdUtil.getOfflinePlayer(fromId);
 | 
				
			||||||
 | 
							OfflinePlayer offlinePlayerTo = IdUtil.getOfflinePlayer(toId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Ensure positive direction
 | 
							// Ensure positive direction
 | 
				
			||||||
		if (amount < 0)
 | 
							if (amount < 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -166,7 +170,7 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
		// Subtract From
 | 
							// Subtract From
 | 
				
			||||||
		if (fromId != null)
 | 
							if (fromId != null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (!economy.withdrawPlayer(fromId, amount).transactionSuccess())
 | 
								if (!economy.withdrawPlayer(offlinePlayerFrom, amount).transactionSuccess())
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -175,12 +179,12 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
		// Add To
 | 
							// Add To
 | 
				
			||||||
		if (toId != null)
 | 
							if (toId != null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (!economy.depositPlayer(toId, amount).transactionSuccess())
 | 
								if (!economy.depositPlayer(offlinePlayerTo, amount).transactionSuccess())
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (fromId != null)
 | 
									if (fromId != null)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					// Undo the withdraw
 | 
										// Undo the withdraw
 | 
				
			||||||
					economy.depositPlayer(fromId, amount);
 | 
										economy.depositPlayer(offlinePlayerFrom, amount);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				return false;
 | 
									return false;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -197,14 +201,14 @@ public class MoneyMixinVault extends MoneyMixinAbstract
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		Economy economy = this.getEconomy();
 | 
							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);
 | 
							double balance = economy.getBalance(IdUtil.getOfflinePlayer(accountId));
 | 
				
			||||||
		economy.withdrawPlayer(accountId, balance);
 | 
							economy.withdrawPlayer(IdUtil.getOfflinePlayer(accountId), balance);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,7 @@ import com.massivecraft.massivecore.mixin.MixinPlayed;
 | 
				
			|||||||
import com.massivecraft.massivecore.store.SenderEntity;
 | 
					import com.massivecraft.massivecore.store.SenderEntity;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
import org.bukkit.GameMode;
 | 
					import org.bukkit.GameMode;
 | 
				
			||||||
 | 
					import org.bukkit.OfflinePlayer;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.command.ConsoleCommandSender;
 | 
					import org.bukkit.command.ConsoleCommandSender;
 | 
				
			||||||
import org.bukkit.entity.Entity;
 | 
					import org.bukkit.entity.Entity;
 | 
				
			||||||
@ -752,6 +753,21 @@ public class IdUtil implements Listener, Runnable
 | 
				
			|||||||
		// Return Null
 | 
							// Return Null
 | 
				
			||||||
		return null;
 | 
							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)
 | 
						public static String getNameFromSender(CommandSender sender)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,6 @@ import com.massivecraft.massivecore.util.extractor.ExtractorPlayer;
 | 
				
			|||||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
 | 
					import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
 | 
				
			||||||
import com.massivecraft.massivecore.util.extractor.ExtractorSender;
 | 
					import com.massivecraft.massivecore.util.extractor.ExtractorSender;
 | 
				
			||||||
import com.massivecraft.massivecore.util.extractor.ExtractorSenderId;
 | 
					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.ExtractorWorld;
 | 
				
			||||||
import com.massivecraft.massivecore.util.extractor.ExtractorWorldName;
 | 
					import com.massivecraft.massivecore.util.extractor.ExtractorWorldName;
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@ -1974,7 +1973,7 @@ public class MUtil
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// The accountId extractor is used for the money mixin.
 | 
							// The accountId extractor is used for the money mixin.
 | 
				
			||||||
		// For now we act on the name instead of the ID since vault needs names.
 | 
							// 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.VehicleEvent;
 | 
				
			||||||
import org.bukkit.event.vehicle.VehicleExitEvent;
 | 
					import org.bukkit.event.vehicle.VehicleExitEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ExtractorLogic
 | 
					public class ExtractorLogic
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user