mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Merge branch 'v6' into feature/v6/pipeline-queue
# Conflicts: # Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
This commit is contained in:
commit
45cc88091e
@ -30,6 +30,7 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Stage;
|
import com.google.inject.Stage;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.plotsquared.bukkit.inject.BackupModule;
|
import com.plotsquared.bukkit.inject.BackupModule;
|
||||||
import com.plotsquared.bukkit.inject.BukkitModule;
|
import com.plotsquared.bukkit.inject.BukkitModule;
|
||||||
@ -42,6 +43,7 @@ import com.plotsquared.bukkit.listener.SingleWorldListener;
|
|||||||
import com.plotsquared.bukkit.listener.WorldEvents;
|
import com.plotsquared.bukkit.listener.WorldEvents;
|
||||||
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
|
||||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||||
|
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
import com.plotsquared.bukkit.util.BukkitChatManager;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -103,6 +105,7 @@ import com.plotsquared.core.util.EventDispatcher;
|
|||||||
import com.plotsquared.core.util.FileUtils;
|
import com.plotsquared.core.util.FileUtils;
|
||||||
import com.plotsquared.core.util.PermHandler;
|
import com.plotsquared.core.util.PermHandler;
|
||||||
import com.plotsquared.core.util.PlatformWorldManager;
|
import com.plotsquared.core.util.PlatformWorldManager;
|
||||||
|
import com.plotsquared.core.util.PlayerManager;
|
||||||
import com.plotsquared.core.util.PremiumVerification;
|
import com.plotsquared.core.util.PremiumVerification;
|
||||||
import com.plotsquared.core.util.ReflectionUtils;
|
import com.plotsquared.core.util.ReflectionUtils;
|
||||||
import com.plotsquared.core.util.SetupUtils;
|
import com.plotsquared.core.util.SetupUtils;
|
||||||
@ -1161,10 +1164,17 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
|||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public com.plotsquared.core.location.World<?> getPlatformWorld(
|
@Override @Nonnull public com.plotsquared.core.location.World<?> getPlatformWorld(@Nonnull final String worldName) {
|
||||||
@Nonnull final String worldName) {
|
|
||||||
return BukkitWorld.of(worldName);
|
return BukkitWorld.of(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @Nonnull public PlatformWorldManager<?> getWorldManager() {
|
||||||
|
return getInjector().getInstance(Key.get(new TypeLiteral<PlatformWorldManager<World>>() {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @Nonnull public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> getPlayerManager() {
|
||||||
|
return getInjector().getInstance(Key.get(new TypeLiteral<PlayerManager<BukkitPlayer, Player>>() {}));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import java.util.Iterator;
|
|||||||
* Plot (X,Y) tuples for plot locations
|
* Plot (X,Y) tuples for plot locations
|
||||||
* within a plot area
|
* within a plot area
|
||||||
*/
|
*/
|
||||||
public class PlotId {
|
public final class PlotId {
|
||||||
|
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
@ -48,7 +48,7 @@ public class PlotId {
|
|||||||
* @param x The plot x coordinate
|
* @param x The plot x coordinate
|
||||||
* @param y The plot y coordinate
|
* @param y The plot y coordinate
|
||||||
*/
|
*/
|
||||||
private PlotId(int x, int y) {
|
private PlotId(final int x, final int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.hash = (this.getX() << 16) | (this.getY() & 0xFFFF);
|
this.hash = (this.getX() << 16) | (this.getY() & 0xFFFF);
|
||||||
@ -61,20 +61,21 @@ public class PlotId {
|
|||||||
* @param y The plot y coordinate
|
* @param y The plot y coordinate
|
||||||
*/
|
*/
|
||||||
@Nonnull public static PlotId of(final int x, final int y) {
|
@Nonnull public static PlotId of(final int x, final int y) {
|
||||||
return PlotId.of(x, y);
|
return new PlotId(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Plot Id based on a string
|
* Get a Plot Id based on a string
|
||||||
*
|
*
|
||||||
* @param string to create id from
|
* @param string to create id from
|
||||||
* @return the PlotId representation of the arguement
|
* @return the PlotId representation of the argument
|
||||||
* @throws IllegalArgumentException if the string does not contain a valid PlotId
|
* @throws IllegalArgumentException if the string does not contain a valid PlotId
|
||||||
*/
|
*/
|
||||||
@Nonnull public static PlotId fromString(@Nonnull String string) {
|
@Nonnull public static PlotId fromString(@Nonnull final String string) {
|
||||||
PlotId plot = fromStringOrNull(string);
|
final PlotId plot = fromStringOrNull(string);
|
||||||
if (plot == null)
|
if (plot == null) {
|
||||||
throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
|
throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
|
||||||
|
}
|
||||||
return plot;
|
return plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,8 +85,8 @@ public class PlotId {
|
|||||||
* @param string ID string
|
* @param string ID string
|
||||||
* @return Plot ID, or {@code null} if none could be parsed
|
* @return Plot ID, or {@code null} if none could be parsed
|
||||||
*/
|
*/
|
||||||
@Nullable public static PlotId fromStringOrNull(@Nonnull String string) {
|
@Nullable public static PlotId fromStringOrNull(@Nonnull final String string) {
|
||||||
String[] parts = string.split("[;,.]");
|
final String[] parts = string.split("[;,.]");
|
||||||
if (parts.length < 2) {
|
if (parts.length < 2) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -94,7 +95,7 @@ public class PlotId {
|
|||||||
try {
|
try {
|
||||||
x = Integer.parseInt(parts[0]);
|
x = Integer.parseInt(parts[0]);
|
||||||
y = Integer.parseInt(parts[1]);
|
y = Integer.parseInt(parts[1]);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (final NumberFormatException ignored) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return of(x, y);
|
return of(x, y);
|
||||||
@ -126,7 +127,7 @@ public class PlotId {
|
|||||||
* @return X component
|
* @return X component
|
||||||
*/
|
*/
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return this.getX();
|
return this.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +136,7 @@ public class PlotId {
|
|||||||
* @return Y component
|
* @return Y component
|
||||||
*/
|
*/
|
||||||
public int getY() {
|
public int getY() {
|
||||||
return this.getY();
|
return this.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,8 +145,8 @@ public class PlotId {
|
|||||||
* @return Next plot ID
|
* @return Next plot ID
|
||||||
*/
|
*/
|
||||||
@Nonnull public PlotId getNextId() {
|
@Nonnull public PlotId getNextId() {
|
||||||
int absX = Math.abs(x);
|
final int absX = Math.abs(x);
|
||||||
int absY = Math.abs(y);
|
final int absY = Math.abs(y);
|
||||||
if (absX > absY) {
|
if (absX > absY) {
|
||||||
if (x > 0) {
|
if (x > 0) {
|
||||||
return PlotId.of(x, y + 1);
|
return PlotId.of(x, y + 1);
|
||||||
|
@ -35,13 +35,20 @@ import com.sk89q.worldedit.world.block.BlockType;
|
|||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
import com.sk89q.worldedit.world.block.FuzzyBlockState;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link BlockState} related utility methods
|
||||||
|
*/
|
||||||
public final class BlockUtil {
|
public final class BlockUtil {
|
||||||
private static ParserContext PARSER_CONTEXT = new ParserContext();
|
|
||||||
private static InputParser<BaseBlock> PARSER;
|
private static final ParserContext PARSER_CONTEXT = new ParserContext();
|
||||||
|
private static final InputParser<BaseBlock> PARSER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PARSER_CONTEXT.setRestricted(false);
|
PARSER_CONTEXT.setRestricted(false);
|
||||||
@ -53,15 +60,35 @@ public final class BlockUtil {
|
|||||||
private BlockUtil() {
|
private BlockUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState get(int id) {
|
/**
|
||||||
|
* Get a {@link BlockState} from a legacy id
|
||||||
|
*
|
||||||
|
* @param id Legacy ID
|
||||||
|
* @return Block state, or {@code null}
|
||||||
|
*/
|
||||||
|
@Nullable public static BlockState get(@Nonnegative final int id) {
|
||||||
return LegacyMapper.getInstance().getBlockFromLegacy(id);
|
return LegacyMapper.getInstance().getBlockFromLegacy(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState get(int id, int data) {
|
/**
|
||||||
|
* Get a {@link BlockState} from a legacy id-data pair
|
||||||
|
*
|
||||||
|
* @param id Legacy ID
|
||||||
|
* @param data Legacy data
|
||||||
|
* @return Block state, or {@code null}
|
||||||
|
*/
|
||||||
|
@Nullable public static BlockState get(@Nonnegative final int id, final int data) {
|
||||||
return LegacyMapper.getInstance().getBlockFromLegacy(id, data);
|
return LegacyMapper.getInstance().getBlockFromLegacy(id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState get(String id) {
|
/**
|
||||||
|
* Get a {@link BlockState} from its ID
|
||||||
|
*
|
||||||
|
* @param id String or integer ID
|
||||||
|
* @return Parsed block state, or {@code null} if none
|
||||||
|
* could be parsed
|
||||||
|
*/
|
||||||
|
@Nullable public static BlockState get(@Nonnull String id) {
|
||||||
if (id.length() == 1 && id.charAt(0) == '*') {
|
if (id.length() == 1 && id.charAt(0) == '*') {
|
||||||
return FuzzyBlockState.builder().type(BlockTypes.AIR).build();
|
return FuzzyBlockState.builder().type(BlockTypes.AIR).build();
|
||||||
}
|
}
|
||||||
@ -90,16 +117,29 @@ public final class BlockUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState[] parse(String commaDelimited) {
|
/**
|
||||||
String[] split = commaDelimited.split(",(?![^\\(\\[]*[\\]\\)])");
|
* Parse a comma delimited list of block states
|
||||||
BlockState[] result = new BlockState[split.length];
|
*
|
||||||
|
* @param commaDelimited List of block states
|
||||||
|
* @return Parsed block states
|
||||||
|
*/
|
||||||
|
@Nonnull public static BlockState[] parse(@Nonnull final String commaDelimited) {
|
||||||
|
final String[] split = commaDelimited.split(",(?![^\\(\\[]*[\\]\\)])");
|
||||||
|
final BlockState[] result = new BlockState[split.length];
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < split.length; i++) {
|
||||||
result[i] = get(split[i]);
|
result[i] = get(split[i]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockState deserialize(@Nonnull final Map<String, Object> map) {
|
/**
|
||||||
|
* Deserialize a serialized {@link BlockState}
|
||||||
|
*
|
||||||
|
* @param map Serialized block state
|
||||||
|
* @return Deserialized block state, or {@code null} if the map is
|
||||||
|
* not a properly serialized block state
|
||||||
|
*/
|
||||||
|
@Nullable public static BlockState deserialize(@Nonnull final Map<String, Object> map) {
|
||||||
if (map.containsKey("material")) {
|
if (map.containsKey("material")) {
|
||||||
final Object object = map.get("material");
|
final Object object = map.get("material");
|
||||||
return get(object.toString());
|
return get(object.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user