mirror of
https://github.com/CodeMC/WorldGuardWrapper.git
synced 2024-11-10 05:05:20 +01:00
Added function to get all set flags of a region
This commit is contained in:
parent
e3c030602e
commit
7edf3711a7
|
@ -4,6 +4,7 @@ import org.bukkit.Location;
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface IWrappedRegion {
|
public interface IWrappedRegion {
|
||||||
|
@ -12,6 +13,8 @@ public interface IWrappedRegion {
|
||||||
|
|
||||||
String getId();
|
String getId();
|
||||||
|
|
||||||
|
Map<IWrappedFlag<?>, Object> getFlags();
|
||||||
|
|
||||||
<T> Optional<T> getFlag(IWrappedFlag<T> flag);
|
<T> Optional<T> getFlag(IWrappedFlag<T> flag);
|
||||||
|
|
||||||
<T> void setFlag(IWrappedFlag<T> flag, T value);
|
<T> void setFlag(IWrappedFlag<T> flag, T value);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||||
import com.sk89q.worldguard.protection.flags.Flag;
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||||
|
@ -16,14 +15,11 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedPrimitiveFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedStatusFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.implementation.legacy.region.WrappedRegion;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
|
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
|
|
||||||
|
@ -57,32 +53,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
.orElse(null), flag));
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find a better way to define wrapper mappings and register mappings
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
|
||||||
final IWrappedFlag<T> wrappedFlag;
|
|
||||||
if (type.equals(WrappedState.class)) {
|
|
||||||
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
|
||||||
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Enum.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Location.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(String.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Vector.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
|
||||||
}
|
|
||||||
return wrappedFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaPlugin getWorldGuardPlugin() {
|
public JavaPlugin getWorldGuardPlugin() {
|
||||||
return WorldGuardPlugin.inst();
|
return WorldGuardPlugin.inst();
|
||||||
|
@ -97,7 +67,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
||||||
for (Flag<?> currentFlag : DefaultFlag.getFlags()) {
|
for (Flag<?> currentFlag : DefaultFlag.getFlags()) {
|
||||||
if (currentFlag.getName().equalsIgnoreCase(name)) {
|
if (currentFlag.getName().equalsIgnoreCase(name)) {
|
||||||
return Optional.of(wrap(currentFlag, type));
|
return Optional.of(WorldGuardFlagUtilities.wrap(currentFlag, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import lombok.Getter;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
|
import org.codemc.worldguardwrapper.implementation.legacy.utility.WorldGuardVectorUtilities;
|
||||||
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.legacy.flag.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
||||||
|
@ -17,6 +18,8 @@ import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -71,6 +74,19 @@ public class WrappedRegion implements IWrappedRegion {
|
||||||
return handle.getId();
|
return handle.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||||
|
Map<IWrappedFlag<?>, Object> result = new HashMap<>();
|
||||||
|
handle.getFlags().forEach((flag, value) -> {
|
||||||
|
if (value != null) {
|
||||||
|
IWrappedFlag<?> wrappedFlag = WorldGuardFlagUtilities.wrap(flag, value.getClass());
|
||||||
|
Optional<?> wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value);
|
||||||
|
wrappedValue.ifPresent(val -> result.put(wrappedFlag, val));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.legacy.utility;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedPrimitiveFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.legacy.flag.WrappedStatusFlag;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class WorldGuardFlagUtilities {
|
||||||
|
|
||||||
|
// TODO: find a better way to define wrapper mappings and register mappings
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
||||||
|
final IWrappedFlag<T> wrappedFlag;
|
||||||
|
if (type.equals(WrappedState.class)) {
|
||||||
|
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
||||||
|
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Enum.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Location.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(String.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Vector.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||||
|
}
|
||||||
|
return wrappedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,9 +21,8 @@ import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.implementation.v6.region.WrappedRegion;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
|
|
||||||
|
@ -58,32 +57,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
.orElse(null), flag));
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find a better way to define wrapper mappings and register mappings
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
|
||||||
final IWrappedFlag<T> wrappedFlag;
|
|
||||||
if (type.equals(WrappedState.class)) {
|
|
||||||
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
|
||||||
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Enum.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Location.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(String.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Vector.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
|
||||||
}
|
|
||||||
return wrappedFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaPlugin getWorldGuardPlugin() {
|
public JavaPlugin getWorldGuardPlugin() {
|
||||||
return WorldGuardPlugin.inst();
|
return WorldGuardPlugin.inst();
|
||||||
|
@ -97,7 +70,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
||||||
return Optional.ofNullable(flagRegistry.get(name))
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
.map(flag -> wrap(flag, type));
|
.map(flag -> WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,7 +104,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
flagRegistry.register(flag);
|
flagRegistry.register(flag);
|
||||||
return Optional.of(wrap(flag, type));
|
return Optional.of(WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
} catch (FlagConflictException ignored) {
|
} catch (FlagConflictException ignored) {
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v6.flag.AbstractWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
import org.codemc.worldguardwrapper.implementation.v6.utility.WorldGuardVectorUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
|
@ -17,6 +18,8 @@ import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -71,6 +74,19 @@ public class WrappedRegion implements IWrappedRegion {
|
||||||
return handle.getId();
|
return handle.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||||
|
Map<IWrappedFlag<?>, Object> result = new HashMap<>();
|
||||||
|
handle.getFlags().forEach((flag, value) -> {
|
||||||
|
if (value != null) {
|
||||||
|
IWrappedFlag<?> wrappedFlag = WorldGuardFlagUtilities.wrap(flag, value.getClass());
|
||||||
|
Optional<?> wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value);
|
||||||
|
wrappedValue.ifPresent(val -> result.put(wrappedFlag, val));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.v6.utility;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedPrimitiveFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v6.flag.WrappedStatusFlag;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class WorldGuardFlagUtilities {
|
||||||
|
|
||||||
|
// TODO: find a better way to define wrapper mappings and register mappings
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
||||||
|
final IWrappedFlag<T> wrappedFlag;
|
||||||
|
if (type.equals(WrappedState.class)) {
|
||||||
|
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
||||||
|
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Enum.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Location.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(String.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Vector.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||||
|
}
|
||||||
|
return wrappedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -25,9 +25,8 @@ import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7.flag.WrappedPrimitiveFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v7.flag.WrappedStatusFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.implementation.v7.region.WrappedRegion;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -62,32 +61,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
.orElse(null), flag));
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find a better way to define wrapper mappings and register mappings
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
|
||||||
final IWrappedFlag<T> wrappedFlag;
|
|
||||||
if (type.equals(WrappedState.class)) {
|
|
||||||
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
|
||||||
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Enum.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Location.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(String.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Vector.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
|
||||||
}
|
|
||||||
return wrappedFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaPlugin getWorldGuardPlugin() {
|
public JavaPlugin getWorldGuardPlugin() {
|
||||||
return WorldGuardPlugin.inst();
|
return WorldGuardPlugin.inst();
|
||||||
|
@ -101,7 +74,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
||||||
return Optional.ofNullable(flagRegistry.get(name))
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
.map(flag -> wrap(flag, type));
|
.map(flag -> WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,7 +108,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
flagRegistry.register(flag);
|
flagRegistry.register(flag);
|
||||||
return Optional.of(wrap(flag, type));
|
return Optional.of(WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
} catch (FlagConflictException ignored) {
|
} catch (FlagConflictException ignored) {
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
@ -11,12 +11,15 @@ import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v7.flag.AbstractWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -71,6 +74,19 @@ public class WrappedRegion implements IWrappedRegion {
|
||||||
return handle.getId();
|
return handle.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||||
|
Map<IWrappedFlag<?>, Object> result = new HashMap<>();
|
||||||
|
handle.getFlags().forEach((flag, value) -> {
|
||||||
|
if (value != null) {
|
||||||
|
IWrappedFlag<?> wrappedFlag = WorldGuardFlagUtilities.wrap(flag, value.getClass());
|
||||||
|
Optional<?> wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value);
|
||||||
|
wrappedValue.ifPresent(val -> result.put(wrappedFlag, val));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.v7.utility;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7.flag.WrappedPrimitiveFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7.flag.WrappedStatusFlag;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class WorldGuardFlagUtilities {
|
||||||
|
|
||||||
|
// TODO: find a better way to define wrapper mappings and register mappings
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
||||||
|
final IWrappedFlag<T> wrappedFlag;
|
||||||
|
if (type.equals(WrappedState.class)) {
|
||||||
|
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
||||||
|
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Enum.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Location.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(String.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Vector.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||||
|
}
|
||||||
|
return wrappedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,9 +26,8 @@ import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.flag.WrappedState;
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.IWorldGuardImplementation;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedPrimitiveFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedStatusFlag;
|
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.region.WrappedRegion;
|
import org.codemc.worldguardwrapper.implementation.v7fawe.region.WrappedRegion;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7fawe.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -67,32 +66,6 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
.orElse(null), flag));
|
.orElse(null), flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find a better way to define wrapper mappings and register mappings
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
|
||||||
final IWrappedFlag<T> wrappedFlag;
|
|
||||||
if (type.equals(WrappedState.class)) {
|
|
||||||
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
|
||||||
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Enum.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Location.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(String.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else if (type.equals(Vector.class)) {
|
|
||||||
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
|
||||||
}
|
|
||||||
return wrappedFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaPlugin getWorldGuardPlugin() {
|
public JavaPlugin getWorldGuardPlugin() {
|
||||||
return WorldGuardPlugin.inst();
|
return WorldGuardPlugin.inst();
|
||||||
|
@ -106,7 +79,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
public <T> Optional<IWrappedFlag<T>> getFlag(String name, Class<T> type) {
|
||||||
return Optional.ofNullable(flagRegistry.get(name))
|
return Optional.ofNullable(flagRegistry.get(name))
|
||||||
.map(flag -> wrap(flag, type));
|
.map(flag -> WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,7 +113,7 @@ public class WorldGuardImplementation implements IWorldGuardImplementation {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
flagRegistry.register(flag);
|
flagRegistry.register(flag);
|
||||||
return Optional.of(wrap(flag, type));
|
return Optional.of(WorldGuardFlagUtilities.wrap(flag, type));
|
||||||
} catch (FlagConflictException ignored) {
|
} catch (FlagConflictException ignored) {
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
@ -11,12 +11,15 @@ import org.bukkit.World;
|
||||||
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation;
|
import org.codemc.worldguardwrapper.implementation.v7fawe.WorldGuardImplementation;
|
||||||
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag;
|
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.AbstractWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7fawe.utility.WorldGuardFlagUtilities;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
import org.codemc.worldguardwrapper.region.IWrappedDomain;
|
||||||
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
import org.codemc.worldguardwrapper.region.IWrappedRegion;
|
||||||
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
import org.codemc.worldguardwrapper.selection.ICuboidSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
import org.codemc.worldguardwrapper.selection.IPolygonalSelection;
|
||||||
import org.codemc.worldguardwrapper.selection.ISelection;
|
import org.codemc.worldguardwrapper.selection.ISelection;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -71,6 +74,19 @@ public class WrappedRegion implements IWrappedRegion {
|
||||||
return handle.getId();
|
return handle.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<IWrappedFlag<?>, Object> getFlags() {
|
||||||
|
Map<IWrappedFlag<?>, Object> result = new HashMap<>();
|
||||||
|
handle.getFlags().forEach((flag, value) -> {
|
||||||
|
if (value != null) {
|
||||||
|
IWrappedFlag<?> wrappedFlag = WorldGuardFlagUtilities.wrap(flag, value.getClass());
|
||||||
|
Optional<?> wrappedValue = ((AbstractWrappedFlag<?>) wrappedFlag).fromWGValue(value);
|
||||||
|
wrappedValue.ifPresent(val -> result.put(wrappedFlag, val));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
public <T> Optional<T> getFlag(IWrappedFlag<T> flag) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.codemc.worldguardwrapper.implementation.v7fawe.utility;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.protection.flags.Flag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.codemc.worldguardwrapper.flag.IWrappedFlag;
|
||||||
|
import org.codemc.worldguardwrapper.flag.WrappedState;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedPrimitiveFlag;
|
||||||
|
import org.codemc.worldguardwrapper.implementation.v7fawe.flag.WrappedStatusFlag;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class WorldGuardFlagUtilities {
|
||||||
|
|
||||||
|
// TODO: find a better way to define wrapper mappings and register mappings
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
public <T> IWrappedFlag<T> wrap(Flag<?> flag, Class<T> type) {
|
||||||
|
final IWrappedFlag<T> wrappedFlag;
|
||||||
|
if (type.equals(WrappedState.class)) {
|
||||||
|
wrappedFlag = (IWrappedFlag<T>) new WrappedStatusFlag((Flag<StateFlag.State>) flag);
|
||||||
|
} else if (type.equals(Boolean.class) || type.equals(boolean.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Double.class) || type.equals(double.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Enum.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Integer.class) || type.equals(int.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Location.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(String.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else if (type.equals(Vector.class)) {
|
||||||
|
wrappedFlag = new WrappedPrimitiveFlag(flag);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported flag type " + type.getName());
|
||||||
|
}
|
||||||
|
return wrappedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user