mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Major code reformatting
This commit is contained in:
@ -94,22 +94,22 @@ public class SpongeMain implements IPlotMain {
|
||||
|
||||
// @Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
return this.game;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
return this.server;
|
||||
}
|
||||
|
||||
public GameProfileManager getResolver() {
|
||||
if (resolver == null) {
|
||||
resolver = game.getServer().getGameProfileManager();
|
||||
if (this.resolver == null) {
|
||||
this.resolver = this.game.getServer().getGameProfileManager();
|
||||
}
|
||||
return resolver;
|
||||
return this.resolver;
|
||||
}
|
||||
|
||||
public SpongeMain getPlugin() {
|
||||
@ -117,22 +117,22 @@ public class SpongeMain implements IPlotMain {
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void init(final GameInitializationEvent event) {
|
||||
public void init(GameInitializationEvent event) {
|
||||
log("PlotSquared: Game init");
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onInit(final GamePreInitializationEvent event) {
|
||||
public void onInit(GamePreInitializationEvent event) {
|
||||
log("PlotSquared: Game pre init");
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onServerAboutToStart(final GameAboutToStartServerEvent event) {
|
||||
public void onServerAboutToStart(GameAboutToStartServerEvent event) {
|
||||
log("PlotSquared: Server init");
|
||||
THIS = this;
|
||||
new PS(this, "Sponge");
|
||||
server = game.getServer();
|
||||
game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
|
||||
this.server = this.game.getServer();
|
||||
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,11 +141,11 @@ public class SpongeMain implements IPlotMain {
|
||||
if (!Settings.CONSOLE_COLOR) {
|
||||
message = message.replaceAll('\u00a7' + "[a-z|0-9]", "");
|
||||
}
|
||||
if (server == null || server.getConsole() == null) {
|
||||
logger.info(message);
|
||||
if (this.server == null || this.server.getConsole() == null) {
|
||||
this.logger.info(message);
|
||||
return;
|
||||
}
|
||||
server.getConsole().sendMessage(SpongeUtil.getText(message));
|
||||
this.server.getConsole().sendMessage(SpongeUtil.getText(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -166,17 +166,17 @@ public class SpongeMain implements IPlotMain {
|
||||
|
||||
@Override
|
||||
public int[] getPluginVersion() {
|
||||
PluginContainer plugin = game.getPluginManager().fromInstance(this).get();
|
||||
PluginContainer plugin = this.game.getPluginManager().fromInstance(this).get();
|
||||
String version = plugin.getVersion().get();
|
||||
final String[] split = version.split("\\.");
|
||||
String[] split = version.split("\\.");
|
||||
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), split.length == 3 ? Integer.parseInt(split[2]) : 0};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getServerVersion() {
|
||||
log("Checking minecraft version: Sponge: ");
|
||||
final String version = game.getPlatform().getMinecraftVersion().getName();
|
||||
final String[] split = version.split("\\.");
|
||||
String version = this.game.getPlatform().getMinecraftVersion().getName();
|
||||
String[] split = version.split("\\.");
|
||||
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), split.length == 3 ? Integer.parseInt(split[2]) : 0};
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ public class SpongeMain implements IPlotMain {
|
||||
try {
|
||||
Class.forName("com.sk89q.worldedit.WorldEdit");
|
||||
return true;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -282,7 +282,7 @@ public class SpongeMain implements IPlotMain {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(final PlotPlayer player) {
|
||||
public void unregister(PlotPlayer player) {
|
||||
SpongeUtil.removePlayer(player.getName());
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ public class SpongeMain implements IPlotMain {
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
try {
|
||||
Metrics metrics = new Metrics(game, (PluginContainer) this);
|
||||
Metrics metrics = new Metrics(this.game, (PluginContainer) this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (IOException e) {
|
||||
@ -313,17 +313,17 @@ public class SpongeMain implements IPlotMain {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(final String worldname) {
|
||||
public void setGenerator(String worldname) {
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
// create world
|
||||
final ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
|
||||
ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
|
||||
String manager = worldConfig.getString("generator.plugin", "PlotSquared");
|
||||
String generator = worldConfig.getString("generator.init", manager);
|
||||
|
||||
final int type = worldConfig.getInt("generator.type");
|
||||
final int terrain = worldConfig.getInt("generator.terrain");
|
||||
final SetupObject setup = new SetupObject();
|
||||
int type = worldConfig.getInt("generator.type");
|
||||
int terrain = worldConfig.getInt("generator.terrain");
|
||||
SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = generator;
|
||||
setup.type = type;
|
||||
@ -349,14 +349,13 @@ public class SpongeMain implements IPlotMain {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotPlayer wrapPlayer(final Object obj) {
|
||||
if (obj instanceof Player) {
|
||||
return SpongeUtil.getPlayer((Player) obj);
|
||||
}
|
||||
else if (obj instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) obj);
|
||||
} else if (obj instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) obj);
|
||||
public PlotPlayer wrapPlayer(Object player) {
|
||||
if (player instanceof Player) {
|
||||
return SpongeUtil.getPlayer((Player) player);
|
||||
} else if (player instanceof String) {
|
||||
return UUIDHandler.getPlayer((String) player);
|
||||
} else if (player instanceof UUID) {
|
||||
return UUIDHandler.getPlayer((UUID) player);
|
||||
}
|
||||
// TODO FIXME offline player
|
||||
return null;
|
||||
@ -395,7 +394,7 @@ public class SpongeMain implements IPlotMain {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
Collection<WorldGeneratorModifier> wgms = game.getRegistry().getAllOf(WorldGeneratorModifier.class);
|
||||
Collection<WorldGeneratorModifier> wgms = this.game.getRegistry().getAllOf(WorldGeneratorModifier.class);
|
||||
for (WorldGeneratorModifier wgm : wgms) {
|
||||
if (StringMan.isEqualIgnoreCaseToAny(name, wgm.getName(), wgm.getId())) {
|
||||
if (wgm instanceof GeneratorWrapper<?>) {
|
||||
@ -415,7 +414,7 @@ public class SpongeMain implements IPlotMain {
|
||||
@Override
|
||||
public List<String> getPluginIds() {
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (PluginContainer plugin : game.getPluginManager().getPlugins()) {
|
||||
for (PluginContainer plugin : this.game.getPluginManager().getPlugins()) {
|
||||
names.add(plugin.getName() + ";" + plugin.getVersion() + ":" + true);
|
||||
}
|
||||
return names;
|
||||
|
@ -5,7 +5,7 @@ import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotGameMode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.sponge.util.SpongeUtil;
|
||||
@ -28,13 +28,13 @@ import java.util.UUID;
|
||||
public class SpongePlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private long last = 0;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
public SpongePlayer(final Player player) {
|
||||
|
||||
public SpongePlayer(Player player) {
|
||||
this.player = player;
|
||||
super.populatePersistentMetaMap();
|
||||
}
|
||||
@ -46,208 +46,201 @@ public class SpongePlayer extends PlotPlayer {
|
||||
|
||||
@Override
|
||||
public long getPreviousLogin() {
|
||||
if (last != 0) {
|
||||
return last;
|
||||
if (this.last != 0) {
|
||||
return this.last;
|
||||
}
|
||||
final Value<Instant> data = player.getJoinData().lastPlayed();
|
||||
Value<Instant> data = this.player.getJoinData().lastPlayed();
|
||||
if (data.exists()) {
|
||||
return last = data.get().getEpochSecond() * 1000;
|
||||
return this.last = data.get().getEpochSecond() * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
final Location loc = super.getLocation();
|
||||
return loc == null ? SpongeUtil.getLocation(player) : loc;
|
||||
Location location = super.getLocation();
|
||||
if (location == null) {
|
||||
return SpongeUtil.getLocation(this.player);
|
||||
} else {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocationFull() {
|
||||
return SpongeUtil.getLocationFull(player);
|
||||
return SpongeUtil.getLocationFull(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(this);
|
||||
if (this.uuid == null) {
|
||||
this.uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
return uuid;
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String perm) {
|
||||
public boolean hasPermission(String permission) {
|
||||
if (Settings.PERMISSION_CACHING) {
|
||||
if (noPerm.contains(perm)) {
|
||||
if (this.noPerm.contains(permission)) {
|
||||
return false;
|
||||
}
|
||||
if (hasPerm.contains(perm)) {
|
||||
if (this.hasPerm.contains(permission)) {
|
||||
return true;
|
||||
}
|
||||
final boolean result = player.hasPermission(perm);
|
||||
boolean result = this.player.hasPermission(permission);
|
||||
if (!result) {
|
||||
noPerm.add(perm);
|
||||
this.noPerm.add(permission);
|
||||
return false;
|
||||
}
|
||||
hasPerm.add(perm);
|
||||
this.hasPerm.add(permission);
|
||||
return true;
|
||||
}
|
||||
return player.hasPermission(perm);
|
||||
return this.player.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(final String message) {
|
||||
player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
||||
public void sendMessage(String message) {
|
||||
this.player.sendMessage(ChatTypes.CHAT, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(final Location loc) {
|
||||
if ((Math.abs(loc.getX()) >= 30000000) || (Math.abs(loc.getZ()) >= 30000000)) {
|
||||
public void teleport(Location location) {
|
||||
if ((Math.abs(location.getX()) >= 30000000) || (Math.abs(location.getZ()) >= 30000000)) {
|
||||
return;
|
||||
}
|
||||
final String world = player.getWorld().getName();
|
||||
if (!world.equals(loc.getWorld())) {
|
||||
player.transferToWorld(loc.getWorld(), new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
String world = this.player.getWorld().getName();
|
||||
if (!world.equals(location.getWorld())) {
|
||||
this.player.transferToWorld(location.getWorld(), new Vector3d(location.getX(), location.getY(), location.getZ()));
|
||||
} else {
|
||||
org.spongepowered.api.world.Location current = player.getLocation();
|
||||
current = current.setPosition(new Vector3d(loc.getX(), loc.getY(), loc.getZ()));
|
||||
player.setLocation(current);
|
||||
org.spongepowered.api.world.Location current = this.player.getLocation();
|
||||
current = current.setPosition(new Vector3d(location.getX(), location.getY(), location.getZ()));
|
||||
this.player.setLocation(current);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return player.isOnline();
|
||||
return this.player.isOnline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (name == null) {
|
||||
name = player.getName();
|
||||
if (this.name == null) {
|
||||
this.name = this.player.getName();
|
||||
}
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(final Location loc) {
|
||||
final TargetedLocationData target = player.getOrCreate(TargetedLocationData.class).get();
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(loc).getPosition());
|
||||
public void setCompassTarget(Location location) {
|
||||
TargetedLocationData target = this.player.getOrCreate(TargetedLocationData.class).get();
|
||||
target.set(Keys.TARGETED_LOCATION, SpongeUtil.getLocation(location).getPosition());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void loadData() {
|
||||
public void setWeather(PlotWeather weather) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveData() {
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(final PlotWeather weather) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotGamemode getGamemode() {
|
||||
final GameMode gamemode = player.getGameModeData().type().get();
|
||||
public PlotGameMode getGameMode() {
|
||||
GameMode gamemode = this.player.getGameModeData().type().get();
|
||||
if (gamemode == GameModes.ADVENTURE) {
|
||||
return PlotGamemode.ADVENTURE;
|
||||
return PlotGameMode.ADVENTURE;
|
||||
}
|
||||
if (gamemode == GameModes.CREATIVE) {
|
||||
return PlotGamemode.CREATIVE;
|
||||
return PlotGameMode.CREATIVE;
|
||||
}
|
||||
if (gamemode == GameModes.SPECTATOR) {
|
||||
return PlotGamemode.SPECTATOR;
|
||||
return PlotGameMode.SPECTATOR;
|
||||
}
|
||||
if (gamemode == GameModes.SURVIVAL) {
|
||||
return PlotGamemode.SURVIVAL;
|
||||
return PlotGameMode.SURVIVAL;
|
||||
}
|
||||
throw new UnsupportedOperationException("INVALID GAMEMODE");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGamemode(final PlotGamemode gamemode) {
|
||||
switch (gamemode) {
|
||||
public void setGameMode(PlotGameMode gameMode) {
|
||||
switch (gameMode) {
|
||||
case ADVENTURE:
|
||||
player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.ADVENTURE);
|
||||
return;
|
||||
case CREATIVE:
|
||||
player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.CREATIVE);
|
||||
return;
|
||||
case SPECTATOR:
|
||||
player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.SPECTATOR);
|
||||
return;
|
||||
case SURVIVAL:
|
||||
player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
this.player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTime(final long time) {
|
||||
public void setTime(long time) {
|
||||
// TODO Auto-generated method stub
|
||||
if (time != Long.MAX_VALUE) {} else {}
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFlight(final boolean fly) {
|
||||
player.offer(Keys.IS_FLYING, fly);
|
||||
player.offer(Keys.CAN_FLY, fly);
|
||||
public void setFlight(boolean fly) {
|
||||
this.player.offer(Keys.IS_FLYING, fly);
|
||||
this.player.offer(Keys.CAN_FLY, fly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playMusic(final Location loc, final int id) {
|
||||
public void playMusic(Location location, int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
player.playSound(null, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(null, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2256:
|
||||
player.playSound(SoundTypes.RECORDS_11, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_11, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2257:
|
||||
player.playSound(SoundTypes.RECORDS_13, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_13, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2258:
|
||||
player.playSound(SoundTypes.RECORDS_BLOCKS, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_BLOCKS, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2259:
|
||||
player.playSound(SoundTypes.RECORDS_CAT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_CAT, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2260:
|
||||
player.playSound(SoundTypes.RECORDS_CHIRP, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_CHIRP, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2261:
|
||||
player.playSound(SoundTypes.RECORDS_FAR, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_FAR, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2262:
|
||||
player.playSound(SoundTypes.RECORDS_MALL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_MALL, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2263:
|
||||
player.playSound(SoundTypes.RECORDS_MELLOHI, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_MELLOHI, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2264:
|
||||
player.playSound(SoundTypes.RECORDS_STAL, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_STAL, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2265:
|
||||
player.playSound(SoundTypes.RECORDS_STRAD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_STRAD, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2266:
|
||||
player.playSound(SoundTypes.RECORDS_WAIT, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_WAIT, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
case 2267:
|
||||
player.playSound(SoundTypes.RECORDS_WARD, SpongeUtil.getLocation(loc).getPosition(), 1);
|
||||
this.player.playSound(SoundTypes.RECORDS_WARD, SpongeUtil.getLocation(location).getPosition(), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(final String message) {
|
||||
player.kick(SpongeUtil.getText(message));
|
||||
public void kick(String message) {
|
||||
this.player.kick(SpongeUtil.getText(message));
|
||||
}
|
||||
|
||||
@Override public void stopSpectating() {
|
||||
@ -257,6 +250,6 @@ public class SpongePlayer extends PlotPlayer {
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
BanService service = Sponge.getServiceManager().provide(BanService.class).get();
|
||||
return service.isBanned(player.getProfile());
|
||||
return service.isBanned(this.player.getProfile());
|
||||
}
|
||||
}
|
||||
|
@ -53,24 +53,29 @@ import java.util.Optional;
|
||||
public class SpongeUtil extends WorldUtil {
|
||||
|
||||
public static Cause CAUSE = Cause.of(NamedCause.source("PlotSquared"));
|
||||
|
||||
public static Location getLocation(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
private static BiomeType[] biomes;
|
||||
private static HashMap<String, Integer> biomeMap;
|
||||
|
||||
private static HashMap<BlockState, PlotBlock> stateMap;
|
||||
private static BlockState[] stateArray;
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
private static World lastWorld;
|
||||
private static String last;
|
||||
|
||||
public static Location getLocation(Entity player) {
|
||||
String world = player.getWorld().getName();
|
||||
org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public static BiomeType getBiome(String biome) {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
return biomes[biomeMap.get(biome.toUpperCase())];
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getCause(Cause cause, Class<T> clazz) {
|
||||
Optional<?> root = Optional.of(cause.root());
|
||||
if (root.isPresent()) {
|
||||
@ -114,7 +119,7 @@ public class SpongeUtil extends WorldUtil {
|
||||
return TextSerializers.LEGACY_FORMATTING_CODE.deserialize(C.color(m));
|
||||
}
|
||||
|
||||
public static Translation getTranslation(final String m) {
|
||||
public static Translation getTranslation(String m) {
|
||||
return new Translation() {
|
||||
|
||||
@Override
|
||||
@ -123,19 +128,16 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(final Locale l, final Object... args) {
|
||||
public String get(Locale l, Object... args) {
|
||||
return m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(final Locale l) {
|
||||
public String get(Locale l) {
|
||||
return m;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static HashMap<BlockState, PlotBlock> stateMap;
|
||||
private static BlockState[] stateArray;
|
||||
|
||||
private static void initBlockCache() {
|
||||
try {
|
||||
@ -171,28 +173,25 @@ public class SpongeUtil extends WorldUtil {
|
||||
return stateMap.get(state);
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.spongepowered.api.world.Location<World> block) {
|
||||
public static Location getLocation(org.spongepowered.api.world.Location<World> block) {
|
||||
return getLocation(block.getExtent().getName(), block);
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final Entity player) {
|
||||
final String world = player.getWorld().getName();
|
||||
final Vector3d rot = player.getRotation();
|
||||
final float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
final org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
final Vector3i pos = loc.getBlockPosition();
|
||||
|
||||
public static Location getLocationFull(Entity player) {
|
||||
String world = player.getWorld().getName();
|
||||
Vector3d rot = player.getRotation();
|
||||
float[] pitchYaw = MathMan.getPitchAndYaw((float) rot.getX(), (float) rot.getY(), (float) rot.getZ());
|
||||
org.spongepowered.api.world.Location loc = player.getLocation();
|
||||
Vector3i pos = loc.getBlockPosition();
|
||||
return new Location(world, pos.getX(), pos.getY(), pos.getZ(), pitchYaw[1], pitchYaw[0]);
|
||||
}
|
||||
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
|
||||
public static PlotPlayer getPlayer(final Player player) {
|
||||
|
||||
public static PlotPlayer getPlayer(Player player) {
|
||||
if (player == lastPlayer) {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
final String name = player.getName();
|
||||
final PlotPlayer pp = UUIDHandler.getPlayer(name);
|
||||
String name = player.getName();
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(name);
|
||||
if (pp != null) {
|
||||
return pp;
|
||||
}
|
||||
@ -201,22 +200,19 @@ public class SpongeUtil extends WorldUtil {
|
||||
lastPlayer = player;
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Player getPlayer(final PlotPlayer player) {
|
||||
|
||||
public static Player getPlayer(PlotPlayer player) {
|
||||
if (player instanceof SpongePlayer) {
|
||||
return ((SpongePlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static World lastWorld;
|
||||
private static String last;
|
||||
|
||||
public static World getWorld(final String world) {
|
||||
public static World getWorld(String world) {
|
||||
if (StringMan.isEqual(world, last)) {
|
||||
return lastWorld;
|
||||
}
|
||||
final Optional<World> optional = Sponge.getServer().getWorld(world);
|
||||
Optional<World> optional = Sponge.getServer().getWorld(world);
|
||||
if (!optional.isPresent()) {
|
||||
last = null;
|
||||
return lastWorld = null;
|
||||
@ -224,18 +220,18 @@ public class SpongeUtil extends WorldUtil {
|
||||
last = world;
|
||||
return lastWorld = optional.get();
|
||||
}
|
||||
|
||||
public static void removePlayer(final String player) {
|
||||
|
||||
public static void removePlayer(String player) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
}
|
||||
|
||||
public static Location getLocation(final String world, final org.spongepowered.api.world.Location spawn) {
|
||||
|
||||
public static Location getLocation(String world, org.spongepowered.api.world.Location spawn) {
|
||||
return new Location(world, spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
|
||||
}
|
||||
|
||||
public static String getWorldName(final org.spongepowered.api.world.Location origin) {
|
||||
final Extent extent = origin.getExtent();
|
||||
|
||||
public static String getWorldName(org.spongepowered.api.world.Location origin) {
|
||||
Extent extent = origin.getExtent();
|
||||
if (extent == lastWorld) {
|
||||
return lastWorld.getName();
|
||||
}
|
||||
@ -245,13 +241,13 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static org.spongepowered.api.world.Location getLocation(final Location loc) {
|
||||
final Optional<World> world = SpongeMain.THIS.getServer().getWorld(loc.getWorld());
|
||||
|
||||
public static org.spongepowered.api.world.Location<World> getLocation(Location location) {
|
||||
Optional<World> world = SpongeMain.THIS.getServer().getWorld(location.getWorld());
|
||||
if (!world.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
return new org.spongepowered.api.world.Location(world.get(), loc.getX(), loc.getY(), loc.getZ());
|
||||
return new org.spongepowered.api.world.Location<>(world.get(), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static Location getLocation(String world, Vector3i position) {
|
||||
@ -263,8 +259,8 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(final PlotBlock block) {
|
||||
final BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
||||
public boolean isBlockSolid(PlotBlock block) {
|
||||
BlockState state = SpongeUtil.getBlockState(block.id, block.data);
|
||||
Optional<SolidCubeProperty> property = state.getType().getProperty(SolidCubeProperty.class);
|
||||
if (property.isPresent()) {
|
||||
return property.get().getValue();
|
||||
@ -277,42 +273,42 @@ public class SpongeUtil extends WorldUtil {
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
try {
|
||||
|
||||
double match;
|
||||
short id;
|
||||
byte data;
|
||||
final String[] split = name.split(":");
|
||||
String[] split = name.split(":");
|
||||
if (split.length == 2) {
|
||||
data = Byte.parseByte(split[1]);
|
||||
name = split[0];
|
||||
} else {
|
||||
data = 0;
|
||||
}
|
||||
short id;
|
||||
double match;
|
||||
if (MathMan.isInteger(split[0])) {
|
||||
id = Short.parseShort(split[0]);
|
||||
match = 0;
|
||||
} else {
|
||||
List<BlockType> types = ReflectionUtils.getStaticFields(BlockTypes.class);
|
||||
final StringComparison<BlockType>.ComparisonResult comparison =
|
||||
StringComparison<BlockType>.ComparisonResult comparison =
|
||||
new StringComparison<BlockType>(name, types.toArray(new BlockType[types.size()])) {
|
||||
@Override
|
||||
public String getString(final BlockType type) {
|
||||
public String getString(BlockType type) {
|
||||
return type.getId();
|
||||
}
|
||||
}.getBestMatchAdvanced();
|
||||
match = comparison.match;
|
||||
id = SpongeUtil.getPlotBlock(comparison.best.getDefaultState()).id;
|
||||
}
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
PlotBlock block = new PlotBlock(id, data);
|
||||
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(final PlotBlock block) {
|
||||
public String getClosestMatchingName(PlotBlock block) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@ -326,13 +322,13 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addItems(final String world, final PlotItem items) {
|
||||
public boolean addItems(String world, PlotItem items) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("NOT IMPLEMENTED YET");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(final String biome) {
|
||||
public int getBiomeFromString(String biome) {
|
||||
if (biomes == null) {
|
||||
initBiomeCache();
|
||||
}
|
||||
@ -340,28 +336,28 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBiome(final String world, final int x, final int z) {
|
||||
public String getBiome(String world, int x, int z) {
|
||||
return SpongeUtil.getWorld(world).getBiome(x, z).getName().toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(final Location loc) {
|
||||
final BlockState state = SpongeUtil.getWorld(loc.getWorld()).getBlock(loc.getX(), loc.getY(), loc.getZ());
|
||||
public PlotBlock getBlock(Location location) {
|
||||
BlockState state = SpongeUtil.getWorld(location.getWorld()).getBlock(location.getX(), location.getY(), location.getZ());
|
||||
return SpongeUtil.getPlotBlock(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getSpawn(final String world) {
|
||||
final Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
public Location getSpawn(String world) {
|
||||
Location result = SpongeUtil.getLocation(world, SpongeUtil.getWorld(world).getSpawnLocation());
|
||||
result.setY(getHighestBlock(world, result.getX(), result.getZ()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawn(Location loc) {
|
||||
World world = getWorld(loc.getWorld());
|
||||
public void setSpawn(Location location) {
|
||||
World world = getWorld(location.getWorld());
|
||||
if (world != null) {
|
||||
world.getProperties().setSpawnPosition(new Vector3i(loc.getX(), loc.getY(), loc.getZ()));
|
||||
world.getProperties().setSpawnPosition(new Vector3i(location.getX(), location.getY(), location.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,22 +367,22 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSign(final Location loc) {
|
||||
final World world = SpongeUtil.getWorld(loc.getWorld());
|
||||
final Optional<TileEntity> block = world.getTileEntity(loc.getX(), loc.getY(), loc.getZ());
|
||||
public String[] getSign(Location location) {
|
||||
World world = SpongeUtil.getWorld(location.getWorld());
|
||||
Optional<TileEntity> block = world.getTileEntity(location.getX(), location.getY(), location.getZ());
|
||||
if (!block.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return null;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final Optional<SignData> optional = sign.get(SignData.class);
|
||||
Sign sign = (Sign) tile;
|
||||
Optional<SignData> optional = sign.get(SignData.class);
|
||||
if (!optional.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
final String[] result = new String[4];
|
||||
String[] result = new String[4];
|
||||
ListValue<Text> lines = optional.get().lines();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result[i] = lines.get(i).toString();
|
||||
@ -395,7 +391,7 @@ public class SpongeUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world) {
|
||||
public boolean isWorld(String world) {
|
||||
return SpongeUtil.getWorld(world) != null;
|
||||
}
|
||||
|
||||
@ -406,12 +402,12 @@ public class SpongeUtil extends WorldUtil {
|
||||
|
||||
@Override
|
||||
public int getHighestBlock(String worldname, int x, int z) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
if (world == null) {
|
||||
return 64;
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
final BlockState block = world.getBlock(x, y, z);
|
||||
BlockState block = world.getBlock(x, y, z);
|
||||
if (block.getType() != BlockTypes.AIR) {
|
||||
return y + 1;
|
||||
}
|
||||
@ -421,18 +417,18 @@ public class SpongeUtil extends WorldUtil {
|
||||
|
||||
@Override
|
||||
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
world.setBlock(x, y, z, BlockTypes.WALL_SIGN.getDefaultState());
|
||||
final Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
Optional<TileEntity> block = world.getTileEntity(x, y, z);
|
||||
if (!block.isPresent()) {
|
||||
return;
|
||||
}
|
||||
final TileEntity tile = block.get();
|
||||
TileEntity tile = block.get();
|
||||
if (!(tile instanceof Sign)) {
|
||||
return;
|
||||
}
|
||||
final Sign sign = (Sign) tile;
|
||||
final List<Text> text = new ArrayList<>(4);
|
||||
Sign sign = (Sign) tile;
|
||||
List<Text> text = new ArrayList<>(4);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
text.add(SpongeUtil.getText(lines[i]));
|
||||
}
|
||||
@ -441,8 +437,8 @@ public class SpongeUtil extends WorldUtil {
|
||||
|
||||
@Override
|
||||
public void setBiomes(String worldname, RegionWrapper region, String biomename) {
|
||||
final World world = SpongeUtil.getWorld(worldname);
|
||||
final BiomeType biome = SpongeUtil.getBiome(biomename);
|
||||
World world = SpongeUtil.getWorld(worldname);
|
||||
BiomeType biome = SpongeUtil.getBiome(biomename);
|
||||
for (int x = region.minX; x <= region.maxX; x++) {
|
||||
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||
world.setBiome(x, z, biome);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.plotsquared.sponge.util.block;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -18,24 +17,29 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import org.spongepowered.api.world.Chunk;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class FastQueue extends SlowQueue {
|
||||
|
||||
public HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
public final SendChunk chunkSender;
|
||||
public HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
|
||||
public FastQueue() throws NoSuchMethodException, RuntimeException {
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toUpdate.isEmpty()) {
|
||||
if (FastQueue.this.toUpdate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
||||
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue.this.toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && (count < 128)) {
|
||||
chunks.add(i.next().getValue());
|
||||
i.remove();
|
||||
@ -47,31 +51,31 @@ public class FastQueue extends SlowQueue {
|
||||
update(chunks);
|
||||
}
|
||||
}, 1);
|
||||
chunkSender = new SendChunk();
|
||||
this.chunkSender = new SendChunk();
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
public void update(final Collection<Chunk> chunks) {
|
||||
public void update(Collection<Chunk> chunks) {
|
||||
if (chunks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (!MainUtil.canSendChunk) {
|
||||
for (final Chunk chunk : chunks) {
|
||||
for (Chunk chunk : chunks) {
|
||||
chunk.unloadChunk();
|
||||
chunk.loadChunk(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
chunkSender.sendChunk(chunks);
|
||||
} catch (final Throwable e) {
|
||||
this.chunkSender.sendChunk(chunks);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param pc
|
||||
*/
|
||||
@Override
|
||||
@ -80,12 +84,12 @@ public class FastQueue extends SlowQueue {
|
||||
Chunk spongeChunk = pc.getChunk();
|
||||
net.minecraft.world.World nmsWorld = (net.minecraft.world.World) spongeChunk.getWorld();
|
||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, spongeChunk);
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, spongeChunk);
|
||||
}
|
||||
spongeChunk.loadChunk(true);
|
||||
try {
|
||||
final boolean flag = !nmsWorld.provider.getHasNoSky();
|
||||
boolean flag = !nmsWorld.provider.getHasNoSky();
|
||||
// Sections
|
||||
net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
|
||||
ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray();
|
||||
@ -97,12 +101,12 @@ public class FastQueue extends SlowQueue {
|
||||
while (iter.hasNext()) {
|
||||
Entry<BlockPos,TileEntity> tile = iter.next();
|
||||
BlockPos pos = tile.getKey();
|
||||
final int lx = pos.getX() & 15;
|
||||
final int ly = pos.getY();
|
||||
final int lz = pos.getZ() & 15;
|
||||
final int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||
final int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||
final char[] array = fs.getIdArray(j);
|
||||
int lx = pos.getX() & 15;
|
||||
int ly = pos.getY();
|
||||
int lz = pos.getZ() & 15;
|
||||
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||
char[] array = fs.getIdArray(j);
|
||||
if (array == null) {
|
||||
continue;
|
||||
}
|
||||
@ -121,7 +125,7 @@ public class FastQueue extends SlowQueue {
|
||||
if (fs.getCount(j) == 0) {
|
||||
continue;
|
||||
}
|
||||
final char[] newArray = fs.getIdArray(j);
|
||||
char[] newArray = fs.getIdArray(j);
|
||||
if (newArray == null) {
|
||||
continue;
|
||||
}
|
||||
@ -132,10 +136,10 @@ public class FastQueue extends SlowQueue {
|
||||
sections[j] = section;
|
||||
continue;
|
||||
}
|
||||
final char[] currentArray = section.getData();
|
||||
char[] currentArray = section.getData();
|
||||
boolean fill = true;
|
||||
for (int k = 0; k < newArray.length; k++) {
|
||||
final char n = newArray[k];
|
||||
char n = newArray[k];
|
||||
switch (n) {
|
||||
case 0:
|
||||
fill = false;
|
||||
@ -176,7 +180,7 @@ public class FastQueue extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param wrap
|
||||
*/
|
||||
@Override
|
||||
@ -185,15 +189,15 @@ public class FastQueue extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param pc
|
||||
*/
|
||||
@Override
|
||||
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
|
||||
try {
|
||||
FastChunk bc = (FastChunk) pc;
|
||||
final Chunk spongeChunk = bc.getChunk();
|
||||
final net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
|
||||
Chunk spongeChunk = bc.getChunk();
|
||||
net.minecraft.world.chunk.Chunk nmsChunk = (net.minecraft.world.chunk.Chunk) spongeChunk;
|
||||
if (!spongeChunk.isLoaded()) {
|
||||
if (!spongeChunk.loadChunk(false)) {
|
||||
return false;
|
||||
@ -204,14 +208,14 @@ public class FastQueue extends SlowQueue {
|
||||
}
|
||||
// TODO load adjaced chunks
|
||||
nmsChunk.generateSkylightMap();
|
||||
if ((bc.getTotalRelight() == 0 && !fixAll)) {
|
||||
if (bc.getTotalRelight() == 0 && !fixAll) {
|
||||
return true;
|
||||
}
|
||||
ExtendedBlockStorage[] sections = nmsChunk.getBlockStorageArray();
|
||||
net.minecraft.world.World nmsWorld = nmsChunk.getWorld();
|
||||
|
||||
final int X = pc.getX() << 4;
|
||||
final int Z = pc.getZ() << 4;
|
||||
int X = pc.getX() << 4;
|
||||
int Z = pc.getZ() << 4;
|
||||
|
||||
|
||||
for (int j = 0; j < sections.length; j++) {
|
||||
@ -222,14 +226,14 @@ public class FastQueue extends SlowQueue {
|
||||
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
||||
continue;
|
||||
}
|
||||
final char[] array = section.getData();
|
||||
char[] array = section.getData();
|
||||
int l = PseudoRandom.random.random(2);
|
||||
for (int k = 0; k < array.length; k++) {
|
||||
final int i = array[k];
|
||||
int i = array[k];
|
||||
if (i < 16) {
|
||||
continue;
|
||||
}
|
||||
final short id = (short) (i >> 4);
|
||||
short id = (short) (i >> 4);
|
||||
switch (id) { // Lighting
|
||||
default:
|
||||
if (!fixAll) {
|
||||
@ -254,9 +258,9 @@ public class FastQueue extends SlowQueue {
|
||||
case 130:
|
||||
case 138:
|
||||
case 169:
|
||||
final int x = MainUtil.x_loc[j][k];
|
||||
final int y = MainUtil.y_loc[j][k];
|
||||
final int z = MainUtil.z_loc[j][k];
|
||||
int x = MainUtil.x_loc[j][k];
|
||||
int y = MainUtil.y_loc[j][k];
|
||||
int z = MainUtil.z_loc[j][k];
|
||||
if (isSurrounded(sections, x, y, z)) {
|
||||
continue;
|
||||
}
|
||||
@ -266,7 +270,7 @@ public class FastQueue extends SlowQueue {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -302,17 +306,17 @@ public class FastQueue extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param world
|
||||
* @param locs
|
||||
* @param locations
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
World spongeWorld = SpongeUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locs) {
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, spongeWorld.getChunk(loc.x, 0, loc.z).get());
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, spongeWorld.getChunk(loc.x, 0, loc.z).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,18 +8,18 @@ import org.spongepowered.api.world.extent.MutableBiomeArea;
|
||||
import org.spongepowered.api.world.extent.MutableBlockVolume;
|
||||
|
||||
public class GenChunk extends PlotChunk<Chunk> {
|
||||
|
||||
public boolean modified = false;
|
||||
private final MutableBlockVolume terain;
|
||||
|
||||
private final MutableBlockVolume terrain;
|
||||
private final MutableBiomeArea biome;
|
||||
private final int bz;
|
||||
private final int bx;
|
||||
|
||||
public GenChunk(MutableBlockVolume terain, MutableBiomeArea biome, ChunkWrapper wrap) {
|
||||
public boolean modified = false;
|
||||
|
||||
public GenChunk(MutableBlockVolume terrain, MutableBiomeArea biome, ChunkWrapper wrap) {
|
||||
super(wrap);
|
||||
this.bx = wrap.x << 4;
|
||||
this.bz = wrap.z << 4;
|
||||
this.terain = terain;
|
||||
this.terrain = terrain;
|
||||
this.biome = biome;
|
||||
}
|
||||
|
||||
@ -32,13 +32,13 @@ public class GenChunk extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (this.biome != null) {
|
||||
this.biome.setBiome(bx + x, bz + z, SpongeUtil.getBiome(biome));
|
||||
this.biome.setBiome(this.bx + x, this.bz + z, SpongeUtil.getBiome(biome));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
terain.setBlock(bx + x, y, bz + z, SpongeUtil.getBlockState(id, data));
|
||||
this.terrain.setBlock(this.bx + x, y, this.bz + z, SpongeUtil.getBlockState(id, data));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user