Tweaks and doc updates.

This commit is contained in:
MattBDev 2016-05-24 22:08:45 -04:00
parent 83f664129f
commit 465f7f4504
7 changed files with 144 additions and 143 deletions

View File

@ -1271,9 +1271,6 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void MobSpawn(CreatureSpawnEvent event) { public void MobSpawn(CreatureSpawnEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) {
return;
}
Location location = BukkitUtil.getLocation(entity.getLocation()); Location location = BukkitUtil.getLocation(entity.getLocation());
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
if (area == null) { if (area == null) {
@ -2128,7 +2125,7 @@ public class PlayerEvents extends PlotListener implements Listener {
plot = null; plot = null;
stub = "road"; stub = "road";
} else { } else {
// Priorize plots for close to seamless pvp zones // Prioritize plots for close to seamless pvp zones
if (victim.getTicksLived() > damager.getTicksLived()) { if (victim.getTicksLived() > damager.getTicksLived()) {
if (dplot == null || !(victim instanceof Player)) { if (dplot == null || !(victim instanceof Player)) {
if (vplot == null) { if (vplot == null) {

View File

@ -8,7 +8,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.comment.PlotComment; import com.intellectualcrafters.plot.object.comment.PlotComment;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -251,8 +250,8 @@ public interface AbstractDB {
void removeDenied(Plot plot, UUID uuid); void removeDenied(Plot plot, UUID uuid);
/** /**
* @param plot Plot Object * @param plot the plot
* @param uuid Player uuid that should be added * @param uuid the uuid of the player to deny
*/ */
void setDenied(Plot plot, UUID uuid); void setDenied(Plot plot, UUID uuid);

View File

@ -2,7 +2,7 @@ package com.intellectualcrafters.plot.flag;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
public class Flag<V> { public abstract class Flag<V> {
private final String name; private final String name;
@ -11,28 +11,22 @@ public class Flag<V> {
* key/value pair. For a flag to be usable by a player, you need to * key/value pair. For a flag to be usable by a player, you need to
* register it with PlotSquared. * register it with PlotSquared.
* *
* @param name Flag name * @param name the flag name
*/ */
public Flag(String name) { public Flag(String name) {
this.name = name; this.name = name;
} }
public String valueToString(Object value) { public abstract String valueToString(Object value);
return null;
}
@Override @Override
public String toString() { public final String toString() {
return "Flag { name='" + getName() + "'}"; return "Flag { name='" + getName() + "'}";
} }
public V parseValue(String value) { public abstract V parseValue(String value);
return null;
}
public String getValueDescription() { public abstract String getValueDescription();
return "";
}
public final String getName() { public final String getName() {
return this.name; return this.name;

View File

@ -62,36 +62,38 @@ public class FlagManager {
} }
/** /**
* Reserve a flag so that it cannot be set by players * Reserve a flag so that it cannot be set by players.
* @param flag * @param flag the flag to reserve
* @return false if the flag was already reserved, otherwise true
*/ */
public static void reserveFlag(Flag<?> flag) { public static boolean reserveFlag(Flag<?> flag) {
reserved.add(flag); return reserved.add(flag);
} }
/** /**
* Get if a flag is reserved * Check if a flag is reserved.
* @param flag * @param flag the flag to check
* @return * @return true if the flag is reserved, false otherwise
*/ */
public static boolean isReserved(Flag<?> flag) { public static boolean isReserved(Flag<?> flag) {
return reserved.contains(flag); return reserved.contains(flag);
} }
/** /**
* Get the reserved flags * Get an immutable set of reserved flags.
* @return * @return a set of reserved flags
*/ */
public static Set<Flag<?>> getReservedFlags() { public static Set<Flag<?>> getReservedFlags() {
return Collections.unmodifiableSet(reserved); return Collections.unmodifiableSet(reserved);
} }
/** /**
* Unreserve a flag * Unreserve a flag.
* @param flag * @param flag the flag to unreserve
* @return true if the flag was unreserved
*/ */
public static void unreserveFlag(Flag<?> flag) { public static boolean unreserveFlag(Flag<?> flag) {
reserved.remove(flag); return reserved.remove(flag);
} }
public static String toString(HashMap<Flag<?>, Object> flags) { public static String toString(HashMap<Flag<?>, Object> flags) {
@ -162,12 +164,12 @@ public class FlagManager {
/** /**
* *
* @param plot * @param plot the plot
* @return set of flags * @return a map of flags and their values
*/ */
public static Map<Flag<?>, Object> getPlotFlags(Plot plot) { public static Map<Flag<?>, Object> getPlotFlags(Plot plot) {
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
return null; return Collections.emptyMap();
} }
return getSettingFlags(plot.getArea(), plot.getSettings()); return getSettingFlags(plot.getArea(), plot.getSettings());
} }
@ -195,6 +197,12 @@ public class FlagManager {
return getPlotFlags(area, settings, false); return getPlotFlags(area, settings, false);
} }
/**
* Removes a flag from a certain plot.
* @param plot the plot to remove the flag from
* @param id the flag to remove
* @return true if the plot contained the flag and was removed successfully
*/
public static boolean removePlotFlag(Plot plot, Flag<?> id) { public static boolean removePlotFlag(Plot plot, Flag<?> id) {
Object value = plot.getFlags().remove(id); Object value = plot.getFlags().remove(id);
if (value == null) { if (value == null) {
@ -273,11 +281,11 @@ public class FlagManager {
} }
/** /**
* Get an Flag by a String * Get a {@link Flag} specified by a {@code String}.
* *
* @param string the flag name * @param string the flag name
* *
* @return the flag or null if the flag the provided name does not exist * @return the {@code Flag} object defined by {@code string}
*/ */
public static Flag<?> getFlag(String string) { public static Flag<?> getFlag(String string) {
for (Flag flag : Flags.getFlags()) { for (Flag flag : Flags.getFlags()) {
@ -306,10 +314,10 @@ public class FlagManager {
} }
public static Map<Flag<?>, Object> parseFlags(List<String> flagstrings) { public static Map<Flag<?>, Object> parseFlags(List<String> flagStrings) {
HashMap<Flag<?>, Object> map = new HashMap<>(); HashMap<Flag<?>, Object> map = new HashMap<>();
for (String key : flagstrings) { for (String key : flagStrings) {
String[] split; String[] split;
if (key.contains(";")) { if (key.contains(";")) {
split = key.split(";"); split = key.split(";");

View File

@ -113,6 +113,8 @@ public class Flags {
return "Flag value must a timestamp or a boolean"; return "Flag value must a timestamp or a boolean";
} }
}; };
public static final BooleanFlag SLEEP = new BooleanFlag("sleep");
private static final HashSet<Flag<?>> flags = Sets.newHashSet(MUSIC, DESCRIPTION, ANALYSIS, GREETING, FAREWELL, FEED, HEAL, private static final HashSet<Flag<?>> flags = Sets.newHashSet(MUSIC, DESCRIPTION, ANALYSIS, GREETING, FAREWELL, FEED, HEAL,
GAMEMODE, GAMEMODE,
DONE, DONE,

View File

@ -22,6 +22,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.WorldUtil;
import com.plotsquared.listener.PlotListener; import com.plotsquared.listener.PlotListener;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.PathIterator; import java.awt.geom.PathIterator;
@ -126,9 +127,9 @@ public class Plot {
* *
* @see Plot#getPlot(Location) for existing plots * @see Plot#getPlot(Location) for existing plots
* *
* @param area * @param area the PlotArea where the plot is located
* @param id * @param id the plot id
* @param owner * @param owner the plot owner
*/ */
public Plot(PlotArea area, PlotId id, UUID owner) { public Plot(PlotArea area, PlotId id, UUID owner) {
this.area = area; this.area = area;
@ -142,8 +143,8 @@ public class Plot {
* *
* @see Plot#getPlot(Location) for existing plots * @see Plot#getPlot(Location) for existing plots
* *
* @param area * @param area the PlotArea where the plot is located
* @param id * @param id the plot id
*/ */
public Plot(PlotArea area, PlotId id) { public Plot(PlotArea area, PlotId id) {
this.area = area; this.area = area;
@ -157,9 +158,9 @@ public class Plot {
* *
* @see Plot#getPlot(Location) for existing plots * @see Plot#getPlot(Location) for existing plots
* *
* @param area * @param area the PlotArea where the plot is located
* @param id * @param id the plot id
* @param owner * @param owner the owner of the plot
* @param temp * @param temp
*/ */
public Plot(PlotArea area, PlotId id, UUID owner, int temp) { public Plot(PlotArea area, PlotId id, UUID owner, int temp) {
@ -174,8 +175,8 @@ public class Plot {
* *
* @see Plot#getPlot(Location) for existing plots * @see Plot#getPlot(Location) for existing plots
* *
* @param id * @param id the plot id
* @param owner * @param owner the plot owner
* @param trusted * @param trusted
* @param denied * @param denied
* @param merged * @param merged
@ -236,7 +237,7 @@ public class Plot {
* *
* @see PlotPlayer#getCurrentPlot() if a player is expected here. * @see PlotPlayer#getCurrentPlot() if a player is expected here.
* *
* @param location * @param location the location of the plot
* @return * @return
*/ */
public static Plot getPlot(Location location) { public static Plot getPlot(Location location) {
@ -314,7 +315,7 @@ public class Plot {
} }
/** /**
* Check if the plot has a set owner * Check if the plot has an owner.
* *
* @return false if there is no owner * @return false if there is no owner
*/ */
@ -324,8 +325,8 @@ public class Plot {
/** /**
* Check if a UUID is a plot owner (merged plots may have multiple owners) * Check if a UUID is a plot owner (merged plots may have multiple owners)
* @param uuid * @param uuid the player uuid
* @return * @return if the provided uuid is the owner of the plot
*/ */
public boolean isOwner(UUID uuid) { public boolean isOwner(UUID uuid) {
if (uuid.equals(this.owner)) { if (uuid.equals(this.owner)) {
@ -349,11 +350,11 @@ public class Plot {
/** /**
* Get a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots). * Get a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots).
* @return the Plot owners * @return the plot owners
*/ */
public Set<UUID> getOwners() { public Set<UUID> getOwners() {
if (this.owner == null) { if (this.owner == null) {
return Collections.emptySet(); return ImmutableSet.of();
} }
if (isMerged()) { if (isMerged()) {
Set<Plot> plots = getConnectedPlots(); Set<Plot> plots = getConnectedPlots();
@ -508,7 +509,7 @@ public class Plot {
/** /**
* Check if the plot is merged in any direction. * Check if the plot is merged in any direction.
* @return * @return is the plot merged or not
*/ */
public boolean isMerged() { public boolean isMerged() {
return getSettings().getMerged(0) || getSettings().getMerged(2) || getSettings().getMerged(1) || getSettings().getMerged(3); return getSettings().getMerged(0) || getSettings().getMerged(2) || getSettings().getMerged(1) || getSettings().getMerged(3);
@ -518,7 +519,7 @@ public class Plot {
* Get the timestamp of when the plot was created (unreliable)<br> * Get the timestamp of when the plot was created (unreliable)<br>
* - not accurate if the plot was created before this was implemented<br> * - not accurate if the plot was created before this was implemented<br>
* - Milliseconds since the epoch<br> * - Milliseconds since the epoch<br>
* @return * @return the creation date of the plot
*/ */
public long getTimestamp() { public long getTimestamp() {
if (this.timestamp == 0) { if (this.timestamp == 0) {
@ -583,7 +584,7 @@ public class Plot {
/** /**
* Get the denied users. * Get the denied users.
* @return * @return a set of denied users
*/ */
public HashSet<UUID> getDenied() { public HashSet<UUID> getDenied() {
if (this.denied == null) { if (this.denied == null) {
@ -613,7 +614,7 @@ public class Plot {
/** /**
* Get the trusted users. * Get the trusted users.
* @return * @return a set of trusted users
*/ */
public HashSet<UUID> getTrusted() { public HashSet<UUID> getTrusted() {
if (this.trusted == null) { if (this.trusted == null) {
@ -643,7 +644,7 @@ public class Plot {
/** /**
* Get the members * Get the members
* @return * @return a set of members
*/ */
public HashSet<UUID> getMembers() { public HashSet<UUID> getMembers() {
if (this.members == null) { if (this.members == null) {
@ -673,7 +674,7 @@ public class Plot {
/** /**
* Deny someone (updates database as well) * Deny someone (updates database as well)
* @param uuid * @param uuid the uuid of the player to deny.
*/ */
public void addDenied(UUID uuid) { public void addDenied(UUID uuid) {
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
@ -686,7 +687,7 @@ public class Plot {
/** /**
* Add someone as a helper (updates database as well) * Add someone as a helper (updates database as well)
* *
* @param uuid * @param uuid the uuid of the player to trust
*/ */
public void addTrusted(UUID uuid) { public void addTrusted(UUID uuid) {
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
@ -699,7 +700,7 @@ public class Plot {
/** /**
* Add someone as a trusted user (updates database as well) * Add someone as a trusted user (updates database as well)
* *
* @param uuid * @param uuid the uuid of the player to add as a member
*/ */
public void addMember(UUID uuid) { public void addMember(UUID uuid) {
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
@ -942,7 +943,8 @@ public class Plot {
/** /**
* Remove a flag from this plot * Remove a flag from this plot
* @param flag * @param flag the flag to remove
* @return
*/ */
public boolean removeFlag(Flag<?> flag) { public boolean removeFlag(Flag<?> flag) {
return FlagManager.removePlotFlag(this, flag); return FlagManager.removePlotFlag(this, flag);
@ -958,7 +960,8 @@ public class Plot {
/** /**
* Get the flag for a given key * Get the flag for a given key
* @param key * @param key the flag
* @param def if the key is null, the value to return
*/ */
public <V> V getFlag(Flag<V> key, V def) { public <V> V getFlag(Flag<V> key, V def) {
V value = FlagManager.getPlotFlagRaw(this, key); V value = FlagManager.getPlotFlagRaw(this, key);
@ -1289,18 +1292,18 @@ public class Plot {
return this.create(this.owner, true); return this.create(this.owner, true);
} }
public boolean claim(final PlotPlayer pp, boolean teleport, String schematic) { public boolean claim(final PlotPlayer player, boolean teleport, String schematic) {
if (!canClaim(pp)) { if (!canClaim(player)) {
return false; return false;
} }
boolean result = EventUtil.manager.callClaim(pp, this, false); boolean result = EventUtil.manager.callClaim(player, this, false);
if (!result || !create(pp.getUUID(), true)) { if (!result || !create(player.getUUID(), true)) {
return false; return false;
} }
setSign(pp.getName()); setSign(player.getName());
MainUtil.sendMessage(pp, C.CLAIMED); MainUtil.sendMessage(player, C.CLAIMED);
if (teleport) { if (teleport) {
teleportPlayer(pp); teleportPlayer(player);
} }
PlotArea plotworld = getArea(); PlotArea plotworld = getArea();
if (plotworld.SCHEMATIC_ON_CLAIM) { if (plotworld.SCHEMATIC_ON_CLAIM) {
@ -1317,9 +1320,9 @@ public class Plot {
@Override @Override
public void run(Boolean value) { public void run(Boolean value) {
if (value) { if (value) {
MainUtil.sendMessage(pp, C.SCHEMATIC_PASTE_SUCCESS); MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
} else { } else {
MainUtil.sendMessage(pp, C.SCHEMATIC_PASTE_FAILED); MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
} }
} }
}); });
@ -1333,7 +1336,7 @@ public class Plot {
* - The plot will not be created if the owner is null<br> * - The plot will not be created if the owner is null<br>
* - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot * - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot
* creation. * creation.
* @param uuid * @param uuid the uuid of the plot owner
* @param notify * @param notify
* @return true if plot was created successfully * @return true if plot was created successfully
*/ */
@ -1384,6 +1387,7 @@ public class Plot {
/** /**
* Get the biome. * Get the biome.
* @return the name of the biome
*/ */
public String getBiome() { public String getBiome() {
Location loc = this.getBottomAbs(); Location loc = this.getBottomAbs();
@ -1408,8 +1412,8 @@ public class Plot {
/** /**
* Swap the settings for two plots. * Swap the settings for two plots.
* @param plot * @param plot the plot to swap data with
* @param whenDone * @param whenDone the task to run at the end of this method.
* @return * @return
*/ */
public boolean swapData(Plot plot, Runnable whenDone) { public boolean swapData(Plot plot, Runnable whenDone) {
@ -1444,27 +1448,27 @@ public class Plot {
/** /**
* Move the settings for a plot. * Move the settings for a plot.
* @param pos2 * @param plot the plot to move
* @param whenDone * @param whenDone
* @return * @return
*/ */
public boolean moveData(Plot pos2, Runnable whenDone) { public boolean moveData(Plot plot, Runnable whenDone) {
if (this.owner == null) { if (this.owner == null) {
PS.debug(pos2 + " is unowned (single)"); PS.debug(plot + " is unowned (single)");
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return false; return false;
} }
if (pos2.hasOwner()) { if (plot.hasOwner()) {
PS.debug(pos2 + " is unowned (multi)"); PS.debug(plot + " is unowned (multi)");
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return false; return false;
} }
this.area.removePlot(this.id); this.area.removePlot(this.id);
this.getId().x = pos2.getId().x; this.getId().x = plot.getId().x;
this.getId().y = pos2.getId().y; this.getId().y = plot.getId().y;
this.getId().recalculateHash(); this.getId().recalculateHash();
this.area.addPlotAbs(this); this.area.addPlotAbs(this);
DBFunc.movePlot(this, pos2); DBFunc.movePlot(this, plot);
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return true; return true;
} }
@ -1585,7 +1589,7 @@ public class Plot {
/** /**
* @deprecated in favor of getCorners()[1]; * @deprecated in favor of getCorners()[1];
* @return * @return the top corner of the plot
*/ */
@Deprecated @Deprecated
public Location getTop() { public Location getTop() {
@ -2532,8 +2536,8 @@ public class Plot {
/** /**
* Teleport a player to a plot and send them the teleport message. * Teleport a player to a plot and send them the teleport message.
* @param player The player * @param player the player
* @return If the teleportation is allowed. * @return if the teleport succeeded
*/ */
public boolean teleportPlayer(final PlotPlayer player) { public boolean teleportPlayer(final PlotPlayer player) {
Plot plot = this.getBasePlot(false); Plot plot = this.getBasePlot(false);
@ -2623,7 +2627,7 @@ public class Plot {
} }
/** /**
* Merges 2 plots Removes the road inbetween <br>- Assumes plots are directly next to each other <br> - saves to DB * Merges 2 plots Removes the road in-between <br>- Assumes plots are directly next to each other <br> - saves to DB
* *
* @param lesserPlot * @param lesserPlot
* @param removeRoads * @param removeRoads

View File

@ -29,19 +29,19 @@ import java.util.UUID;
public class PlotListener { public class PlotListener {
public static boolean plotEntry(final PlotPlayer pp, final Plot plot) { public static boolean plotEntry(final PlotPlayer player, final Plot plot) {
if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) { if (plot.isDenied(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.entry.denied")) {
return false; return false;
} }
Plot last = pp.getMeta("lastplot"); Plot last = player.getMeta("lastplot");
if ((last != null) && !last.getId().equals(plot.getId())) { if ((last != null) && !last.getId().equals(plot.getId())) {
plotExit(pp, last); plotExit(player, last);
} }
if (ExpireManager.IMP != null) { if (ExpireManager.IMP != null) {
ExpireManager.IMP.handleEntry(pp, plot); ExpireManager.IMP.handleEntry(player, plot);
} }
pp.setMeta("lastplot", plot); player.setMeta("lastplot", plot);
EventUtil.manager.callEntry(pp, plot); EventUtil.manager.callEntry(player, plot);
if (plot.hasOwner()) { if (plot.hasOwner()) {
Map<Flag<?>, Object> flags = FlagManager.getPlotFlags(plot); Map<Flag<?>, Object> flags = FlagManager.getPlotFlags(plot);
boolean titles = Settings.TITLES; boolean titles = Settings.TITLES;
@ -54,17 +54,14 @@ public class PlotListener {
return true; return true;
} }
} else { } else {
Optional<Boolean> titleFlag = plot.getFlag(Flags.TITLES); titles = plot.getFlag(Flags.TITLES, true);
if (titleFlag.isPresent()) {
titles = titleFlag.get();
}
Optional<String> greetingFlag = plot.getFlag(Flags.GREETING); Optional<String> greetingFlag = plot.getFlag(Flags.GREETING);
if (greetingFlag.isPresent()) { if (greetingFlag.isPresent()) {
greeting = greetingFlag.get(); greeting = greetingFlag.get();
MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal<String>() { MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, player, false, new RunnableVal<String>() {
@Override @Override
public void run(String value) { public void run(String value) {
MainUtil.sendMessage(pp, value); MainUtil.sendMessage(player, value);
} }
}); });
} else { } else {
@ -72,79 +69,79 @@ public class PlotListener {
} }
Optional<Boolean> enter = plot.getFlag(Flags.NOTIFY_ENTER); Optional<Boolean> enter = plot.getFlag(Flags.NOTIFY_ENTER);
if (enter.isPresent() && enter.get()) { if (enter.isPresent() && enter.get()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid); PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if (owner != null && !owner.getUUID().equals(pp.getUUID())) { if (owner != null && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(owner, MainUtil.sendMessage(owner,
C.NOTIFY_ENTER.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString())); C.NOTIFY_ENTER.s().replace("%player", player.getName()).replace("%plot", plot.getId().toString()));
} }
} }
} }
} }
Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE); Optional<PlotGameMode> gamemodeFlag = plot.getFlag(Flags.GAMEMODE);
if (gamemodeFlag.isPresent()) { if (gamemodeFlag.isPresent()) {
if (pp.getGameMode() != gamemodeFlag.get()) { if (player.getGameMode() != gamemodeFlag.get()) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
pp.setGameMode(gamemodeFlag.get()); player.setGameMode(gamemodeFlag.get());
} else { } else {
MainUtil.sendMessage(pp, MainUtil.sendMessage(player,
StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.get())); StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.get()));
} }
} }
} }
Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY); Optional<Boolean> flyFlag = plot.getFlag(Flags.FLY);
if (flyFlag.isPresent()) { if (flyFlag.isPresent()) {
pp.setFlight(flyFlag.get()); player.setFlight(flyFlag.get());
} }
Optional<Long> timeFlag = plot.getFlag(Flags.TIME); Optional<Long> timeFlag = plot.getFlag(Flags.TIME);
if (timeFlag.isPresent()) { if (timeFlag.isPresent()) {
try { try {
long time = timeFlag.get(); long time = timeFlag.get();
pp.setTime(time); player.setTime(time);
} catch (Exception ignored) { } catch (Exception ignored) {
FlagManager.removePlotFlag(plot, Flags.TIME); FlagManager.removePlotFlag(plot, Flags.TIME);
} }
} }
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER); Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
if (weatherFlag.isPresent()) { if (weatherFlag.isPresent()) {
pp.setWeather(weatherFlag.get()); player.setWeather(weatherFlag.get());
} }
Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC); Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC);
if (musicFlag.isPresent()) { if (musicFlag.isPresent()) {
Integer id = musicFlag.get(); Integer id = musicFlag.get();
if ((id >= 2256 && id <= 2267) || (id == 0)) { if ((id >= 2256 && id <= 2267) || (id == 0)) {
Location loc = pp.getLocation(); Location loc = player.getLocation();
Location lastLoc = pp.getMeta("music"); Location lastLoc = player.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.playMusic(lastLoc, 0); player.playMusic(lastLoc, 0);
if (id == 0) { if (id == 0) {
pp.deleteMeta("music"); player.deleteMeta("music");
} }
} }
if (id != 0) { if (id != 0) {
try { try {
pp.setMeta("music", loc); player.setMeta("music", loc);
pp.playMusic(loc, id); player.playMusic(loc, id);
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
} }
} else { } else {
Location lastLoc = pp.getMeta("music"); Location lastLoc = player.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.deleteMeta("music"); player.deleteMeta("music");
pp.playMusic(lastLoc, 0); player.playMusic(lastLoc, 0);
} }
} }
CommentManager.sendTitle(pp, plot); CommentManager.sendTitle(player, plot);
} }
if (titles) { if (titles) {
if (!C.TITLE_ENTERED_PLOT.s().isEmpty() || !C.TITLE_ENTERED_PLOT_SUB.s().isEmpty()) { if (!C.TITLE_ENTERED_PLOT.s().isEmpty() || !C.TITLE_ENTERED_PLOT_SUB.s().isEmpty()) {
TaskManager.runTaskLaterAsync(new Runnable() { TaskManager.runTaskLaterAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
Plot lastPlot = pp.getMeta("lastplot"); Plot lastPlot = player.getMeta("lastplot");
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) { if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
Map<String, String> replacements = new HashMap<>(); Map<String, String> replacements = new HashMap<>();
replacements.put("%x%", String.valueOf(lastPlot.getId().x)); replacements.put("%x%", String.valueOf(lastPlot.getId().x));
@ -155,7 +152,7 @@ public class PlotListener {
replacements.put("%s", MainUtil.getName(plot.owner)); replacements.put("%s", MainUtil.getName(plot.owner));
String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements); String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements);
String sub = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements); String sub = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements);
AbstractTitle.sendTitle(pp, main, sub); AbstractTitle.sendTitle(player, main, sub);
} }
} }
}, 20); }, 20);
@ -166,60 +163,60 @@ public class PlotListener {
return true; return true;
} }
public static boolean plotExit(final PlotPlayer pp, Plot plot) { public static boolean plotExit(final PlotPlayer player, Plot plot) {
pp.deleteMeta("lastplot"); player.deleteMeta("lastplot");
EventUtil.manager.callLeave(pp, plot); EventUtil.manager.callLeave(player, plot);
if (plot.hasOwner()) { if (plot.hasOwner()) {
PlotArea pw = plot.getArea(); PlotArea pw = plot.getArea();
if (pw == null) { if (pw == null) {
return true; return true;
} }
if (plot.getFlag(Flags.GAMEMODE).isPresent()) { if (plot.getFlag(Flags.GAMEMODE).isPresent()) {
if (pp.getGameMode() != pw.GAMEMODE) { if (player.getGameMode() != pw.GAMEMODE) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) { if (!Permissions.hasPermission(player, "plots.gamemode.bypass")) {
pp.setGameMode(pw.GAMEMODE); player.setGameMode(pw.GAMEMODE);
} else { } else {
MainUtil.sendMessage(pp, StringMan MainUtil.sendMessage(player, StringMan
.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.toString(), "{gamemode}", pw.GAMEMODE.name().toLowerCase())); .replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.toString(), "{gamemode}", pw.GAMEMODE.name().toLowerCase()));
} }
} }
} }
Optional<String> farewell = plot.getFlag(Flags.FAREWELL); Optional<String> farewell = plot.getFlag(Flags.FAREWELL);
if (farewell.isPresent()) { if (farewell.isPresent()) {
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, pp, false, new RunnableVal<String>() { MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, player, false, new RunnableVal<String>() {
@Override @Override
public void run(String value) { public void run(String value) {
MainUtil.sendMessage(pp, value); MainUtil.sendMessage(player, value);
} }
}); });
} }
Optional<Boolean> leave = plot.getFlag(Flags.NOTIFY_LEAVE); Optional<Boolean> leave = plot.getFlag(Flags.NOTIFY_LEAVE);
if (leave.isPresent() && leave.get()) { if (leave.isPresent() && leave.get()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid); PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) { if ((owner != null) && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString())); MainUtil.sendMessage(player, C.NOTIFY_LEAVE.s().replace("%player", player.getName()).replace("%plot", plot.getId().toString()));
} }
} }
} }
} }
if (plot.getFlag(Flags.FLY).isPresent()) { if (plot.getFlag(Flags.FLY).isPresent()) {
PlotGameMode gamemode = pp.getGameMode(); PlotGameMode gamemode = player.getGameMode();
if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) { if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
pp.setFlight(false); player.setFlight(false);
} }
} }
if (plot.getFlag(Flags.TIME).isPresent()) { if (plot.getFlag(Flags.TIME).isPresent()) {
pp.setTime(Long.MAX_VALUE); player.setTime(Long.MAX_VALUE);
} }
if (plot.getFlag(Flags.WEATHER).isPresent()) { if (plot.getFlag(Flags.WEATHER).isPresent()) {
pp.setWeather(PlotWeather.RESET); player.setWeather(PlotWeather.RESET);
} }
Location lastLoc = pp.getMeta("music"); Location lastLoc = player.getMeta("music");
if (lastLoc != null) { if (lastLoc != null) {
pp.deleteMeta("music"); player.deleteMeta("music");
pp.playMusic(lastLoc, 0); player.playMusic(lastLoc, 0);
} }
} }
return true; return true;