mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-13 10:54:43 +02:00
Major code reformatting
This commit is contained in:
@ -20,31 +20,31 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(final PlotMessage m, final String color) {
|
||||
public void color(PlotMessage m, String color) {
|
||||
m.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
||||
final List<FancyMessage> lines = new ArrayList<>();
|
||||
for (final PlotMessage tooltip : tooltips) {
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
List<FancyMessage> lines = new ArrayList<>();
|
||||
for (PlotMessage tooltip : tooltips) {
|
||||
lines.add(tooltip.$(this));
|
||||
}
|
||||
m.$(this).formattedTooltip(lines);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(final PlotMessage m, final String command) {
|
||||
public void command(PlotMessage m, String command) {
|
||||
m.$(this).command(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(final PlotMessage m, final String text) {
|
||||
public void text(PlotMessage m, String text) {
|
||||
m.$(this).then(ChatColor.stripColor(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
||||
public void send(PlotMessage m, PlotPlayer player) {
|
||||
if (ConsolePlayer.isConsole(player)) {
|
||||
player.sendMessage(m.$(this).toOldMessageFormat());
|
||||
} else {
|
||||
@ -53,7 +53,7 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(final PlotMessage m, final String command) {
|
||||
public void suggest(PlotMessage m, String command) {
|
||||
m.$(this).suggest(command);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -31,8 +31,8 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
|
||||
final String[] args) {
|
||||
public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel,
|
||||
String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
||||
}
|
||||
@ -47,7 +47,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String perm) {
|
||||
public boolean hasPermission(String permission) {
|
||||
return commandSender.hasPermission(commandLabel);
|
||||
}
|
||||
|
||||
@ -66,12 +66,12 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
|
||||
final String[] strings) {
|
||||
public List<String> onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String s,
|
||||
String[] strings) {
|
||||
if (!(commandSender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||
PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||
if (strings.length < 1) {
|
||||
if (strings.length == 0 || "plots".startsWith(s)) {
|
||||
return Collections.singletonList("plots");
|
||||
@ -80,11 +80,11 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
if (strings.length > 1) {
|
||||
return null;
|
||||
}
|
||||
final Set<String> tabOptions = new HashSet<>();
|
||||
final String arg = strings[0].toLowerCase();
|
||||
Set<String> tabOptions = new HashSet<>();
|
||||
String arg = strings[0].toLowerCase();
|
||||
ArrayList<String> labels = new ArrayList<>();
|
||||
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||
final String label = cmd.getCommand();
|
||||
for (Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||
String label = cmd.getCommand();
|
||||
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
||||
aliases.add(label);
|
||||
for (String alias : aliases) {
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class BukkitEconHandler extends EconHandler {
|
||||
|
||||
@ -19,80 +17,80 @@ public class BukkitEconHandler extends EconHandler {
|
||||
|
||||
public Economy getEconomy() {
|
||||
init();
|
||||
return econ;
|
||||
return this.econ;
|
||||
}
|
||||
|
||||
public Permission getPermissions() {
|
||||
init();
|
||||
return perms;
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
public boolean init() {
|
||||
if (econ == null || perms == null) {
|
||||
if (this.econ == null || this.perms == null) {
|
||||
setupPermissions();
|
||||
setupEconomy();
|
||||
}
|
||||
return econ != null && perms != null;
|
||||
return this.econ != null && this.perms != null;
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
final RegisteredServiceProvider<Permission> permissionProvider =
|
||||
RegisteredServiceProvider<Permission> permissionProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
perms = permissionProvider.getProvider();
|
||||
this.perms = permissionProvider.getProvider();
|
||||
}
|
||||
return perms != null;
|
||||
return this.perms != null;
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
final RegisteredServiceProvider<Economy> economyProvider =
|
||||
RegisteredServiceProvider<Economy> economyProvider =
|
||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
econ = economyProvider.getProvider();
|
||||
this.econ = economyProvider.getProvider();
|
||||
}
|
||||
return econ != null;
|
||||
return this.econ != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMoney(final PlotPlayer player) {
|
||||
final double bal = super.getMoney(player);
|
||||
public double getMoney(PlotPlayer player) {
|
||||
double bal = super.getMoney(player);
|
||||
if (Double.isNaN(bal)) {
|
||||
return econ.getBalance(((BukkitPlayer) player).player);
|
||||
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||
}
|
||||
return bal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withdrawMoney(final PlotPlayer player, final double amount) {
|
||||
econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||
public void withdrawMoney(PlotPlayer player, double amount) {
|
||||
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depositMoney(final PlotPlayer player, final double amount) {
|
||||
econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||
public void depositMoney(PlotPlayer player, double amount) {
|
||||
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void depositMoney(final OfflinePlotPlayer player, final double amount) {
|
||||
econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPermission(final String world, final String player, final String perm, final boolean value) {
|
||||
public void setPermission(String world, String player, String perm, boolean value) {
|
||||
if (value) {
|
||||
perms.playerAdd(world, player, perm);
|
||||
this.perms.playerAdd(world, player, perm);
|
||||
} else {
|
||||
perms.playerRemove(world, player, perm);
|
||||
this.perms.playerRemove(world, player, perm);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(final String world, final String player, final String perm) {
|
||||
return perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||
public boolean hasPermission(String world, String player, String perm) {
|
||||
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBalance(PlotPlayer player) {
|
||||
return econ.getBalance(player.getName());
|
||||
return this.econ.getBalance(player.getName());
|
||||
}
|
||||
}
|
||||
|
@ -35,91 +35,91 @@ import java.util.UUID;
|
||||
|
||||
public class BukkitEventUtil extends EventUtil {
|
||||
|
||||
public Player getPlayer(final PlotPlayer player) {
|
||||
public Player getPlayer(PlotPlayer player) {
|
||||
if (player instanceof BukkitPlayer) {
|
||||
return ((BukkitPlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean callEvent(final Event event) {
|
||||
public boolean callEvent(Event event) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto) {
|
||||
public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callTeleport(final PlotPlayer player, final Location from, final Plot plot) {
|
||||
public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callClear(final Plot plot) {
|
||||
public boolean callClear(Plot plot) {
|
||||
return callEvent(new PlotClearEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(final Plot plot) {
|
||||
public void callDelete(Plot plot) {
|
||||
callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagAdd(final Flag flag, final Plot plot) {
|
||||
public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final Plot plot) {
|
||||
public boolean callFlagRemove(Flag flag, Plot plot) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(final Plot plot, final ArrayList<PlotId> plots) {
|
||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getArea().worldname), plot, plots));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callUnlink(final PlotArea area, final ArrayList<PlotId> plots) {
|
||||
public boolean callUnlink(PlotArea area, ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callEntry(final PlotPlayer player, final Plot plot) {
|
||||
public void callEntry(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callLeave(final PlotPlayer player, final Plot plot) {
|
||||
public void callLeave(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added) {
|
||||
public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) {
|
||||
public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) {
|
||||
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
return event.getRating();
|
||||
}
|
||||
|
@ -49,11 +49,11 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
}
|
||||
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
||||
@Override
|
||||
public void setBiome(final int a, final int b, final Biome c) {
|
||||
public void setBiome(int a, int b, Biome c) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(final int a, final int b) {
|
||||
public Biome getBiome(int a, int b) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@ -76,8 +76,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
|
||||
System.gc();
|
||||
System.gc();
|
||||
final short[][][] oldblocks = new short[256][width][length];
|
||||
final short[][][] newblocks = new short[256][width][length];
|
||||
final short[][][] oldBlocks = new short[256][width][length];
|
||||
final short[][][] newBlocks = new short[256][width][length];
|
||||
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
@ -86,38 +86,38 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
@Override
|
||||
public void run(int[] value) {
|
||||
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
||||
final int X = value[0];
|
||||
final int Z = value[1];
|
||||
final short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
||||
final int xb = (X << 4) - bx;
|
||||
final int zb = (Z << 4) - bz;
|
||||
int X = value[0];
|
||||
int Z = value[1];
|
||||
short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
||||
int xb = (X << 4) - bx;
|
||||
int zb = (Z << 4) - bz;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
if (result[i] == null) {
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int x = MainUtil.x_loc[i][j] + xb;
|
||||
int x = MainUtil.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) {
|
||||
continue;
|
||||
}
|
||||
final int z = MainUtil.z_loc[i][j] + zb;
|
||||
int z = MainUtil.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) {
|
||||
continue;
|
||||
}
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
oldblocks[y][x][z] = 0;
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
oldBlocks[y][x][z] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < result[i].length; j++) {
|
||||
final int x = MainUtil.x_loc[i][j] + xb;
|
||||
int x = MainUtil.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) {
|
||||
continue;
|
||||
}
|
||||
final int z = MainUtil.z_loc[i][j] + zb;
|
||||
int z = MainUtil.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) {
|
||||
continue;
|
||||
}
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
oldblocks[y][x][z] = result[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
oldBlocks[y][x][z] = result[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,19 +128,19 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final int size = width * length;
|
||||
final int[] changes = new int[size];
|
||||
final int[] faces = new int[size];
|
||||
final int[] data = new int[size];
|
||||
final int[] air = new int[size];
|
||||
final int[] variety = new int[size];
|
||||
int size = width * length;
|
||||
int[] changes = new int[size];
|
||||
int[] faces = new int[size];
|
||||
int[] data = new int[size];
|
||||
int[] air = new int[size];
|
||||
int[] variety = new int[size];
|
||||
int i = 0;
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
final HashSet<Short> types = new HashSet<>();
|
||||
HashSet<Short> types = new HashSet<>();
|
||||
for (int y = 0; y < 256; y++) {
|
||||
final short old = oldblocks[y][x][z];
|
||||
final short now = newblocks[y][x][z];
|
||||
short old = oldBlocks[y][x][z];
|
||||
short now = newBlocks[y][x][z];
|
||||
if (old != now) {
|
||||
changes[i]++;
|
||||
}
|
||||
@ -150,28 +150,28 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
// check vertices
|
||||
// modifications_adjacent
|
||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
||||
if (newblocks[y - 1][x][z] == 0) {
|
||||
if (newBlocks[y - 1][x][z] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
if (newblocks[y][x - 1][z] == 0) {
|
||||
if (newBlocks[y][x - 1][z] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
if (newblocks[y][x][z - 1] == 0) {
|
||||
if (newBlocks[y][x][z - 1] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
if (newblocks[y + 1][x][z] == 0) {
|
||||
if (newBlocks[y + 1][x][z] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
if (newblocks[y][x + 1][z] == 0) {
|
||||
if (newBlocks[y][x + 1][z] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
if (newblocks[y][x][z + 1] == 0) {
|
||||
if (newBlocks[y][x][z + 1] == 0) {
|
||||
faces[i]++;
|
||||
}
|
||||
}
|
||||
|
||||
final Material material = Material.getMaterial(now);
|
||||
final Class<? extends MaterialData> md = material.getData();
|
||||
Material material = Material.getMaterial(now);
|
||||
Class<? extends MaterialData> md = material.getData();
|
||||
if (md.equals(Directional.class)) {
|
||||
data[i] += 8;
|
||||
} else if (!md.equals(MaterialData.class)) {
|
||||
@ -188,7 +188,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
// put in analysis obj
|
||||
|
||||
// run whenDone
|
||||
final PlotAnalysis analysis = new PlotAnalysis();
|
||||
PlotAnalysis analysis = new PlotAnalysis();
|
||||
analysis.changes = (int) (MathMan.getMean(changes) * 100);
|
||||
analysis.faces = (int) (MathMan.getMean(faces) * 100);
|
||||
analysis.data = (int) (MathMan.getMean(data) * 100);
|
||||
@ -217,8 +217,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
|
||||
@Override
|
||||
public void run(int[] value) {
|
||||
final int X = value[0];
|
||||
final int Z = value[1];
|
||||
int X = value[0];
|
||||
int Z = value[1];
|
||||
worldObj.loadChunk(X, Z);
|
||||
int minX;
|
||||
if (X == cbx) {
|
||||
@ -245,20 +245,20 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
maxZ = 16;
|
||||
}
|
||||
|
||||
final int cbx = X << 4;
|
||||
final int cbz = Z << 4;
|
||||
int cbx = X << 4;
|
||||
int cbz = Z << 4;
|
||||
|
||||
final int xb = cbx - bx;
|
||||
final int zb = cbz - bz;
|
||||
int xb = cbx - bx;
|
||||
int zb = cbz - bz;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
final int xx = cbx + x;
|
||||
int xx = cbx + x;
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
final int zz = cbz + z;
|
||||
int zz = cbz + z;
|
||||
for (int y = 0; y < 256; y++) {
|
||||
final Block block = worldObj.getBlockAt(xx, y, zz);
|
||||
final int xr = xb + x;
|
||||
final int zr = zb + z;
|
||||
newblocks[y][xr][zr] = (short) block.getTypeId();
|
||||
Block block = worldObj.getBlockAt(xx, y, zz);
|
||||
int xr = xb + x;
|
||||
int zr = zb + z;
|
||||
newBlocks[y][xr][zr] = (short) block.getTypeId();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -275,17 +275,17 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2,
|
||||
final PlotBlock[] blocks) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
public int checkModified(String worldname, int x1, int x2, int y1, int y2, int z1, int z2,
|
||||
PlotBlock[] blocks) {
|
||||
World world = BukkitUtil.getWorld(worldname);
|
||||
int count = 0;
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
final int id = block.getTypeId();
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
int id = block.getTypeId();
|
||||
boolean same = false;
|
||||
for (final PlotBlock p : blocks) {
|
||||
for (PlotBlock p : blocks) {
|
||||
if (id == p.id) {
|
||||
same = true;
|
||||
break;
|
||||
@ -301,15 +301,15 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
final int maxY = world.getMaxHeight();
|
||||
public int get_ey(String worldname, int sx, int ex, int sz, int ez, int sy) {
|
||||
World world = BukkitUtil.getWorld(worldname);
|
||||
int maxY = world.getMaxHeight();
|
||||
int ey = sy;
|
||||
for (int x = sx; x <= ex; x++) {
|
||||
for (int z = sz; z <= ez; z++) {
|
||||
for (int y = sy; y < maxY; y++) {
|
||||
if (y > ey) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (!block.getType().equals(Material.AIR)) {
|
||||
ey = y;
|
||||
}
|
||||
|
@ -19,11 +19,11 @@ import java.util.List;
|
||||
|
||||
public class BukkitInventoryUtil extends InventoryUtil {
|
||||
|
||||
public static ItemStack getItem(final PlotItemStack item) {
|
||||
public static ItemStack getItem(PlotItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
final ItemStack stack = new ItemStack(item.id, item.amount, item.data);
|
||||
ItemStack stack = new ItemStack(item.id, item.amount, item.data);
|
||||
ItemMeta meta = null;
|
||||
if (item.name != null) {
|
||||
meta = stack.getItemMeta();
|
||||
@ -33,8 +33,8 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
if (meta == null) {
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
final List<String> lore = new ArrayList<>();
|
||||
for (final String entry : item.lore) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String entry : item.lore) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
@ -46,12 +46,12 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(final PlotInventory inv) {
|
||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
final Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||
final PlotItemStack[] items = inv.getItems();
|
||||
public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.size * 9; i++) {
|
||||
final PlotItemStack item = items[i];
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
@ -61,19 +61,19 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(final PlotInventory inv) {
|
||||
public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
inv.player.deleteMeta("inventory");
|
||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
bp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item) {
|
||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
final InventoryView opened = bp.player.getOpenInventory();
|
||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
@ -81,22 +81,22 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
bp.player.updateInventory();
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(final ItemStack item) {
|
||||
public PlotItemStack getItem(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
final int id = item.getTypeId();
|
||||
final short data = item.getDurability();
|
||||
final int amount = item.getAmount();
|
||||
int id = item.getTypeId();
|
||||
short data = item.getDurability();
|
||||
int amount = item.getAmount();
|
||||
String name = null;
|
||||
String[] lore = null;
|
||||
if (item.hasItemMeta()) {
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
final List<String> itemLore = meta.getLore();
|
||||
List<String> itemLore = meta.getLore();
|
||||
lore = itemLore.toArray(new String[itemLore.size()]);
|
||||
}
|
||||
}
|
||||
@ -104,10 +104,10 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotItemStack[] getItems(final PlotPlayer player) {
|
||||
final BukkitPlayer bp = (BukkitPlayer) player;
|
||||
final PlayerInventory inv = bp.player.getInventory();
|
||||
final PlotItemStack[] items = new PlotItemStack[36];
|
||||
public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
BukkitPlayer bp = (BukkitPlayer) player;
|
||||
PlayerInventory inv = bp.player.getInventory();
|
||||
PlotItemStack[] items = new PlotItemStack[36];
|
||||
for (int i = 0; i < 36; i++) {
|
||||
items[i] = getItem(inv.getItem(i));
|
||||
}
|
||||
@ -115,12 +115,12 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(final PlotInventory inv) {
|
||||
public boolean isOpen(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
final InventoryView opened = bp.player.getOpenInventory();
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING && opened.getTitle() == null;
|
||||
}
|
||||
}
|
||||
|
@ -16,35 +16,35 @@ public class BukkitPlainChatManager extends ChatManager<List<StringBuilder>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void color(final PlotMessage m, final String color) {
|
||||
final List<StringBuilder> parts = m.$(this);
|
||||
public void color(PlotMessage m, String color) {
|
||||
List<StringBuilder> parts = m.$(this);
|
||||
parts.get(parts.size() - 1).insert(0, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
||||
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(final PlotMessage m, final String command) {
|
||||
public void command(PlotMessage m, String command) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(final PlotMessage m, final String text) {
|
||||
public void text(PlotMessage m, String text) {
|
||||
m.$(this).add(new StringBuilder(ChatColor.stripColor(text)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
||||
final StringBuilder built = new StringBuilder();
|
||||
for (final StringBuilder sb : m.$(this)) {
|
||||
public void send(PlotMessage m, PlotPlayer player) {
|
||||
StringBuilder built = new StringBuilder();
|
||||
for (StringBuilder sb : m.$(this)) {
|
||||
built.append(sb);
|
||||
}
|
||||
player.sendMessage(built.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(final PlotMessage m, final String command) {
|
||||
public void suggest(PlotMessage m, String command) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,10 +50,7 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Schematic Handler
|
||||
*
|
||||
|
||||
|
||||
* Schematic Handler.
|
||||
*/
|
||||
public class BukkitSchematicHandler extends SchematicHandler {
|
||||
|
||||
@ -66,10 +63,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
// Main positions
|
||||
Location[] corners = MainUtil.getCorners(world, regions);
|
||||
final Location bot = corners[0];
|
||||
final Location top = corners[1];
|
||||
Location top = corners[1];
|
||||
|
||||
final int width = (top.getX() - bot.getX()) + 1;
|
||||
final int height = (top.getY() - bot.getY()) + 1;
|
||||
int height = (top.getY() - bot.getY()) + 1;
|
||||
final int length = (top.getZ() - bot.getZ()) + 1;
|
||||
// Main Schematic tag
|
||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||
@ -136,16 +133,16 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
long start = System.currentTimeMillis();
|
||||
while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) {
|
||||
// save schematics
|
||||
final ChunkLoc chunk = chunks.remove(0);
|
||||
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||
ChunkLoc chunk = chunks.remove(0);
|
||||
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||
if (!bc.load(false)) {
|
||||
continue;
|
||||
}
|
||||
final int X = chunk.x;
|
||||
final int Z = chunk.z;
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
int xxb = X << 4;
|
||||
int zzb = Z << 4;
|
||||
int xxt = xxb + 15;
|
||||
@ -164,16 +161,16 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
zzt = p2z;
|
||||
}
|
||||
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||
final int ry = y - sy;
|
||||
final int i1 = ry * width * length;
|
||||
int ry = y - sy;
|
||||
int i1 = ry * width * length;
|
||||
for (int z = zzb; z <= zzt; z++) {
|
||||
final int rz = z - bz;
|
||||
final int i2 = i1 + (rz * width);
|
||||
int rz = z - bz;
|
||||
int i2 = i1 + (rz * width);
|
||||
for (int x = xxb; x <= xxt; x++) {
|
||||
final int rx = x - bx;
|
||||
final int index = i2 + rx;
|
||||
final Block block = worldObj.getBlockAt(x, y, z);
|
||||
final int id = block.getTypeId();
|
||||
int rx = x - bx;
|
||||
int index = i2 + rx;
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
int id = block.getTypeId();
|
||||
switch (id) {
|
||||
case 0:
|
||||
case 2:
|
||||
@ -281,13 +278,13 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
case 151:
|
||||
case 178: {
|
||||
// TODO implement fully
|
||||
final BlockState state = block.getState();
|
||||
BlockState state = block.getState();
|
||||
if (state != null) {
|
||||
final StateWrapper wrapper = new StateWrapper(state);
|
||||
final CompoundTag rawTag = wrapper.getTag();
|
||||
StateWrapper wrapper = new StateWrapper(state);
|
||||
CompoundTag rawTag = wrapper.getTag();
|
||||
if (rawTag != null) {
|
||||
final Map<String, Tag> values = new HashMap<>();
|
||||
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
values.put("id", new StringTag("id", wrapper.getId()));
|
||||
|
@ -29,13 +29,13 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
if (!SetupUtils.generators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final String testWorld = "CheckingPlotSquaredGenerator";
|
||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
String testWorld = "CheckingPlotSquaredGenerator";
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.isEnabled()) {
|
||||
final ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
||||
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
||||
if (generator != null) {
|
||||
PS.get().removePlotAreas(testWorld);
|
||||
final String name = plugin.getDescription().getName();
|
||||
String name = plugin.getDescription().getName();
|
||||
GeneratorWrapper<?> wrapped;
|
||||
if (generator instanceof GeneratorWrapper<?>) {
|
||||
wrapped = (GeneratorWrapper<?>) generator;
|
||||
@ -49,10 +49,10 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String setupWorld(final SetupObject object) {
|
||||
public String setupWorld(SetupObject object) {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
||||
final String world = object.world;
|
||||
String world = object.world;
|
||||
int type = object.type;
|
||||
String worldPath = "worlds." + object.world;
|
||||
if (!PS.get().config.contains(worldPath)) {
|
||||
@ -69,7 +69,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
||||
HashMap<String, Object> options = new HashMap<>();
|
||||
for (final ConfigurationNode step : steps) {
|
||||
for (ConfigurationNode step : steps) {
|
||||
options.put(step.getConstant(), step.getValue());
|
||||
}
|
||||
options.put("generator.type", object.type);
|
||||
@ -98,7 +98,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
for (final ConfigurationNode step : steps) {
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
||||
@ -114,7 +114,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
for (final ConfigurationNode step : steps) {
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
break;
|
||||
@ -122,7 +122,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
} catch (final IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (object.setupGenerator != null) {
|
||||
@ -142,7 +142,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
final WorldCreator wc = new WorldCreator(object.world);
|
||||
WorldCreator wc = new WorldCreator(object.world);
|
||||
wc.generator(object.setupGenerator);
|
||||
wc.environment(Environment.NORMAL);
|
||||
Bukkit.createWorld(wc);
|
||||
@ -166,34 +166,34 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
return object.world;
|
||||
}
|
||||
|
||||
public void setGenerator(final String world, final String generator) {
|
||||
if ((Bukkit.getWorlds().isEmpty()) || !Bukkit.getWorlds().get(0).getName().equals(world)) {
|
||||
public void setGenerator(String world, String generator) {
|
||||
if (Bukkit.getWorlds().isEmpty() || !Bukkit.getWorlds().get(0).getName().equals(world)) {
|
||||
return;
|
||||
}
|
||||
final File file = new File("bukkit.yml").getAbsoluteFile();
|
||||
final YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
File file = new File("bukkit.yml").getAbsoluteFile();
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
yml.set("worlds." + world + ".generator", generator);
|
||||
try {
|
||||
yml.save(file);
|
||||
} catch (final IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGenerator(final PlotArea plotworld) {
|
||||
public String getGenerator(PlotArea plotworld) {
|
||||
if (SetupUtils.generators.isEmpty()) {
|
||||
updateGenerators();
|
||||
}
|
||||
final World world = Bukkit.getWorld(plotworld.worldname);
|
||||
World world = Bukkit.getWorld(plotworld.worldname);
|
||||
if (world == null) {
|
||||
return null;
|
||||
}
|
||||
final ChunkGenerator generator = world.getGenerator();
|
||||
ChunkGenerator generator = world.getGenerator();
|
||||
if (!(generator instanceof BukkitPlotGenerator)) {
|
||||
return null;
|
||||
}
|
||||
for (final Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
|
||||
for (Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
|
||||
GeneratorWrapper<?> current = entry.getValue();
|
||||
if (current.equals(generator)) {
|
||||
return entry.getKey();
|
||||
|
@ -7,37 +7,38 @@ import org.bukkit.Bukkit;
|
||||
public class BukkitTaskManager extends TaskManager {
|
||||
|
||||
@Override
|
||||
public int taskRepeat(final Runnable r, final int interval) {
|
||||
public int taskRepeat(Runnable r, int interval) {
|
||||
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") @Override
|
||||
public int taskRepeatAsync(final Runnable r, final int interval) {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int taskRepeatAsync(Runnable r, int interval) {
|
||||
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskAsync(final Runnable r) {
|
||||
public void taskAsync(Runnable r) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void task(final Runnable r) {
|
||||
public void task(Runnable r) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLater(final Runnable r, final int delay) {
|
||||
public void taskLater(Runnable r, int delay) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void taskLaterAsync(final Runnable r, final int delay) {
|
||||
public void taskLaterAsync(Runnable r, int delay) {
|
||||
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelTask(final int task) {
|
||||
public void cancelTask(int task) {
|
||||
if (task != -1) {
|
||||
Bukkit.getScheduler().cancelTask(task);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import org.bukkit.material.Step;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.WoodenStep;
|
||||
import org.bukkit.material.Wool;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -42,26 +43,26 @@ public class BukkitUtil extends WorldUtil {
|
||||
private static Player lastPlayer = null;
|
||||
private static PlotPlayer lastPlotPlayer = null;
|
||||
|
||||
public static void removePlayer(final String plr) {
|
||||
public static void removePlayer(String plr) {
|
||||
lastPlayer = null;
|
||||
lastPlotPlayer = null;
|
||||
}
|
||||
|
||||
public static PlotPlayer getPlayer(final OfflinePlayer op) {
|
||||
public static PlotPlayer getPlayer(OfflinePlayer op) {
|
||||
if (op.isOnline()) {
|
||||
return getPlayer(op.getPlayer());
|
||||
}
|
||||
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||
Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||
player.loadData();
|
||||
return new BukkitPlayer(player, true);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -71,63 +72,64 @@ public class BukkitUtil extends WorldUtil {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.bukkit.Location loc) {
|
||||
return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()));
|
||||
public static Location getLocation(org.bukkit.Location location) {
|
||||
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), MathMan.roundInt(location.getY()),
|
||||
MathMan.roundInt(location.getZ()));
|
||||
}
|
||||
|
||||
public static org.bukkit.Location getLocation(final Location loc) {
|
||||
return new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ());
|
||||
public static org.bukkit.Location getLocation(Location location) {
|
||||
return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static World getWorld(final String string) {
|
||||
public static World getWorld(String string) {
|
||||
if (StringMan.isEqual(string, lastString)) {
|
||||
if (lastWorld != null) {
|
||||
return lastWorld;
|
||||
}
|
||||
}
|
||||
final World world = Bukkit.getWorld(string);
|
||||
World world = Bukkit.getWorld(string);
|
||||
lastString = string;
|
||||
lastWorld = world;
|
||||
return world;
|
||||
}
|
||||
|
||||
public static String getWorld(final Entity entity) {
|
||||
public static String getWorld(Entity entity) {
|
||||
return entity.getWorld().getName();
|
||||
}
|
||||
|
||||
public static List<Entity> getEntities(final String worldname) {
|
||||
public static List<Entity> getEntities(String worldname) {
|
||||
return getWorld(worldname).getEntities();
|
||||
}
|
||||
|
||||
public static Location getLocation(final Entity entity) {
|
||||
final org.bukkit.Location loc = entity.getLocation();
|
||||
final String world = loc.getWorld().getName();
|
||||
public static Location getLocation(Entity entity) {
|
||||
org.bukkit.Location loc = entity.getLocation();
|
||||
String world = loc.getWorld().getName();
|
||||
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
public static Location getLocationFull(final Entity entity) {
|
||||
final org.bukkit.Location loc = entity.getLocation();
|
||||
public static Location getLocationFull(Entity entity) {
|
||||
org.bukkit.Location loc = entity.getLocation();
|
||||
return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()),
|
||||
loc.getYaw(), loc.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world) {
|
||||
public boolean isWorld(String world) {
|
||||
return getWorld(world) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBiome(final String world, final int x, final int z) {
|
||||
public String getBiome(String world, int x, int z) {
|
||||
return getWorld(world).getBiome(x, z).name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
|
||||
final World world = getWorld(worldname);
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||
World world = getWorld(worldname);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
// block.setType(Material.AIR);
|
||||
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
|
||||
final BlockState blockstate = block.getState();
|
||||
BlockState blockstate = block.getState();
|
||||
if (blockstate instanceof Sign) {
|
||||
final Sign sign = (Sign) blockstate;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
@ -144,11 +146,11 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSign(final Location loc) {
|
||||
final Block block = getWorld(loc.getWorld()).getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
||||
public String[] getSign(Location location) {
|
||||
Block block = getWorld(location.getWorld()).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
if (block != null) {
|
||||
if (block.getState() instanceof Sign) {
|
||||
final Sign sign = (Sign) block.getState();
|
||||
Sign sign = (Sign) block.getState();
|
||||
return sign.getLines();
|
||||
}
|
||||
}
|
||||
@ -156,16 +158,16 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getSpawn(final String world) {
|
||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
public Location getSpawn(String world) {
|
||||
org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
||||
}
|
||||
|
||||
@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.setSpawnLocation(loc.getX(), loc.getY(), loc.getZ());
|
||||
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,24 +180,24 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighestBlock(final String world, final int x, final int z) {
|
||||
public int getHighestBlock(String world, int x, int z) {
|
||||
return getWorld(world).getHighestBlockAt(x, z).getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBiomeFromString(final String biomeStr) {
|
||||
public int getBiomeFromString(String biomeStr) {
|
||||
try {
|
||||
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
return Arrays.asList(Biome.values()).indexOf(biome);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (IllegalArgumentException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getBiomeList() {
|
||||
final Biome[] biomes = Biome.values();
|
||||
final String[] list = new String[biomes.length];
|
||||
Biome[] biomes = Biome.values();
|
||||
String[] list = new String[biomes.length];
|
||||
for (int i = 0; i < biomes.length; i++) {
|
||||
list[i] = biomes[i].name();
|
||||
}
|
||||
@ -203,18 +205,18 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addItems(final String worldname, final PlotItem items) {
|
||||
final World world = getWorld(worldname);
|
||||
final Block block = world.getBlockAt(items.x, items.y, items.z);
|
||||
public boolean addItems(String worldName, PlotItem items) {
|
||||
World world = getWorld(worldName);
|
||||
Block block = world.getBlockAt(items.x, items.y, items.z);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
final BlockState state = block.getState();
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof InventoryHolder) {
|
||||
final InventoryHolder holder = (InventoryHolder) state;
|
||||
final Inventory inv = holder.getInventory();
|
||||
InventoryHolder holder = (InventoryHolder) state;
|
||||
Inventory inv = holder.getInventory();
|
||||
for (int i = 0; i < items.id.length; i++) {
|
||||
final ItemStack item = new ItemStack(items.id[i], items.amount[i], items.data[i]);
|
||||
ItemStack item = new ItemStack(items.id[i], items.amount[i], items.data[i]);
|
||||
inv.addItem(item);
|
||||
}
|
||||
state.update(true);
|
||||
@ -224,11 +226,11 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockSolid(final PlotBlock block) {
|
||||
public boolean isBlockSolid(PlotBlock block) {
|
||||
try {
|
||||
final Material material = Material.getMaterial(block.id);
|
||||
Material material = Material.getMaterial(block.id);
|
||||
if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
|
||||
final Class<? extends MaterialData> data = material.getData();
|
||||
Class<? extends MaterialData> data = material.getData();
|
||||
if (data.equals(MaterialData.class) && !material.isTransparent() && material.isOccluding()
|
||||
|| data.equals(Tree.class)
|
||||
|| data.equals(Sandstone.class)
|
||||
@ -245,16 +247,16 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClosestMatchingName(final PlotBlock block) {
|
||||
public String getClosestMatchingName(PlotBlock block) {
|
||||
try {
|
||||
return Material.getMaterial(block.id).name();
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -262,13 +264,14 @@ public class BukkitUtil extends WorldUtil {
|
||||
@Override
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||
try {
|
||||
final Material material = Material.valueOf(name.toUpperCase());
|
||||
Material material = Material.valueOf(name.toUpperCase());
|
||||
return new StringComparison<PlotBlock>().new ComparisonResult(0, new PlotBlock((short) material.getId(), (byte) 0));
|
||||
} catch (IllegalArgumentException e) {
|
||||
//ignored
|
||||
}
|
||||
try {
|
||||
byte data;
|
||||
final String[] split = name.split(":");
|
||||
String[] split = name.split(":");
|
||||
if (split.length == 2) {
|
||||
data = Byte.parseByte(split[1]);
|
||||
name = split[0];
|
||||
@ -281,23 +284,24 @@ public class BukkitUtil extends WorldUtil {
|
||||
id = Short.parseShort(split[0]);
|
||||
match = 0;
|
||||
} else {
|
||||
final StringComparison<Material>.ComparisonResult comparison = new StringComparison<>(name, Material.values()).getBestMatchAdvanced();
|
||||
StringComparison<Material>.ComparisonResult comparison = new StringComparison<>(name, Material.values()).getBestMatchAdvanced();
|
||||
match = comparison.match;
|
||||
id = (short) comparison.best.getId();
|
||||
}
|
||||
final PlotBlock block = new PlotBlock(id, data);
|
||||
final StringComparison<PlotBlock> outer = new StringComparison<>();
|
||||
PlotBlock block = new PlotBlock(id, data);
|
||||
StringComparison<PlotBlock> outer = new StringComparison<>();
|
||||
return outer.new ComparisonResult(match, block);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
//ignored
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiomes(final String worldname, RegionWrapper region, final String biomeStr) {
|
||||
final World world = getWorld(worldname);
|
||||
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
public void setBiomes(String worldName, RegionWrapper region, String biomeStr) {
|
||||
World world = getWorld(worldName);
|
||||
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
for (int x = region.minX; x <= region.maxX; x++) {
|
||||
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||
world.setBiome(x, z, biome);
|
||||
@ -306,9 +310,9 @@ public class BukkitUtil extends WorldUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(final Location loc) {
|
||||
final World world = getWorld(loc.getWorld());
|
||||
final Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
||||
public PlotBlock getBlock(Location location) {
|
||||
World world = getWorld(location.getWorld());
|
||||
Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
if (block == null) {
|
||||
return PlotBlock.EVERYTHING;
|
||||
}
|
||||
|
@ -27,13 +27,24 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@ -76,13 +87,13 @@ public class Metrics {
|
||||
*/
|
||||
private volatile BukkitTask task = null;
|
||||
|
||||
public Metrics(final Plugin plugin) throws IOException {
|
||||
public Metrics(Plugin plugin) throws IOException {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
guid = UUID.randomUUID().toString();
|
||||
debug = false;
|
||||
this.guid = UUID.randomUUID().toString();
|
||||
this.debug = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,19 +103,19 @@ public class Metrics {
|
||||
*
|
||||
* @return byte[] the file as a byte array
|
||||
*/
|
||||
public static byte[] gzip(final String input) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
public static byte[] gzip(String input) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzos = null;
|
||||
try {
|
||||
gzos = new GZIPOutputStream(baos);
|
||||
gzos.write(input.getBytes("UTF-8"));
|
||||
} catch (final IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (gzos != null) {
|
||||
try {
|
||||
gzos.close();
|
||||
} catch (final IOException ignore) {
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,14 +131,14 @@ public class Metrics {
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
private static void appendJSONPair(final StringBuilder json, final String key, final String value) {
|
||||
private static void appendJSONPair(StringBuilder json, String key, String value) {
|
||||
boolean isValueNumeric = false;
|
||||
try {
|
||||
if (value.equals("0") || !value.endsWith("0")) {
|
||||
Double.parseDouble(value);
|
||||
isValueNumeric = true;
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
isValueNumeric = false;
|
||||
}
|
||||
if (json.charAt(json.length() - 1) != '{') {
|
||||
@ -149,11 +160,11 @@ public class Metrics {
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
private static String escapeJSON(final String text) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
private static String escapeJSON(String text) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append('"');
|
||||
for (int index = 0; index < text.length(); index++) {
|
||||
final char chr = text.charAt(index);
|
||||
char chr = text.charAt(index);
|
||||
switch (chr) {
|
||||
case '"':
|
||||
case '\\':
|
||||
@ -174,7 +185,7 @@ public class Metrics {
|
||||
break;
|
||||
default:
|
||||
if (chr < ' ') {
|
||||
final String t = "000" + Integer.toHexString(chr);
|
||||
String t = "000" + Integer.toHexString(chr);
|
||||
builder.append("\\u" + t.substring(t.length() - 4));
|
||||
} else {
|
||||
builder.append(chr);
|
||||
@ -193,7 +204,7 @@ public class Metrics {
|
||||
*
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String urlEncode(final String text) throws UnsupportedEncodingException {
|
||||
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
@ -205,14 +216,14 @@ public class Metrics {
|
||||
*
|
||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||
*/
|
||||
public Graph createGraph(final String name) {
|
||||
public Graph createGraph(String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Graph name cannot be null");
|
||||
}
|
||||
// Construct the graph object
|
||||
final Graph graph = new Graph(name);
|
||||
Graph graph = new Graph(name);
|
||||
// Now we can add our graph
|
||||
graphs.add(graph);
|
||||
this.graphs.add(graph);
|
||||
// and return back
|
||||
return graph;
|
||||
}
|
||||
@ -222,11 +233,11 @@ public class Metrics {
|
||||
*
|
||||
* @param graph The name of the graph
|
||||
*/
|
||||
public void addGraph(final Graph graph) {
|
||||
public void addGraph(Graph graph) {
|
||||
if (graph == null) {
|
||||
throw new IllegalArgumentException("Graph cannot be null");
|
||||
}
|
||||
graphs.add(graph);
|
||||
this.graphs.add(graph);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,24 +249,24 @@ public class Metrics {
|
||||
*/
|
||||
public boolean start() {
|
||||
// Is metrics already running?
|
||||
if (task != null) {
|
||||
if (this.task != null) {
|
||||
return true;
|
||||
}
|
||||
// Begin hitting the server with glorious data
|
||||
task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
|
||||
this.task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
|
||||
private boolean firstPost = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
postPlugin(!firstPost);
|
||||
postPlugin(!this.firstPost);
|
||||
// After the first post we set firstPost to
|
||||
// false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (final IOException e) {
|
||||
this.firstPost = false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
if (debug) {
|
||||
if (Metrics.this.debug) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -271,7 +282,7 @@ public class Metrics {
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// Enable Task, if it is not running
|
||||
if (task == null) {
|
||||
if (this.task == null) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
@ -283,9 +294,9 @@ public class Metrics {
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// Disable Task, if it is running
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
task = null;
|
||||
if (this.task != null) {
|
||||
this.task.cancel();
|
||||
this.task = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +312,7 @@ public class Metrics {
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
final File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
File pluginsFolder = this.plugin.getDataFolder().getParentFile();
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
@ -309,18 +320,13 @@ public class Metrics {
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
private void postPlugin(boolean isPing) throws IOException {
|
||||
// Server software specific section
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
final String pluginName = description.getName();
|
||||
final boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE
|
||||
// if
|
||||
// online
|
||||
// mode
|
||||
// is
|
||||
// enabled
|
||||
final String pluginVersion = description.getVersion();
|
||||
final String serverVersion = Bukkit.getVersion();
|
||||
PluginDescriptionFile description = this.plugin.getDescription();
|
||||
String pluginName = description.getName();
|
||||
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||
String pluginVersion = description.getVersion();
|
||||
String serverVersion = Bukkit.getVersion();
|
||||
int playersOnline = 0;
|
||||
try {
|
||||
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) {
|
||||
@ -334,20 +340,19 @@ public class Metrics {
|
||||
// END server software specific section -- all code below does not use
|
||||
// any code outside of this class / Java
|
||||
// Construct the post data
|
||||
final StringBuilder json = new StringBuilder(1024);
|
||||
StringBuilder json = new StringBuilder(1024);
|
||||
json.append('{');
|
||||
// The plugin's description file containg all of the plugin data such as
|
||||
// name, version, author, etc
|
||||
appendJSONPair(json, "guid", guid);
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
appendJSONPair(json, "guid", this.guid);
|
||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||
appendJSONPair(json, "server_version", serverVersion);
|
||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||
// New data as of R6
|
||||
final String osname = System.getProperty("os.name");
|
||||
String osname = System.getProperty("os.name");
|
||||
String osarch = System.getProperty("os.arch");
|
||||
final String osversion = System.getProperty("os.version");
|
||||
final String java_version = System.getProperty("java.version");
|
||||
final int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
String osversion = System.getProperty("os.version");
|
||||
String java_version = System.getProperty("java.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
// normalize os arch .. amd64 -> x86_64
|
||||
if (osarch.equals("amd64")) {
|
||||
osarch = "x86_64";
|
||||
@ -362,8 +367,8 @@ public class Metrics {
|
||||
if (isPing) {
|
||||
appendJSONPair(json, "ping", "1");
|
||||
}
|
||||
if (!graphs.isEmpty()) {
|
||||
synchronized (graphs) {
|
||||
if (!this.graphs.isEmpty()) {
|
||||
synchronized (this.graphs) {
|
||||
json.append(',');
|
||||
json.append('"');
|
||||
json.append("graphs");
|
||||
@ -371,10 +376,10 @@ public class Metrics {
|
||||
json.append(':');
|
||||
json.append('{');
|
||||
boolean firstGraph = true;
|
||||
for (final Graph graph : graphs) {
|
||||
final StringBuilder graphJson = new StringBuilder();
|
||||
for (Graph graph : this.graphs) {
|
||||
StringBuilder graphJson = new StringBuilder();
|
||||
graphJson.append('{');
|
||||
for (final Plotter plotter : graph.getPlotters()) {
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||
}
|
||||
graphJson.append('}');
|
||||
@ -392,7 +397,7 @@ public class Metrics {
|
||||
// close json
|
||||
json.append('}');
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
@ -402,8 +407,8 @@ public class Metrics {
|
||||
} else {
|
||||
connection = url.openConnection();
|
||||
}
|
||||
final byte[] uncompressed = json.toString().getBytes();
|
||||
final byte[] compressed = gzip(json.toString());
|
||||
byte[] uncompressed = json.toString().getBytes();
|
||||
byte[] compressed = gzip(json.toString());
|
||||
// Headers
|
||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
@ -412,7 +417,7 @@ public class Metrics {
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.setDoOutput(true);
|
||||
if (debug) {
|
||||
if (this.debug) {
|
||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||
}
|
||||
try {
|
||||
@ -423,7 +428,7 @@ public class Metrics {
|
||||
String response;
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
response = reader.readLine();
|
||||
if (debug) {
|
||||
if (this.debug) {
|
||||
PS.debug("[Metrics] Response for " + pluginName + ": " + response);
|
||||
}
|
||||
}
|
||||
@ -437,18 +442,17 @@ public class Metrics {
|
||||
} else {
|
||||
// Is this the first update this hour?
|
||||
if ("1".equals(response) || response.contains("This is your first update this hour")) {
|
||||
synchronized (graphs) {
|
||||
for (final Graph graph : graphs) {
|
||||
for (final Plotter plotter : graph.getPlotters()) {
|
||||
synchronized (this.graphs) {
|
||||
for (Graph graph : this.graphs) {
|
||||
for (Plotter plotter : graph.getPlotters()) {
|
||||
plotter.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (debug) {
|
||||
} catch (Exception e) {
|
||||
if (this.debug) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -483,7 +487,7 @@ public class Metrics {
|
||||
*/
|
||||
private final Set<Plotter> plotters = new LinkedHashSet<>();
|
||||
|
||||
private Graph(final String name) {
|
||||
private Graph(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -493,7 +497,7 @@ public class Metrics {
|
||||
* @return the Graph's name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -501,8 +505,8 @@ public class Metrics {
|
||||
*
|
||||
* @param plotter the plotter to add to the graph
|
||||
*/
|
||||
public void addPlotter(final Plotter plotter) {
|
||||
plotters.add(plotter);
|
||||
public void addPlotter(Plotter plotter) {
|
||||
this.plotters.add(plotter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,8 +514,8 @@ public class Metrics {
|
||||
*
|
||||
* @param plotter the plotter to remove from the graph
|
||||
*/
|
||||
public void removePlotter(final Plotter plotter) {
|
||||
plotters.remove(plotter);
|
||||
public void removePlotter(Plotter plotter) {
|
||||
this.plotters.remove(plotter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -520,21 +524,21 @@ public class Metrics {
|
||||
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||
*/
|
||||
public Set<Plotter> getPlotters() {
|
||||
return Collections.unmodifiableSet(plotters);
|
||||
return Collections.unmodifiableSet(this.plotters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Graph)) {
|
||||
return false;
|
||||
}
|
||||
final Graph graph = (Graph) object;
|
||||
return graph.name.equals(name);
|
||||
Graph graph = (Graph) object;
|
||||
return graph.name.equals(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -547,7 +551,7 @@ public class Metrics {
|
||||
/**
|
||||
* Interface used to collect custom data for a plugin
|
||||
*/
|
||||
public static abstract class Plotter {
|
||||
public abstract static class Plotter {
|
||||
|
||||
/**
|
||||
* The plot's name
|
||||
@ -566,7 +570,7 @@ public class Metrics {
|
||||
*
|
||||
* @param name the name of the plotter to use, which will show up on the website
|
||||
*/
|
||||
public Plotter(final String name) {
|
||||
public Plotter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -585,7 +589,7 @@ public class Metrics {
|
||||
* @return the plotted point's column name
|
||||
*/
|
||||
public String getColumnName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -600,12 +604,12 @@ public class Metrics {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
public boolean equals(Object object) {
|
||||
if (!(object instanceof Plotter)) {
|
||||
return false;
|
||||
}
|
||||
final Plotter plotter = (Plotter) object;
|
||||
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
||||
Plotter plotter = (Plotter) object;
|
||||
return plotter.name.equals(this.name) && plotter.getValue() == getValue();
|
||||
}
|
||||
}
|
||||
}
|
@ -15,12 +15,27 @@ import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.AbstractList;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@ -48,39 +63,43 @@ public class NbtFactory {
|
||||
// Loading/saving compounds
|
||||
private LoadCompoundMethod LOAD_COMPOUND;
|
||||
private Method SAVE_COMPOUND;
|
||||
|
||||
/**
|
||||
* Construct an instance of the NBT factory by deducing the class of NBTBase.
|
||||
*/
|
||||
private NbtFactory() {
|
||||
if (BASE_CLASS == null) {
|
||||
if (this.BASE_CLASS == null) {
|
||||
try {
|
||||
// Keep in mind that I do use hard-coded field names - but it's okay as long as we're dealing
|
||||
// with CraftBukkit or its derivatives. This does not work in MCPC+ however.
|
||||
final ClassLoader loader = NbtFactory.class.getClassLoader();
|
||||
ClassLoader loader = NbtFactory.class.getClassLoader();
|
||||
|
||||
final String packageName = getPackageName();
|
||||
final Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
||||
String packageName = getPackageName();
|
||||
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
||||
|
||||
// Prepare NBT
|
||||
COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
||||
BASE_CLASS = COMPOUND_CLASS.getSuperclass();
|
||||
NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId");
|
||||
NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class);
|
||||
this.COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
||||
this.BASE_CLASS = this.COMPOUND_CLASS.getSuperclass();
|
||||
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
||||
this.NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
||||
|
||||
// Prepare CraftItemStack
|
||||
CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
||||
CRAFT_HANDLE = getField(null, CRAFT_STACK, "handle");
|
||||
STACK_TAG = getField(null, CRAFT_HANDLE.getType(), "tag");
|
||||
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
||||
this.CRAFT_HANDLE = getField(null, this.CRAFT_STACK, "handle");
|
||||
this.STACK_TAG = getField(null, this.CRAFT_HANDLE.getType(), "tag");
|
||||
|
||||
// Loading/saving
|
||||
final String nmsPackage = BASE_CLASS.getPackage().getName();
|
||||
String nmsPackage = this.BASE_CLASS.getPackage().getName();
|
||||
initializeNMS(loader, nmsPackage);
|
||||
|
||||
LOAD_COMPOUND = READ_LIMITER_CLASS != null ? new LoadMethodSkinUpdate(STREAM_TOOLS, READ_LIMITER_CLASS) :
|
||||
new LoadMethodWorldUpdate(STREAM_TOOLS);
|
||||
SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, STREAM_TOOLS, null, BASE_CLASS, DataOutput.class);
|
||||
if (this.READ_LIMITER_CLASS != null) {
|
||||
this.LOAD_COMPOUND = new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
||||
} else {
|
||||
this.LOAD_COMPOUND = new LoadMethodWorldUpdate(this.STREAM_TOOLS);
|
||||
}
|
||||
this.SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, this.STREAM_TOOLS, null, this.BASE_CLASS, DataOutput.class);
|
||||
|
||||
} catch (final ClassNotFoundException e) {
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalStateException("Unable to find offline player.", e);
|
||||
}
|
||||
}
|
||||
@ -101,7 +120,7 @@ public class NbtFactory {
|
||||
* Construct a new NBT list of an unspecified type.
|
||||
* @return The NBT list.
|
||||
*/
|
||||
public static NbtList createList(final Object... content) {
|
||||
public static NbtList createList(Object... content) {
|
||||
return createList(Arrays.asList(content));
|
||||
}
|
||||
|
||||
@ -109,11 +128,11 @@ public class NbtFactory {
|
||||
* Construct a new NBT list of an unspecified type.
|
||||
* @return The NBT list.
|
||||
*/
|
||||
public static NbtList createList(final Iterable<? extends Object> iterable) {
|
||||
final NbtList list = get().new NbtList(INSTANCE.createNbtTag(NbtType.TAG_LIST, null));
|
||||
public static NbtList createList(Iterable<? extends Object> iterable) {
|
||||
NbtList list = get().new NbtList(INSTANCE.createNbtTag(NbtType.TAG_LIST, null));
|
||||
|
||||
// Add the content as well
|
||||
for (final Object obj : iterable) {
|
||||
for (Object obj : iterable) {
|
||||
list.add(obj);
|
||||
}
|
||||
return list;
|
||||
@ -121,7 +140,6 @@ public class NbtFactory {
|
||||
|
||||
/**
|
||||
* Construct a new NBT compound.
|
||||
* <p>
|
||||
*
|
||||
* @return The NBT compound.
|
||||
*/
|
||||
@ -134,29 +152,33 @@ public class NbtFactory {
|
||||
* @param nmsList - the NBT list.
|
||||
* @return The wrapper.
|
||||
*/
|
||||
public static NbtList fromList(final Object nmsList) {
|
||||
public static NbtList fromList(Object nmsList) {
|
||||
return get().new NbtList(nmsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the content of a file from a stream.
|
||||
* <p>
|
||||
*
|
||||
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
|
||||
* @param stream - the stream supplier.
|
||||
* @param option - whether or not to decompress the input stream.
|
||||
* @return The decoded NBT compound.
|
||||
* @throws IOException If anything went wrong.
|
||||
*/
|
||||
public static NbtCompound fromStream(final InputSupplier<? extends InputStream> stream, final StreamOptions option) throws IOException {
|
||||
public static NbtCompound fromStream(InputSupplier<? extends InputStream> stream, StreamOptions option) throws IOException {
|
||||
InputStream input = null;
|
||||
DataInputStream data = null;
|
||||
boolean suppress = true;
|
||||
|
||||
try {
|
||||
input = stream.getInput();
|
||||
data = new DataInputStream(new BufferedInputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPInputStream(input) : input));
|
||||
if (option == StreamOptions.GZIP_COMPRESSION) {
|
||||
data = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)));
|
||||
} else {
|
||||
data = new DataInputStream(new BufferedInputStream(input));
|
||||
}
|
||||
|
||||
final NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
|
||||
NbtCompound result = fromCompound(get().LOAD_COMPOUND.loadNbt(data));
|
||||
suppress = false;
|
||||
return result;
|
||||
|
||||
@ -171,14 +193,14 @@ public class NbtFactory {
|
||||
|
||||
/**
|
||||
* Save the content of a NBT compound to a stream.
|
||||
* <p>
|
||||
*
|
||||
* Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file.
|
||||
* @param source - the NBT compound to save.
|
||||
* @param stream - the stream.
|
||||
* @param option - whether or not to compress the output.
|
||||
* @throws IOException If anything went wrong.
|
||||
*/
|
||||
public static void saveStream(final NbtCompound source, final ByteSink stream, final StreamOptions option) throws IOException {
|
||||
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option) throws IOException {
|
||||
OutputStream output = null;
|
||||
DataOutputStream data = null;
|
||||
boolean suppress = true;
|
||||
@ -204,7 +226,7 @@ public class NbtFactory {
|
||||
* @param nmsCompound - the NBT compund.
|
||||
* @return The wrapper.
|
||||
*/
|
||||
public static NbtCompound fromCompound(final Object nmsCompound) {
|
||||
public static NbtCompound fromCompound(Object nmsCompound) {
|
||||
return get().new NbtCompound(nmsCompound);
|
||||
}
|
||||
|
||||
@ -215,9 +237,9 @@ public class NbtFactory {
|
||||
* @param compound - the new NBT compound, or NULL to remove it.
|
||||
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
|
||||
*/
|
||||
public static void setItemTag(final ItemStack stack, final NbtCompound compound) {
|
||||
public static void setItemTag(ItemStack stack, NbtCompound compound) {
|
||||
checkItemStack(stack);
|
||||
final Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||
|
||||
// Now update the tag compound
|
||||
setFieldValue(get().STACK_TAG, nms, compound.getHandle());
|
||||
@ -232,14 +254,14 @@ public class NbtFactory {
|
||||
* @param stack - the item stack.
|
||||
* @return A wrapper for its NBT tag.
|
||||
*/
|
||||
public static NbtCompound fromItemTag(final ItemStack stack) {
|
||||
public static NbtCompound fromItemTag(ItemStack stack) {
|
||||
checkItemStack(stack);
|
||||
final Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||
final Object tag = getFieldValue(get().STACK_TAG, nms);
|
||||
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||
Object tag = getFieldValue(get().STACK_TAG, nms);
|
||||
|
||||
// Create the tag if it doesn't exist
|
||||
if (tag == null) {
|
||||
final NbtCompound compound = createCompound();
|
||||
NbtCompound compound = createCompound();
|
||||
setItemTag(stack, compound);
|
||||
return compound;
|
||||
}
|
||||
@ -251,17 +273,17 @@ public class NbtFactory {
|
||||
* @param stack - the stack to convert.
|
||||
* @return The CraftItemStack version.
|
||||
*/
|
||||
public static ItemStack getCraftItemStack(final ItemStack stack) {
|
||||
public static ItemStack getCraftItemStack(ItemStack stack) {
|
||||
// Any need to convert?
|
||||
if ((stack == null) || get().CRAFT_STACK.isAssignableFrom(stack.getClass())) {
|
||||
return stack;
|
||||
}
|
||||
try {
|
||||
// Call the private constructor
|
||||
final Constructor<?> caller = INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
|
||||
Constructor<?> caller = INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
|
||||
caller.setAccessible(true);
|
||||
return (ItemStack) caller.newInstance(stack);
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Unable to convert " + stack + " + to a CraftItemStack.");
|
||||
}
|
||||
}
|
||||
@ -270,7 +292,7 @@ public class NbtFactory {
|
||||
* Ensure that the given stack can store arbitrary NBT information.
|
||||
* @param stack - the stack to check.
|
||||
*/
|
||||
private static void checkItemStack(final ItemStack stack) {
|
||||
private static void checkItemStack(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
throw new IllegalArgumentException("Stack cannot be NULL.");
|
||||
}
|
||||
@ -289,26 +311,26 @@ public class NbtFactory {
|
||||
* @param params - the parameters to supply.
|
||||
* @return The result of the method.
|
||||
*/
|
||||
private static Object invokeMethod(final Method method, final Object target, final Object... params) {
|
||||
private static Object invokeMethod(Method method, Object target, Object... params) {
|
||||
try {
|
||||
return method.invoke(target, params);
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to invoke method " + method + " for " + target, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setFieldValue(final Field field, final Object target, final Object value) {
|
||||
private static void setFieldValue(Field field, Object target, Object value) {
|
||||
try {
|
||||
field.set(target, value);
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to set " + field + " for " + target, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getFieldValue(final Field field, final Object target) {
|
||||
private static Object getFieldValue(Field field, Object target) {
|
||||
try {
|
||||
return field.get(target);
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to retrieve " + field + " for " + target, e);
|
||||
}
|
||||
}
|
||||
@ -323,9 +345,9 @@ public class NbtFactory {
|
||||
* @return The first method by this name.
|
||||
* @throws IllegalStateException If we cannot find this method.
|
||||
*/
|
||||
private static Method getMethod(final int requireMod, final int bannedMod, final Class<?> clazz, final String methodName,
|
||||
final Class<?>... params) {
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName,
|
||||
Class<?>... params) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
// Limitation: Doesn't handle overloads
|
||||
if (((method.getModifiers() & requireMod) == requireMod)
|
||||
&& ((method.getModifiers() & bannedMod) == 0)
|
||||
@ -351,12 +373,12 @@ public class NbtFactory {
|
||||
* @return The first field by this name.
|
||||
* @throws IllegalStateException If we cannot find this field.
|
||||
*/
|
||||
private static Field getField(final Object instance, Class<?> clazz, final String fieldName) {
|
||||
private static Field getField(Object instance, Class<?> clazz, String fieldName) {
|
||||
if (clazz == null) {
|
||||
clazz = instance.getClass();
|
||||
}
|
||||
// Ignore access rules
|
||||
for (final Field field : clazz.getDeclaredFields()) {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (field.getName().equals(fieldName)) {
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
@ -369,18 +391,18 @@ public class NbtFactory {
|
||||
throw new IllegalStateException("Unable to find field " + fieldName + " in " + instance);
|
||||
}
|
||||
|
||||
private void initializeNMS(final ClassLoader loader, final String nmsPackage) {
|
||||
private void initializeNMS(ClassLoader loader, String nmsPackage) {
|
||||
try {
|
||||
STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
||||
READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
||||
} catch (final ClassNotFoundException e) {
|
||||
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
||||
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Ignore - we will detect this later
|
||||
}
|
||||
}
|
||||
|
||||
private String getPackageName() {
|
||||
final Server server = Bukkit.getServer();
|
||||
final String name = server != null ? server.getClass().getPackage().getName() : null;
|
||||
Server server = Bukkit.getServer();
|
||||
String name = server != null ? server.getClass().getPackage().getName() : null;
|
||||
|
||||
if ((name != null) && name.contains("craftbukkit")) {
|
||||
return name;
|
||||
@ -391,12 +413,12 @@ public class NbtFactory {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> getDataMap(final Object handle) {
|
||||
private Map<String, Object> getDataMap(Object handle) {
|
||||
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle), handle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Object> getDataList(final Object handle) {
|
||||
private List<Object> getDataList(Object handle) {
|
||||
return (List<Object>) getFieldValue(getDataField(NbtType.TAG_LIST, handle), handle);
|
||||
}
|
||||
|
||||
@ -405,7 +427,7 @@ public class NbtFactory {
|
||||
* @param value - the value of the element to create. Can be a List or a Map.
|
||||
* @return The NBT element.
|
||||
*/
|
||||
private Object unwrapValue(final Object value) {
|
||||
private Object unwrapValue(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
@ -430,13 +452,13 @@ public class NbtFactory {
|
||||
* @param nms - the NBT element.
|
||||
* @return The wrapper equivalent.
|
||||
*/
|
||||
private Object wrapNative(final Object nms) {
|
||||
private Object wrapNative(Object nms) {
|
||||
if (nms == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BASE_CLASS.isAssignableFrom(nms.getClass())) {
|
||||
final NbtType type = getNbtType(nms);
|
||||
if (this.BASE_CLASS.isAssignableFrom(nms.getClass())) {
|
||||
NbtType type = getNbtType(nms);
|
||||
|
||||
// Handle the different types
|
||||
switch (type) {
|
||||
@ -457,8 +479,8 @@ public class NbtFactory {
|
||||
* @param value - the value, or NULL to keep the original value.
|
||||
* @return The created tag.
|
||||
*/
|
||||
private Object createNbtTag(final NbtType type, final Object value) {
|
||||
final Object tag = invokeMethod(NBT_CREATE_TAG, null, (byte) type.id);
|
||||
private Object createNbtTag(NbtType type, Object value) {
|
||||
Object tag = invokeMethod(this.NBT_CREATE_TAG, null, (byte) type.id);
|
||||
|
||||
if (value != null) {
|
||||
setFieldValue(getDataField(type, tag), tag, value);
|
||||
@ -472,11 +494,11 @@ public class NbtFactory {
|
||||
* @param nms - the NBT class instance.
|
||||
* @return The corresponding field.
|
||||
*/
|
||||
private Field getDataField(final NbtType type, final Object nms) {
|
||||
if (DATA_FIELD[type.id] == null) {
|
||||
DATA_FIELD[type.id] = getField(nms, null, type.getFieldName());
|
||||
private Field getDataField(NbtType type, Object nms) {
|
||||
if (this.DATA_FIELD[type.id] == null) {
|
||||
this.DATA_FIELD[type.id] = getField(nms, null, type.getFieldName());
|
||||
}
|
||||
return DATA_FIELD[type.id];
|
||||
return this.DATA_FIELD[type.id];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -484,8 +506,8 @@ public class NbtFactory {
|
||||
* @param nms - the native NBT tag.
|
||||
* @return The corresponding type.
|
||||
*/
|
||||
private NbtType getNbtType(final Object nms) {
|
||||
final int type = (Byte) invokeMethod(NBT_GET_TYPE, nms);
|
||||
private NbtType getNbtType(Object nms) {
|
||||
int type = (Byte) invokeMethod(this.NBT_GET_TYPE, nms);
|
||||
return NBT_ENUM.get(type);
|
||||
}
|
||||
|
||||
@ -494,8 +516,8 @@ public class NbtFactory {
|
||||
* @param primitive - the primitive type.
|
||||
* @return The corresponding type.
|
||||
*/
|
||||
private NbtType getPrimitiveType(final Object primitive) {
|
||||
final NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
||||
private NbtType getPrimitiveType(Object primitive) {
|
||||
NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
||||
|
||||
// Display the illegal value at least
|
||||
if (type == null) {
|
||||
@ -529,7 +551,7 @@ public class NbtFactory {
|
||||
// Unique NBT type
|
||||
public final int id;
|
||||
|
||||
NbtType(final int id, final Class<?> type) {
|
||||
NbtType(int id, Class<?> type) {
|
||||
this.id = id;
|
||||
NBT_CLASS.put(id, type);
|
||||
NBT_ENUM.put(id, this);
|
||||
@ -567,9 +589,9 @@ public class NbtFactory {
|
||||
|
||||
protected Method staticMethod;
|
||||
|
||||
protected void setMethod(final Method method) {
|
||||
staticMethod = method;
|
||||
staticMethod.setAccessible(true);
|
||||
protected void setMethod(Method method) {
|
||||
this.staticMethod = method;
|
||||
this.staticMethod.setAccessible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -577,7 +599,7 @@ public class NbtFactory {
|
||||
* @param input - the input stream.
|
||||
* @return The loaded NBT compound.
|
||||
*/
|
||||
public abstract Object loadNbt(final DataInput input);
|
||||
public abstract Object loadNbt(DataInput input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -585,13 +607,13 @@ public class NbtFactory {
|
||||
*/
|
||||
private static class LoadMethodWorldUpdate extends LoadCompoundMethod {
|
||||
|
||||
public LoadMethodWorldUpdate(final Class<?> streamClass) {
|
||||
public LoadMethodWorldUpdate(Class<?> streamClass) {
|
||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object loadNbt(final DataInput input) {
|
||||
return invokeMethod(staticMethod, null, input);
|
||||
public Object loadNbt(DataInput input) {
|
||||
return invokeMethod(this.staticMethod, null, input);
|
||||
}
|
||||
}
|
||||
|
||||
@ -602,15 +624,15 @@ public class NbtFactory {
|
||||
|
||||
private Object readLimiter;
|
||||
|
||||
public LoadMethodSkinUpdate(final Class<?> streamClass, final Class<?> readLimiterClass) {
|
||||
public LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
|
||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
|
||||
|
||||
// Find the unlimited read limiter
|
||||
for (final Field field : readLimiterClass.getDeclaredFields()) {
|
||||
for (Field field : readLimiterClass.getDeclaredFields()) {
|
||||
if (readLimiterClass.isAssignableFrom(field.getType())) {
|
||||
try {
|
||||
readLimiter = field.get(null);
|
||||
} catch (final Exception e) {
|
||||
this.readLimiter = field.get(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot retrieve read limiter.", e);
|
||||
}
|
||||
}
|
||||
@ -618,8 +640,8 @@ public class NbtFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object loadNbt(final DataInput input) {
|
||||
return invokeMethod(staticMethod, null, input, readLimiter);
|
||||
public Object loadNbt(DataInput input) {
|
||||
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
||||
}
|
||||
}
|
||||
|
||||
@ -643,44 +665,44 @@ public class NbtFactory {
|
||||
*/
|
||||
public final class NbtCompound extends ConvertedMap {
|
||||
|
||||
private NbtCompound(final Object handle) {
|
||||
private NbtCompound(Object handle) {
|
||||
super(handle, getDataMap(handle));
|
||||
}
|
||||
|
||||
// Simplifiying access to each value
|
||||
public Byte getByte(final String key, final Byte defaultValue) {
|
||||
public Byte getByte(String key, Byte defaultValue) {
|
||||
return containsKey(key) ? (Byte) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public Short getShort(final String key, final Short defaultValue) {
|
||||
public Short getShort(String key, Short defaultValue) {
|
||||
return containsKey(key) ? (Short) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public Integer getInteger(final String key, final Integer defaultValue) {
|
||||
public Integer getInteger(String key, Integer defaultValue) {
|
||||
return containsKey(key) ? (Integer) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public Long getLong(final String key, final Long defaultValue) {
|
||||
public Long getLong(String key, Long defaultValue) {
|
||||
return containsKey(key) ? (Long) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public Float getFloat(final String key, final Float defaultValue) {
|
||||
public Float getFloat(String key, Float defaultValue) {
|
||||
return containsKey(key) ? (Float) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public Double getDouble(final String key, final Double defaultValue) {
|
||||
public Double getDouble(String key, Double defaultValue) {
|
||||
return containsKey(key) ? (Double) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public String getString(final String key, final String defaultValue) {
|
||||
public String getString(String key, String defaultValue) {
|
||||
return containsKey(key) ? (String) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public byte[] getByteArray(final String key, final byte[] defaultValue) {
|
||||
public byte[] getByteArray(String key, byte[] defaultValue) {
|
||||
return containsKey(key) ? (byte[]) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
public int[] getIntegerArray(final String key, final int[] defaultValue) {
|
||||
public int[] getIntegerArray(String key, int[] defaultValue) {
|
||||
return containsKey(key) ? (int[]) get(key) : defaultValue;
|
||||
}
|
||||
|
||||
@ -690,7 +712,7 @@ public class NbtFactory {
|
||||
* @param createNew - whether or not to create a new list if its missing.
|
||||
* @return An existing list, a new list or NULL.
|
||||
*/
|
||||
public NbtList getList(final String key, final boolean createNew) {
|
||||
public NbtList getList(String key, boolean createNew) {
|
||||
NbtList list = (NbtList) get(key);
|
||||
|
||||
if ((list == null) && createNew) {
|
||||
@ -705,7 +727,7 @@ public class NbtFactory {
|
||||
* @param createNew - whether or not to create a new map if its missing.
|
||||
* @return An existing map, a new map or NULL.
|
||||
*/
|
||||
public NbtCompound getMap(final String key, final boolean createNew) {
|
||||
public NbtCompound getMap(String key, boolean createNew) {
|
||||
return getMap(Collections.singletonList(key), createNew);
|
||||
}
|
||||
|
||||
@ -720,9 +742,9 @@ public class NbtFactory {
|
||||
* @param value - the new value of this entry.
|
||||
* @return This compound, for chaining.
|
||||
*/
|
||||
public NbtCompound putPath(final String path, final Object value) {
|
||||
final List<String> entries = getPathElements(path);
|
||||
final Map<String, Object> map = getMap(entries.subList(0, entries.size() - 1), true);
|
||||
public NbtCompound putPath(String path, Object value) {
|
||||
List<String> entries = getPathElements(path);
|
||||
Map<String, Object> map = getMap(entries.subList(0, entries.size() - 1), true);
|
||||
|
||||
map.put(entries.get(entries.size() - 1), value);
|
||||
return this;
|
||||
@ -737,9 +759,9 @@ public class NbtFactory {
|
||||
* @return The value, or NULL if not found.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getPath(final String path) {
|
||||
final List<String> entries = getPathElements(path);
|
||||
final NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
||||
public <T> T getPath(String path) {
|
||||
List<String> entries = getPathElements(path);
|
||||
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
||||
|
||||
if (map != null) {
|
||||
return (T) map.get(entries.get(entries.size() - 1));
|
||||
@ -755,7 +777,7 @@ public class NbtFactory {
|
||||
* @param option - whether or not to compress the output.
|
||||
* @throws IOException If anything went wrong.
|
||||
*/
|
||||
public void saveTo(final ByteSink stream, final StreamOptions option) throws IOException {
|
||||
public void saveTo(ByteSink stream, StreamOptions option) throws IOException {
|
||||
saveStream(this, stream, option);
|
||||
}
|
||||
|
||||
@ -765,10 +787,10 @@ public class NbtFactory {
|
||||
* @param createNew - whether or not to create new compounds on the way.
|
||||
* @return The map at this location.
|
||||
*/
|
||||
private NbtCompound getMap(final Iterable<String> path, final boolean createNew) {
|
||||
private NbtCompound getMap(Iterable<String> path, boolean createNew) {
|
||||
NbtCompound current = this;
|
||||
|
||||
for (final String entry : path) {
|
||||
for (String entry : path) {
|
||||
NbtCompound child = (NbtCompound) current.get(entry);
|
||||
|
||||
if (child == null) {
|
||||
@ -787,7 +809,7 @@ public class NbtFactory {
|
||||
* @param path - the path to split.
|
||||
* @return The elements.
|
||||
*/
|
||||
private List<String> getPathElements(final String path) {
|
||||
private List<String> getPathElements(String path) {
|
||||
return Lists.newArrayList(Splitter.on(".").omitEmptyStrings().split(path));
|
||||
}
|
||||
}
|
||||
@ -803,7 +825,7 @@ public class NbtFactory {
|
||||
*/
|
||||
public final class NbtList extends ConvertedList {
|
||||
|
||||
private NbtList(final Object handle) {
|
||||
private NbtList(Object handle) {
|
||||
super(handle, getDataList(handle));
|
||||
}
|
||||
}
|
||||
@ -817,15 +839,15 @@ public class NbtFactory {
|
||||
// Don't recreate wrapper objects
|
||||
private final ConcurrentMap<Object, Object> cache = new MapMaker().weakKeys().makeMap();
|
||||
|
||||
public Object wrap(final Object value) {
|
||||
Object current = cache.get(value);
|
||||
public Object wrap(Object value) {
|
||||
Object current = this.cache.get(value);
|
||||
|
||||
if (current == null) {
|
||||
current = wrapNative(value);
|
||||
|
||||
// Only cache composite objects
|
||||
if ((current instanceof ConvertedMap) || (current instanceof ConvertedList)) {
|
||||
cache.put(value, current);
|
||||
this.cache.put(value, current);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
@ -844,57 +866,57 @@ public class NbtFactory {
|
||||
|
||||
private final CachedNativeWrapper cache = new CachedNativeWrapper();
|
||||
|
||||
public ConvertedMap(final Object handle, final Map<String, Object> original) {
|
||||
public ConvertedMap(Object handle, Map<String, Object> original) {
|
||||
this.handle = handle;
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
// For converting back and forth
|
||||
protected Object wrapOutgoing(final Object value) {
|
||||
return cache.wrap(value);
|
||||
protected Object wrapOutgoing(Object value) {
|
||||
return this.cache.wrap(value);
|
||||
}
|
||||
|
||||
protected Object unwrapIncoming(final Object wrapped) {
|
||||
protected Object unwrapIncoming(Object wrapped) {
|
||||
return unwrapValue(wrapped);
|
||||
}
|
||||
|
||||
// Modification
|
||||
@Override
|
||||
public Object put(final String key, final Object value) {
|
||||
return wrapOutgoing(original.put(key, unwrapIncoming(value)));
|
||||
public Object put(String key, Object value) {
|
||||
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
||||
}
|
||||
|
||||
// Performance
|
||||
@Override
|
||||
public Object get(final Object key) {
|
||||
return wrapOutgoing(original.get(key));
|
||||
public Object get(Object key) {
|
||||
return wrapOutgoing(this.original.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(final Object key) {
|
||||
return wrapOutgoing(original.remove(key));
|
||||
public Object remove(Object key) {
|
||||
return wrapOutgoing(this.original.remove(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(final Object key) {
|
||||
return original.containsKey(key);
|
||||
public boolean containsKey(Object key) {
|
||||
return this.original.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Entry<String, Object>> entrySet() {
|
||||
return new AbstractSet<Entry<String, Object>>() {
|
||||
@Override
|
||||
public boolean add(final Entry<String, Object> e) {
|
||||
final String key = e.getKey();
|
||||
final Object value = e.getValue();
|
||||
public boolean add(Entry<String, Object> e) {
|
||||
String key = e.getKey();
|
||||
Object value = e.getValue();
|
||||
|
||||
original.put(key, unwrapIncoming(value));
|
||||
ConvertedMap.this.original.put(key, unwrapIncoming(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return original.size();
|
||||
return ConvertedMap.this.original.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -905,7 +927,7 @@ public class NbtFactory {
|
||||
}
|
||||
|
||||
private Iterator<Entry<String, Object>> iterator() {
|
||||
final Iterator<Entry<String, Object>> proxy = original.entrySet().iterator();
|
||||
final Iterator<Entry<String, Object>> proxy = this.original.entrySet().iterator();
|
||||
|
||||
return new Iterator<Entry<String, Object>>() {
|
||||
@Override
|
||||
@ -915,7 +937,7 @@ public class NbtFactory {
|
||||
|
||||
@Override
|
||||
public Entry<String, Object> next() {
|
||||
final Entry<String, Object> entry = proxy.next();
|
||||
Entry<String, Object> entry = proxy.next();
|
||||
|
||||
return new SimpleEntry<String, Object>(entry.getKey(), wrapOutgoing(entry.getValue()));
|
||||
}
|
||||
@ -929,7 +951,7 @@ public class NbtFactory {
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return handle;
|
||||
return this.handle;
|
||||
}
|
||||
}
|
||||
|
||||
@ -945,61 +967,61 @@ public class NbtFactory {
|
||||
private final List<Object> original;
|
||||
private final CachedNativeWrapper cache = new CachedNativeWrapper();
|
||||
|
||||
public ConvertedList(final Object handle, final List<Object> original) {
|
||||
if (NBT_LIST_TYPE == null) {
|
||||
NBT_LIST_TYPE = getField(handle, null, "type");
|
||||
public ConvertedList(Object handle, List<Object> original) {
|
||||
if (NbtFactory.this.NBT_LIST_TYPE == null) {
|
||||
NbtFactory.this.NBT_LIST_TYPE = getField(handle, null, "type");
|
||||
}
|
||||
this.handle = handle;
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
protected Object wrapOutgoing(final Object value) {
|
||||
return cache.wrap(value);
|
||||
protected Object wrapOutgoing(Object value) {
|
||||
return this.cache.wrap(value);
|
||||
}
|
||||
|
||||
protected Object unwrapIncoming(final Object wrapped) {
|
||||
protected Object unwrapIncoming(Object wrapped) {
|
||||
return unwrapValue(wrapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(final int index) {
|
||||
return wrapOutgoing(original.get(index));
|
||||
public Object get(int index) {
|
||||
return wrapOutgoing(this.original.get(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return original.size();
|
||||
return this.original.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object set(final int index, final Object element) {
|
||||
return wrapOutgoing(original.set(index, unwrapIncoming(element)));
|
||||
public Object set(int index, Object element) {
|
||||
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final int index, final Object element) {
|
||||
final Object nbt = unwrapIncoming(element);
|
||||
public void add(int index, Object element) {
|
||||
Object nbt = unwrapIncoming(element);
|
||||
|
||||
// Set the list type if its the first element
|
||||
if (size() == 0) {
|
||||
setFieldValue(NBT_LIST_TYPE, handle, (byte) getNbtType(nbt).id);
|
||||
setFieldValue(NbtFactory.this.NBT_LIST_TYPE, this.handle, (byte) getNbtType(nbt).id);
|
||||
}
|
||||
original.add(index, nbt);
|
||||
this.original.add(index, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object remove(final int index) {
|
||||
return wrapOutgoing(original.remove(index));
|
||||
public Object remove(int index) {
|
||||
return wrapOutgoing(this.original.remove(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(final Object o) {
|
||||
return original.remove(unwrapIncoming(o));
|
||||
public boolean remove(Object o) {
|
||||
return this.original.remove(unwrapIncoming(o));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return handle;
|
||||
return this.handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,15 @@ import java.util.UUID;
|
||||
|
||||
public class OfflinePlayerUtil {
|
||||
|
||||
public static Player loadPlayer(final String name) {
|
||||
public static Player loadPlayer(String name) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(final UUID id) {
|
||||
public static Player loadPlayer(UUID id) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(id));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(final OfflinePlayer player) {
|
||||
public static Player loadPlayer(OfflinePlayer player) {
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
@ -37,21 +37,21 @@ public class OfflinePlayerUtil {
|
||||
return loadPlayer(player.getUniqueId(), player.getName());
|
||||
}
|
||||
|
||||
private static Player loadPlayer(final UUID id, final String name) {
|
||||
final Object server = getMinecraftServer();
|
||||
final Object interactManager = newPlayerInteractManager();
|
||||
final Object worldServer = getWorldServer();
|
||||
final Object profile = newGameProfile(id, name);
|
||||
final Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||
final Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||
private static Player loadPlayer(UUID id, String name) {
|
||||
Object server = getMinecraftServer();
|
||||
Object interactManager = newPlayerInteractManager();
|
||||
Object worldServer = getWorldServer();
|
||||
Object profile = newGameProfile(id, name);
|
||||
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||
Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||
getUtilClass("com.mojang.authlib.GameProfile"),
|
||||
getNmsClass("PlayerInteractManager"));
|
||||
final Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||
Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||
return (Player) getBukkitEntity(entityPlayer);
|
||||
}
|
||||
|
||||
private static Object newGameProfile(final UUID id, final String name) {
|
||||
final Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
||||
private static Object newGameProfile(UUID id, String name) {
|
||||
Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
||||
if (gameProfileClass == null) { //Before uuids
|
||||
return name;
|
||||
}
|
||||
@ -65,17 +65,17 @@ public class OfflinePlayerUtil {
|
||||
}
|
||||
|
||||
private static Object newPlayerInteractManager() {
|
||||
final Object worldServer = getWorldServer();
|
||||
final Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
||||
final Class<?> worldClass = getNmsClass("World");
|
||||
final Constructor c = makeConstructor(playerInteractClass, worldClass);
|
||||
Object worldServer = getWorldServer();
|
||||
Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
||||
Class<?> worldClass = getNmsClass("World");
|
||||
Constructor c = makeConstructor(playerInteractClass, worldClass);
|
||||
return callConstructor(c, worldServer);
|
||||
}
|
||||
|
||||
private static Object getWorldServer() {
|
||||
final Object server = getMinecraftServer();
|
||||
final Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
||||
final Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
||||
Object server = getMinecraftServer();
|
||||
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
||||
Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
||||
return callMethod(getWorldServer, server, 0);
|
||||
}
|
||||
|
||||
@ -85,8 +85,8 @@ public class OfflinePlayerUtil {
|
||||
return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
|
||||
}
|
||||
|
||||
private static Entity getBukkitEntity(final Object o) {
|
||||
final Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
||||
private static Entity getBukkitEntity(Object o) {
|
||||
Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
||||
return callMethod(getBukkitEntity, o);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
@ -17,11 +19,12 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
/**
|
||||
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
|
||||
*
|
||||
@ -29,17 +32,9 @@ import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
*/
|
||||
public class SendChunk {
|
||||
|
||||
// // Ref Class
|
||||
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
private final RefClass classPacket = getRefClass("{nms}.Packet");
|
||||
private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
private final RefMethod methodGetHandlePlayer;
|
||||
private final RefMethod methodGetHandleChunk;
|
||||
private final RefConstructor MapChunk;
|
||||
private final RefConstructor mapChunk;
|
||||
private final RefField connection;
|
||||
private final RefMethod send;
|
||||
private final RefMethod methodInitLighting;
|
||||
@ -48,32 +43,39 @@ public class SendChunk {
|
||||
* Constructor
|
||||
*/
|
||||
public SendChunk() {
|
||||
methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
methodInitLighting = classChunk.getMethod("initLighting");
|
||||
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||
connection = classEntityPlayer.getField("playerConnection");
|
||||
send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
||||
RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||
this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||
this.connection = classEntityPlayer.getField("playerConnection");
|
||||
RefClass classPacket = getRefClass("{nms}.Packet");
|
||||
RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
||||
this.send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
||||
}
|
||||
|
||||
public void sendChunk(final Collection<Chunk> input) {
|
||||
final HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
||||
final HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||
final int view = Bukkit.getServer().getViewDistance();
|
||||
for (final Chunk chunk : chunks) {
|
||||
final String world = chunk.getWorld().getName();
|
||||
public void sendChunk(Collection<Chunk> input) {
|
||||
HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
||||
HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||
int view = Bukkit.getServer().getViewDistance();
|
||||
for (Chunk chunk : chunks) {
|
||||
String world = chunk.getWorld().getName();
|
||||
ArrayList<Chunk> list = map.get(world);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
map.put(world, list);
|
||||
}
|
||||
list.add(chunk);
|
||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||
methodInitLighting.of(c).call();
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
}
|
||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||
PlotPlayer pp = entry.getValue();
|
||||
final Plot plot = pp.getCurrentPlot();
|
||||
Plot plot = pp.getCurrentPlot();
|
||||
Location loc = null;
|
||||
String world;
|
||||
if (plot != null) {
|
||||
@ -82,29 +84,29 @@ public class SendChunk {
|
||||
loc = pp.getLocation();
|
||||
world = loc.getWorld();
|
||||
}
|
||||
final ArrayList<Chunk> list = map.get(world);
|
||||
ArrayList<Chunk> list = map.get(world);
|
||||
if (list == null) {
|
||||
continue;
|
||||
}
|
||||
if (loc == null) {
|
||||
loc = pp.getLocation();
|
||||
}
|
||||
final int cx = loc.getX() >> 4;
|
||||
final int cz = loc.getZ() >> 4;
|
||||
final Player player = ((BukkitPlayer) pp).player;
|
||||
final Object entity = methodGetHandlePlayer.of(player).call();
|
||||
int cx = loc.getX() >> 4;
|
||||
int cz = loc.getZ() >> 4;
|
||||
Player player = ((BukkitPlayer) pp).player;
|
||||
Object entity = this.methodGetHandlePlayer.of(player).call();
|
||||
|
||||
for (final Chunk chunk : list) {
|
||||
final int dx = Math.abs(cx - chunk.getX());
|
||||
final int dz = Math.abs(cz - chunk.getZ());
|
||||
for (Chunk chunk : list) {
|
||||
int dx = Math.abs(cx - chunk.getX());
|
||||
int dz = Math.abs(cz - chunk.getZ());
|
||||
if ((dx > view) || (dz > view)) {
|
||||
continue;
|
||||
}
|
||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
chunks.remove(chunk);
|
||||
final Object con = connection.of(entity).get();
|
||||
final Object packet = MapChunk.create(c, true, 65535);
|
||||
send.of(con).call(packet);
|
||||
Object con = this.connection.of(entity).get();
|
||||
Object packet = this.mapChunk.create(c, true, 65535);
|
||||
this.send.of(con).call(packet);
|
||||
}
|
||||
}
|
||||
for (final Chunk chunk : chunks) {
|
||||
@ -113,8 +115,8 @@ public class SendChunk {
|
||||
public void run() {
|
||||
try {
|
||||
chunk.unload(true, false);
|
||||
} catch (final Throwable e) {
|
||||
final String worldname = chunk.getWorld().getName();
|
||||
} catch (Throwable e) {
|
||||
String worldname = chunk.getWorld().getName();
|
||||
PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
||||
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||
PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname
|
||||
@ -125,10 +127,10 @@ public class SendChunk {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendChunk(final String worldname, final Collection<ChunkLoc> locs) {
|
||||
final World myworld = Bukkit.getWorld(worldname);
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
for (final ChunkLoc loc : locs) {
|
||||
public void sendChunk(String worldname, Collection<ChunkLoc> locs) {
|
||||
World myworld = Bukkit.getWorld(worldname);
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
for (ChunkLoc loc : locs) {
|
||||
if (myworld.isChunkLoaded(loc.x, loc.z)) {
|
||||
chunks.add(myworld.getChunkAt(loc.x, loc.z));
|
||||
}
|
||||
|
@ -14,24 +14,24 @@ import java.util.Iterator;
|
||||
|
||||
public class SetGenCB {
|
||||
|
||||
public static void setGenerator(final World world) throws Exception {
|
||||
public static void setGenerator(World world) throws Exception {
|
||||
SetupUtils.manager.updateGenerators();
|
||||
PS.get().removePlotAreas(world.getName());
|
||||
final ChunkGenerator gen = world.getGenerator();
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen == null) {
|
||||
return;
|
||||
}
|
||||
final String name = gen.getClass().getCanonicalName();
|
||||
String name = gen.getClass().getCanonicalName();
|
||||
boolean set = false;
|
||||
for (final GeneratorWrapper<?> wrapper : SetupUtils.generators.values()) {
|
||||
for (GeneratorWrapper<?> wrapper : SetupUtils.generators.values()) {
|
||||
ChunkGenerator newGen = (ChunkGenerator) wrapper.getPlatformGenerator();
|
||||
if (newGen == null) {
|
||||
newGen = (ChunkGenerator) wrapper;
|
||||
}
|
||||
if (newGen.getClass().getCanonicalName().equals(name)) {
|
||||
// set generator
|
||||
final Field generator = world.getClass().getDeclaredField("generator");
|
||||
final Field populators = world.getClass().getDeclaredField("populators");
|
||||
Field generator = world.getClass().getDeclaredField("generator");
|
||||
Field populators = world.getClass().getDeclaredField("populators");
|
||||
generator.setAccessible(true);
|
||||
populators.setAccessible(true);
|
||||
// Set populators (just in case)
|
||||
@ -45,7 +45,7 @@ public class SetGenCB {
|
||||
}
|
||||
}
|
||||
if (!set) {
|
||||
final Iterator<BlockPopulator> iter = world.getPopulators().iterator();
|
||||
Iterator<BlockPopulator> iter = world.getPopulators().iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next() instanceof BukkitAugmentedGenerator) {
|
||||
iter.remove();
|
||||
|
@ -17,12 +17,13 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
public short[] relight;
|
||||
public int[][] biomes;
|
||||
public Chunk chunk;
|
||||
public FastChunk_1_8_3(final ChunkWrapper chunk) {
|
||||
|
||||
public FastChunk_1_8_3(ChunkWrapper chunk) {
|
||||
super(chunk);
|
||||
ids = new char[16][];
|
||||
count = new short[16];
|
||||
air = new short[16];
|
||||
relight = new short[16];
|
||||
this.ids = new char[16][];
|
||||
this.count = new short[16];
|
||||
this.air = new short[16];
|
||||
this.relight = new short[16];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,17 +34,17 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
final ChunkWrapper cl = getChunkWrapper();
|
||||
chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||
if (this.chunk == null) {
|
||||
ChunkWrapper cl = getChunkWrapper();
|
||||
this.chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||
}
|
||||
return chunk;
|
||||
return this.chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunkWrapper(final ChunkWrapper loc) {
|
||||
public void setChunkWrapper(ChunkWrapper loc) {
|
||||
super.setChunkWrapper(loc);
|
||||
chunk = null;
|
||||
this.chunk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,44 +52,44 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getCount(final int i) {
|
||||
return count[i];
|
||||
public int getCount(int i) {
|
||||
return this.count[i];
|
||||
}
|
||||
|
||||
public int getAir(final int i) {
|
||||
return air[i];
|
||||
public int getAir(int i) {
|
||||
return this.air[i];
|
||||
}
|
||||
|
||||
public void setCount(int i, short value) {
|
||||
count[i] = value;
|
||||
this.count[i] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of block changes in a specified section
|
||||
* Get the number of block changes in a specified section.
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getRelight(final int i) {
|
||||
return relight[i];
|
||||
public int getRelight(int i) {
|
||||
return this.relight[i];
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
int total = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
total += count[i];
|
||||
total += this.count[i];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotalRelight() {
|
||||
if (getTotalCount() == 0) {
|
||||
Arrays.fill(count, (short) 1);
|
||||
Arrays.fill(relight, Short.MAX_VALUE);
|
||||
Arrays.fill(this.count, (short) 1);
|
||||
Arrays.fill(this.relight, Short.MAX_VALUE);
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
int total = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
total += relight[i];
|
||||
total += this.relight[i];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@ -98,24 +99,24 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public char[] getIdArray(final int i) {
|
||||
return ids[i];
|
||||
public char[] getIdArray(int i) {
|
||||
return this.ids[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(final int x, final int y, final int z, final int id, byte data) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
char[] vs = ids[i];
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
char[] vs = this.ids[i];
|
||||
if (vs == null) {
|
||||
vs = ids[i] = new char[4096];
|
||||
count[i]++;
|
||||
vs = this.ids[i] = new char[4096];
|
||||
this.count[i]++;
|
||||
} else if (vs[j] == 0) {
|
||||
count[i]++;
|
||||
this.count[i]++;
|
||||
}
|
||||
switch (id) {
|
||||
case 0:
|
||||
air[i]++;
|
||||
this.air[i]++;
|
||||
vs[j] = (char) 1;
|
||||
return;
|
||||
case 10:
|
||||
@ -129,7 +130,7 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
case 124:
|
||||
case 138:
|
||||
case 169:
|
||||
relight[i]++;
|
||||
this.relight[i]++;
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
@ -193,7 +194,7 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
case 130:
|
||||
case 76:
|
||||
case 62:
|
||||
relight[i]++;
|
||||
this.relight[i]++;
|
||||
case 54:
|
||||
case 146:
|
||||
case 61:
|
||||
@ -212,12 +213,12 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
||||
toReturn.air = air.clone();
|
||||
toReturn.count = count.clone();
|
||||
toReturn.relight = relight.clone();
|
||||
toReturn.ids = new char[ids.length][];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
char[] matrix = ids[i];
|
||||
toReturn.air = this.air.clone();
|
||||
toReturn.count = this.count.clone();
|
||||
toReturn.relight = this.relight.clone();
|
||||
toReturn.ids = new char[this.ids.length][];
|
||||
for (int i = 0; i < this.ids.length; i++) {
|
||||
char[] matrix = this.ids[i];
|
||||
if (matrix != null) {
|
||||
toReturn.ids[i] = new char[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.ids[i], 0, matrix.length);
|
||||
@ -229,18 +230,18 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
||||
toReturn.air = air;
|
||||
toReturn.count = count;
|
||||
toReturn.relight = relight;
|
||||
toReturn.ids = ids;
|
||||
toReturn.air = this.air;
|
||||
toReturn.count = this.count;
|
||||
toReturn.relight = this.relight;
|
||||
toReturn.ids = this.ids;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (biomes == null) {
|
||||
biomes = new int[16][16];
|
||||
if (this.biomes == null) {
|
||||
this.biomes = new int[16][16];
|
||||
}
|
||||
biomes[x][z] = biome;
|
||||
this.biomes[x][z] = biome;
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,13 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
public short[] relight;
|
||||
public int[][] biomes;
|
||||
public Chunk chunk;
|
||||
public FastChunk_1_9(final ChunkWrapper chunk) {
|
||||
|
||||
public FastChunk_1_9(ChunkWrapper chunk) {
|
||||
super(chunk);
|
||||
ids = new int[16][];
|
||||
count = new short[16];
|
||||
air = new short[16];
|
||||
relight = new short[16];
|
||||
this.ids = new int[16][];
|
||||
this.count = new short[16];
|
||||
this.air = new short[16];
|
||||
this.relight = new short[16];
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,17 +34,17 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
|
||||
@Override
|
||||
public Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
final ChunkWrapper cl = getChunkWrapper();
|
||||
chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||
if (this.chunk == null) {
|
||||
ChunkWrapper cl = getChunkWrapper();
|
||||
this.chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||
}
|
||||
return chunk;
|
||||
return this.chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunkWrapper(final ChunkWrapper loc) {
|
||||
public void setChunkWrapper(ChunkWrapper loc) {
|
||||
super.setChunkWrapper(loc);
|
||||
chunk = null;
|
||||
this.chunk = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,16 +52,16 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getCount(final int i) {
|
||||
return count[i];
|
||||
public int getCount(int i) {
|
||||
return this.count[i];
|
||||
}
|
||||
|
||||
public int getAir(final int i) {
|
||||
return air[i];
|
||||
public int getAir(int i) {
|
||||
return this.air[i];
|
||||
}
|
||||
|
||||
public void setCount(int i, short value) {
|
||||
count[i] = value;
|
||||
this.count[i] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,27 +69,27 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int getRelight(final int i) {
|
||||
return relight[i];
|
||||
public int getRelight(int i) {
|
||||
return this.relight[i];
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
int total = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
total += count[i];
|
||||
total += this.count[i];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotalRelight() {
|
||||
if (getTotalCount() == 0) {
|
||||
Arrays.fill(count, (short) 1);
|
||||
Arrays.fill(relight, Short.MAX_VALUE);
|
||||
Arrays.fill(this.count, (short) 1);
|
||||
Arrays.fill(this.relight, Short.MAX_VALUE);
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
int total = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
total += relight[i];
|
||||
total += this.relight[i];
|
||||
}
|
||||
return total;
|
||||
}
|
||||
@ -98,28 +99,28 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public int[] getIdArray(final int i) {
|
||||
return ids[i];
|
||||
public int[] getIdArray(int i) {
|
||||
return this.ids[i];
|
||||
}
|
||||
|
||||
public int[][] getIdArrays() {
|
||||
return ids;
|
||||
return this.ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(final int x, final int y, final int z, final int id, byte data) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
int[] vs = ids[i];
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
int[] vs = this.ids[i];
|
||||
if (vs == null) {
|
||||
vs = ids[i] = new int[4096];
|
||||
count[i]++;
|
||||
vs = this.ids[i] = new int[4096];
|
||||
this.count[i]++;
|
||||
} else if (vs[j] == 0) {
|
||||
count[i]++;
|
||||
this.count[i]++;
|
||||
}
|
||||
switch (id) {
|
||||
case 0:
|
||||
air[i]++;
|
||||
this.air[i]++;
|
||||
vs[j] = -1;
|
||||
return;
|
||||
case 10:
|
||||
@ -133,7 +134,7 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
case 124:
|
||||
case 138:
|
||||
case 169:
|
||||
relight[i]++;
|
||||
this.relight[i]++;
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
@ -192,12 +193,12 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
vs[j] = (id);
|
||||
vs[j] = id;
|
||||
return;
|
||||
case 130:
|
||||
case 76:
|
||||
case 62:
|
||||
relight[i]++;
|
||||
this.relight[i]++;
|
||||
case 54:
|
||||
case 146:
|
||||
case 61:
|
||||
@ -216,12 +217,12 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
||||
toReturn.air = air.clone();
|
||||
toReturn.count = count.clone();
|
||||
toReturn.relight = relight.clone();
|
||||
toReturn.ids = new int[ids.length][];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
int[] matrix = ids[i];
|
||||
toReturn.air = this.air.clone();
|
||||
toReturn.count = this.count.clone();
|
||||
toReturn.relight = this.relight.clone();
|
||||
toReturn.ids = new int[this.ids.length][];
|
||||
for (int i = 0; i < this.ids.length; i++) {
|
||||
int[] matrix = this.ids[i];
|
||||
if (matrix != null) {
|
||||
toReturn.ids[i] = new int[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.ids[i], 0, matrix.length);
|
||||
@ -233,18 +234,18 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
||||
toReturn.air = air;
|
||||
toReturn.count = count;
|
||||
toReturn.relight = relight;
|
||||
toReturn.ids = ids;
|
||||
toReturn.air = this.air;
|
||||
toReturn.count = this.count;
|
||||
toReturn.relight = this.relight;
|
||||
toReturn.ids = this.ids;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (biomes == null) {
|
||||
biomes = new int[16][16];
|
||||
if (this.biomes == null) {
|
||||
this.biomes = new int[16][16];
|
||||
}
|
||||
biomes[x][z] = biome;
|
||||
this.biomes[x][z] = biome;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.util.block;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -21,8 +23,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public class FastQueue_1_7 extends SlowQueue {
|
||||
|
||||
private final RefClass classBlock = getRefClass("{nms}.Block");
|
||||
@ -37,24 +37,24 @@ public class FastQueue_1_7 extends SlowQueue {
|
||||
|
||||
private final SendChunk chunksender;
|
||||
|
||||
private HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
|
||||
public FastQueue_1_7() throws NoSuchMethodException, RuntimeException {
|
||||
methodGetHandle = classCraftWorld.getMethod("getHandle");
|
||||
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class);
|
||||
methodGetById = classBlock.getMethod("getById", int.class);
|
||||
methodInitLighting = classChunk.getMethod("initLighting");
|
||||
chunksender = new SendChunk();
|
||||
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||
this.methodA = this.classChunk.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class);
|
||||
this.methodGetById = this.classBlock.getMethod("getById", int.class);
|
||||
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||
this.chunksender = new SendChunk();
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toUpdate.isEmpty()) {
|
||||
if (FastQueue_1_7.this.toUpdate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_7.this.toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && (count < 128)) {
|
||||
chunks.add(i.next().getValue());
|
||||
i.remove();
|
||||
@ -69,12 +69,12 @@ public class FastQueue_1_7 extends SlowQueue {
|
||||
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.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.unload(true, false);
|
||||
chunk.load();
|
||||
@ -82,8 +82,8 @@ public class FastQueue_1_7 extends SlowQueue {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
chunksender.sendChunk(chunks);
|
||||
} catch (final Throwable e) {
|
||||
this.chunksender.sendChunk(chunks);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
@ -91,36 +91,36 @@ public class FastQueue_1_7 extends SlowQueue {
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* @param pc
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
SlowChunk sc = (SlowChunk) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, chunk);
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
SlowChunk sc = (SlowChunk) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, chunk);
|
||||
}
|
||||
chunk.load(true);
|
||||
World world = chunk.getWorld();
|
||||
final Object w = methodGetHandle.of(world).call();
|
||||
final Object c = methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||
Object w = this.methodGetHandle.of(world).call();
|
||||
Object c = this.methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||
for (int i = 0; i < sc.result.length; i++) {
|
||||
PlotBlock[] result2 = sc.result[i];
|
||||
if (result2 == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int x = MainUtil.x_loc[i][j];
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
final int z = MainUtil.z_loc[i][j];
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
PlotBlock newBlock = result2[j];
|
||||
if (newBlock.id == -1) {
|
||||
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
||||
continue;
|
||||
}
|
||||
final Object block = methodGetById.call(newBlock.id);
|
||||
methodA.of(c).call(x, y, z, block, newBlock.data);
|
||||
Object block = this.methodGetById.call(newBlock.id);
|
||||
this.methodA.of(c).call(x, y, z, block, newBlock.data);
|
||||
}
|
||||
}
|
||||
int[][] biomes = sc.biomes;
|
||||
@ -152,29 +152,29 @@ public class FastQueue_1_7 extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* This should be overridden by any specialized queues
|
||||
* @param chunk
|
||||
* @param fixAll
|
||||
*/
|
||||
@Override
|
||||
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
||||
Object c = methodGetHandle.of(chunk.getChunk()).call();
|
||||
methodInitLighting.of(c).call();
|
||||
Object c = this.methodGetHandle.of(chunk.getChunk()).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locs) {
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
toUpdate.remove(wrapper);
|
||||
this.toUpdate.remove(wrapper);
|
||||
}
|
||||
chunksender.sendChunk(world, locs);
|
||||
this.chunksender.sendChunk(world, locations);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.plotsquared.bukkit.util.block;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
@ -23,8 +25,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public class FastQueue_1_8 extends SlowQueue {
|
||||
|
||||
private final RefMethod methodInitLighting;
|
||||
@ -34,31 +34,31 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
private final RefClass classWorld = getRefClass("{nms}.World");
|
||||
private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||
private HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private RefMethod methodGetHandle;
|
||||
private RefMethod methodGetChunkAt;
|
||||
private RefMethod methodA;
|
||||
private RefMethod methodGetByCombinedId;
|
||||
private RefConstructor constructorBlockPosition;
|
||||
private SendChunk chunksender;
|
||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private final RefMethod methodGetHandle;
|
||||
private final RefMethod methodGetChunkAt;
|
||||
private final RefMethod methodA;
|
||||
private final RefMethod methodGetByCombinedId;
|
||||
private final RefConstructor constructorBlockPosition;
|
||||
private final SendChunk chunksender;
|
||||
|
||||
public FastQueue_1_8() throws NoSuchMethodException, RuntimeException {
|
||||
methodInitLighting = classChunk.getMethod("initLighting");
|
||||
constructorBlockPosition = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
||||
methodGetHandle = classCraftWorld.getMethod("getHandle");
|
||||
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||
methodA = classChunk.getMethod("a", classBlockPosition, classIBlockData);
|
||||
chunksender = new SendChunk();
|
||||
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||
this.constructorBlockPosition = this.classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
this.methodGetByCombinedId = this.classBlock.getMethod("getByCombinedId", int.class);
|
||||
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||
this.methodA = this.classChunk.getMethod("a", this.classBlockPosition, this.classIBlockData);
|
||||
this.chunksender = new SendChunk();
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toUpdate.isEmpty()) {
|
||||
if (FastQueue_1_8.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_1_8.this.toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && (count < 128)) {
|
||||
chunks.add(i.next().getValue());
|
||||
i.remove();
|
||||
@ -73,12 +73,12 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
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.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.unload(true, false);
|
||||
chunk.load();
|
||||
@ -86,38 +86,38 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
chunksender.sendChunk(chunks);
|
||||
} catch (final Throwable e) {
|
||||
this.chunksender.sendChunk(chunks);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param pc
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
SlowChunk sc = (SlowChunk) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, chunk);
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
SlowChunk sc = (SlowChunk) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, chunk);
|
||||
}
|
||||
chunk.load(true);
|
||||
World world = chunk.getWorld();
|
||||
final Object w = methodGetHandle.of(world).call();
|
||||
final Object c = methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||
Object w = this.methodGetHandle.of(world).call();
|
||||
Object c = this.methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||
for (int i = 0; i < sc.result.length; i++) {
|
||||
PlotBlock[] result2 = sc.result[i];
|
||||
if (result2 == null) {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int x = MainUtil.x_loc[i][j];
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
final int z = MainUtil.z_loc[i][j];
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
PlotBlock newBlock = result2[j];
|
||||
if (newBlock.id == -1) {
|
||||
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
||||
@ -162,7 +162,7 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
case 33:
|
||||
case 151:
|
||||
case 178: {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (block.getData() == newBlock.data) {
|
||||
if (block.getTypeId() != newBlock.id) {
|
||||
block.setTypeId(newBlock.id, false);
|
||||
@ -179,8 +179,8 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
}
|
||||
|
||||
// Start data value shortcut
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
final int currentId = block.getTypeId();
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
int currentId = block.getTypeId();
|
||||
if (currentId == newBlock.id) {
|
||||
switch (newBlock.id) {
|
||||
case 0:
|
||||
@ -323,9 +323,9 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
// End blockstate workaround //
|
||||
|
||||
// check sign
|
||||
final Object pos = constructorBlockPosition.create(x, y, z);
|
||||
final Object combined = methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
||||
methodA.of(chunk).call(pos, combined);
|
||||
Object pos = this.constructorBlockPosition.create(x, y, z);
|
||||
Object combined = this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
||||
this.methodA.of(chunk).call(pos, combined);
|
||||
}
|
||||
}
|
||||
int[][] biomes = sc.biomes;
|
||||
@ -348,7 +348,7 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param wrap
|
||||
*/
|
||||
@Override
|
||||
@ -357,27 +357,27 @@ public class FastQueue_1_8 extends SlowQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param fixAll
|
||||
*/
|
||||
@Override
|
||||
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
||||
Object c = methodGetHandle.of(chunk.getChunk()).call();
|
||||
methodInitLighting.of(c).call();
|
||||
Object c = this.methodGetHandle.of(chunk.getChunk()).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* @param locs
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param locations
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locs) {
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
toUpdate.remove(wrapper);
|
||||
this.toUpdate.remove(wrapper);
|
||||
}
|
||||
chunksender.sendChunk(world, locs);
|
||||
this.chunksender.sendChunk(world, locations);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
package com.plotsquared.bukkit.util.block;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotChunk;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
|
||||
import com.intellectualcrafters.plot.util.SetQueue;
|
||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.util.SendChunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
@ -20,59 +25,57 @@ import org.bukkit.block.Biome;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||
import java.util.Set;
|
||||
|
||||
public class FastQueue_1_8_3 extends SlowQueue {
|
||||
|
||||
private final SendChunk chunksender;
|
||||
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
private final RefClass classPacket = getRefClass("{nms}.Packet");
|
||||
private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
private final RefClass classWorld = getRefClass("{nms}.World");
|
||||
private final RefField mustSave = classChunk.getField("mustSave");
|
||||
private final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||
private final RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||
private HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private RefMethod methodGetHandleChunk;
|
||||
private RefConstructor MapChunk;
|
||||
private RefMethod methodInitLighting;
|
||||
private RefConstructor classBlockPositionConstructor;
|
||||
private RefConstructor classChunkSectionConstructor;
|
||||
private RefMethod methodX;
|
||||
private RefMethod methodAreNeighborsLoaded;
|
||||
private RefField fieldSections;
|
||||
private RefField fieldWorld;
|
||||
private RefMethod methodGetIdArray;
|
||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private final RefMethod methodGetHandleChunk;
|
||||
private final RefConstructor MapChunk;
|
||||
private final RefMethod methodInitLighting;
|
||||
private final RefConstructor classBlockPositionConstructor;
|
||||
private final RefConstructor classChunkSectionConstructor;
|
||||
private final RefMethod methodX;
|
||||
private final RefMethod methodAreNeighborsLoaded;
|
||||
private final RefField fieldSections;
|
||||
private final RefField fieldWorld;
|
||||
private final RefMethod methodGetIdArray;
|
||||
|
||||
public FastQueue_1_8_3() throws NoSuchMethodException, RuntimeException {
|
||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
methodInitLighting = classChunk.getMethod("initLighting");
|
||||
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||
classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
||||
fieldSections = classChunk.getField("sections");
|
||||
fieldWorld = classChunk.getField("world");
|
||||
methodGetIdArray = classChunkSection.getMethod("getIdArray");
|
||||
methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||
classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||
chunksender = new SendChunk();
|
||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||
this.MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||
RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
RefClass classWorld = getRefClass("{nms}.World");
|
||||
this.methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
||||
this.fieldSections = classChunk.getField("sections");
|
||||
this.fieldWorld = classChunk.getField("world");
|
||||
RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||
this.methodGetIdArray = classChunkSection.getMethod("getIdArray");
|
||||
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||
this.chunksender = new SendChunk();
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toUpdate.isEmpty()) {
|
||||
if (FastQueue_1_8_3.this.toUpdate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && (count < 128)) {
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_8_3.this.toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && count < 128) {
|
||||
chunks.add(i.next().getValue());
|
||||
i.remove();
|
||||
count++;
|
||||
@ -86,12 +89,12 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
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.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.unload(true, false);
|
||||
chunk.load();
|
||||
@ -99,70 +102,70 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
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
|
||||
* @param pc
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
FastChunk_1_8_3 fs = (FastChunk_1_8_3) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
final World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, chunk);
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
FastChunk_1_8_3 fs = (FastChunk_1_8_3) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, chunk);
|
||||
}
|
||||
chunk.load(true);
|
||||
try {
|
||||
final boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||
boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||
|
||||
// Sections
|
||||
final Method getHandele = chunk.getClass().getDeclaredMethod("getHandle");
|
||||
final Object c = getHandele.invoke(chunk);
|
||||
final Class<? extends Object> clazz = c.getClass();
|
||||
final Field sf = clazz.getDeclaredField("sections");
|
||||
sf.setAccessible(true);
|
||||
final Field tf = clazz.getDeclaredField("tileEntities");
|
||||
final Field ef = clazz.getDeclaredField("entitySlices");
|
||||
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||
Object c = getHandle.invoke(chunk);
|
||||
Class<? extends Object> clazz = c.getClass();
|
||||
Field sections1 = clazz.getDeclaredField("sections");
|
||||
sections1.setAccessible(true);
|
||||
Field tileEntities = clazz.getDeclaredField("tileEntities");
|
||||
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||
|
||||
final Object[] sections = (Object[]) sf.get(c);
|
||||
final HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
||||
final List<?>[] entities = (List<?>[]) ef.get(c);
|
||||
Object[] sections = (Object[]) sections1.get(c);
|
||||
HashMap<?, ?> tiles = (HashMap<?, ?>) tileEntities.get(c);
|
||||
List<?>[] entities = (List<?>[]) entitySlices.get(c);
|
||||
|
||||
Method xm = null;
|
||||
Method ym = null;
|
||||
Method zm = null;
|
||||
Method getX = null;
|
||||
Method getY = null;
|
||||
Method getZ = null;
|
||||
|
||||
// Trim tiles
|
||||
final Set<Entry<?, ?>> entryset = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||
final Iterator<Entry<?, ?>> iter = entryset.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Entry<?, ?> tile = iter.next();
|
||||
final Object pos = tile.getKey();
|
||||
if (xm == null) {
|
||||
final Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||
xm = clazz2.getDeclaredMethod("getX");
|
||||
ym = clazz2.getDeclaredMethod("getY");
|
||||
zm = clazz2.getDeclaredMethod("getZ");
|
||||
Set<Entry<?, ?>> entrySet = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||
Iterator<Entry<?, ?>> iterator = entrySet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<?, ?> tile = iterator.next();
|
||||
Object pos = tile.getKey();
|
||||
if (getX == null) {
|
||||
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||
getX = clazz2.getDeclaredMethod("getX");
|
||||
getY = clazz2.getDeclaredMethod("getY");
|
||||
getZ = clazz2.getDeclaredMethod("getZ");
|
||||
}
|
||||
final int lx = (int) xm.invoke(pos) & 15;
|
||||
final int ly = (int) ym.invoke(pos);
|
||||
final int lz = (int) zm.invoke(pos) & 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 = (int) getX.invoke(pos) & 15;
|
||||
int ly = (int) getY.invoke(pos);
|
||||
int lz = (int) getZ.invoke(pos) & 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;
|
||||
}
|
||||
if (array[k] != 0) {
|
||||
iter.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +181,7 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
if (fs.getCount(j) == 0) {
|
||||
continue;
|
||||
}
|
||||
final char[] newArray = fs.getIdArray(j);
|
||||
char[] newArray = fs.getIdArray(j);
|
||||
if (newArray == null) {
|
||||
continue;
|
||||
}
|
||||
@ -187,10 +190,10 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
section = sections[j] = newChunkSection(j << 4, flag, newArray);
|
||||
continue;
|
||||
}
|
||||
final char[] currentArray = getIdArray(section);
|
||||
char[] currentArray = getIdArray(section);
|
||||
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;
|
||||
@ -209,8 +212,8 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
}
|
||||
}
|
||||
// Clear
|
||||
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException |
|
||||
NoSuchFieldException e) {
|
||||
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException
|
||||
| NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int[][] biomes = fs.biomes;
|
||||
@ -232,16 +235,16 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
}
|
||||
}
|
||||
|
||||
public Object newChunkSection(final int i, final boolean flag, final char[] ids) {
|
||||
return classChunkSectionConstructor.create(i, flag, ids);
|
||||
public Object newChunkSection(int i, boolean flag, char[] ids) {
|
||||
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||
}
|
||||
|
||||
public char[] getIdArray(final Object obj) {
|
||||
return (char[]) methodGetIdArray.of(obj).call();
|
||||
public char[] getIdArray(Object obj) {
|
||||
return (char[]) this.methodGetIdArray.of(obj).call();
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param wrap
|
||||
*/
|
||||
@Override
|
||||
@ -251,13 +254,13 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* @param pc
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
|
||||
public boolean fixLighting(PlotChunk<Chunk> plotChunk, boolean fixAll) {
|
||||
try {
|
||||
FastChunk_1_8_3 bc = (FastChunk_1_8_3) pc;
|
||||
final Chunk chunk = bc.getChunk();
|
||||
FastChunk_1_8_3 bc = (FastChunk_1_8_3) plotChunk;
|
||||
Chunk chunk = bc.getChunk();
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load(false);
|
||||
} else {
|
||||
@ -266,12 +269,12 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
}
|
||||
|
||||
// Initialize lighting
|
||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
|
||||
if (fixAll && !(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
if (fixAll && !(boolean) this.methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = bc.getChunkWrapper();
|
||||
String worldname = wrapper.world;
|
||||
String worldName = wrapper.world;
|
||||
for (int x = wrapper.x - 1; x <= wrapper.x + 1; x++) {
|
||||
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
|
||||
if (x != 0 && z != 0) {
|
||||
@ -279,44 +282,46 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
||||
while (!other.isLoaded()) {
|
||||
other.load(true);
|
||||
}
|
||||
ChunkManager.manager.loadChunk(worldname, new ChunkLoc(x, z), true);
|
||||
ChunkManager.manager.loadChunk(worldName, new ChunkLoc(x, z), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
// return false;
|
||||
// }
|
||||
/*
|
||||
if (!(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
methodInitLighting.of(c).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
|
||||
if ((bc.getTotalRelight() == 0 && !fixAll)) {
|
||||
if (bc.getTotalRelight() == 0 && !fixAll) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Object[] sections = (Object[]) fieldSections.of(c).get();
|
||||
final Object w = fieldWorld.of(c).get();
|
||||
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||
Object w = this.fieldWorld.of(c).get();
|
||||
|
||||
final int X = chunk.getX() << 4;
|
||||
final int Z = chunk.getZ() << 4;
|
||||
int X = chunk.getX() << 4;
|
||||
int Z = chunk.getZ() << 4;
|
||||
|
||||
RefExecutor relight = methodX.of(w);
|
||||
RefExecutor relight = this.methodX.of(w);
|
||||
for (int j = 0; j < sections.length; j++) {
|
||||
final Object section = sections[j];
|
||||
Object section = sections[j];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
||||
continue;
|
||||
}
|
||||
final char[] array = getIdArray(section);
|
||||
char[] array = getIdArray(section);
|
||||
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) {
|
||||
@ -341,19 +346,19 @@ public class FastQueue_1_8_3 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;
|
||||
}
|
||||
final Object pos = classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||
relight.call(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -389,17 +394,16 @@ public class FastQueue_1_8_3 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) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locs) {
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
toUpdate.remove(wrapper);
|
||||
this.toUpdate.remove(wrapper);
|
||||
}
|
||||
chunksender.sendChunk(world, locs);
|
||||
this.chunksender.sendChunk(world, locations);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ import java.util.Set;
|
||||
public class FastQueue_1_9 extends SlowQueue {
|
||||
|
||||
private final Object air;
|
||||
private final SendChunk chunksender;
|
||||
private final SendChunk chunkSender;
|
||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||
private final RefMethod methodGetHandleChunk;
|
||||
private final RefMethod methodInitLighting;
|
||||
@ -55,36 +55,36 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
|
||||
public FastQueue_1_9() throws RuntimeException {
|
||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
methodInitLighting = classChunk.getMethod("initLighting");
|
||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||
RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||
classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||
RefClass classWorld = getRefClass("{nms}.World");
|
||||
methodW = classWorld.getMethod("w", classBlockPosition.getRealClass());
|
||||
fieldSections = classChunk.getField("sections");
|
||||
fieldWorld = classChunk.getField("world");
|
||||
this.methodW = classWorld.getMethod("w", classBlockPosition.getRealClass());
|
||||
this.fieldSections = classChunk.getField("sections");
|
||||
this.fieldWorld = classChunk.getField("world");
|
||||
RefClass classBlock = getRefClass("{nms}.Block");
|
||||
RefClass classIBlockData = getRefClass("{nms}.IBlockData");
|
||||
methodGetCombinedId = classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
||||
methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
||||
this.methodGetCombinedId = classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
||||
this.methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
||||
RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||
methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
||||
methodGetType = classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
||||
methodSetType = classChunkSection.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
||||
methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||
classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||
air = methodGetByCombinedId.call(0);
|
||||
chunksender = new SendChunk();
|
||||
this.methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
||||
this.methodGetType = classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
||||
this.methodSetType = classChunkSection.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
||||
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||
this.air = this.methodGetByCombinedId.call(0);
|
||||
this.chunkSender = new SendChunk();
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (toUpdate.isEmpty()) {
|
||||
if (FastQueue_1_9.this.toUpdate.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
||||
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_9.this.toUpdate.entrySet().iterator();
|
||||
while (i.hasNext() && count < 128) {
|
||||
chunks.add(i.next().getValue());
|
||||
i.remove();
|
||||
@ -99,12 +99,12 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
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.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.unload(true, true);
|
||||
chunk.load();
|
||||
@ -112,8 +112,8 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
chunksender.sendChunk(chunks);
|
||||
} catch (final Throwable e) {
|
||||
this.chunkSender.sendChunk(chunks);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.canSendChunk = false;
|
||||
}
|
||||
@ -121,60 +121,60 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* @param pc
|
||||
* @param plotChunk
|
||||
*/
|
||||
@Override
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
FastChunk_1_9 fs = (FastChunk_1_9) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
final World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
||||
if (!toUpdate.containsKey(wrapper)) {
|
||||
toUpdate.put(wrapper, chunk);
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
FastChunk_1_9 fs = (FastChunk_1_9) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||
if (!this.toUpdate.containsKey(wrapper)) {
|
||||
this.toUpdate.put(wrapper, chunk);
|
||||
}
|
||||
chunk.load(true);
|
||||
try {
|
||||
final boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||
boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||
|
||||
// Sections
|
||||
final Method getHandele = chunk.getClass().getDeclaredMethod("getHandle");
|
||||
final Object c = getHandele.invoke(chunk);
|
||||
final Class<? extends Object> clazz = c.getClass();
|
||||
final Field sf = clazz.getDeclaredField("sections");
|
||||
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||
Object c = getHandle.invoke(chunk);
|
||||
Class<? extends Object> clazz = c.getClass();
|
||||
Field sf = clazz.getDeclaredField("sections");
|
||||
sf.setAccessible(true);
|
||||
final Field tf = clazz.getDeclaredField("tileEntities");
|
||||
final Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||
Field tf = clazz.getDeclaredField("tileEntities");
|
||||
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||
|
||||
final Object[] sections = (Object[]) sf.get(c);
|
||||
final HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
||||
final Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
||||
Object[] sections = (Object[]) sf.get(c);
|
||||
HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
||||
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
||||
|
||||
Method xm = null;
|
||||
Method ym = null;
|
||||
Method zm = null;
|
||||
// Trim tiles
|
||||
final Set<Entry<?, ?>> entryset = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||
final Iterator<Entry<?, ?>> iter = entryset.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final Entry<?, ?> tile = iter.next();
|
||||
final Object pos = tile.getKey();
|
||||
Set<Entry<?, ?>> entrySet = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||
Iterator<Entry<?, ?>> iterator = entrySet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<?, ?> tile = iterator.next();
|
||||
Object pos = tile.getKey();
|
||||
if (xm == null) {
|
||||
final Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||
xm = clazz2.getDeclaredMethod("getX");
|
||||
ym = clazz2.getDeclaredMethod("getY");
|
||||
zm = clazz2.getDeclaredMethod("getZ");
|
||||
}
|
||||
final int lx = (int) xm.invoke(pos) & 15;
|
||||
final int ly = (int) ym.invoke(pos);
|
||||
final int lz = (int) zm.invoke(pos) & 15;
|
||||
final int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||
final int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||
final int[] array = fs.getIdArray(j);
|
||||
int lx = (int) xm.invoke(pos) & 15;
|
||||
int ly = (int) ym.invoke(pos);
|
||||
int lz = (int) zm.invoke(pos) & 15;
|
||||
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||
int[] array = fs.getIdArray(j);
|
||||
if (array == null) {
|
||||
continue;
|
||||
}
|
||||
if (array[k] != 0) {
|
||||
iter.remove();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
if (fs.getCount(j) == 0) {
|
||||
continue;
|
||||
}
|
||||
final int[] newArray = fs.getIdArray(j);
|
||||
int[] newArray = fs.getIdArray(j);
|
||||
if (newArray == null) {
|
||||
continue;
|
||||
}
|
||||
@ -206,11 +206,11 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
section = sections[j] = newChunkSection(j << 4, flag, array);
|
||||
continue;
|
||||
}
|
||||
final Object currentArray = getBlocks(section);
|
||||
RefExecutor setType = methodSetType.of(section);
|
||||
Object currentArray = getBlocks(section);
|
||||
RefExecutor setType = this.methodSetType.of(section);
|
||||
boolean fill = true;
|
||||
for (int k = 0; k < newArray.length; k++) {
|
||||
final int n = newArray[k];
|
||||
int n = newArray[k];
|
||||
switch (n) {
|
||||
case 0:
|
||||
fill = false;
|
||||
@ -220,15 +220,15 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
int x = MainUtil.x_loc[j][k];
|
||||
int y = MainUtil.y_loc[j][k];
|
||||
int z = MainUtil.z_loc[j][k];
|
||||
setType.call(x, y & 15, z, air);
|
||||
setType.call(x, y & 15, z, this.air);
|
||||
continue;
|
||||
}
|
||||
default: {
|
||||
int x = MainUtil.x_loc[j][k];
|
||||
int y = MainUtil.y_loc[j][k];
|
||||
int z = MainUtil.z_loc[j][k];
|
||||
Object iblock = methodGetByCombinedId.call((int) n);
|
||||
setType.call(x, y & 15, z, iblock);
|
||||
Object iBlock = this.methodGetByCombinedId.call((int) n);
|
||||
setType.call(x, y & 15, z, iBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -260,12 +260,12 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
}
|
||||
}
|
||||
|
||||
public Object newChunkSection(final int i, final boolean flag, final char[] ids) {
|
||||
return classChunkSectionConstructor.create(i, flag, ids);
|
||||
public Object newChunkSection(int i, boolean flag, char[] ids) {
|
||||
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||
}
|
||||
|
||||
public Object getBlocks(final Object obj) {
|
||||
return methodGetBlocks.of(obj).call();
|
||||
public Object getBlocks(Object obj) {
|
||||
return this.methodGetBlocks.of(obj).call();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,7 +285,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
|
||||
try {
|
||||
FastChunk_1_9 bc = (FastChunk_1_9) pc;
|
||||
final Chunk chunk = bc.getChunk();
|
||||
Chunk chunk = bc.getChunk();
|
||||
if (!chunk.isLoaded()) {
|
||||
chunk.load(false);
|
||||
} else {
|
||||
@ -294,9 +294,9 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
}
|
||||
|
||||
// Initialize lighting
|
||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
|
||||
if (fixAll && !(boolean) methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
if (fixAll && !(boolean) this.methodAreNeighborsLoaded.of(c).call(1)) {
|
||||
World world = chunk.getWorld();
|
||||
ChunkWrapper wrapper = bc.getChunkWrapper();
|
||||
String worldname = wrapper.world;
|
||||
@ -313,36 +313,36 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
}
|
||||
}
|
||||
|
||||
methodInitLighting.of(c).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
|
||||
if (bc.getTotalRelight() == 0 && !fixAll) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Object[] sections = (Object[]) fieldSections.of(c).get();
|
||||
final Object w = fieldWorld.of(c).get();
|
||||
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||
Object w = this.fieldWorld.of(c).get();
|
||||
|
||||
final int X = chunk.getX() << 4;
|
||||
final int Z = chunk.getZ() << 4;
|
||||
int X = chunk.getX() << 4;
|
||||
int Z = chunk.getZ() << 4;
|
||||
|
||||
RefExecutor relight = methodW.of(w);
|
||||
RefExecutor relight = this.methodW.of(w);
|
||||
for (int j = 0; j < sections.length; j++) {
|
||||
final Object section = sections[j];
|
||||
Object section = sections[j];
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
|
||||
continue;
|
||||
}
|
||||
final int[] array = bc.getIdArray(j);
|
||||
int[] array = bc.getIdArray(j);
|
||||
if (array != null) {
|
||||
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) {
|
||||
@ -367,20 +367,20 @@ public class FastQueue_1_9 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(bc.getIdArrays(), x, y, z)) {
|
||||
continue;
|
||||
}
|
||||
final Object pos = classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||
relight.call(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -397,7 +397,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
public boolean isSolid(int i) {
|
||||
if (i != 0) {
|
||||
Material material = Material.getMaterial(i);
|
||||
return material != null && Material.getMaterial(i).isOccluding();
|
||||
return material != null && Material.getMaterial(i).isOccluding();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -420,8 +420,8 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
|
||||
public int getId(Object section, int x, int y, int z) {
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
Object iblock = methodGetType.of(section).call(x, y & 15, z);
|
||||
return (int) methodGetCombinedId.call(iblock);
|
||||
Object iBlock = this.methodGetType.of(section).call(x, y & 15, z);
|
||||
return (int) this.methodGetCombinedId.call(iBlock);
|
||||
}
|
||||
|
||||
public int getId(Object[] sections, int x, int y, int z) {
|
||||
@ -436,26 +436,26 @@ public class FastQueue_1_9 extends SlowQueue {
|
||||
if (section == null) {
|
||||
return 0;
|
||||
}
|
||||
// Object array = getBlocks(section);
|
||||
// Object array = getBlocks(section);
|
||||
return getId(section, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overridden by any specialized queues
|
||||
* @param world
|
||||
* @param locs
|
||||
* @param locations
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(final String world, final Collection<ChunkLoc> locs) {
|
||||
public void sendChunk(final String world, final Collection<ChunkLoc> locations) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
for (ChunkLoc loc : locs) {
|
||||
for (ChunkLoc loc : locations) {
|
||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||
toUpdate.remove(wrapper);
|
||||
this.toUpdate.remove(wrapper);
|
||||
}
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chunksender.sendChunk(world, locs);
|
||||
FastQueue_1_9.this.chunkSender.sendChunk(world, locations);
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
@ -33,40 +33,40 @@ public class GenChunk extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public Chunk getChunkAbs() {
|
||||
ChunkWrapper wrap = getChunkWrapper();
|
||||
if (chunk == null || wrap.x != chunk.getX() || wrap.z != chunk.getZ()) {
|
||||
chunk = BukkitUtil.getWorld(wrap.world).getChunkAt(wrap.x, wrap.z);
|
||||
if (this.chunk == null || wrap.x != this.chunk.getX() || wrap.z != this.chunk.getZ()) {
|
||||
this.chunk = BukkitUtil.getWorld(wrap.world).getChunkAt(wrap.x, wrap.z);
|
||||
}
|
||||
return chunk;
|
||||
return this.chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
grid.setBiome(x, z, biomes[biome]);
|
||||
this.grid.setBiome(x, z, this.biomes[biome]);
|
||||
}
|
||||
|
||||
public void setBiome(int x, int z, Biome biome) {
|
||||
if (grid != null) {
|
||||
grid.setBiome(x, z, biome);
|
||||
if (this.grid != null) {
|
||||
this.grid.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
if (result == null) {
|
||||
cd.setBlock(x, y, z, id, data);
|
||||
if (this.result == null) {
|
||||
this.cd.setBlock(x, y, z, id, data);
|
||||
return;
|
||||
}
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
short[] v = result[i];
|
||||
short[] v = this.result[i];
|
||||
if (v == null) {
|
||||
result[i] = v = new short[4096];
|
||||
this.result[i] = v = new short[4096];
|
||||
}
|
||||
int j = MainUtil.CACHE_J[y][x][z];
|
||||
v[j] = (short) id;
|
||||
if (data != 0) {
|
||||
byte[] vd = result_data[i];
|
||||
byte[] vd = this.result_data[i];
|
||||
if (vd == null) {
|
||||
result_data[i] = vd = new byte[4096];
|
||||
this.result_data[i] = vd = new byte[4096];
|
||||
}
|
||||
vd[j] = data;
|
||||
}
|
||||
@ -75,32 +75,32 @@ public class GenChunk extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
||||
if (result != null) {
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
short[] matrix = result[i];
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
short[] matrix = this.result[i];
|
||||
if (matrix != null) {
|
||||
toReturn.result[i] = new short[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < result_data.length; i++) {
|
||||
byte[] matrix = result_data[i];
|
||||
for (int i = 0; i < this.result_data.length; i++) {
|
||||
byte[] matrix = this.result_data[i];
|
||||
if (matrix != null) {
|
||||
toReturn.result_data[i] = new byte[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.result_data[i], 0, matrix.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
toReturn.cd = cd;
|
||||
toReturn.cd = this.cd;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
||||
toReturn.result = result;
|
||||
toReturn.result_data = result_data;
|
||||
toReturn.cd = cd;
|
||||
toReturn.result = this.result;
|
||||
toReturn.result_data = this.result_data;
|
||||
toReturn.cd = this.cd;
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
||||
|
||||
public PlotBlock[][] result = new PlotBlock[16][];
|
||||
public int[][] biomes;
|
||||
|
||||
public SlowChunk(ChunkWrapper chunk) {
|
||||
super(chunk);
|
||||
}
|
||||
@ -23,25 +24,25 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, int biome) {
|
||||
if (biomes == null) {
|
||||
biomes = new int[16][16];
|
||||
if (this.biomes == null) {
|
||||
this.biomes = new int[16][16];
|
||||
}
|
||||
biomes[x][z] = biome;
|
||||
this.biomes[x][z] = biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||
if (result[y >> 4] == null) {
|
||||
result[y >> 4] = new PlotBlock[4096];
|
||||
if (this.result[y >> 4] == null) {
|
||||
this.result[y >> 4] = new PlotBlock[4096];
|
||||
}
|
||||
result[MainUtil.CACHE_I[y][x][z]][MainUtil.CACHE_J[y][x][z]] = new PlotBlock((short) id, data);
|
||||
this.result[MainUtil.CACHE_I[y][x][z]][MainUtil.CACHE_J[y][x][z]] = new PlotBlock((short) id, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotChunk clone() {
|
||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
PlotBlock[] matrix = result[i];
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
PlotBlock[] matrix = this.result[i];
|
||||
if (matrix != null) {
|
||||
toReturn.result[i] = new PlotBlock[matrix.length];
|
||||
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
||||
@ -53,7 +54,7 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
||||
@Override
|
||||
public PlotChunk shallowClone() {
|
||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||
toReturn.result = result;
|
||||
toReturn.result = this.result;
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@ -30,18 +30,18 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
if (y > 255 || y < 0) {
|
||||
return false;
|
||||
}
|
||||
final ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, x >> 4, z >> 4);
|
||||
ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, x >> 4, z >> 4);
|
||||
x = x & 15;
|
||||
z = z & 15;
|
||||
PlotChunk<Chunk> result = blocks.get(wrap);
|
||||
PlotChunk<Chunk> result = this.blocks.get(wrap);
|
||||
if (result == null) {
|
||||
result = getChunk(wrap);
|
||||
result.setBlock(x, y, z, id, data);
|
||||
final PlotChunk<Chunk> previous = blocks.put(wrap, result);
|
||||
PlotChunk<Chunk> previous = this.blocks.put(wrap, result);
|
||||
if (previous == null) {
|
||||
return true;
|
||||
}
|
||||
blocks.put(wrap, previous);
|
||||
this.blocks.put(wrap, previous);
|
||||
result = previous;
|
||||
}
|
||||
result.setBlock(x, y, z, id, data);
|
||||
@ -50,7 +50,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
|
||||
@Override
|
||||
public void setChunk(PlotChunk<Chunk> chunk) {
|
||||
blocks.put(chunk.getChunkWrapper(), chunk);
|
||||
this.blocks.put(chunk.getChunkWrapper(), chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,11 +59,11 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
throw new IllegalStateException("Must be called from main thread!");
|
||||
}
|
||||
try {
|
||||
if (blocks.isEmpty()) {
|
||||
if (this.blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = blocks.entrySet().iterator();
|
||||
final PlotChunk<Chunk> toReturn = iter.next().getValue();
|
||||
Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = this.blocks.entrySet().iterator();
|
||||
PlotChunk<Chunk> toReturn = iter.next().getValue();
|
||||
if (SetQueue.IMP.isWaiting()) {
|
||||
return null;
|
||||
}
|
||||
@ -71,7 +71,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
execute(toReturn);
|
||||
fixLighting(toReturn, true);
|
||||
return toReturn;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -83,17 +83,17 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
throw new IllegalStateException("Must be called from main thread!");
|
||||
}
|
||||
try {
|
||||
if (blocks.isEmpty()) {
|
||||
if (this.blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
final PlotChunk<Chunk> toReturn = blocks.remove(wrap);
|
||||
PlotChunk<Chunk> toReturn = this.blocks.remove(wrap);
|
||||
if (toReturn == null) {
|
||||
return null;
|
||||
}
|
||||
execute(toReturn);
|
||||
fixLighting(toReturn, fixLighting);
|
||||
return toReturn;
|
||||
} catch (final Throwable e) {
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@ -101,16 +101,16 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
blocks.clear();
|
||||
this.blocks.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param pc
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param plotChunk
|
||||
*/
|
||||
public void execute(PlotChunk<Chunk> pc) {
|
||||
SlowChunk sc = (SlowChunk) pc;
|
||||
Chunk chunk = pc.getChunk();
|
||||
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||
SlowChunk sc = (SlowChunk) plotChunk;
|
||||
Chunk chunk = plotChunk.getChunk();
|
||||
chunk.load(true);
|
||||
for (int i = 0; i < sc.result.length; i++) {
|
||||
PlotBlock[] result2 = sc.result[i];
|
||||
@ -118,9 +118,9 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
final int x = MainUtil.x_loc[i][j];
|
||||
final int y = MainUtil.y_loc[i][j];
|
||||
final int z = MainUtil.z_loc[i][j];
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
Block block = chunk.getBlock(x, y, z);
|
||||
PlotBlock newBlock = result2[j];
|
||||
if (newBlock == null) {
|
||||
@ -252,7 +252,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param wrap
|
||||
*/
|
||||
@Override
|
||||
@ -261,7 +261,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param fixAll
|
||||
*/
|
||||
@Override
|
||||
@ -271,11 +271,11 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be overriden by any specialized queues
|
||||
* @param locs
|
||||
* This should be overridden by any specialized queues.
|
||||
* @param locations
|
||||
*/
|
||||
@Override
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
||||
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user