PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java

292 lines
6.6 KiB
Java
Raw Normal View History

2015-02-20 11:53:18 +01:00
package com.intellectualcrafters.plot.object;
2015-07-30 19:24:01 +02:00
import java.util.Set;
2015-07-27 19:50:04 +02:00
import java.util.UUID;
2015-07-30 19:24:01 +02:00
import java.util.concurrent.ConcurrentHashMap;
2015-07-27 17:14:38 +02:00
2015-07-30 19:24:01 +02:00
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.commands.RequiredType;
import com.intellectualcrafters.plot.util.MainUtil;
2015-07-30 16:25:16 +02:00
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
2015-07-30 19:24:01 +02:00
import com.intellectualcrafters.plot.util.UUIDHandler;
2015-07-30 16:25:16 +02:00
import com.plotsquared.general.commands.CommandCaller;
2015-02-20 11:53:18 +01:00
/**
* Created 2015-02-20 for PlotSquared
*
* @author Citymonstret
*/
2015-07-30 19:24:01 +02:00
public abstract class PlotPlayer implements CommandCaller {
2015-04-06 14:16:24 +02:00
2015-07-30 19:24:01 +02:00
/**
* The metadata map
*/
private ConcurrentHashMap<String, Object> meta;
/**
* Wrap a Player object to get a PlotPlayer<br>
* - This will usually be cached, so no new object creation
* @param obj
* @return
*/
public static PlotPlayer wrap(Object obj) {
return PS.get().IMP.wrapPlayer(obj);
}
2015-04-06 14:16:24 +02:00
2015-07-30 19:24:01 +02:00
/**
* Get the cached PlotPlayer from a username<br>
* - This will return null if the player has just logged in or is not online
* @param name
* @return
*/
public static PlotPlayer get(String name) {
return UUIDHandler.getPlayer(name);
}
2015-02-23 02:32:27 +01:00
2015-07-30 19:24:01 +02:00
/**
* Set some session only metadata for the player
* @param key
* @param value
*/
public void setMeta(String key, Object value) {
if (this.meta == null) {
this.meta = new ConcurrentHashMap<String, Object>();
}
this.meta.put(key, value);
}
/**
* Get the metadata for a key
* @param key
* @return
*/
public Object getMeta(String key) {
if (this.meta != null) {
return this.meta.get(key);
}
return null;
}
/**
* Delete the metadata for a key<br>
* - metadata is session only
* - deleting other plugin's metadata may cause issues
* @param key
*/
public void deleteMeta(String key) {
if (this.meta != null) {
this.meta.remove(key);
}
}
2015-02-23 12:37:36 +01:00
2015-07-30 19:24:01 +02:00
/**
* Returns the player's name
* @see #getName()
*/
public String toString() {
return getName();
}
2015-02-23 02:32:27 +01:00
2015-07-30 19:24:01 +02:00
/**
* Get the player's current plot<br>
* - This is cached
* @return
*/
public Plot getCurrentPlot() {
return (Plot) getMeta("lastplot");
}
2015-02-20 12:23:48 +01:00
2015-07-30 19:24:01 +02:00
/**
* Get the total number of allowed plots
* @return
*/
public int getAllowedPlots() {
return MainUtil.getAllowedPlots(this);
}
/**
* Get the number of plots the player owns
* @return
*/
public int getPlotCount() {
return MainUtil.getPlayerPlotCount(this);
}
/**
* Get the number of plots the player owns in the world
* @param world
* @return
*/
public int getPlotCount(String world) {
return MainUtil.getPlayerPlotCount(world, this);
}
/**
* Get the plots the player owns
* @see #PS.java for more searching functions
* @return Set of plots
*/
public Set<Plot> getPlots() {
return PS.get().getPlots(this);
}
/**
* Return the PlotWorld the player is currently in, or null
* @return
*/
public PlotWorld getPlotWorld() {
return PS.get().getPlotWorld(getLocation().getWorld());
}
@Override
public RequiredType getSuperCaller() {
return RequiredType.PLAYER;
}
2015-02-23 02:32:27 +01:00
2015-07-30 19:24:01 +02:00
/////////////// PLAYER META ///////////////
////////////// PARTIALLY IMPLEMENTED ///////////
/**
* Get the player's last recorded location
* @return
*/
public Location getLocation() {
Location loc = (Location) getMeta("location");
if (loc != null) {
return loc;
}
return null;
}
////////////////////////////////////////////////
2015-07-20 07:14:46 +02:00
2015-07-30 19:24:01 +02:00
/**
* Get the previous time the player logged in
* @return
*/
public abstract long getPreviousLogin();
/**
* Get the player's full location (including yaw/pitch)
* @return
*/
public abstract Location getLocationFull();
/**
* Get the player's UUID
* @return
*/
public abstract UUID getUUID();
/**
* Check the player's permissions<br>
* - Will be cached if permission caching is enabled
*/
public abstract boolean hasPermission(final String perm);
/**
* Send the player a message
*/
public abstract void sendMessage(final String message);
/**
* Teleport the player to a location
* @param loc
*/
public abstract void teleport(final Location loc);
2015-02-23 02:32:27 +01:00
2015-07-30 19:24:01 +02:00
/**
* Is the player online
* @return
*/
public abstract boolean isOnline();
2015-02-22 13:46:47 +01:00
2015-07-30 19:24:01 +02:00
/**
* Get the player's name
* @return
*/
public abstract String getName();
2015-02-23 02:32:27 +01:00
2015-07-30 19:24:01 +02:00
/**
* Set the compass target
* @param loc
*/
public abstract void setCompassTarget(Location loc);
2015-05-04 11:52:37 +02:00
2015-07-30 19:24:01 +02:00
/**
* Load the player data from disk (if applicable)
*/
public abstract void loadData();
2015-07-30 19:24:01 +02:00
/**
* Save the player data from disk (if applicable)
*/
public abstract void saveData();
2015-06-05 14:39:31 +02:00
/**
* 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
*/
2015-07-30 19:24:01 +02:00
public abstract void setAttribute(String key);
2015-06-05 14:39:31 +02:00
/**
* The attribute will be either true or false
* @param key
*/
2015-07-30 19:24:01 +02:00
public abstract boolean getAttribute(String key);
2015-06-05 14:39:31 +02:00
/**
* Remove an attribute from a player
* @param key
*/
2015-07-30 19:24:01 +02:00
public abstract void removeAttribute(String key);
2015-06-05 14:39:31 +02:00
2015-07-30 19:24:01 +02:00
/**
* Set the player's local weather
* @param weather
*/
public abstract void setWeather(PlotWeather weather);
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Get the player's gamemode
* @return
*/
public abstract PlotGamemode getGamemode();
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Set the player's gamemode
* @param gamemode
*/
public abstract void setGamemode(PlotGamemode gamemode);
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Set the player's local time
* @param time
*/
public abstract void setTime(long time);
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Set the player's fly mode
* @param fly
*/
public abstract void setFlight(boolean fly);
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Play music at a location for the player
* @param loc
* @param id
*/
public abstract void playMusic(Location loc, int id);
2015-07-30 16:25:16 +02:00
2015-07-30 19:24:01 +02:00
/**
* Kick the player from the game
* @param message
*/
public abstract void kick(String message);
2015-02-20 11:53:18 +01:00
}