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.Key;
|
||||
import com.google.inject.Stage;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.plotsquared.bukkit.inject.BackupModule;
|
||||
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.placeholder.PlaceholderFormatter;
|
||||
import com.plotsquared.bukkit.placeholder.Placeholders;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayer;
|
||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
||||
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.PermHandler;
|
||||
import com.plotsquared.core.util.PlatformWorldManager;
|
||||
import com.plotsquared.core.util.PlayerManager;
|
||||
import com.plotsquared.core.util.PremiumVerification;
|
||||
import com.plotsquared.core.util.ReflectionUtils;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
@ -1162,9 +1165,16 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override public com.plotsquared.core.location.World<?> getPlatformWorld(
|
||||
@Nonnull final String worldName) {
|
||||
@Override @Nonnull public com.plotsquared.core.location.World<?> getPlatformWorld(@Nonnull final String 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
|
||||
* within a plot area
|
||||
*/
|
||||
public class PlotId {
|
||||
public final class PlotId {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
@ -48,7 +48,7 @@ public class PlotId {
|
||||
* @param x The plot x 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.y = y;
|
||||
this.hash = (this.getX() << 16) | (this.getY() & 0xFFFF);
|
||||
@ -61,20 +61,21 @@ public class PlotId {
|
||||
* @param y The plot y coordinate
|
||||
*/
|
||||
@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
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
@Nonnull public static PlotId fromString(@Nonnull String string) {
|
||||
PlotId plot = fromStringOrNull(string);
|
||||
if (plot == null)
|
||||
@Nonnull public static PlotId fromString(@Nonnull final String string) {
|
||||
final PlotId plot = fromStringOrNull(string);
|
||||
if (plot == null) {
|
||||
throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
|
||||
}
|
||||
return plot;
|
||||
}
|
||||
|
||||
@ -84,8 +85,8 @@ public class PlotId {
|
||||
* @param string ID string
|
||||
* @return Plot ID, or {@code null} if none could be parsed
|
||||
*/
|
||||
@Nullable public static PlotId fromStringOrNull(@Nonnull String string) {
|
||||
String[] parts = string.split("[;,.]");
|
||||
@Nullable public static PlotId fromStringOrNull(@Nonnull final String string) {
|
||||
final String[] parts = string.split("[;,.]");
|
||||
if (parts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
@ -94,7 +95,7 @@ public class PlotId {
|
||||
try {
|
||||
x = Integer.parseInt(parts[0]);
|
||||
y = Integer.parseInt(parts[1]);
|
||||
} catch (NumberFormatException ignored) {
|
||||
} catch (final NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
return of(x, y);
|
||||
@ -126,7 +127,7 @@ public class PlotId {
|
||||
* @return X component
|
||||
*/
|
||||
public int getX() {
|
||||
return this.getX();
|
||||
return this.x;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,7 +136,7 @@ public class PlotId {
|
||||
* @return Y component
|
||||
*/
|
||||
public int getY() {
|
||||
return this.getY();
|
||||
return this.y;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,8 +145,8 @@ public class PlotId {
|
||||
* @return Next plot ID
|
||||
*/
|
||||
@Nonnull public PlotId getNextId() {
|
||||
int absX = Math.abs(x);
|
||||
int absY = Math.abs(y);
|
||||
final int absX = Math.abs(x);
|
||||
final int absY = Math.abs(y);
|
||||
if (absX > absY) {
|
||||
if (x > 0) {
|
||||
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.FuzzyBlockState;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link BlockState} related utility methods
|
||||
*/
|
||||
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 {
|
||||
PARSER_CONTEXT.setRestricted(false);
|
||||
@ -53,15 +60,35 @@ public final class 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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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) == '*') {
|
||||
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(",(?![^\\(\\[]*[\\]\\)])");
|
||||
BlockState[] result = new BlockState[split.length];
|
||||
/**
|
||||
* Parse a comma delimited list of block states
|
||||
*
|
||||
* @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++) {
|
||||
result[i] = get(split[i]);
|
||||
}
|
||||
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")) {
|
||||
final Object object = map.get("material");
|
||||
return get(object.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user