From 4c18214da165a2e0fcfb767ca6b07ab98846826e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 17 Feb 2020 20:05:57 +0100 Subject: [PATCH] Fix entity util --- .../plotsquared/plot/flags/FlagContainer.java | 2 +- .../plotsquared/plot/object/Plot.java | 6 ++++++ .../plotsquared/plot/util/EntityUtil.java | 13 ++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java index 1fde1eb04..502ff0aee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flags/FlagContainer.java @@ -165,7 +165,7 @@ import java.util.Map; } @SuppressWarnings("ALL") - protected static > T castUnsafe(final PlotFlag flag) { + public static > T castUnsafe(final PlotFlag flag) { return (T) flag; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index e1bf0fc1d..2bbf9afd6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -3167,6 +3167,12 @@ public class Plot { return this.flagContainer.getFlag(flagClass).getValue(); } + public > T getFlag(final V flag) { + final Class flagClass = flag.getClass(); + final PlotFlag flagInstance = this.flagContainer.getFlagErased(flagClass); + return FlagContainer.castUnsafe(flagInstance).getValue(); + } + public boolean setFlag(PlotFlag plotFlag) { flagContainer.addFlag(plotFlag); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EntityUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EntityUtil.java index fec85fbe7..0af7be2a4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EntityUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EntityUtil.java @@ -1,8 +1,7 @@ package com.github.intellectualsites.plotsquared.plot.util; -import com.github.intellectualsites.plotsquared.plot.config.Settings; -import com.github.intellectualsites.plotsquared.plot.flag.Flags; -import com.github.intellectualsites.plotsquared.plot.flag.IntegerFlag; +import com.github.intellectualsites.plotsquared.plot.config.Settings;; +import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag; import com.github.intellectualsites.plotsquared.plot.flags.implementations.DoneFlag; import com.github.intellectualsites.plotsquared.plot.object.Plot; import lombok.NonNull; @@ -38,14 +37,14 @@ import lombok.experimental.UtilityClass; return i; } - public static boolean checkEntity(Plot plot, IntegerFlag... flags) { + public static boolean checkEntity(Plot plot, PlotFlag ... flags) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { return true; } int[] mobs = null; - for (IntegerFlag flag : flags) { + for (PlotFlag flag : flags) { final int i = capNumeral(flag.getName()); - int cap = plot.getFlag(flag, Integer.MAX_VALUE); + int cap = plot.getFlag(flag); if (cap == Integer.MAX_VALUE) { continue; } @@ -62,7 +61,7 @@ import lombok.experimental.UtilityClass; } } if (mobs != null) { - for (IntegerFlag flag : flags) { + for (PlotFlag flag : flags) { final int i = capNumeral(flag.getName()); mobs[i]++; }