mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 11:44:42 +02:00
Refactor + optimizations
This commit is contained in:
@ -12,7 +12,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
|
||||
public class ConsolePlayer implements PlotPlayer {
|
||||
public class ConsolePlayer extends PlotPlayer {
|
||||
|
||||
private static ConsolePlayer instance;
|
||||
private Location loc;
|
||||
@ -82,11 +82,6 @@ public class ConsolePlayer implements PlotPlayer {
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
|
@ -29,6 +29,7 @@ import java.util.UUID;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
@ -473,6 +474,14 @@ public class Plot {
|
||||
MainUtil.setBiome(this, biome, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the biome (String)
|
||||
*/
|
||||
public String getBiome() {
|
||||
final Location loc = getBottom().add(1, 0, 1);
|
||||
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the top location for the plot
|
||||
* @return
|
||||
|
@ -1,9 +1,15 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.general.commands.CommandCaller;
|
||||
|
||||
/**
|
||||
@ -11,33 +17,214 @@ import com.plotsquared.general.commands.CommandCaller;
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public interface PlotPlayer extends CommandCaller {
|
||||
public abstract class PlotPlayer implements CommandCaller {
|
||||
|
||||
long getPreviousLogin();
|
||||
|
||||
Location getLocation();
|
||||
|
||||
Location getLocationFull();
|
||||
|
||||
UUID getUUID();
|
||||
|
||||
boolean hasPermission(final String perm);
|
||||
|
||||
void sendMessage(final String message);
|
||||
/**
|
||||
* The metadata map
|
||||
*/
|
||||
private ConcurrentHashMap<String, Object> meta;
|
||||
|
||||
void teleport(final Location loc);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
boolean isOp();
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
boolean isOnline();
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
String getName();
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
void setCompassTarget(Location loc);
|
||||
/**
|
||||
* Returns the player's name
|
||||
* @see #getName()
|
||||
*/
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
void loadData();
|
||||
/**
|
||||
* Get the player's current plot<br>
|
||||
* - This is cached
|
||||
* @return
|
||||
*/
|
||||
public Plot getCurrentPlot() {
|
||||
return (Plot) getMeta("lastplot");
|
||||
}
|
||||
|
||||
void saveData();
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/////////////// 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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Is the player online
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean isOnline();
|
||||
|
||||
/**
|
||||
* Get the player's name
|
||||
* @return
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Set the compass target
|
||||
* @param loc
|
||||
*/
|
||||
public abstract void setCompassTarget(Location loc);
|
||||
|
||||
/**
|
||||
* Load the player data from disk (if applicable)
|
||||
*/
|
||||
public abstract void loadData();
|
||||
|
||||
/**
|
||||
* Save the player data from disk (if applicable)
|
||||
*/
|
||||
public abstract void saveData();
|
||||
|
||||
/**
|
||||
* Set player data that will persist restarts
|
||||
@ -45,35 +232,60 @@ public interface PlotPlayer extends CommandCaller {
|
||||
* - For session only data use meta
|
||||
* @param key
|
||||
*/
|
||||
void setAttribute(String key);
|
||||
public abstract void setAttribute(String key);
|
||||
|
||||
/**
|
||||
* The attribute will be either true or false
|
||||
* @param key
|
||||
*/
|
||||
boolean getAttribute(String key);
|
||||
public abstract boolean getAttribute(String key);
|
||||
|
||||
/**
|
||||
* Remove an attribute from a player
|
||||
* @param key
|
||||
*/
|
||||
void removeAttribute(String key);
|
||||
public abstract void removeAttribute(String key);
|
||||
|
||||
void setMeta(String key, Object value);
|
||||
Object getMeta(String key);
|
||||
void deleteMeta(String key);
|
||||
/**
|
||||
* Set the player's local weather
|
||||
* @param weather
|
||||
*/
|
||||
public abstract void setWeather(PlotWeather weather);
|
||||
|
||||
void setWeather(PlotWeather weather);
|
||||
/**
|
||||
* Get the player's gamemode
|
||||
* @return
|
||||
*/
|
||||
public abstract PlotGamemode getGamemode();
|
||||
|
||||
PlotGamemode getGamemode();
|
||||
/**
|
||||
* Set the player's gamemode
|
||||
* @param gamemode
|
||||
*/
|
||||
public abstract void setGamemode(PlotGamemode gamemode);
|
||||
|
||||
void setGamemode(PlotGamemode gamemode);
|
||||
/**
|
||||
* Set the player's local time
|
||||
* @param time
|
||||
*/
|
||||
public abstract void setTime(long time);
|
||||
|
||||
void setTime(long time);
|
||||
/**
|
||||
* Set the player's fly mode
|
||||
* @param fly
|
||||
*/
|
||||
public abstract void setFlight(boolean fly);
|
||||
|
||||
void setFlight(boolean fly);
|
||||
/**
|
||||
* Play music at a location for the player
|
||||
* @param loc
|
||||
* @param id
|
||||
*/
|
||||
public abstract void playMusic(Location loc, int id);
|
||||
|
||||
void playMusic(Location loc, int id);
|
||||
|
||||
void kick(String message);
|
||||
/**
|
||||
* Kick the player from the game
|
||||
* @param message
|
||||
*/
|
||||
public abstract void kick(String message);
|
||||
}
|
||||
|
@ -28,8 +28,6 @@ import java.util.UUID;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* plot settings
|
||||
@ -111,14 +109,6 @@ public class PlotSettings {
|
||||
this.merged[direction] = merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return biome at plot loc
|
||||
*/
|
||||
public String getBiome() {
|
||||
final Location loc = MainUtil.getPlotBottomLoc(this.plot.world, this.plot.getId()).add(1, 0, 1);
|
||||
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
|
||||
}
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
if (this.position == null) {
|
||||
return new BlockLoc(0, 0, 0);
|
||||
|
Reference in New Issue
Block a user