mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Added persistent player attributes API
This commit is contained in:
		@@ -7,6 +7,7 @@ import java.util.List;
 | 
				
			|||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
 | 
					import com.intellectualcrafters.plot.object.BukkitPlayer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.milkbowl.vault.economy.Economy;
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.Bukkit;
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
@@ -109,12 +110,14 @@ import com.intellectualcrafters.plot.util.BlockManager;
 | 
				
			|||||||
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
 | 
					import com.intellectualcrafters.plot.util.BlockUpdateUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ChunkManager;
 | 
					import com.intellectualcrafters.plot.util.ChunkManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ConsoleColors;
 | 
					import com.intellectualcrafters.plot.util.ConsoleColors;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.util.EconHandler;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.EventUtil;
 | 
					import com.intellectualcrafters.plot.util.EventUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.MainUtil;
 | 
					import com.intellectualcrafters.plot.util.MainUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.PlayerManager;
 | 
					import com.intellectualcrafters.plot.util.PlayerManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.SetupUtils;
 | 
					import com.intellectualcrafters.plot.util.SetupUtils;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.TaskManager;
 | 
					import com.intellectualcrafters.plot.util.TaskManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil;
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitEventUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager;
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
 | 
					import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
 | 
				
			||||||
@@ -411,13 +414,10 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Economy getEconomy() {
 | 
					    public EconHandler getEconomyHandler() {
 | 
				
			||||||
        if ((getServer().getPluginManager().getPlugin("Vault") != null) && getServer().getPluginManager().getPlugin("Vault").isEnabled()) {
 | 
					        BukkitEconHandler econ = new BukkitEconHandler();
 | 
				
			||||||
            final RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
 | 
					        if (econ.init()) {
 | 
				
			||||||
            if (economyProvider != null) {
 | 
					            return econ;
 | 
				
			||||||
                MainCommand.subCommands.add(new Buy());
 | 
					 | 
				
			||||||
                return economyProvider.getProvider();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import java.io.File;
 | 
				
			|||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellectualcrafters.plot.config.C;
 | 
					import com.intellectualcrafters.plot.config.C;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.milkbowl.vault.economy.Economy;
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.bukkit.generator.ChunkGenerator;
 | 
					import org.bukkit.generator.ChunkGenerator;
 | 
				
			||||||
@@ -13,6 +14,7 @@ import com.intellectualcrafters.plot.listeners.APlotListener;
 | 
				
			|||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
 | 
					import com.intellectualcrafters.plot.object.PlotPlayer;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.BlockManager;
 | 
					import com.intellectualcrafters.plot.util.BlockManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ChunkManager;
 | 
					import com.intellectualcrafters.plot.util.ChunkManager;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.util.EconHandler;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.EventUtil;
 | 
					import com.intellectualcrafters.plot.util.EventUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.PlayerManager;
 | 
					import com.intellectualcrafters.plot.util.PlayerManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.SetupUtils;
 | 
					import com.intellectualcrafters.plot.util.SetupUtils;
 | 
				
			||||||
@@ -48,7 +50,7 @@ public interface IPlotMain {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    public void registerTNTListener();
 | 
					    public void registerTNTListener();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Economy getEconomy();
 | 
					    public EconHandler getEconomyHandler();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public BlockManager initBlockManager();
 | 
					    public BlockManager initBlockManager();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,7 @@ import com.intellectualcrafters.plot.object.comment.CommentManager;
 | 
				
			|||||||
import com.intellectualcrafters.plot.util.BlockManager;
 | 
					import com.intellectualcrafters.plot.util.BlockManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ChunkManager;
 | 
					import com.intellectualcrafters.plot.util.ChunkManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ClusterManager;
 | 
					import com.intellectualcrafters.plot.util.ClusterManager;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.util.EconHandler;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.EventUtil;
 | 
					import com.intellectualcrafters.plot.util.EventUtil;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.ExpireManager;
 | 
					import com.intellectualcrafters.plot.util.ExpireManager;
 | 
				
			||||||
import com.intellectualcrafters.plot.util.Logger;
 | 
					import com.intellectualcrafters.plot.util.Logger;
 | 
				
			||||||
@@ -89,7 +90,6 @@ public class PlotSquared {
 | 
				
			|||||||
    public static String VERSION = null;
 | 
					    public static String VERSION = null;
 | 
				
			||||||
    public static TaskManager TASK = null;
 | 
					    public static TaskManager TASK = null;
 | 
				
			||||||
    private static boolean LOADING_WORLD = false;
 | 
					    private static boolean LOADING_WORLD = false;
 | 
				
			||||||
    public static Economy economy = null;
 | 
					 | 
				
			||||||
    public static WorldEditPlugin worldEdit = null;
 | 
					    public static WorldEditPlugin worldEdit = null;
 | 
				
			||||||
    private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>();
 | 
					    private final static HashMap<String, PlotWorld> plotworlds = new HashMap<>();
 | 
				
			||||||
    private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>();
 | 
					    private final static HashMap<String, PlotManager> plotmanagers = new HashMap<>();
 | 
				
			||||||
@@ -510,7 +510,7 @@ public class PlotSquared {
 | 
				
			|||||||
            log("Could not determine file path");
 | 
					            log("Could not determine file path");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        VERSION = IMP.getVersion();
 | 
					        VERSION = IMP.getVersion();
 | 
				
			||||||
        economy = IMP.getEconomy();
 | 
					        EconHandler.manager = IMP.getEconomyHandler();
 | 
				
			||||||
        C.setupTranslations();
 | 
					        C.setupTranslations();
 | 
				
			||||||
        C.saveTranslations();
 | 
					        C.saveTranslations();
 | 
				
			||||||
        if (getJavaVersion() < 1.7) {
 | 
					        if (getJavaVersion() < 1.7) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,27 @@ public interface PlotPlayer {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    public void setCompassTarget(Location loc);
 | 
					    public void setCompassTarget(Location loc);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Set player data that will persist restarts
 | 
				
			||||||
 | 
					     *  - Please note that this is not intended to store large values
 | 
				
			||||||
 | 
					     *  - For session only data use meta
 | 
				
			||||||
 | 
					     * @param key
 | 
				
			||||||
 | 
					     * @param value
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public void setAttribute(String key);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * The attribute will be either true or false
 | 
				
			||||||
 | 
					     * @param key
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public boolean getAttribute(String key);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Remove an attribute from a player
 | 
				
			||||||
 | 
					     * @param key
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public void removeAttribute(String key);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    public void setMeta(String key, Object value);
 | 
					    public void setMeta(String key, Object value);
 | 
				
			||||||
    public Object getMeta(String key);
 | 
					    public Object getMeta(String key);
 | 
				
			||||||
    public void deleteMeta(String key);
 | 
					    public void deleteMeta(String key);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,24 +1,15 @@
 | 
				
			|||||||
package com.intellectualcrafters.plot.util;
 | 
					package com.intellectualcrafters.plot.util;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.intellectualcrafters.plot.PlotSquared;
 | 
					 | 
				
			||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
 | 
					import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
 | 
				
			||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
 | 
					import com.intellectualcrafters.plot.object.PlotPlayer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class EconHandler {
 | 
					public abstract class EconHandler {
 | 
				
			||||||
    // TODO economy shit
 | 
					    public static EconHandler manager;
 | 
				
			||||||
    public static double getBalance(final PlotPlayer player) {
 | 
					 | 
				
			||||||
        return PlotSquared.economy.getBalance(player.getName());
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public static void withdrawPlayer(final PlotPlayer player, final double amount) {
 | 
					    public abstract double getMoney(PlotPlayer player);
 | 
				
			||||||
        PlotSquared.economy.withdrawPlayer(player.getName(), amount);
 | 
					    public abstract double withdrawMoney(PlotPlayer player, double amount);
 | 
				
			||||||
    }
 | 
					    public abstract double depositMoney(PlotPlayer player, double amount);
 | 
				
			||||||
 | 
					    public abstract double depositMoney(OfflinePlotPlayer player, double amount);
 | 
				
			||||||
    public static void depositPlayer(final PlotPlayer player, final double amount) {
 | 
					    public abstract void setPermission(PlotPlayer player, String perm, boolean value);
 | 
				
			||||||
        PlotSquared.economy.depositPlayer(player.getName(), amount);
 | 
					    public abstract boolean getPermission(PlotPlayer player, String perm);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static void depositPlayer(final OfflinePlotPlayer player, final double amount) {
 | 
					 | 
				
			||||||
        PlotSquared.economy.depositPlayer(player.getName(), amount);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					package com.intellectualcrafters.plot.util.bukkit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					import org.bukkit.plugin.RegisteredServiceProvider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import net.milkbowl.vault.economy.Economy;
 | 
				
			||||||
 | 
					import net.milkbowl.vault.permission.Permission;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.object.BukkitOfflinePlayer;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.object.BukkitPlayer;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.object.PlotPlayer;
 | 
				
			||||||
 | 
					import com.intellectualcrafters.plot.util.EconHandler;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class BukkitEconHandler extends EconHandler {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private Economy econ;
 | 
				
			||||||
 | 
					    private Permission perms;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public boolean init() {
 | 
				
			||||||
 | 
					        if (econ == null || perms == null) {
 | 
				
			||||||
 | 
					            setupPermissions();
 | 
				
			||||||
 | 
					            setupEconomy();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return econ != null && perms != null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    private boolean setupPermissions()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
 | 
				
			||||||
 | 
					        if (permissionProvider != null) {
 | 
				
			||||||
 | 
					            perms = permissionProvider.getProvider();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return (perms != null);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean setupEconomy()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
 | 
				
			||||||
 | 
					        if (economyProvider != null) {
 | 
				
			||||||
 | 
					            econ = economyProvider.getProvider();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return (econ != null);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public double getMoney(PlotPlayer player) {
 | 
				
			||||||
 | 
					        econ.getBalance(player.getName());
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public double withdrawMoney(PlotPlayer player, double amount) {
 | 
				
			||||||
 | 
					        econ.withdrawPlayer(player.getName(), amount);
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public double depositMoney(PlotPlayer player, double amount) {
 | 
				
			||||||
 | 
					        econ.depositPlayer(player.getName(), amount);
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public double depositMoney(OfflinePlotPlayer player, double amount) {
 | 
				
			||||||
 | 
					        econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void setPermission(PlotPlayer player, String perm, boolean value) {
 | 
				
			||||||
 | 
					        if (value) {
 | 
				
			||||||
 | 
					            perms.playerAdd(((BukkitPlayer) player).player, perm);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            perms.playerRemove(((BukkitPlayer) player).player, perm);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean getPermission(PlotPlayer player, String perm) {
 | 
				
			||||||
 | 
					        return player.hasPermission(perm);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user