Merge branch 'optional' into breaking

This commit is contained in:
matt 2019-01-09 20:01:32 -05:00
commit 7302480728
17 changed files with 44 additions and 137 deletions

View File

@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventTy
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.google.common.base.Optional;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -1693,7 +1692,7 @@ import java.util.regex.Pattern;
return; return;
} }
Plot plot = area.getOwnedPlot(location); Plot plot = area.getOwnedPlot(location);
if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) { if (plot == null || !plot.getFlag(Flags.EXPLOSION).orElse(false)) {
event.setCancelled(true); event.setCancelled(true);
} }
event.blockList().removeIf( event.blockList().removeIf(
@ -2170,7 +2169,7 @@ import java.util.regex.Pattern;
|| !plotIgnited.equals(plot)) || || !plotIgnited.equals(plot)) ||
(igniteCause == BlockIgniteEvent.IgniteCause.SPREAD (igniteCause == BlockIgniteEvent.IgniteCause.SPREAD
|| igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && ( || igniteCause == BlockIgniteEvent.IgniteCause.LAVA) && (
!plot.getFlag(Flags.BLOCK_IGNITION).or(false) || plotIgnited == null !plot.getFlag(Flags.BLOCK_IGNITION).orElse(false) || plotIgnited == null
|| !plotIgnited.equals(plot))) { || !plotIgnited.equals(plot))) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -7,7 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.google.common.base.Optional;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -28,6 +27,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -139,15 +139,11 @@ public class PlotPlusListener extends PlotListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Plot plot = event.getPlot(); Plot plot = event.getPlot();
Optional<Integer[]> feed = plot.getFlag(Flags.FEED); Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
if (feed.isPresent()) { feed.ifPresent( value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
Integer[] value = feed.get(); );
feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
}
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL); Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
if (heal.isPresent()) { heal.ifPresent( value -> healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
Integer[] value = heal.get(); );
healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
}
} }
@EventHandler @EventHandler

View File

@ -11,8 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.google.common.base.Optional;
import java.util.Optional;
import java.util.Set; import java.util.Set;
@CommandDeclaration(command = "buy", description = "Buy the plot you are standing on", @CommandDeclaration(command = "buy", description = "Buy the plot you are standing on",

View File

@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.google.common.base.Optional;
import java.util.*; import java.util.*;

View File

@ -10,10 +10,10 @@ import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import com.github.intellectualsites.plotsquared.plot.util.CommentManager; import com.github.intellectualsites.plotsquared.plot.util.CommentManager;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.google.common.base.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
@CommandDeclaration(command = "inbox", description = "Review the comments for a plot", @CommandDeclaration(command = "inbox", description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox", usage = "/plot inbox [inbox] [delete <index>|clear|page]", permission = "plots.inbox",

View File

@ -8,7 +8,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.google.common.base.Optional;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -162,10 +161,9 @@ public class ListCmd extends SubCommand {
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) { for (Plot plot : PlotSquared.get().getPlots()) {
Optional<String> flag = plot.getFlag(Flags.DONE); Optional<String> flag = plot.getFlag(Flags.DONE);
if (!flag.isPresent()) { if (flag.isPresent()) {
continue; plots.add(plot);
} }
plots.add(plot);
} }
Collections.sort(plots, new Comparator<Plot>() { Collections.sort(plots, new Comparator<Plot>() {
@Override public int compare(Plot a, Plot b) { @Override public int compare(Plot a, Plot b) {

View File

@ -5,10 +5,8 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
/** /**
@ -16,38 +14,9 @@ import java.util.*;
*/ */
public class FlagManager { public class FlagManager {
/**
* Some events can be called millions of times each second (e.g. physics)
* and reusing is a lot faster.
*/
private static final Optional MUTABLE_OPTIONAL;
private static Field MUTABLE_OPTIONAL_FIELD;
static {
MUTABLE_OPTIONAL = Optional.of(new Object());
try {
MUTABLE_OPTIONAL_FIELD = MUTABLE_OPTIONAL.getClass().getDeclaredField("reference");
MUTABLE_OPTIONAL_FIELD.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
public static <V> Optional<V> getPlotFlag(Plot plot, Flag<V> key) { public static <V> Optional<V> getPlotFlag(Plot plot, Flag<V> key) {
V value = FlagManager.getPlotFlagRaw(plot, key); V value = FlagManager.getPlotFlagRaw(plot, key);
if (value != null) { return Optional.ofNullable(value);
if (PlotSquared.get().isMainThread(Thread.currentThread())) {
try {
MUTABLE_OPTIONAL_FIELD.set(MUTABLE_OPTIONAL, value);
return MUTABLE_OPTIONAL;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return Optional.of(value);
}
return Optional.absent();
} }
/** /**

View File

@ -8,10 +8,10 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.google.common.base.Optional;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public class PlotListener { public class PlotListener {
@ -122,9 +122,8 @@ public class PlotListener {
} }
} }
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER); Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
if (weatherFlag.isPresent()) { weatherFlag.ifPresent(player::setWeather);
player.setWeather(weatherFlag.get()); Optional<String> musicFlag = plot.getFlag(Flags.MUSIC);
} Optional<String> musicFlag = plot.getFlag(Flags.MUSIC);
if (musicFlag.isPresent()) { if (musicFlag.isPresent()) {
final String id = musicFlag.get(); final String id = musicFlag.get();
final PlotBlock block = PlotBlock.get(id); final PlotBlock block = PlotBlock.get(id);
@ -211,14 +210,13 @@ public class PlotListener {
} }
} }
Optional<String> farewell = plot.getFlag(Flags.FAREWELL); Optional<String> farewell = plot.getFlag(Flags.FAREWELL);
if (farewell.isPresent()) { farewell.ifPresent(s -> MainUtil.format(C.PREFIX_FAREWELL.s() + s, plot, player, false,
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.get(), plot, player, false,
new RunnableVal<String>() { new RunnableVal<String>() {
@Override public void run(String value) { @Override
public void run(String value) {
MainUtil.sendMessage(player, 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(player, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {

View File

@ -16,7 +16,6 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis; import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
import com.google.common.base.Optional;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;

View File

@ -3,7 +3,6 @@ package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import com.google.common.base.Optional;
import java.util.*; import java.util.*;
@ -146,7 +145,7 @@ public class PlotSettings {
public Optional<ArrayList<PlotComment>> getComments(String inbox) { public Optional<ArrayList<PlotComment>> getComments(String inbox) {
ArrayList<PlotComment> c = new ArrayList<>(); ArrayList<PlotComment> c = new ArrayList<>();
if (this.comments == null) { if (this.comments == null) {
return Optional.absent(); return Optional.empty();
} }
for (PlotComment comment : this.comments) { for (PlotComment comment : this.comments) {
if (comment.inbox.equals(inbox)) { if (comment.inbox.equals(inbox)) {

View File

@ -4,10 +4,10 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.google.common.base.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class InboxOwner extends CommentInbox { public class InboxOwner extends CommentInbox {

View File

@ -4,10 +4,10 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.object.Plot; import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.google.common.base.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class InboxPublic extends CommentInbox { public class InboxPublic extends CommentInbox {

View File

@ -8,11 +8,11 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.google.common.base.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
public abstract class EventUtil { public abstract class EventUtil {
@ -154,7 +154,7 @@ public abstract class EventUtil {
return Permissions return Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (plot.getFlag(Flags.HANGING_BREAK).or(false)) { if (plot.getFlag(Flags.HANGING_BREAK).orElse(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -170,7 +170,7 @@ public abstract class EventUtil {
return Permissions return Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (plot.getFlag(Flags.MISC_BREAK).or(false)) { if (plot.getFlag(Flags.MISC_BREAK).orElse(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -186,7 +186,7 @@ public abstract class EventUtil {
return Permissions return Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms); .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_ROAD.s(), notifyPerms);
} }
if (plot.getFlag(Flags.VEHICLE_BREAK).or(false)) { if (plot.getFlag(Flags.VEHICLE_BREAK).orElse(false)) {
return true; return true;
} }
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -210,12 +210,7 @@ public abstract class EventUtil {
notifyPerms); notifyPerms);
} }
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flagValue.orElse(null);
if (flagValue.isPresent()) {
value = flagValue.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
return Permissions return Permissions
@ -235,12 +230,7 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms); .hasPermission(player, C.PERMISSION_ADMIN_BUILD_UNOWNED.s(), notifyPerms);
} }
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flagValue.orElse(null);
if (flagValue.isPresent()) {
value = flagValue.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -261,16 +251,11 @@ public abstract class EventUtil {
return Permissions return Permissions
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false); .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), false);
} }
if (plot.getFlag(Flags.DEVICE_INTERACT).or(false)) { if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flagValue.orElse(null);
if (flagValue.isPresent()) {
value = flagValue.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -291,16 +276,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.HOSTILE_INTERACT).or(false)) { if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flagValue.orElse(null);
if (flagValue.isPresent()) {
value = flagValue.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -322,16 +302,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.MISC_INTERACT).or(false)) { if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flag.orElse(null);
if (flag.isPresent()) {
value = flag.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -353,16 +328,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.VEHICLE_USE).or(false)) { if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flag.orElse(null);
if (flag.isPresent()) {
value = flag.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -384,16 +354,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.MOB_PLACE).or(false)) { if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE); Optional<HashSet<PlotBlock>> flagValue = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flagValue.orElse(null);
if (flagValue.isPresent()) {
value = flagValue.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -417,16 +382,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.MISC_PLACE).or(false)) { if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flag.orElse(null);
if (flag.isPresent()) {
value = flag.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions
@ -449,16 +409,11 @@ public abstract class EventUtil {
.hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(), .hasPermission(player, C.PERMISSION_ADMIN_INTERACT_UNOWNED.s(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.VEHICLE_PLACE).or(false)) { if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) {
return true; return true;
} }
Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE); Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.PLACE);
HashSet<PlotBlock> value; HashSet<PlotBlock> value = flag.orElse(null);
if (flag.isPresent()) {
value = flag.get();
} else {
value = null;
}
if (value == null || !PlotBlock.containsEverything(value) && !value if (value == null || !PlotBlock.containsEverything(value) && !value
.contains(block.getPlotBlock())) { .contains(block.getPlotBlock())) {
if (Permissions if (Permissions

View File

@ -10,7 +10,6 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.object.stream.AbstractDelegateOutputStream; import com.github.intellectualsites.plotsquared.plot.object.stream.AbstractDelegateOutputStream;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.google.common.base.Optional;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;

View File

@ -12,7 +12,6 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.google.common.base.Optional;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

View File

@ -8,7 +8,6 @@ import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.google.common.base.Optional;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.*; import java.util.*;

View File

@ -9,12 +9,12 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest; import com.github.intellectualsites.plotsquared.plot.util.EventUtilTest;
import com.google.common.base.Optional;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -39,9 +39,7 @@ public class FlagTest {
testBlock = PlotBlock.get((short) 1, (byte) 0); testBlock = PlotBlock.get((short) 1, (byte) 0);
flag.get().add(testBlock); flag.get().add(testBlock);
} }
if (flag.isPresent()) { flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection)));
System.out.println(Flags.USE.valueToString(flag.get()));
}
Optional<HashSet<PlotBlock>> flag2 = plot.getFlag(Flags.USE); Optional<HashSet<PlotBlock>> flag2 = plot.getFlag(Flags.USE);
if (flag2.isPresent()) { if (flag2.isPresent()) {
// assertThat(flag2.get(), (Matcher<? super HashSet<PlotBlock>>) IsCollectionContaining.hasItem(testBlock)); // assertThat(flag2.get(), (Matcher<? super HashSet<PlotBlock>>) IsCollectionContaining.hasItem(testBlock));