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

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