mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Major code reformatting
This commit is contained in:
parent
e18e1d4816
commit
9e2c6f2182
@ -42,8 +42,8 @@ import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
|||||||
import com.plotsquared.bukkit.listeners.ChunkListener;
|
import com.plotsquared.bukkit.listeners.ChunkListener;
|
||||||
import com.plotsquared.bukkit.listeners.ForceFieldListener;
|
import com.plotsquared.bukkit.listeners.ForceFieldListener;
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents;
|
import com.plotsquared.bukkit.listeners.PlayerEvents;
|
||||||
|
import com.plotsquared.bukkit.listeners.PlayerEvents183;
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
|
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
|
||||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8_3;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener;
|
import com.plotsquared.bukkit.listeners.PlotPlusListener;
|
||||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
import com.plotsquared.bukkit.listeners.WorldEvents;
|
||||||
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
|
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
|
||||||
@ -87,6 +87,7 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
import org.bukkit.metadata.MetadataValue;
|
import org.bukkit.metadata.MetadataValue;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -104,14 +105,14 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getServerVersion() {
|
public int[] getServerVersion() {
|
||||||
if (version == null) {
|
if (this.version == null) {
|
||||||
try {
|
try {
|
||||||
version = new int[3];
|
this.version = new int[3];
|
||||||
final String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\.");
|
||||||
version[0] = Integer.parseInt(split[0]);
|
this.version[0] = Integer.parseInt(split[0]);
|
||||||
version[1] = Integer.parseInt(split[1]);
|
this.version[1] = Integer.parseInt(split[1]);
|
||||||
if (split.length == 3) {
|
if (split.length == 3) {
|
||||||
version[2] = Integer.parseInt(split[2]);
|
this.version[2] = Integer.parseInt(split[2]);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -120,7 +121,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
return new int[]{Integer.MAX_VALUE, 0, 0};
|
return new int[]{Integer.MAX_VALUE, 0, 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -146,7 +147,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
Bukkit.getServer().getConsoleSender().sendMessage(message);
|
||||||
return;
|
return;
|
||||||
} catch (final Throwable e) {}
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.out.println(ConsoleColors.fromString(message));
|
System.out.println(ConsoleColors.fromString(message));
|
||||||
}
|
}
|
||||||
@ -160,14 +162,14 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getPluginVersion() {
|
public int[] getPluginVersion() {
|
||||||
final String[] split = getDescription().getVersion().split("\\.");
|
String[] split = getDescription().getVersion().split("\\.");
|
||||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
|
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCommands() {
|
public void registerCommands() {
|
||||||
final BukkitCommand bcmd = new BukkitCommand();
|
BukkitCommand bcmd = new BukkitCommand();
|
||||||
final PluginCommand plotCommand = getCommand("plots");
|
PluginCommand plotCommand = getCommand("plots");
|
||||||
plotCommand.setExecutor(bcmd);
|
plotCommand.setExecutor(bcmd);
|
||||||
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||||
plotCommand.setTabCompleter(bcmd);
|
plotCommand.setTabCompleter(bcmd);
|
||||||
@ -204,15 +206,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Entity> entities = world.getEntities();
|
List<Entity> entities = world.getEntities();
|
||||||
Iterator<Entity> iter = entities.iterator();
|
Iterator<Entity> iterator = entities.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Entity entity = iter.next();
|
Entity entity = iterator.next();
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case EGG:
|
case EGG:
|
||||||
case ENDER_CRYSTAL:
|
case ENDER_CRYSTAL:
|
||||||
case COMPLEX_PART:
|
case COMPLEX_PART:
|
||||||
case FISHING_HOOK:
|
case FISHING_HOOK:
|
||||||
case ENDER_SIGNAL:
|
case ENDER_SIGNAL:
|
||||||
|
case LINGERING_POTION:
|
||||||
|
case AREA_EFFECT_CLOUD:
|
||||||
case EXPERIENCE_ORB:
|
case EXPERIENCE_ORB:
|
||||||
case LEASH_HITCH:
|
case LEASH_HITCH:
|
||||||
case FIREWORK:
|
case FIREWORK:
|
||||||
@ -227,6 +231,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
case THROWN_EXP_BOTTLE:
|
case THROWN_EXP_BOTTLE:
|
||||||
case SPLASH_POTION:
|
case SPLASH_POTION:
|
||||||
case SNOWBALL:
|
case SNOWBALL:
|
||||||
|
case SHULKER_BULLET:
|
||||||
|
case SPECTRAL_ARROW:
|
||||||
|
case TIPPED_ARROW:
|
||||||
case ENDER_PEARL:
|
case ENDER_PEARL:
|
||||||
case ARROW: {
|
case ARROW: {
|
||||||
// managed elsewhere | projectile
|
// managed elsewhere | projectile
|
||||||
@ -248,11 +255,11 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
if (!Settings.KILL_ROAD_VEHICLES) {
|
if (!Settings.KILL_ROAD_VEHICLES) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
com.intellectualcrafters.plot.object.Location loc = BukkitUtil.getLocation(entity.getLocation());
|
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||||
Plot plot = loc.getPlot();
|
Plot plot = location.getPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (loc.isPlotArea()) {
|
if (location.isPlotArea()) {
|
||||||
iter.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -263,13 +270,14 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
Plot origin = (Plot) meta.get(0).value();
|
Plot origin = (Plot) meta.get(0).value();
|
||||||
if (!plot.equals(origin.getBasePlot(false))) {
|
if (!plot.equals(origin.getBasePlot(false))) {
|
||||||
iter.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case SMALL_FIREBALL:
|
case SMALL_FIREBALL:
|
||||||
case FIREBALL:
|
case FIREBALL:
|
||||||
|
case DRAGON_FIREBALL:
|
||||||
case DROPPED_ITEM: {
|
case DROPPED_ITEM: {
|
||||||
// dropped item
|
// dropped item
|
||||||
continue;
|
continue;
|
||||||
@ -311,22 +319,23 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
case WITHER:
|
case WITHER:
|
||||||
case WOLF:
|
case WOLF:
|
||||||
case ZOMBIE:
|
case ZOMBIE:
|
||||||
|
case SHULKER:
|
||||||
default: {
|
default: {
|
||||||
if (!Settings.KILL_ROAD_MOBS) {
|
if (!Settings.KILL_ROAD_MOBS) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Location loc = entity.getLocation();
|
Location location = entity.getLocation();
|
||||||
if (BukkitUtil.getLocation(loc).isPlotRoad()) {
|
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||||
final Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
||||||
iter.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,8 +345,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
final public ChunkGenerator getDefaultWorldGenerator(String world, String id) {
|
||||||
final HybridGen result = new HybridGen();
|
HybridGen result = new HybridGen();
|
||||||
if (!PS.get().setupPlotWorld(world, id, result)) {
|
if (!PS.get().setupPlotWorld(world, id, result)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -351,7 +360,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
|
if (PS.get().checkVersion(getServerVersion(), 1, 8, 3)) {
|
||||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this);
|
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,15 +384,8 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
public boolean initWorldEdit() {
|
public boolean initWorldEdit() {
|
||||||
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||||
BukkitMain.worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
BukkitMain.worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
|
||||||
final String version = BukkitMain.worldEdit.getDescription().getVersion();
|
getServer().getPluginManager().registerEvents(new WEListener(), this);
|
||||||
if (version != null && version.startsWith("5.")) {
|
return true;
|
||||||
log("&cThis version of WorldEdit does not support PlotSquared.");
|
|
||||||
log("&cPlease use WorldEdit 6+ for masking support");
|
|
||||||
log("&c - http://builds.enginehub.org/job/worldedit");
|
|
||||||
} else {
|
|
||||||
getServer().getPluginManager().registerEvents(new WEListener(), this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -391,11 +393,11 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
@Override
|
@Override
|
||||||
public EconHandler getEconomyHandler() {
|
public EconHandler getEconomyHandler() {
|
||||||
try {
|
try {
|
||||||
final BukkitEconHandler econ = new BukkitEconHandler();
|
BukkitEconHandler econ = new BukkitEconHandler();
|
||||||
if (econ.init()) {
|
if (econ.init()) {
|
||||||
return econ;
|
return econ;
|
||||||
}
|
}
|
||||||
} catch (final Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -405,15 +407,14 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
try {
|
try {
|
||||||
new SendChunk();
|
new SendChunk();
|
||||||
MainUtil.canSendChunk = true;
|
MainUtil.canSendChunk = true;
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
|
if (PS.get().checkVersion(getServerVersion(), 1, 9, 0)) {
|
||||||
try {
|
try {
|
||||||
return new FastQueue_1_9();
|
return new FastQueue_1_9();
|
||||||
}
|
} catch (Throwable e) {
|
||||||
catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return new SlowQueue();
|
return new SlowQueue();
|
||||||
}
|
}
|
||||||
@ -464,13 +465,13 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeneratorWrapper<?> getGenerator(final String world, final String name) {
|
public GeneratorWrapper<?> getGenerator(String world, String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
|
||||||
if (gen_plugin != null && gen_plugin.isEnabled()) {
|
if (genPlugin != null && genPlugin.isEnabled()) {
|
||||||
ChunkGenerator gen = gen_plugin.getDefaultWorldGenerator(world, "");
|
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
|
||||||
if (gen instanceof GeneratorWrapper<?>) {
|
if (gen instanceof GeneratorWrapper<?>) {
|
||||||
return (GeneratorWrapper<?>) gen;
|
return (GeneratorWrapper<?>) gen;
|
||||||
}
|
}
|
||||||
@ -492,7 +493,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUIDHandlerImplementation initUUIDHandler() {
|
public UUIDHandlerImplementation initUUIDHandler() {
|
||||||
final boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
|
boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6);
|
||||||
UUIDWrapper wrapper;
|
UUIDWrapper wrapper;
|
||||||
if (Settings.OFFLINE_MODE) {
|
if (Settings.OFFLINE_MODE) {
|
||||||
if (Settings.UUID_LOWERCASE) {
|
if (Settings.UUID_LOWERCASE) {
|
||||||
@ -523,11 +524,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.OFFLINE_MODE) {
|
if (Settings.OFFLINE_MODE) {
|
||||||
log(C.PREFIX + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
|
log(C.PREFIX
|
||||||
|
+ " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||||
|
+ "Bukkit");
|
||||||
} else {
|
} else {
|
||||||
log(C.PREFIX + " &6PlotSquared is using online UUIDs");
|
log(C.PREFIX + " &6PlotSquared is using online UUIDs");
|
||||||
}
|
}
|
||||||
return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper);
|
if (Settings.USE_SQLUUIDHANDLER) {
|
||||||
|
return new SQLUUIDHandler(wrapper);
|
||||||
|
} else {
|
||||||
|
return new FileUUIDHandler(wrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -541,7 +548,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregister(final PlotPlayer player) {
|
public void unregister(PlotPlayer player) {
|
||||||
BukkitUtil.removePlayer(player.getName());
|
BukkitUtil.removePlayer(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,41 +584,41 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGenerator(final String worldname) {
|
public void setGenerator(String worldName) {
|
||||||
World world = BukkitUtil.getWorld(worldname);
|
World world = BukkitUtil.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
// create world
|
// create world
|
||||||
final ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldname);
|
ConfigurationSection worldConfig = PS.get().config.getConfigurationSection("worlds." + worldName);
|
||||||
String manager = worldConfig.getString("generator.plugin", "PlotSquared");
|
String manager = worldConfig.getString("generator.plugin", "PlotSquared");
|
||||||
String generator = worldConfig.getString("generator.init", manager);
|
String generator = worldConfig.getString("generator.init", manager);
|
||||||
final int type = worldConfig.getInt("generator.type");
|
int type = worldConfig.getInt("generator.type");
|
||||||
final int terrain = worldConfig.getInt("generator.terrain");
|
int terrain = worldConfig.getInt("generator.terrain");
|
||||||
final SetupObject setup = new SetupObject();
|
SetupObject setup = new SetupObject();
|
||||||
setup.plotManager = manager;
|
setup.plotManager = manager;
|
||||||
setup.setupGenerator = generator;
|
setup.setupGenerator = generator;
|
||||||
setup.type = type;
|
setup.type = type;
|
||||||
setup.terrain = terrain;
|
setup.terrain = terrain;
|
||||||
setup.step = new ConfigurationNode[0];
|
setup.step = new ConfigurationNode[0];
|
||||||
setup.world = worldname;
|
setup.world = worldName;
|
||||||
SetupUtils.manager.setupWorld(setup);
|
SetupUtils.manager.setupWorld(setup);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (!PS.get().hasPlotArea(worldname)) {
|
if (!PS.get().hasPlotArea(worldName)) {
|
||||||
SetGenCB.setGenerator(BukkitUtil.getWorld(worldname));
|
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
log("Failed to reload world: " + world);
|
log("Failed to reload world: " + world);
|
||||||
Bukkit.getServer().unloadWorld(world, false);
|
Bukkit.getServer().unloadWorld(world, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
world = Bukkit.getWorld(worldname);
|
world = Bukkit.getWorld(worldName);
|
||||||
final ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen instanceof BukkitPlotGenerator) {
|
if (gen instanceof BukkitPlotGenerator) {
|
||||||
PS.get().loadWorld(worldname, (BukkitPlotGenerator) gen);
|
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
||||||
} else if (gen != null) {
|
} else if (gen != null) {
|
||||||
PS.get().loadWorld(worldname, new BukkitPlotGenerator(worldname, gen));
|
PS.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
|
||||||
} else if (PS.get().config.contains("worlds." + worldname)) {
|
} else if (PS.get().config.contains("worlds." + worldName)) {
|
||||||
PS.get().loadWorld(worldname, null);
|
PS.get().loadWorld(worldName, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,15 +634,15 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotPlayer wrapPlayer(final Object obj) {
|
public PlotPlayer wrapPlayer(Object player) {
|
||||||
if (obj instanceof Player) {
|
if (player instanceof Player) {
|
||||||
return BukkitUtil.getPlayer((Player) obj);
|
return BukkitUtil.getPlayer((Player) player);
|
||||||
} else if (obj instanceof OfflinePlayer) {
|
} else if (player instanceof OfflinePlayer) {
|
||||||
return BukkitUtil.getPlayer((OfflinePlayer) obj);
|
return BukkitUtil.getPlayer((OfflinePlayer) player);
|
||||||
} else if (obj instanceof String) {
|
} else if (player instanceof String) {
|
||||||
return UUIDHandler.getPlayer((String) obj);
|
return UUIDHandler.getPlayer((String) player);
|
||||||
} else if (obj instanceof UUID) {
|
} else if (player instanceof UUID) {
|
||||||
return UUIDHandler.getPlayer((UUID) obj);
|
return UUIDHandler.getPlayer((UUID) player);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a wrapper around an array class of an arbitrary reference type,
|
* Represents a wrapper around an array class of an arbitrary reference type,
|
||||||
* which properly implements "value" hash code and equality functions.
|
* which properly implements "value" hash code and equality functions.
|
||||||
@ -17,57 +17,17 @@ import org.apache.commons.lang.Validate;
|
|||||||
* @see Arrays
|
* @see Arrays
|
||||||
*/
|
*/
|
||||||
public final class ArrayWrapper<E> {
|
public final class ArrayWrapper<E> {
|
||||||
|
|
||||||
|
private E[] _array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an array wrapper with some elements.
|
* Creates an array wrapper with some elements.
|
||||||
* @param elements The elements of the array.
|
* @param elements The elements of the array.
|
||||||
*/
|
*/
|
||||||
public ArrayWrapper(final E... elements) {
|
public ArrayWrapper(E... elements) {
|
||||||
setArray(elements);
|
setArray(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private E[] _array;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a reference to the wrapped array instance.
|
|
||||||
* @return The array wrapped by this instance.
|
|
||||||
*/
|
|
||||||
public E[] getArray() {
|
|
||||||
return _array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set this wrapper to wrap a new array instance.
|
|
||||||
* @param array The new wrapped array.
|
|
||||||
*/
|
|
||||||
public void setArray(final E[] array) {
|
|
||||||
Validate.notNull(array, "The array must not be null.");
|
|
||||||
_array = array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if this object has a value equivalent to another object.
|
|
||||||
* @see Arrays#equals(Object[], Object[])
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object other) {
|
|
||||||
if (!(other instanceof ArrayWrapper)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Arrays.equals(_array, ((ArrayWrapper) other)._array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the hash code represented by this objects value.
|
|
||||||
* @see Arrays#hashCode(Object[])
|
|
||||||
* @return This object's hash code.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Arrays.hashCode(_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an iterable element collection to an array of elements.
|
* Converts an iterable element collection to an array of elements.
|
||||||
* The iteration order of the specified object will be used as the array element order.
|
* The iteration order of the specified object will be used as the array element order.
|
||||||
@ -76,28 +36,66 @@ public final class ArrayWrapper<E> {
|
|||||||
* @return An array of elements in the specified iterable.
|
* @return An array of elements in the specified iterable.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> T[] toArray(final Iterable<? extends T> list, final Class<T> c) {
|
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
|
||||||
int size = -1;
|
int size = -1;
|
||||||
if (list instanceof Collection<?>) {
|
if (list instanceof Collection<?>) {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes") Collection coll = (Collection) list;
|
||||||
final Collection coll = (Collection) list;
|
|
||||||
size = coll.size();
|
size = coll.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
size = 0;
|
size = 0;
|
||||||
// Ugly hack: Count it ourselves
|
// Ugly hack: Count it ourselves
|
||||||
for (@SuppressWarnings("unused")
|
for (@SuppressWarnings("unused") T element : list) {
|
||||||
final T element : list) {
|
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final T[] result = (T[]) Array.newInstance(c, size);
|
T[] result = (T[]) Array.newInstance(c, size);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (final T element : list) { // Assumes iteration order is consistent
|
for (T element : list) { // Assumes iteration order is consistent
|
||||||
result[i++] = element; // Assign array element at index THEN increment counter
|
result[i++] = element; // Assign array element at index THEN increment counter
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a reference to the wrapped array instance.
|
||||||
|
* @return The array wrapped by this instance.
|
||||||
|
*/
|
||||||
|
public E[] getArray() {
|
||||||
|
return this._array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set this wrapper to wrap a new array instance.
|
||||||
|
* @param array The new wrapped array.
|
||||||
|
*/
|
||||||
|
public void setArray(E[] array) {
|
||||||
|
Validate.notNull(array, "The array must not be null.");
|
||||||
|
this._array = array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if this object has a value equivalent to another object.
|
||||||
|
* @see Arrays#equals(Object[], Object[])
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (!(other instanceof ArrayWrapper)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Arrays.equals(this._array, ((ArrayWrapper) other)._array);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the hash code represented by this objects value.
|
||||||
|
* @see Arrays#hashCode(Object[])
|
||||||
|
* @return This object's hash code.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Arrays.hashCode(this._array);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,10 @@ import java.util.Map;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
|
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features
|
||||||
* This class allows plugins to emulate the functionality of the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Commands#tellraw">tellraw command</a>.
|
* provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
|
||||||
|
* This class allows plugins to emulate the functionality of the vanilla Minecraft
|
||||||
|
* <a href="http://minecraft.gamepedia.com/Commands#tellraw">tellraw command</a>.
|
||||||
* <p>
|
* <p>
|
||||||
* This class follows the builder pattern, allowing for method chaining.
|
* This class follows the builder pattern, allowing for method chaining.
|
||||||
* It is set up such that invocations of property-setting methods will affect the current editing component,
|
* It is set up such that invocations of property-setting methods will affect the current editing component,
|
||||||
@ -53,48 +55,49 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
// The ChatSerializer's instance of Gson
|
// The ChatSerializer's instance of Gson
|
||||||
private static Object nmsChatSerializerGsonInstance;
|
private static Object nmsChatSerializerGsonInstance;
|
||||||
private static Method fromJsonMethod;
|
private static Method fromJsonMethod;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ConfigurationSerialization.registerClass(FancyMessage.class);
|
ConfigurationSerialization.registerClass(FancyMessage.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MessagePart> messageParts;
|
private List<MessagePart> messageParts;
|
||||||
private String jsonString;
|
private String jsonString;
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a JSON message with text.
|
* Creates a JSON message with text.
|
||||||
* @param firstPartText The existing text in the message.
|
* @param firstPartText The existing text in the message.
|
||||||
*/
|
*/
|
||||||
public FancyMessage(final String firstPartText) {
|
public FancyMessage(String firstPartText) {
|
||||||
this(rawText(firstPartText));
|
this(rawText(firstPartText));
|
||||||
}
|
}
|
||||||
|
|
||||||
public FancyMessage(final TextualComponent firstPartText) {
|
public FancyMessage(TextualComponent firstPartText) {
|
||||||
messageParts = new ArrayList<>();
|
this.messageParts = new ArrayList<>();
|
||||||
messageParts.add(new MessagePart(firstPartText));
|
this.messageParts.add(new MessagePart(firstPartText));
|
||||||
jsonString = null;
|
this.jsonString = null;
|
||||||
dirty = false;
|
this.dirty = false;
|
||||||
|
|
||||||
if (nmsPacketPlayOutChatConstructor == null) {
|
if (nmsPacketPlayOutChatConstructor == null) {
|
||||||
try {
|
try {
|
||||||
nmsPacketPlayOutChatConstructor = Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
|
nmsPacketPlayOutChatConstructor =
|
||||||
|
Reflection.getNMSClass("PacketPlayOutChat").getDeclaredConstructor(Reflection.getNMSClass("IChatBaseComponent"));
|
||||||
nmsPacketPlayOutChatConstructor.setAccessible(true);
|
nmsPacketPlayOutChatConstructor.setAccessible(true);
|
||||||
} catch (final NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
|
Bukkit.getLogger().log(Level.SEVERE, "Could not find Minecraft method or constructor.", e);
|
||||||
} catch (final SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access constructor.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a JSON message without text.
|
* Creates a JSON message without text.
|
||||||
*/
|
*/
|
||||||
public FancyMessage() {
|
public FancyMessage() {
|
||||||
this((TextualComponent) null);
|
this((TextualComponent) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize a JSON-represented message from a mapping of key-value pairs.
|
* Deserialize a JSON-represented message from a mapping of key-value pairs.
|
||||||
* This is called by the Bukkit serialization API.
|
* This is called by the Bukkit serialization API.
|
||||||
@ -102,8 +105,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @param serialized The key-value mapping which represents a fancy message.
|
* @param serialized The key-value mapping which represents a fancy message.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static FancyMessage deserialize(final Map<String, Object> serialized) {
|
public static FancyMessage deserialize(Map<String, Object> serialized) {
|
||||||
final FancyMessage msg = new FancyMessage();
|
FancyMessage msg = new FancyMessage();
|
||||||
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
||||||
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
||||||
msg.dirty = !serialized.containsKey("JSON");
|
msg.dirty = !serialized.containsKey("JSON");
|
||||||
@ -116,26 +119,26 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @param json The JSON string which represents a fancy message.
|
* @param json The JSON string which represents a fancy message.
|
||||||
* @return A {@code FancyMessage} representing the parametrized JSON message.
|
* @return A {@code FancyMessage} representing the parametrized JSON message.
|
||||||
*/
|
*/
|
||||||
public static FancyMessage deserialize(final String json) {
|
public static FancyMessage deserialize(String json) {
|
||||||
final JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
||||||
final JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
||||||
final FancyMessage returnVal = new FancyMessage();
|
FancyMessage returnVal = new FancyMessage();
|
||||||
returnVal.messageParts.clear();
|
returnVal.messageParts.clear();
|
||||||
for (final JsonElement mPrt : extra) {
|
for (JsonElement mPrt : extra) {
|
||||||
final MessagePart component = new MessagePart();
|
MessagePart component = new MessagePart();
|
||||||
final JsonObject messagePart = mPrt.getAsJsonObject();
|
JsonObject messagePart = mPrt.getAsJsonObject();
|
||||||
for (final Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
||||||
// Deserialize text
|
// Deserialize text
|
||||||
if (TextualComponent.isTextKey(entry.getKey())) {
|
if (TextualComponent.isTextKey(entry.getKey())) {
|
||||||
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
||||||
final Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
||||||
serializedMapForm.put("key", entry.getKey());
|
serializedMapForm.put("key", entry.getKey());
|
||||||
if (entry.getValue().isJsonPrimitive()) {
|
if (entry.getValue().isJsonPrimitive()) {
|
||||||
// Assume string
|
// Assume string
|
||||||
serializedMapForm.put("value", entry.getValue().getAsString());
|
serializedMapForm.put("value", entry.getValue().getAsString());
|
||||||
} else {
|
} else {
|
||||||
// Composite object, but we assume each element is a string
|
// Composite object, but we assume each element is a string
|
||||||
for (final Map.Entry<String, JsonElement> compositeNestedElement : entry.getValue().getAsJsonObject().entrySet()) {
|
for (Map.Entry<String, JsonElement> compositeNestedElement : entry.getValue().getAsJsonObject().entrySet()) {
|
||||||
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
|
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,11 +150,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
} else if (entry.getKey().equals("color")) {
|
} else if (entry.getKey().equals("color")) {
|
||||||
component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
||||||
} else if (entry.getKey().equals("clickEvent")) {
|
} else if (entry.getKey().equals("clickEvent")) {
|
||||||
final JsonObject object = entry.getValue().getAsJsonObject();
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
component.clickActionName = object.get("action").getAsString();
|
component.clickActionName = object.get("action").getAsString();
|
||||||
component.clickActionData = object.get("value").getAsString();
|
component.clickActionData = object.get("value").getAsString();
|
||||||
} else if (entry.getKey().equals("hoverEvent")) {
|
} else if (entry.getKey().equals("hoverEvent")) {
|
||||||
final JsonObject object = entry.getValue().getAsJsonObject();
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
component.hoverActionName = object.get("action").getAsString();
|
component.hoverActionName = object.get("action").getAsString();
|
||||||
if (object.get("value").isJsonPrimitive()) {
|
if (object.get("value").isJsonPrimitive()) {
|
||||||
// Assume string
|
// Assume string
|
||||||
@ -166,7 +169,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
} else if (entry.getKey().equals("insertion")) {
|
} else if (entry.getKey().equals("insertion")) {
|
||||||
component.insertionData = entry.getValue().getAsString();
|
component.insertionData = entry.getValue().getAsString();
|
||||||
} else if (entry.getKey().equals("with")) {
|
} else if (entry.getKey().equals("with")) {
|
||||||
for (final JsonElement object : entry.getValue().getAsJsonArray()) {
|
for (JsonElement object : entry.getValue().getAsJsonArray()) {
|
||||||
if (object.isJsonPrimitive()) {
|
if (object.isJsonPrimitive()) {
|
||||||
component.translationReplacements.add(new JsonString(object.getAsString()));
|
component.translationReplacements.add(new JsonString(object.getAsString()));
|
||||||
} else {
|
} else {
|
||||||
@ -184,10 +187,10 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FancyMessage clone() throws CloneNotSupportedException {
|
public FancyMessage clone() throws CloneNotSupportedException {
|
||||||
final FancyMessage instance = (FancyMessage) super.clone();
|
FancyMessage instance = (FancyMessage) super.clone();
|
||||||
instance.messageParts = new ArrayList<>(messageParts.size());
|
instance.messageParts = new ArrayList<>(this.messageParts.size());
|
||||||
for (int i = 0; i < messageParts.size(); i++) {
|
for (int i = 0; i < this.messageParts.size(); i++) {
|
||||||
instance.messageParts.add(i, messageParts.get(i).clone());
|
instance.messageParts.add(i, this.messageParts.get(i).clone());
|
||||||
}
|
}
|
||||||
instance.dirty = false;
|
instance.dirty = false;
|
||||||
instance.jsonString = null;
|
instance.jsonString = null;
|
||||||
@ -199,141 +202,149 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @param text The new text of the current editing component.
|
* @param text The new text of the current editing component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage text(final String text) {
|
public FancyMessage text(String text) {
|
||||||
final MessagePart latest = latest();
|
MessagePart latest = latest();
|
||||||
latest.text = rawText(text);
|
latest.text = rawText(text);
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the text of the current editing component to a value.
|
* Sets the text of the current editing component to a value.
|
||||||
* @param text The new text of the current editing component.
|
* @param text The new text of the current editing component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage text(final TextualComponent text) {
|
public FancyMessage text(TextualComponent text) {
|
||||||
final MessagePart latest = latest();
|
MessagePart latest = latest();
|
||||||
latest.text = text;
|
latest.text = text;
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the color of the current editing component to a value.
|
* Sets the color of the current editing component to a value.
|
||||||
* @param color The new color of the current editing component.
|
* @param color The new color of the current editing component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
* @exception IllegalArgumentException If the specified {@code ChatColor} enumeration value is not a color (but a format value).
|
* @exception IllegalArgumentException If the specified {@code ChatColor} enumeration value is not a color (but a format value).
|
||||||
*/
|
*/
|
||||||
public FancyMessage color(final ChatColor color) {
|
public FancyMessage color(ChatColor color) {
|
||||||
latest().color = color;
|
latest().color = color;
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stylization of the current editing component.
|
* Sets the stylization of the current editing component.
|
||||||
* @param styles The array of styles to apply to the editing component.
|
* @param styles The array of styles to apply to the editing component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
* @exception IllegalArgumentException If any of the enumeration values in the array do not represent formatters.
|
* @exception IllegalArgumentException If any of the enumeration values in the array do not represent formatters.
|
||||||
*/
|
*/
|
||||||
public FancyMessage style(final ChatColor... styles) {
|
public FancyMessage style(ChatColor... styles) {
|
||||||
for (final ChatColor style : styles) {
|
for (ChatColor style : styles) {
|
||||||
if (!style.isFormat()) {
|
if (!style.isFormat()) {
|
||||||
throw new IllegalArgumentException(style.name() + " is not a style");
|
throw new IllegalArgumentException(style.name() + " is not a style");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
latest().styles.addAll(Arrays.asList(styles));
|
latest().styles.addAll(Arrays.asList(styles));
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to instruct the client to open a file on the client side filesystem when the currently edited part of the {@code FancyMessage} is clicked.
|
* Set the behavior of the current editing component to instruct the client to open a file on the client side filesystem when the currently
|
||||||
|
* edited part of the {@code FancyMessage} is clicked.
|
||||||
* @param path The path of the file on the client filesystem.
|
* @param path The path of the file on the client filesystem.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage file(final String path) {
|
public FancyMessage file(String path) {
|
||||||
onClick("open_file", path);
|
onClick("open_file", path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to instruct the client to open a webpage in the client's web browser when the currently edited part of the {@code FancyMessage} is clicked.
|
* Set the behavior of the current editing component to instruct the client to open a webpage in the client's web browser when the currently
|
||||||
|
* edited part of the {@code FancyMessage} is clicked.
|
||||||
* @param url The URL of the page to open when the link is clicked.
|
* @param url The URL of the page to open when the link is clicked.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage link(final String url) {
|
public FancyMessage link(String url) {
|
||||||
onClick("open_url", url);
|
onClick("open_url", url);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to instruct the client to replace the chat input box content with the specified string when the currently edited part of the {@code FancyMessage} is clicked.
|
* Set the behavior of the current editing component to instruct the client to replace the chat input box content with the specified string
|
||||||
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.
|
* when the currently edited part of the {@code FancyMessage} is clicked.
|
||||||
|
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message,
|
||||||
|
* usually with the enter key.
|
||||||
* @param command The text to display in the chat bar of the client.
|
* @param command The text to display in the chat bar of the client.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage suggest(final String command) {
|
public FancyMessage suggest(String command) {
|
||||||
onClick("suggest_command", command);
|
onClick("suggest_command", command);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to instruct the client to append the chat input box content with the specified string when the currently edited part of the {@code FancyMessage} is SHIFT-CLICKED.
|
* Set the behavior of the current editing component to instruct the client to append the chat input box content with the specified string when
|
||||||
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message, usually with the enter key.
|
* the currently edited part of the {@code FancyMessage} is SHIFT-CLICKED.
|
||||||
|
* The client will not immediately send the command to the server to be executed unless the client player submits the command/chat message,
|
||||||
|
* usually with the enter key.
|
||||||
* @param command The text to append to the chat bar of the client.
|
* @param command The text to append to the chat bar of the client.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage insert(final String command) {
|
public FancyMessage insert(String command) {
|
||||||
latest().insertionData = command;
|
latest().insertionData = command;
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to instruct the client to send the specified string to the server as a chat message when the currently edited part of the {@code FancyMessage} is clicked.
|
* Set the behavior of the current editing component to instruct the client to send the specified string to the server as a chat message when
|
||||||
|
* the currently edited part of the {@code FancyMessage} is clicked.
|
||||||
* The client <b>will</b> immediately send the command to the server to be executed when the editing component is clicked.
|
* The client <b>will</b> immediately send the command to the server to be executed when the editing component is clicked.
|
||||||
* @param command The text to display in the chat bar of the client.
|
* @param command The text to display in the chat bar of the client.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage command(final String command) {
|
public FancyMessage command(String command) {
|
||||||
onClick("run_command", command);
|
onClick("run_command", command);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param name The name of the achievement to display, excluding the "achievement." prefix.
|
* @param name The name of the achievement to display, excluding the "achievement." prefix.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage achievementTooltip(final String name) {
|
public FancyMessage achievementTooltip(String name) {
|
||||||
onHover("show_achievement", new JsonString("achievement." + name));
|
onHover("show_achievement", new JsonString("achievement." + name));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param which The achievement to display.
|
* @param which The achievement to display.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage achievementTooltip(final Achievement which) {
|
public FancyMessage achievementTooltip(Achievement which) {
|
||||||
try {
|
try {
|
||||||
final Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
|
Object achievement =
|
||||||
|
Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
|
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about a parameterless statistic when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about a parameterless statistic when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
@ -341,36 +352,38 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied.
|
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied.
|
||||||
*/
|
*/
|
||||||
public FancyMessage statisticTooltip(final Statistic which) {
|
public FancyMessage statisticTooltip(Statistic which) {
|
||||||
final Type type = which.getType();
|
Type type = which.getType();
|
||||||
if (type != Type.UNTYPED) {
|
if (type != Type.UNTYPED) {
|
||||||
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
|
throw new IllegalArgumentException("That statistic requires an additional " + type + " parameter!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
|
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about a statistic parameter with a material when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about a statistic parameter with a material when the client hovers
|
||||||
|
* over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param which The statistic to display.
|
* @param which The statistic to display.
|
||||||
* @param item The sole material parameter to the statistic.
|
* @param item The sole material parameter to the statistic.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
|
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not
|
||||||
|
* required.
|
||||||
*/
|
*/
|
||||||
public FancyMessage statisticTooltip(final Statistic which, final Material item) {
|
public FancyMessage statisticTooltip(Statistic which, Material item) {
|
||||||
final Type type = which.getType();
|
Type type = which.getType();
|
||||||
if (type == Type.UNTYPED) {
|
if (type == Type.UNTYPED) {
|
||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
@ -378,30 +391,33 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
|
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class)
|
||||||
|
.invoke(null, which, item);
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about a statistic parameter with an entity type when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about a statistic parameter with an entity type when the client
|
||||||
|
* hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param which The statistic to display.
|
* @param which The statistic to display.
|
||||||
* @param entity The sole entity type parameter to the statistic.
|
* @param entity The sole entity type parameter to the statistic.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not required.
|
* @exception IllegalArgumentException If the statistic requires a parameter which was not supplied, or was supplied a parameter that was not
|
||||||
|
* required.
|
||||||
*/
|
*/
|
||||||
public FancyMessage statisticTooltip(final Statistic which, final EntityType entity) {
|
public FancyMessage statisticTooltip(Statistic which, EntityType entity) {
|
||||||
final Type type = which.getType();
|
Type type = which.getType();
|
||||||
if (type == Type.UNTYPED) {
|
if (type == Type.UNTYPED) {
|
||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
@ -409,66 +425,69 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
|
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class)
|
||||||
|
.invoke(null, which, entity);
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
return this;
|
return this;
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param itemJSON A string representing the JSON-serialized NBT data tag of an {@link ItemStack}.
|
* @param itemJSON A string representing the JSON-serialized NBT data tag of an {@link ItemStack}.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final String itemJSON) {
|
public FancyMessage itemTooltip(String itemJSON) {
|
||||||
onHover("show_item", new JsonString(itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
|
onHover("show_item", new JsonString(itemJSON)); // Seems a bit hacky, considering we have a JSON object as a parameter
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
* Set the behavior of the current editing component to display information about an item when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param itemStack The stack for which to display information.
|
* @param itemStack The stack for which to display information.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
public FancyMessage itemTooltip(ItemStack itemStack) {
|
||||||
try {
|
try {
|
||||||
final Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
Object nmsItem =
|
||||||
|
Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
||||||
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound"))
|
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound"))
|
||||||
.invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
|
.invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param text The text, which supports newlines, which will be displayed to the client upon hovering.
|
* @param text The text, which supports newlines, which will be displayed to the client upon hovering.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage tooltip(final String text) {
|
public FancyMessage tooltip(String text) {
|
||||||
onHover("show_text", new JsonString(text));
|
onHover("show_text", new JsonString(text));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
* Set the behavior of the current editing component to display raw text when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.
|
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in
|
||||||
|
* which the lines of the tooltip are created.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage tooltip(final Iterable<String> lines) {
|
public FancyMessage tooltip(Iterable<String> lines) {
|
||||||
tooltip(ArrayWrapper.toArray(lines, String.class));
|
tooltip(ArrayWrapper.toArray(lines, String.class));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -497,8 +516,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @param lines The lines of text which will be displayed to the client upon hovering.
|
* @param lines The lines of text which will be displayed to the client upon hovering.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage tooltip(final String... lines) {
|
public FancyMessage tooltip(String... lines) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
builder.append(lines[i]);
|
builder.append(lines[i]);
|
||||||
if (i != lines.length - 1) {
|
if (i != lines.length - 1) {
|
||||||
@ -508,15 +527,15 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
tooltip(builder.toString());
|
tooltip(builder.toString());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display formatted text when the client hovers over the text.
|
* Set the behavior of the current editing component to display formatted text when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param text The formatted text which will be displayed to the client upon hovering.
|
* @param text The formatted text which will be displayed to the client upon hovering.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage formattedTooltip(final FancyMessage text) {
|
public FancyMessage formattedTooltip(FancyMessage text) {
|
||||||
for (final MessagePart component : text.messageParts) {
|
for (MessagePart component : text.messageParts) {
|
||||||
if (component.clickActionData != null && component.clickActionName != null) {
|
if (component.clickActionData != null && component.clickActionName != null) {
|
||||||
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
||||||
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
||||||
@ -526,25 +545,25 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
onHover("show_text", text);
|
onHover("show_text", text);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param lines The lines of formatted text which will be displayed to the client upon hovering.
|
* @param lines The lines of formatted text which will be displayed to the client upon hovering.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage formattedTooltip(final FancyMessage... lines) {
|
public FancyMessage formattedTooltip(FancyMessage... lines) {
|
||||||
if (lines.length < 1) {
|
if (lines.length < 1) {
|
||||||
onHover(null, null); // Clear tooltip
|
onHover(null, null); // Clear tooltip
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
final FancyMessage result = new FancyMessage();
|
FancyMessage result = new FancyMessage();
|
||||||
result.messageParts.clear(); // Remove the one existing text component that exists by default, which destabilizes the object
|
result.messageParts.clear(); // Remove the one existing text component that exists by default, which destabilizes the object
|
||||||
|
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
try {
|
try {
|
||||||
for (final MessagePart component : lines[i]) {
|
for (MessagePart component : lines[i]) {
|
||||||
if (component.clickActionData != null && component.clickActionName != null) {
|
if (component.clickActionData != null && component.clickActionName != null) {
|
||||||
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
throw new IllegalArgumentException("The tooltip text cannot have click data.");
|
||||||
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
||||||
@ -557,176 +576,185 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
if (i != lines.length - 1) {
|
if (i != lines.length - 1) {
|
||||||
result.messageParts.add(new MessagePart(rawText("\n")));
|
result.messageParts.add(new MessagePart(rawText("\n")));
|
||||||
}
|
}
|
||||||
} catch (final CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Failed to clone object", e);
|
Bukkit.getLogger().log(Level.WARNING, "Failed to clone object", e);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formattedTooltip(result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
|
return formattedTooltip(result.messageParts.isEmpty() ? null : result); // Throws NPE if size is 0, intended
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
* Set the behavior of the current editing component to display the specified lines of formatted text when the client hovers over the text.
|
||||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||||
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in which the lines of the tooltip are created.
|
* @param lines The lines of text which will be displayed to the client upon hovering. The iteration order of this object will be the order in
|
||||||
|
* which the lines of the tooltip are created.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
public FancyMessage formattedTooltip(Iterable<FancyMessage> lines) {
|
||||||
return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class));
|
return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the
|
||||||
|
* message.
|
||||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage translationReplacements(final String... replacements) {
|
public FancyMessage translationReplacements(String... replacements) {
|
||||||
for (final String str : replacements) {
|
for (String str : replacements) {
|
||||||
latest().translationReplacements.add(new JsonString(str));
|
latest().translationReplacements.add(new JsonString(str));
|
||||||
}
|
}
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the
|
||||||
|
* message.
|
||||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage translationReplacements(final FancyMessage... replacements) {
|
public FancyMessage translationReplacements(FancyMessage... replacements) {
|
||||||
Collections.addAll(latest().translationReplacements, replacements);
|
Collections.addAll(latest().translationReplacements, replacements);
|
||||||
|
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the message.
|
* If the text is a translatable key, and it has replaceable values, this function can be used to set the replacements that will be used in the
|
||||||
|
* message.
|
||||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
public FancyMessage translationReplacements(Iterable<FancyMessage> replacements) {
|
||||||
return translationReplacements(ArrayWrapper.toArray(replacements, FancyMessage.class));
|
return translationReplacements(ArrayWrapper.toArray(replacements, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this
|
||||||
|
* method.
|
||||||
* @param text The text which will populate the new message component.
|
* @param text The text which will populate the new message component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage then(final String text) {
|
public FancyMessage then(String text) {
|
||||||
return then(rawText(text));
|
return then(rawText(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this
|
||||||
|
* method.
|
||||||
* @param text The text which will populate the new message component.
|
* @param text The text which will populate the new message component.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage then(final TextualComponent text) {
|
public FancyMessage then(TextualComponent text) {
|
||||||
if (!latest().hasText()) {
|
if (!latest().hasText()) {
|
||||||
throw new IllegalStateException("previous message part has no text");
|
throw new IllegalStateException("previous message part has no text");
|
||||||
}
|
}
|
||||||
messageParts.add(new MessagePart(text));
|
this.messageParts.add(new MessagePart(text));
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate construction of the current editing component, and begin construction of a new message component.
|
* Terminate construction of the current editing component, and begin construction of a new message component.
|
||||||
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this method.
|
* After a successful call to this method, all setter methods will refer to a new message component, created as a result of the call to this
|
||||||
|
* method.
|
||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage then() {
|
public FancyMessage then() {
|
||||||
if (!latest().hasText()) {
|
if (!latest().hasText()) {
|
||||||
throw new IllegalStateException("previous message part has no text");
|
throw new IllegalStateException("previous message part has no text");
|
||||||
}
|
}
|
||||||
messageParts.add(new MessagePart());
|
this.messageParts.add(new MessagePart());
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeJson(final JsonWriter writer) throws IOException {
|
public void writeJson(JsonWriter writer) throws IOException {
|
||||||
if (messageParts.size() == 1) {
|
if (this.messageParts.size() == 1) {
|
||||||
latest().writeJson(writer);
|
latest().writeJson(writer);
|
||||||
} else {
|
} else {
|
||||||
writer.beginObject().name("text").value("").name("extra").beginArray();
|
writer.beginObject().name("text").value("").name("extra").beginArray();
|
||||||
for (final MessagePart part : this) {
|
for (MessagePart part : this) {
|
||||||
part.writeJson(writer);
|
part.writeJson(writer);
|
||||||
}
|
}
|
||||||
writer.endArray().endObject();
|
writer.endArray().endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
|
* Serialize this fancy message, converting it into syntactically-valid JSON using a {@link JsonWriter}.
|
||||||
* This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
|
* This JSON should be compatible with vanilla formatter commands such as {@code /tellraw}.
|
||||||
* @return The JSON string representing this object.
|
* @return The JSON string representing this object.
|
||||||
*/
|
*/
|
||||||
public String toJSONString() {
|
public String toJSONString() {
|
||||||
if (!dirty && jsonString != null) {
|
if (!this.dirty && this.jsonString != null) {
|
||||||
return jsonString;
|
return this.jsonString;
|
||||||
}
|
}
|
||||||
final StringWriter string = new StringWriter();
|
StringWriter string = new StringWriter();
|
||||||
final JsonWriter json = new JsonWriter(string);
|
JsonWriter json = new JsonWriter(string);
|
||||||
try {
|
try {
|
||||||
writeJson(json);
|
writeJson(json);
|
||||||
json.close();
|
json.close();
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("invalid message");
|
throw new RuntimeException("invalid message");
|
||||||
}
|
}
|
||||||
jsonString = string.toString();
|
this.jsonString = string.toString();
|
||||||
dirty = false;
|
this.dirty = false;
|
||||||
return jsonString;
|
return this.jsonString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends this message to a player. The player will receive the fully-fledged formatted display of this message.
|
* Sends this message to a player. The player will receive the fully-fledged formatted display of this message.
|
||||||
* @param player The player who will receive the message.
|
* @param player The player who will receive the message.
|
||||||
*/
|
*/
|
||||||
public void send(final Player player) {
|
public void send(Player player) {
|
||||||
send(player, toJSONString());
|
send(player, toJSONString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void send(final CommandSender sender, final String jsonString) {
|
private void send(CommandSender sender, String jsonString) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(toOldMessageFormat());
|
sender.sendMessage(toOldMessageFormat());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
try {
|
||||||
final Object handle = Reflection.getHandle(player);
|
Object handle = Reflection.getHandle(player);
|
||||||
final Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
|
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet"))
|
||||||
} catch (final IllegalArgumentException e) {
|
.invoke(connection, createChatPacket(jsonString));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||||
} catch (final IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||||
} catch (final InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Underlying class is abstract.", e);
|
||||||
} catch (final InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||||
} catch (final NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not find method.", e);
|
||||||
} catch (final ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not find class.", e);
|
Bukkit.getLogger().log(Level.WARNING, "Could not find class.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createChatPacket(final String json) throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException,
|
private Object createChatPacket(String json)
|
||||||
ClassNotFoundException {
|
throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException,
|
||||||
|
ClassNotFoundException {
|
||||||
if (nmsChatSerializerGsonInstance == null) {
|
if (nmsChatSerializerGsonInstance == null) {
|
||||||
// Find the field and its value, completely bypassing obfuscation
|
// Find the field and its value, completely bypassing obfuscation
|
||||||
Class<?> chatSerializerClazz;
|
Class<?> chatSerializerClazz;
|
||||||
|
|
||||||
final String version = Reflection.getVersion();
|
String version = Reflection.getVersion();
|
||||||
final double majorVersion = Double.parseDouble(version.replace('_', '.').substring(1, 4));
|
double majorVersion = Double.parseDouble(version.replace('_', '.').substring(1, 4));
|
||||||
final int lesserVersion = Integer.parseInt(version.substring(6, 7));
|
int lesserVersion = Integer.parseInt(version.substring(6, 7));
|
||||||
|
|
||||||
if (majorVersion < 1.8 || majorVersion == 1.8 && lesserVersion == 1) {
|
if (majorVersion < 1.8 || majorVersion == 1.8 && lesserVersion == 1) {
|
||||||
chatSerializerClazz = Reflection.getNMSClass("ChatSerializer");
|
chatSerializerClazz = Reflection.getNMSClass("ChatSerializer");
|
||||||
@ -738,8 +766,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new ClassNotFoundException("Can't find the ChatSerializer class");
|
throw new ClassNotFoundException("Can't find the ChatSerializer class");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Field declaredField : chatSerializerClazz.getDeclaredFields()) {
|
for (Field declaredField : chatSerializerClazz.getDeclaredFields()) {
|
||||||
if (Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType().getName().endsWith("Gson")) {
|
if (Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType()
|
||||||
|
.getName().endsWith("Gson")) {
|
||||||
// We've found our field
|
// We've found our field
|
||||||
declaredField.setAccessible(true);
|
declaredField.setAccessible(true);
|
||||||
nmsChatSerializerGsonInstance = declaredField.get(null);
|
nmsChatSerializerGsonInstance = declaredField.get(null);
|
||||||
@ -754,11 +783,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
than to reflectively call it
|
than to reflectively call it
|
||||||
Of course, the implementation may change, but fuzzy matches might break with signature changes
|
Of course, the implementation may change, but fuzzy matches might break with signature changes
|
||||||
*/
|
*/
|
||||||
final Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent"));
|
Object serializedChatComponent = fromJsonMethod.invoke(nmsChatSerializerGsonInstance, json, Reflection.getNMSClass("IChatBaseComponent"));
|
||||||
|
|
||||||
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
|
return nmsPacketPlayOutChatConstructor.newInstance(serializedChatComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends this message to a command sender.
|
* Sends this message to a command sender.
|
||||||
* If the sender is a player, they will receive the fully-fledged formatted display of this message.
|
* If the sender is a player, they will receive the fully-fledged formatted display of this message.
|
||||||
@ -766,22 +795,22 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @param sender The command sender who will receive the message.
|
* @param sender The command sender who will receive the message.
|
||||||
* @see #toOldMessageFormat()
|
* @see #toOldMessageFormat()
|
||||||
*/
|
*/
|
||||||
public void send(final CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
send(sender, toJSONString());
|
send(sender, toJSONString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends this message to multiple command senders.
|
* Sends this message to multiple command senders.
|
||||||
* @param senders The command senders who will receive the message.
|
* @param senders The command senders who will receive the message.
|
||||||
* @see #send(CommandSender)
|
* @see #send(CommandSender)
|
||||||
*/
|
*/
|
||||||
public void send(final Iterable<? extends CommandSender> senders) {
|
public void send(Iterable<? extends CommandSender> senders) {
|
||||||
final String string = toJSONString();
|
String string = toJSONString();
|
||||||
for (final CommandSender sender : senders) {
|
for (CommandSender sender : senders) {
|
||||||
send(sender, string);
|
send(sender, string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert this message to a human-readable string with limited formatting.
|
* Convert this message to a human-readable string with limited formatting.
|
||||||
* This method is used to send this message to clients without JSON formatting support.
|
* This method is used to send this message to clients without JSON formatting support.
|
||||||
@ -799,49 +828,49 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return A human-readable string representing limited formatting in addition to the core text of this message.
|
* @return A human-readable string representing limited formatting in addition to the core text of this message.
|
||||||
*/
|
*/
|
||||||
public String toOldMessageFormat() {
|
public String toOldMessageFormat() {
|
||||||
final StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
for (final MessagePart part : this) {
|
for (MessagePart part : this) {
|
||||||
result.append(part.color == null ? "" : part.color);
|
result.append(part.color == null ? "" : part.color);
|
||||||
for (final ChatColor formatSpecifier : part.styles) {
|
for (ChatColor formatSpecifier : part.styles) {
|
||||||
result.append(formatSpecifier);
|
result.append(formatSpecifier);
|
||||||
}
|
}
|
||||||
result.append(part.text);
|
result.append(part.text);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessagePart latest() {
|
private MessagePart latest() {
|
||||||
return messageParts.get(messageParts.size() - 1);
|
return this.messageParts.get(this.messageParts.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClick(final String name, final String data) {
|
private void onClick(String name, String data) {
|
||||||
final MessagePart latest = latest();
|
MessagePart latest = latest();
|
||||||
latest.clickActionName = name;
|
latest.clickActionName = name;
|
||||||
latest.clickActionData = data;
|
latest.clickActionData = data;
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onHover(final String name, final JsonRepresentedObject data) {
|
private void onHover(String name, JsonRepresentedObject data) {
|
||||||
final MessagePart latest = latest();
|
MessagePart latest = latest();
|
||||||
latest.hoverActionName = name;
|
latest.hoverActionName = name;
|
||||||
latest.hoverActionData = data;
|
latest.hoverActionData = data;
|
||||||
dirty = true;
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doc copied from interface
|
// Doc copied from interface
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
final HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("messageParts", messageParts);
|
map.put("messageParts", this.messageParts);
|
||||||
// map.put("JSON", toJSONString());
|
// map.put("JSON", toJSONString());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>Internally called method. Not for API consumption.</b>
|
* Internally called method. Not for API consumption.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Iterator<MessagePart> iterator() {
|
public Iterator<MessagePart> iterator() {
|
||||||
return messageParts.iterator();
|
return this.messageParts.iterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object that can be serialized to a JSON writer instance.
|
* Represents an object that can be serialized to a JSON writer instance.
|
||||||
*/
|
*/
|
||||||
interface JsonRepresentedObject {
|
interface JsonRepresentedObject {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the JSON representation of this object to the specified writer.
|
* Writes the JSON representation of this object to the specified writer.
|
||||||
* @param writer The JSON writer which will receive the object.
|
* @param writer The JSON writer which will receive the object.
|
||||||
* @throws IOException If an error occurs writing to the stream.
|
* @throws IOException If an error occurs writing to the stream.
|
||||||
*/
|
*/
|
||||||
void writeJson(final JsonWriter writer) throws IOException;
|
void writeJson(JsonWriter writer) throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
|
||||||
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a JSON string value.
|
* Represents a JSON string value.
|
||||||
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
|
* Writes by this object will not write name values nor begin/end objects in the JSON stream.
|
||||||
* All writes merely write the represented string value.
|
* All writes merely write the represented string value.
|
||||||
*/
|
*/
|
||||||
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
final class JsonString implements JsonRepresentedObject, ConfigurationSerializable {
|
||||||
|
|
||||||
private final String _value;
|
private final String _value;
|
||||||
|
|
||||||
public JsonString(final CharSequence value) {
|
public JsonString(CharSequence value) {
|
||||||
_value = value == null ? null : value.toString();
|
this._value = value == null ? null : value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static JsonString deserialize(Map<String, Object> map) {
|
||||||
public void writeJson(final JsonWriter writer) throws IOException {
|
|
||||||
writer.value(getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
final HashMap<String, Object> theSingleValue = new HashMap<String, Object>();
|
|
||||||
theSingleValue.put("stringValue", _value);
|
|
||||||
return theSingleValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JsonString deserialize(final Map<String, Object> map) {
|
|
||||||
return new JsonString(map.get("stringValue").toString());
|
return new JsonString(map.get("stringValue").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeJson(JsonWriter writer) throws IOException {
|
||||||
|
writer.value(getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize() {
|
||||||
|
HashMap<String, Object> theSingleValue = new HashMap<>();
|
||||||
|
theSingleValue.put("stringValue", this._value);
|
||||||
|
return theSingleValue;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return _value;
|
return this._value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
static final BiMap<ChatColor, String> stylesToNames;
|
static final BiMap<ChatColor, String> stylesToNames;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final ImmutableBiMap.Builder<ChatColor, String> builder = ImmutableBiMap.builder();
|
ImmutableBiMap.Builder<ChatColor, String> builder = ImmutableBiMap.builder();
|
||||||
for (final ChatColor style : ChatColor.values()) {
|
for (ChatColor style : ChatColor.values()) {
|
||||||
if (!style.isFormat()) {
|
if (!style.isFormat()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -57,18 +57,18 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
TextualComponent text = null;
|
TextualComponent text = null;
|
||||||
String insertionData = null;
|
String insertionData = null;
|
||||||
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
||||||
|
|
||||||
MessagePart(final TextualComponent text) {
|
MessagePart(TextualComponent text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagePart() {
|
MessagePart() {
|
||||||
text = null;
|
this.text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static MessagePart deserialize(final Map<String, Object> serialized) {
|
public static MessagePart deserialize(Map<String, Object> serialized) {
|
||||||
final MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
||||||
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
||||||
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
||||||
part.hoverActionName = (String) serialized.get("hoverActionName");
|
part.hoverActionName = (String) serialized.get("hoverActionName");
|
||||||
@ -81,70 +81,71 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean hasText() {
|
boolean hasText() {
|
||||||
return text != null;
|
return this.text != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public MessagePart clone() throws CloneNotSupportedException {
|
public MessagePart clone() throws CloneNotSupportedException {
|
||||||
final MessagePart obj = (MessagePart) super.clone();
|
MessagePart obj = (MessagePart) super.clone();
|
||||||
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
obj.styles = (ArrayList<ChatColor>) this.styles.clone();
|
||||||
if (hoverActionData instanceof JsonString) {
|
if (this.hoverActionData instanceof JsonString) {
|
||||||
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
obj.hoverActionData = new JsonString(((JsonString) this.hoverActionData).getValue());
|
||||||
} else if (hoverActionData instanceof FancyMessage) {
|
} else if (this.hoverActionData instanceof FancyMessage) {
|
||||||
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
obj.hoverActionData = ((FancyMessage) this.hoverActionData).clone();
|
||||||
}
|
}
|
||||||
obj.translationReplacements = (ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
obj.translationReplacements = (ArrayList<JsonRepresentedObject>) this.translationReplacements.clone();
|
||||||
return obj;
|
return obj;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeJson(final JsonWriter json) {
|
public void writeJson(JsonWriter json) {
|
||||||
try {
|
try {
|
||||||
json.beginObject();
|
json.beginObject();
|
||||||
text.writeJson(json);
|
this.text.writeJson(json);
|
||||||
json.name("color").value(color.name().toLowerCase());
|
json.name("color").value(this.color.name().toLowerCase());
|
||||||
for (final ChatColor style : styles) {
|
for (ChatColor style : this.styles) {
|
||||||
json.name(stylesToNames.get(style)).value(true);
|
json.name(stylesToNames.get(style)).value(true);
|
||||||
}
|
}
|
||||||
if ((clickActionName != null) && (clickActionData != null)) {
|
if ((this.clickActionName != null) && (this.clickActionData != null)) {
|
||||||
json.name("clickEvent").beginObject().name("action").value(clickActionName).name("value").value(clickActionData).endObject();
|
json.name("clickEvent").beginObject().name("action").value(this.clickActionName).name("value").value(this.clickActionData)
|
||||||
|
.endObject();
|
||||||
}
|
}
|
||||||
if ((hoverActionName != null) && (hoverActionData != null)) {
|
if ((this.hoverActionName != null) && (this.hoverActionData != null)) {
|
||||||
json.name("hoverEvent").beginObject().name("action").value(hoverActionName).name("value");
|
json.name("hoverEvent").beginObject().name("action").value(this.hoverActionName).name("value");
|
||||||
hoverActionData.writeJson(json);
|
this.hoverActionData.writeJson(json);
|
||||||
json.endObject();
|
json.endObject();
|
||||||
}
|
}
|
||||||
if (insertionData != null) {
|
if (this.insertionData != null) {
|
||||||
json.name("insertion").value(insertionData);
|
json.name("insertion").value(this.insertionData);
|
||||||
}
|
}
|
||||||
if ((!translationReplacements.isEmpty()) && (text != null) && TextualComponent.isTranslatableText(text)) {
|
if (!this.translationReplacements.isEmpty() && (this.text != null) && TextualComponent.isTranslatableText(this.text)) {
|
||||||
json.name("with").beginArray();
|
json.name("with").beginArray();
|
||||||
for (final JsonRepresentedObject obj : translationReplacements) {
|
for (JsonRepresentedObject obj : this.translationReplacements) {
|
||||||
obj.writeJson(json);
|
obj.writeJson(json);
|
||||||
}
|
}
|
||||||
json.endArray();
|
json.endArray();
|
||||||
}
|
}
|
||||||
json.endObject();
|
json.endObject();
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A problem occurred during writing of JSON string", e);
|
Bukkit.getLogger().log(Level.WARNING, "A problem occurred during writing of JSON string", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
final HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("text", text);
|
map.put("text", this.text);
|
||||||
map.put("styles", styles);
|
map.put("styles", this.styles);
|
||||||
map.put("color", color.getChar());
|
map.put("color", this.color.getChar());
|
||||||
map.put("hoverActionName", hoverActionName);
|
map.put("hoverActionName", this.hoverActionName);
|
||||||
map.put("hoverActionData", hoverActionData);
|
map.put("hoverActionData", this.hoverActionData);
|
||||||
map.put("clickActionName", clickActionName);
|
map.put("clickActionName", this.clickActionName);
|
||||||
map.put("clickActionData", clickActionData);
|
map.put("clickActionData", this.clickActionData);
|
||||||
map.put("insertion", insertionData);
|
map.put("insertion", this.insertionData);
|
||||||
map.put("translationReplacements", translationReplacements);
|
map.put("translationReplacements", this.translationReplacements);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public final class Reflection {
|
|||||||
private Reflection() {
|
private Reflection() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the version string from the package name of the CraftBukkit server implementation.
|
* Gets the version string from the package name of the CraftBukkit server implementation.
|
||||||
* This is needed to bypass the JAR package name changing on each update.
|
* This is needed to bypass the JAR package name changing on each update.
|
||||||
@ -42,19 +42,20 @@ public final class Reflection {
|
|||||||
public synchronized static String getVersion() {
|
public synchronized static String getVersion() {
|
||||||
return PS.get().IMP.getNMSPackage();
|
return PS.get().IMP.getNMSPackage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
|
* Gets a {@link Class} object representing a type contained within the {@code net.minecraft.server} versioned package.
|
||||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this method simultaneously).
|
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this
|
||||||
|
* method simultaneously).
|
||||||
* @param className The name of the class, excluding the package, within NMS.
|
* @param className The name of the class, excluding the package, within NMS.
|
||||||
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
|
* @return The class instance representing the specified NMS class, or {@code null} if it could not be loaded.
|
||||||
*/
|
*/
|
||||||
public synchronized static Class<?> getNMSClass(final String className) {
|
public synchronized static Class<?> getNMSClass(String className) {
|
||||||
if (_loadedNMSClasses.containsKey(className)) {
|
if (_loadedNMSClasses.containsKey(className)) {
|
||||||
return _loadedNMSClasses.get(className);
|
return _loadedNMSClasses.get(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String fullName = "net.minecraft.server." + getVersion() + "." + className;
|
String fullName = "net.minecraft.server." + getVersion() + "." + className;
|
||||||
Class<?> clazz;
|
Class<?> clazz;
|
||||||
try {
|
try {
|
||||||
clazz = Class.forName(fullName);
|
clazz = Class.forName(fullName);
|
||||||
@ -66,7 +67,7 @@ public final class Reflection {
|
|||||||
_loadedNMSClasses.put(className, clazz);
|
_loadedNMSClasses.put(className, clazz);
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
|
* Gets a {@link Class} object representing a type contained within the {@code org.bukkit.craftbukkit} versioned package.
|
||||||
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this
|
* The class instances returned by this method are cached, such that no lookup will be done twice (unless multiple threads are accessing this
|
||||||
@ -75,12 +76,12 @@ public final class Reflection {
|
|||||||
* .CraftItemStack}.
|
* .CraftItemStack}.
|
||||||
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
|
* @return The class instance representing the specified OBC class, or {@code null} if it could not be loaded.
|
||||||
*/
|
*/
|
||||||
public synchronized static Class<?> getOBCClass(final String className) {
|
public synchronized static Class<?> getOBCClass(String className) {
|
||||||
if (_loadedOBCClasses.containsKey(className)) {
|
if (_loadedOBCClasses.containsKey(className)) {
|
||||||
return _loadedOBCClasses.get(className);
|
return _loadedOBCClasses.get(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className;
|
String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className;
|
||||||
Class<?> clazz;
|
Class<?> clazz;
|
||||||
try {
|
try {
|
||||||
clazz = Class.forName(fullName);
|
clazz = Class.forName(fullName);
|
||||||
@ -92,7 +93,7 @@ public final class Reflection {
|
|||||||
_loadedOBCClasses.put(className, clazz);
|
_loadedOBCClasses.put(className, clazz);
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to get the NMS handle of a CraftBukkit object.
|
* Attempts to get the NMS handle of a CraftBukkit object.
|
||||||
* <p>
|
* <p>
|
||||||
@ -102,7 +103,7 @@ public final class Reflection {
|
|||||||
* @param obj The object for which to retrieve an NMS handle.
|
* @param obj The object for which to retrieve an NMS handle.
|
||||||
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
* @return The NMS handle of the specified object, or {@code null} if it could not be retrieved using {@code getHandle()}.
|
||||||
*/
|
*/
|
||||||
public synchronized static Object getHandle(final Object obj) {
|
public synchronized static Object getHandle(Object obj) {
|
||||||
try {
|
try {
|
||||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
|
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
|
||||||
@ -110,7 +111,7 @@ public final class Reflection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
|
* Retrieves a {@link Field} instance declared by the specified class with the specified name.
|
||||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||||
@ -129,7 +130,7 @@ public final class Reflection {
|
|||||||
* @return A field object with the specified name declared by the specified class.
|
* @return A field object with the specified name declared by the specified class.
|
||||||
* @see Class#getDeclaredField(String)
|
* @see Class#getDeclaredField(String)
|
||||||
*/
|
*/
|
||||||
public synchronized static Field getField(final Class<?> clazz, final String name) {
|
public synchronized static Field getField(Class<?> clazz, String name) {
|
||||||
Map<String, Field> loaded;
|
Map<String, Field> loaded;
|
||||||
if (!_loadedFields.containsKey(clazz)) {
|
if (!_loadedFields.containsKey(clazz)) {
|
||||||
loaded = new HashMap<>();
|
loaded = new HashMap<>();
|
||||||
@ -142,7 +143,7 @@ public final class Reflection {
|
|||||||
return loaded.get(name);
|
return loaded.get(name);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Field field = clazz.getDeclaredField(name);
|
Field field = clazz.getDeclaredField(name);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
loaded.put(name, field);
|
loaded.put(name, field);
|
||||||
return field;
|
return field;
|
||||||
@ -154,7 +155,7 @@ public final class Reflection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
|
* Retrieves a {@link Method} instance declared by the specified class with the specified name and argument types.
|
||||||
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
* Java access modifiers are ignored during this retrieval. No guarantee is made as to whether the field
|
||||||
@ -164,7 +165,8 @@ public final class Reflection {
|
|||||||
* no method will be reflectively looked up twice.
|
* no method will be reflectively looked up twice.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code true} before it is returned.
|
* If a method is deemed suitable for return, {@link Method#setAccessible(boolean) setAccessible} will be invoked with an argument of {@code
|
||||||
|
* true} before it is returned.
|
||||||
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
* This ensures that callers do not have to check or worry about Java access modifiers when dealing with the returned instance.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
@ -175,23 +177,23 @@ public final class Reflection {
|
|||||||
* @param args The formal argument types of the method.
|
* @param args The formal argument types of the method.
|
||||||
* @return A method object with the specified name declared by the specified class.
|
* @return A method object with the specified name declared by the specified class.
|
||||||
*/
|
*/
|
||||||
public synchronized static Method getMethod(final Class<?> clazz, final String name, final Class<?>... args) {
|
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
if (!_loadedMethods.containsKey(clazz)) {
|
if (!_loadedMethods.containsKey(clazz)) {
|
||||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
|
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames = _loadedMethods.get(clazz);
|
||||||
if (!loadedMethodNames.containsKey(name)) {
|
if (!loadedMethodNames.containsKey(name)) {
|
||||||
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
|
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
|
||||||
final ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
|
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
|
||||||
if (loadedSignatures.containsKey(wrappedArg)) {
|
if (loadedSignatures.containsKey(wrappedArg)) {
|
||||||
return loadedSignatures.get(wrappedArg);
|
return loadedSignatures.get(wrappedArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
|
if (m.getName().equals(name) && Arrays.equals(args, m.getParameterTypes())) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
loadedSignatures.put(wrappedArg, m);
|
loadedSignatures.put(wrappedArg, m);
|
||||||
@ -201,5 +203,5 @@ public final class Reflection {
|
|||||||
loadedSignatures.put(wrappedArg, null);
|
loadedSignatures.put(wrappedArg, null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,107 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
ConfigurationSerialization.registerClass(TextualComponent.ComplexTextTypeComponent.class);
|
ConfigurationSerialization.registerClass(TextualComponent.ComplexTextTypeComponent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TextualComponent deserialize(Map<String, Object> map) {
|
||||||
|
if (map.containsKey("key") && (map.size() == 2) && map.containsKey("value")) {
|
||||||
|
// Arbitrary text component
|
||||||
|
return ArbitraryTextTypeComponent.deserialize(map);
|
||||||
|
} else if ((map.size() >= 2) && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
|
||||||
|
// Complex JSON object
|
||||||
|
return ComplexTextTypeComponent.deserialize(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isTextKey(String key) {
|
||||||
|
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean isTranslatableText(TextualComponent component) {
|
||||||
|
return (component instanceof ComplexTextTypeComponent) && component.getKey().equals("translate");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a textual component representing a string literal.
|
||||||
|
* This is the default type of textual component when a single string literal is given to a method.
|
||||||
|
* @param textValue The text which will be represented.
|
||||||
|
* @return The text component representing the specified literal text.
|
||||||
|
*/
|
||||||
|
public static TextualComponent rawText(String textValue) {
|
||||||
|
return new ArbitraryTextTypeComponent("text", textValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a textual component representing a localized string.
|
||||||
|
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a
|
||||||
|
* resource pack.
|
||||||
|
* <p>
|
||||||
|
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to
|
||||||
|
* the client.
|
||||||
|
* </p>
|
||||||
|
* @param translateKey The string key which maps to localized text.
|
||||||
|
* @return The text component representing the specified localized text.
|
||||||
|
*/
|
||||||
|
public static TextualComponent localizedText(String translateKey) {
|
||||||
|
return new ArbitraryTextTypeComponent("translate", translateKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwUnsupportedSnapshot() {
|
||||||
|
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a textual component representing a scoreboard value.
|
||||||
|
* The client will see their own score for the specified objective as the text represented by this component.
|
||||||
|
* <p>
|
||||||
|
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||||
|
* </p>
|
||||||
|
* @param scoreboardObjective The name of the objective for which to display the score.
|
||||||
|
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during
|
||||||
|
* JSON serialization.
|
||||||
|
*/
|
||||||
|
public static TextualComponent objectiveScore(String scoreboardObjective) {
|
||||||
|
return objectiveScore("*", scoreboardObjective);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a textual component representing a scoreboard value.
|
||||||
|
* The client will see the score of the specified player for the specified objective as the text represented by this component.
|
||||||
|
* <p>
|
||||||
|
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||||
|
* </p>
|
||||||
|
* @param playerName The name of the player whos score will be shown. If this string represents the single-character sequence "*", the viewing
|
||||||
|
* player's score will be displayed.
|
||||||
|
* Standard minecraft selectors (@a, @p, etc) are <em>not</em> supported.
|
||||||
|
* @param scoreboardObjective The name of the objective for which to display the score.
|
||||||
|
* @return The text component representing the specified scoreboard score for the specified player, or {@code null} if an error occurs during
|
||||||
|
* JSON serialization.
|
||||||
|
*/
|
||||||
|
public static TextualComponent objectiveScore(String playerName, String scoreboardObjective) {
|
||||||
|
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
||||||
|
// OVERLOADS documentation accordingly
|
||||||
|
|
||||||
|
return new ComplexTextTypeComponent("score",
|
||||||
|
ImmutableMap.<String, String>builder().put("name", playerName).put("objective", scoreboardObjective).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
|
||||||
|
* The client will see the players or entities captured by the specified selector as the text represented by this component.
|
||||||
|
* <p>
|
||||||
|
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
||||||
|
* </p>
|
||||||
|
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in
|
||||||
|
* the place of this text component.
|
||||||
|
* @return The text component representing the name of the entities captured by the selector.
|
||||||
|
*/
|
||||||
|
public static TextualComponent selector(String selector) {
|
||||||
|
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
||||||
|
// OVERLOADS documentation accordingly
|
||||||
|
|
||||||
|
return new ArbitraryTextTypeComponent("selector", selector);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getReadableString();
|
return getReadableString();
|
||||||
@ -51,27 +152,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
* @param writer The object to which to write the JSON data.
|
* @param writer The object to which to write the JSON data.
|
||||||
* @throws IOException If an error occurs while writing to the stream.
|
* @throws IOException If an error occurs while writing to the stream.
|
||||||
*/
|
*/
|
||||||
public abstract void writeJson(final JsonWriter writer) throws IOException;
|
public abstract void writeJson(JsonWriter writer) throws IOException;
|
||||||
|
|
||||||
static TextualComponent deserialize(final Map<String, Object> map) {
|
|
||||||
if (map.containsKey("key") && (map.size() == 2) && map.containsKey("value")) {
|
|
||||||
// Arbitrary text component
|
|
||||||
return ArbitraryTextTypeComponent.deserialize(map);
|
|
||||||
} else if ((map.size() >= 2) && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
|
|
||||||
// Complex JSON object
|
|
||||||
return ComplexTextTypeComponent.deserialize(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isTextKey(final String key) {
|
|
||||||
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isTranslatableText(final TextualComponent component) {
|
|
||||||
return (component instanceof ComplexTextTypeComponent) && component.getKey().equals("translate");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class used to represent all types of text components.
|
* Internal class used to represent all types of text components.
|
||||||
@ -79,33 +160,37 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
*/
|
*/
|
||||||
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
||||||
|
|
||||||
public ArbitraryTextTypeComponent(final String key, final String value) {
|
private String _key;
|
||||||
|
private String _value;
|
||||||
|
|
||||||
|
public ArbitraryTextTypeComponent(String key, String value) {
|
||||||
setKey(key);
|
setKey(key);
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
|
||||||
public String getKey() {
|
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
|
||||||
return _key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(final String key) {
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return this._key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
||||||
_key = key;
|
this._key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return _value;
|
return this._value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(final String value) {
|
public void setValue(String value) {
|
||||||
Preconditions.checkArgument(value != null, "The value must be specified.");
|
Preconditions.checkArgument(value != null, "The value must be specified.");
|
||||||
_value = value;
|
this._value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _key;
|
|
||||||
private String _value;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextualComponent clone() throws CloneNotSupportedException {
|
public TextualComponent clone() throws CloneNotSupportedException {
|
||||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||||
@ -113,7 +198,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeJson(final JsonWriter writer) throws IOException {
|
public void writeJson(JsonWriter writer) throws IOException {
|
||||||
writer.name(getKey()).value(getValue());
|
writer.name(getKey()).value(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,10 +213,6 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArbitraryTextTypeComponent deserialize(final Map<String, Object> map) {
|
|
||||||
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getReadableString() {
|
public String getReadableString() {
|
||||||
return getValue();
|
return getValue();
|
||||||
@ -144,33 +225,46 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
*/
|
*/
|
||||||
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
||||||
|
|
||||||
public ComplexTextTypeComponent(final String key, final Map<String, String> values) {
|
private String _key;
|
||||||
|
private Map<String, String> _value;
|
||||||
|
|
||||||
|
public ComplexTextTypeComponent(String key, Map<String, String> values) {
|
||||||
setKey(key);
|
setKey(key);
|
||||||
setValue(values);
|
setValue(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
|
||||||
public String getKey() {
|
String key = null;
|
||||||
return _key;
|
Map<String, String> value = new HashMap<String, String>();
|
||||||
|
for (Map.Entry<String, Object> valEntry : map.entrySet()) {
|
||||||
|
if (valEntry.getKey().equals("key")) {
|
||||||
|
key = (String) valEntry.getValue();
|
||||||
|
} else if (valEntry.getKey().startsWith("value.")) {
|
||||||
|
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ComplexTextTypeComponent(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(final String key) {
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return this._key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
Preconditions.checkArgument((key != null) && !key.isEmpty(), "The key must be specified.");
|
||||||
_key = key;
|
this._key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getValue() {
|
public Map<String, String> getValue() {
|
||||||
return _value;
|
return this._value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(final Map<String, String> value) {
|
public void setValue(Map<String, String> value) {
|
||||||
Preconditions.checkArgument(value != null, "The value must be specified.");
|
Preconditions.checkArgument(value != null, "The value must be specified.");
|
||||||
_value = value;
|
this._value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _key;
|
|
||||||
private Map<String, String> _value;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextualComponent clone() throws CloneNotSupportedException {
|
public TextualComponent clone() throws CloneNotSupportedException {
|
||||||
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
// Since this is a private and final class, we can just reinstantiate this class instead of casting super.clone
|
||||||
@ -178,10 +272,10 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeJson(final JsonWriter writer) throws IOException {
|
public void writeJson(JsonWriter writer) throws IOException {
|
||||||
writer.name(getKey());
|
writer.name(getKey());
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
for (final Map.Entry<String, String> jsonPair : _value.entrySet()) {
|
for (Map.Entry<String, String> jsonPair : this._value.entrySet()) {
|
||||||
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
|
writer.name(jsonPair.getKey()).value(jsonPair.getValue());
|
||||||
}
|
}
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
@ -193,101 +287,16 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
return new java.util.HashMap<String, Object>() {
|
return new java.util.HashMap<String, Object>() {
|
||||||
{
|
{
|
||||||
put("key", getKey());
|
put("key", getKey());
|
||||||
for (final Map.Entry<String, String> valEntry : getValue().entrySet()) {
|
for (Map.Entry<String, String> valEntry : getValue().entrySet()) {
|
||||||
put("value." + valEntry.getKey(), valEntry.getValue());
|
put("value." + valEntry.getKey(), valEntry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComplexTextTypeComponent deserialize(final Map<String, Object> map) {
|
|
||||||
String key = null;
|
|
||||||
final Map<String, String> value = new HashMap<String, String>();
|
|
||||||
for (final Map.Entry<String, Object> valEntry : map.entrySet()) {
|
|
||||||
if (valEntry.getKey().equals("key")) {
|
|
||||||
key = (String) valEntry.getValue();
|
|
||||||
} else if (valEntry.getKey().startsWith("value.")) {
|
|
||||||
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ComplexTextTypeComponent(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getReadableString() {
|
public String getReadableString() {
|
||||||
return getKey();
|
return getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a textual component representing a string literal.
|
|
||||||
* This is the default type of textual component when a single string literal is given to a method.
|
|
||||||
* @param textValue The text which will be represented.
|
|
||||||
* @return The text component representing the specified literal text.
|
|
||||||
*/
|
|
||||||
public static TextualComponent rawText(final String textValue) {
|
|
||||||
return new ArbitraryTextTypeComponent("text", textValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a textual component representing a localized string.
|
|
||||||
* The client will see this text component as their localized version of the specified string <em>key</em>, which can be overridden by a resource pack.
|
|
||||||
* <p>
|
|
||||||
* If the specified translation key is not present on the client resource pack, the translation key will be displayed as a string literal to the client.
|
|
||||||
* </p>
|
|
||||||
* @param translateKey The string key which maps to localized text.
|
|
||||||
* @return The text component representing the specified localized text.
|
|
||||||
*/
|
|
||||||
public static TextualComponent localizedText(final String translateKey) {
|
|
||||||
return new ArbitraryTextTypeComponent("translate", translateKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void throwUnsupportedSnapshot() {
|
|
||||||
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a textual component representing a scoreboard value.
|
|
||||||
* The client will see their own score for the specified objective as the text represented by this component.
|
|
||||||
* <p>
|
|
||||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
|
||||||
* </p>
|
|
||||||
* @param scoreboardObjective The name of the objective for which to display the score.
|
|
||||||
* @return The text component representing the specified scoreboard score (for the viewing player), or {@code null} if an error occurs during JSON serialization.
|
|
||||||
*/
|
|
||||||
public static TextualComponent objectiveScore(final String scoreboardObjective) {
|
|
||||||
return objectiveScore("*", scoreboardObjective);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a textual component representing a scoreboard value.
|
|
||||||
* The client will see the score of the specified player for the specified objective as the text represented by this component.
|
|
||||||
* <p>
|
|
||||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
|
||||||
* </p>
|
|
||||||
* @param playerName The name of the player whos score will be shown. If this string represents the single-character sequence "*", the viewing player's score will be displayed.
|
|
||||||
* Standard minecraft selectors (@a, @p, etc) are <em>not</em> supported.
|
|
||||||
* @param scoreboardObjective The name of the objective for which to display the score.
|
|
||||||
* @return The text component representing the specified scoreboard score for the specified player, or {@code null} if an error occurs during JSON serialization.
|
|
||||||
*/
|
|
||||||
public static TextualComponent objectiveScore(final String playerName, final String scoreboardObjective) {
|
|
||||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
|
|
||||||
|
|
||||||
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String> builder().put("name", playerName).put("objective", scoreboardObjective).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a textual component representing a player name, retrievable by using a standard minecraft selector.
|
|
||||||
* The client will see the players or entities captured by the specified selector as the text represented by this component.
|
|
||||||
* <p>
|
|
||||||
* <b>This method is currently guaranteed to throw an {@code UnsupportedOperationException} as it is only supported on snapshot clients.</b>
|
|
||||||
* </p>
|
|
||||||
* @param selector The minecraft player or entity selector which will capture the entities whose string representations will be displayed in the place of this text component.
|
|
||||||
* @return The text component representing the name of the entities captured by the selector.
|
|
||||||
*/
|
|
||||||
public static TextualComponent selector(final String selector) {
|
|
||||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE OVERLOADS documentation accordingly
|
|
||||||
|
|
||||||
return new ArbitraryTextTypeComponent("selector", selector);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
|||||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||||
import com.plotsquared.general.commands.Argument;
|
import com.plotsquared.general.commands.Argument;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -55,20 +56,20 @@ import java.util.Map.Entry;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "uuidconvert",
|
command = "uuidconvert",
|
||||||
permission = "plots.admin",
|
permission = "plots.admin",
|
||||||
description = "Debug UUID conversion",
|
description = "Debug UUID conversion",
|
||||||
usage = "/plot uuidconvert <lower|offline|online>",
|
usage = "/plot uuidconvert <lower|offline|online>",
|
||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class DebugUUID extends SubCommand {
|
public class DebugUUID extends SubCommand {
|
||||||
|
|
||||||
public DebugUUID() {
|
public DebugUUID() {
|
||||||
requiredArguments = new Argument[] { Argument.String };
|
this.requiredArguments = new Argument[]{Argument.String};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
public boolean onCommand(final PlotPlayer player, String[] args) {
|
||||||
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
|
||||||
final UUIDWrapper newWrapper;
|
final UUIDWrapper newWrapper;
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
final Class<?> clazz = Class.forName(args[0]);
|
Class<?> clazz = Class.forName(args[0]);
|
||||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
|
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||||
@ -121,38 +122,39 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Collecting playerdata");
|
MainUtil.sendMessage(player, "&7 - Collecting playerdata");
|
||||||
|
|
||||||
final HashSet<String> worlds = new HashSet<>();
|
HashSet<String> worlds = new HashSet<>();
|
||||||
worlds.add(WorldUtil.IMP.getMainWorld());
|
worlds.add(WorldUtil.IMP.getMainWorld());
|
||||||
worlds.add("world");
|
worlds.add("world");
|
||||||
final HashSet<UUID> uuids = new HashSet<>();
|
HashSet<UUID> uuids = new HashSet<>();
|
||||||
final HashSet<String> names = new HashSet<>();
|
HashSet<String> names = new HashSet<>();
|
||||||
for (final String worldname : worlds) {
|
for (String worldname : worlds) {
|
||||||
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
||||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s) {
|
public boolean accept(File f, String s) {
|
||||||
return s.endsWith(".dat");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (dat != null)
|
|
||||||
for (final String current : dat) {
|
|
||||||
final String s = current.replaceAll(".dat$", "");
|
|
||||||
try {
|
|
||||||
final UUID uuid = UUID.fromString(s);
|
|
||||||
uuids.add(uuid);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
MainUtil.sendMessage(player, C.PREFIX + "Invalid playerdata: " + current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final File playersFolder = new File(worldname + File.separator + "players");
|
|
||||||
dat = playersFolder.list(new FilenameFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean accept(final File f, final String s) {
|
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (dat != null) {
|
if (dat != null) {
|
||||||
for (final String current : dat) {
|
for (String current : dat) {
|
||||||
|
String s = current.replaceAll(".dat$", "");
|
||||||
|
try {
|
||||||
|
UUID uuid = UUID.fromString(s);
|
||||||
|
uuids.add(uuid);
|
||||||
|
} catch (Exception e) {
|
||||||
|
MainUtil.sendMessage(player, C.PREFIX + "Invalid playerdata: " + current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File playersFolder = new File(worldname + File.separator + "players");
|
||||||
|
dat = playersFolder.list(new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File f, String s) {
|
||||||
|
return s.endsWith(".dat");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dat != null) {
|
||||||
|
for (String current : dat) {
|
||||||
names.add(current.replaceAll(".dat$", ""));
|
names.add(current.replaceAll(".dat$", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,22 +162,22 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Populating map");
|
MainUtil.sendMessage(player, "&7 - Populating map");
|
||||||
UUID uuid2;
|
UUID uuid2;
|
||||||
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
UUIDWrapper wrapper = new DefaultUUIDWrapper();
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
try {
|
try {
|
||||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||||
uuid = currentUUIDWrapper.getUUID(op);
|
uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
uCReverse.put(uuid2, uuid);
|
uCReverse.put(uuid2, uuid);
|
||||||
}
|
}
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final String name : names) {
|
for (String name : names) {
|
||||||
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||||
uuid2 = newWrapper.getUUID(name);
|
uuid2 = newWrapper.getUUID(name);
|
||||||
if (!uuid.equals(uuid2)) {
|
if (!uuid.equals(uuid2)) {
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
@ -184,11 +186,11 @@ public class DebugUUID extends SubCommand {
|
|||||||
}
|
}
|
||||||
if (uCMap.isEmpty()) {
|
if (uCMap.isEmpty()) {
|
||||||
MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
|
MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
|
||||||
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
|
||||||
if (op.getLastPlayed() != 0) {
|
if (op.getLastPlayed() != 0) {
|
||||||
// String name = op.getName();
|
// String name = op.getName();
|
||||||
// StringWrapper wrap = new StringWrapper(name);
|
// StringWrapper wrap = new StringWrapper(name);
|
||||||
final UUID uuid = currentUUIDWrapper.getUUID(op);
|
UUID uuid = currentUUIDWrapper.getUUID(op);
|
||||||
uuid2 = newWrapper.getUUID(op);
|
uuid2 = newWrapper.getUUID(op);
|
||||||
if (!uuid.equals(uuid2)) {
|
if (!uuid.equals(uuid2)) {
|
||||||
uCMap.put(uuid, uuid2);
|
uCMap.put(uuid, uuid2);
|
||||||
@ -208,8 +210,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (final Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||||
final String name = UUIDHandler.getName(entry.getKey());
|
String name = UUIDHandler.getName(entry.getKey());
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||||
}
|
}
|
||||||
@ -217,10 +219,10 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
||||||
|
|
||||||
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
try {
|
try {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
@ -228,24 +230,24 @@ public class DebugUUID extends SubCommand {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
final String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
final String name = split[0];
|
String name = split[0];
|
||||||
if (name.isEmpty() || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
|
if (name.isEmpty() || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final UUID old = currentUUIDWrapper.getUUID(name);
|
UUID old = currentUUIDWrapper.getUUID(name);
|
||||||
if (old == null) {
|
if (old == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final UUID now = newWrapper.getUUID(name);
|
UUID now = newWrapper.getUUID(name);
|
||||||
UUIDHandler.add(new StringWrapper(name), now);
|
UUIDHandler.add(new StringWrapper(name), now);
|
||||||
uCMap.put(old, now);
|
uCMap.put(old, now);
|
||||||
uCReverse.put(now, old);
|
uCReverse.put(now, old);
|
||||||
} catch (final Exception e2) {
|
} catch (Exception e2) {
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,8 +257,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||||
|
|
||||||
for (final Plot plot : PS.get().getPlots()) {
|
for (Plot plot : PS.get().getPlots()) {
|
||||||
final UUID value = uCMap.get(plot.owner);
|
UUID value = uCMap.get(plot.owner);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
@ -267,7 +269,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Deleting database");
|
MainUtil.sendMessage(player, "&7 - Deleting database");
|
||||||
final AbstractDB database = DBFunc.dbManager;
|
final AbstractDB database = DBFunc.dbManager;
|
||||||
final boolean result = database.deleteTables();
|
boolean result = database.deleteTables();
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Creating tables");
|
MainUtil.sendMessage(player, "&7 - Creating tables");
|
||||||
|
|
||||||
@ -275,8 +277,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
database.createTables();
|
database.createTables();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||||
for (final Plot plot : PS.get().getPlots()) {
|
for (Plot plot : PS.get().getPlots()) {
|
||||||
final UUID value = uCReverse.get(plot.owner);
|
UUID value = uCReverse.get(plot.owner);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
@ -289,7 +291,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -312,7 +314,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||||
database.createPlotsAndData(plots, new Runnable() {
|
database.createPlotsAndData(plots, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -14,60 +14,61 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public abstract class APlotMeConnector {
|
public abstract class APlotMeConnector {
|
||||||
public abstract Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder);
|
|
||||||
|
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
||||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(final Connection connection) throws SQLException;
|
|
||||||
|
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
||||||
public abstract boolean accepts(final String version);
|
|
||||||
|
public abstract boolean accepts(String version);
|
||||||
public String getWorld(final String world) {
|
|
||||||
for (final World newworld : Bukkit.getWorlds()) {
|
public String getWorld(String world) {
|
||||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
for (World newWorld : Bukkit.getWorlds()) {
|
||||||
return newworld.getName();
|
if (newWorld.getName().equalsIgnoreCase(world)) {
|
||||||
|
return newWorld.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidConnection(final Connection connection) {
|
public boolean isValidConnection(Connection connection) {
|
||||||
return connection != null;
|
return connection != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyConfig(final FileConfiguration plotConfig, final String world, final String actualWorldName) {
|
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
||||||
final Integer pathwidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
int pathWidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathwidth);
|
PS.get().config.set("worlds." + actualWorldName + ".road.width", pathWidth);
|
||||||
final Integer plotsize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
int plotSize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotsize);
|
PS.get().config.set("worlds." + actualWorldName + ".plot.size", plotSize);
|
||||||
final String wallblock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
String wallBlock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallblock);
|
PS.get().config.set("worlds." + actualWorldName + ".wall.block", wallBlock);
|
||||||
final String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
PS.get().config.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
||||||
final String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
PS.get().config.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
||||||
final String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
PS.get().config.set("worlds." + actualWorldName + ".road.block", road);
|
||||||
Integer height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
int height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) {
|
public Location getPlotTopLocAbs(int path, int plot, PlotId plotid) {
|
||||||
final int px = plotid.x;
|
int px = plotid.x;
|
||||||
final int pz = plotid.y;
|
int pz = plotid.y;
|
||||||
final int x = (px * (path + plot)) - (int) Math.floor(path / 2) - 1;
|
int x = (px * (path + plot)) - (int) Math.floor(path / 2) - 1;
|
||||||
final int z = (pz * (path + plot)) - (int) Math.floor(path / 2) - 1;
|
int z = (pz * (path + plot)) - (int) Math.floor(path / 2) - 1;
|
||||||
return new Location(null, x, 256, z);
|
return new Location(null, x, 256, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) {
|
public Location getPlotBottomLocAbs(int path, int plot, PlotId plotid) {
|
||||||
final int px = plotid.x;
|
int px = plotid.x;
|
||||||
final int pz = plotid.y;
|
int pz = plotid.y;
|
||||||
final int x = (px * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
|
int x = (px * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
|
||||||
final int z = (pz * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
|
int z = (pz * (path + plot)) - plot - (int) Math.floor(path / 2) - 1;
|
||||||
return new Location(null, x, 1, z);
|
return new Location(null, x, 1, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMerged(final HashMap<String, HashMap<PlotId, boolean[]>> merges, final String world, final PlotId id, final int direction) {
|
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
||||||
final HashMap<PlotId, boolean[]> plots = merges.get(world);
|
HashMap<PlotId, boolean[]> plots = merges.get(world);
|
||||||
PlotId id2 = new PlotId(id.x, id.y);
|
PlotId id2 = new PlotId(id.x, id.y);
|
||||||
boolean[] merge1;
|
boolean[] merge1;
|
||||||
if (plots.containsKey(id)) {
|
if (plots.containsKey(id)) {
|
||||||
|
@ -25,70 +25,71 @@ import java.util.Map.Entry;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ClassicPlotMeConnector extends APlotMeConnector {
|
public class ClassicPlotMeConnector extends APlotMeConnector {
|
||||||
|
|
||||||
private String plugin;
|
private String plugin;
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getPlotMeConnection(final String plugin, final FileConfiguration plotConfig, final String dataFolder) {
|
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
||||||
this.plugin = plugin.toLowerCase();
|
this.plugin = plugin.toLowerCase();
|
||||||
prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase());
|
this.prefix = plotConfig.getString("mySQLprefix", plugin.toLowerCase());
|
||||||
try {
|
try {
|
||||||
if (plotConfig.getBoolean("usemySQL")) {
|
if (plotConfig.getBoolean("usemySQL")) {
|
||||||
final String user = plotConfig.getString("mySQLuname");
|
String user = plotConfig.getString("mySQLuname");
|
||||||
final String password = plotConfig.getString("mySQLpass");
|
String password = plotConfig.getString("mySQLpass");
|
||||||
final String con = plotConfig.getString("mySQLconn");
|
String con = plotConfig.getString("mySQLconn");
|
||||||
return DriverManager.getConnection(con, user, password);
|
return DriverManager.getConnection(con, user, password);
|
||||||
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
// return new MySQL(plotsquared, hostname, port, database, username, password)
|
||||||
} else {
|
} else {
|
||||||
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
return new SQLite(dataFolder + File.separator + "plots.db").openConnection();
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException ignored) {
|
} catch (SQLException | ClassNotFoundException ignored) {
|
||||||
|
//ignored
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(final Connection connection) throws SQLException {
|
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
||||||
final HashMap<String, Integer> plotWidth = new HashMap<>();
|
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||||
final HashMap<String, Integer> roadWidth = new HashMap<>();
|
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||||
final HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||||
final HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||||
PreparedStatement stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "Plots`");
|
PreparedStatement statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Plots`");
|
||||||
ResultSet r = stmt.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
String column = null;
|
String column = null;
|
||||||
final boolean checkUUID = DBFunc.hasColumn(r, "ownerid");
|
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerid");
|
||||||
final boolean checkUUID2 = DBFunc.hasColumn(r, "ownerId");
|
boolean checkUUID2 = DBFunc.hasColumn(resultSet, "ownerId");
|
||||||
if (checkUUID) {
|
if (checkUUID) {
|
||||||
column = "ownerid";
|
column = "ownerid";
|
||||||
} else if (checkUUID2) {
|
} else if (checkUUID2) {
|
||||||
column = "ownerId";
|
column = "ownerId";
|
||||||
}
|
}
|
||||||
final boolean merge = !"plotme".equalsIgnoreCase(plugin) && Settings.CONVERT_PLOTME;
|
boolean merge = !"plotme".equalsIgnoreCase(this.plugin) && Settings.CONVERT_PLOTME;
|
||||||
int missing = 0;
|
int missing = 0;
|
||||||
while (r.next()) {
|
while (resultSet.next()) {
|
||||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
||||||
final String name = r.getString("owner");
|
String name = resultSet.getString("owner");
|
||||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
String world = LikePlotMeConverter.getWorld(resultSet.getString("world"));
|
||||||
if (!plots.containsKey(world)) {
|
if (!plots.containsKey(world)) {
|
||||||
plots.put(world, new HashMap<PlotId, Plot>());
|
plots.put(world, new HashMap<PlotId, Plot>());
|
||||||
if (merge) {
|
if (merge) {
|
||||||
final int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
int plot = PS.get().config.getInt("worlds." + world + ".plot.size");
|
||||||
final int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
int path = PS.get().config.getInt("worlds." + world + ".road.width");
|
||||||
plotWidth.put(world, plot);
|
plotWidth.put(world, plot);
|
||||||
roadWidth.put(world, path);
|
roadWidth.put(world, path);
|
||||||
merges.put(world, new HashMap<PlotId, boolean[]>());
|
merges.put(world, new HashMap<PlotId, boolean[]>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (merge) {
|
if (merge) {
|
||||||
final int tx = r.getInt("topX");
|
int tx = resultSet.getInt("topX");
|
||||||
final int tz = r.getInt("topZ");
|
int tz = resultSet.getInt("topZ");
|
||||||
final int bx = r.getInt("bottomX") - 1;
|
int bx = resultSet.getInt("bottomX") - 1;
|
||||||
final int bz = r.getInt("bottomZ") - 1;
|
int bz = resultSet.getInt("bottomZ") - 1;
|
||||||
final int path = roadWidth.get(world);
|
int path = roadWidth.get(world);
|
||||||
final int plot = plotWidth.get(world);
|
int plot = plotWidth.get(world);
|
||||||
final Location top = getPlotTopLocAbs(path, plot, id);
|
Location top = getPlotTopLocAbs(path, plot, id);
|
||||||
final Location bot = getPlotBottomLocAbs(path, plot, id);
|
Location bot = getPlotBottomLocAbs(path, plot, id);
|
||||||
if (tx > top.getX()) {
|
if (tx > top.getX()) {
|
||||||
setMerged(merges, world, id, 1);
|
setMerged(merges, world, id, 1);
|
||||||
}
|
}
|
||||||
@ -109,14 +110,14 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
} else {
|
} else {
|
||||||
if (checkUUID || checkUUID2) {
|
if (checkUUID || checkUUID2) {
|
||||||
try {
|
try {
|
||||||
final byte[] bytes = r.getBytes(column);
|
byte[] bytes = resultSet.getBytes(column);
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
try {
|
try {
|
||||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||||
final long high = bb.getLong();
|
long high = bb.getLong();
|
||||||
final long low = bb.getLong();
|
long low = bb.getLong();
|
||||||
owner = new UUID(high, low);
|
owner = new UUID(high, low);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
owner = UUID.nameUUIDFromBytes(bytes);
|
owner = UUID.nameUUIDFromBytes(bytes);
|
||||||
}
|
}
|
||||||
@ -138,55 +139,56 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
} else {
|
} else {
|
||||||
UUIDHandler.add(new StringWrapper(name), owner);
|
UUIDHandler.add(new StringWrapper(name), owner);
|
||||||
}
|
}
|
||||||
final Plot plot = new Plot(PlotArea.createGeneric(world), id, owner);
|
Plot plot = new Plot(PlotArea.createGeneric(world), id, owner);
|
||||||
plots.get(world).put(id, plot);
|
plots.get(world).put(id, plot);
|
||||||
}
|
}
|
||||||
if (missing > 0) {
|
if (missing > 0) {
|
||||||
PS.log("&cSome names could not be identified:");
|
PS.log("&cSome names could not be identified:");
|
||||||
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
||||||
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
||||||
PS.log("&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will remain unknown until the player connects)");
|
PS.log("&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will "
|
||||||
|
+ "remain unknown until the player connects)");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
for (Entry<String, HashMap<PlotId, boolean[]>> entry : merges.entrySet()) {
|
||||||
final String world = entry.getKey();
|
String world = entry.getKey();
|
||||||
for (final Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, boolean[]> entry2 : entry.getValue().entrySet()) {
|
||||||
final HashMap<PlotId, Plot> newplots = plots.get(world);
|
HashMap<PlotId, Plot> newplots = plots.get(world);
|
||||||
final Plot plot = newplots.get(entry2.getKey());
|
Plot plot = newplots.get(entry2.getKey());
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
plot.setMerged(entry2.getValue());
|
plot.setMerged(entry2.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.close();
|
resultSet.close();
|
||||||
stmt.close();
|
statement.close();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
PS.log(" - " + prefix + "Denied");
|
PS.log(" - " + this.prefix + "Denied");
|
||||||
stmt = connection.prepareStatement("SELECT * FROM `" + prefix + "Denied`");
|
statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Denied`");
|
||||||
r = stmt.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (r.next()) {
|
while (resultSet.next()) {
|
||||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
||||||
final String name = r.getString("player");
|
String name = resultSet.getString("player");
|
||||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
String world = LikePlotMeConverter.getWorld(resultSet.getString("world"));
|
||||||
UUID denied = UUIDHandler.getUUID(name, null);
|
UUID denied = UUIDHandler.getUUID(name, null);
|
||||||
if (denied == null) {
|
if (denied == null) {
|
||||||
if ("*".equals(name)) {
|
if ("*".equals(name)) {
|
||||||
denied = DBFunc.everyone;
|
denied = DBFunc.everyone;
|
||||||
} else {
|
} else {
|
||||||
if (DBFunc.hasColumn(r, "playerid")) {
|
if (DBFunc.hasColumn(resultSet, "playerid")) {
|
||||||
try {
|
try {
|
||||||
final byte[] bytes = r.getBytes("playerid");
|
byte[] bytes = resultSet.getBytes("playerid");
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
try {
|
try {
|
||||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||||
final long high = bb.getLong();
|
long high = bb.getLong();
|
||||||
final long low = bb.getLong();
|
long low = bb.getLong();
|
||||||
denied = new UUID(high, low);
|
denied = new UUID(high, low);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
denied = UUID.nameUUIDFromBytes(bytes);
|
denied = UUID.nameUUIDFromBytes(bytes);
|
||||||
}
|
}
|
||||||
@ -207,36 +209,34 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "Allowed`");
|
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "Allowed`");
|
||||||
r = stmt.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (r.next()) {
|
while (resultSet.next()) {
|
||||||
final PlotId id = new PlotId(r.getInt("idX"), r.getInt("idZ"));
|
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
||||||
final String name = r.getString("player");
|
String name = resultSet.getString("player");
|
||||||
final String world = LikePlotMeConverter.getWorld(r.getString("world"));
|
String world = LikePlotMeConverter.getWorld(resultSet.getString("world"));
|
||||||
UUID helper = UUIDHandler.getUUID(name, null);
|
UUID helper = UUIDHandler.getUUID(name, null);
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
if ("*".equals(name)) {
|
if ("*".equals(name)) {
|
||||||
helper = DBFunc.everyone;
|
helper = DBFunc.everyone;
|
||||||
} else {
|
} else if (DBFunc.hasColumn(resultSet, "playerid")) {
|
||||||
if (DBFunc.hasColumn(r, "playerid")) {
|
try {
|
||||||
try {
|
byte[] bytes = resultSet.getBytes("playerid");
|
||||||
final byte[] bytes = r.getBytes("playerid");
|
if (bytes != null) {
|
||||||
if (bytes != null) {
|
try {
|
||||||
try {
|
ByteBuffer bb = ByteBuffer.wrap(bytes);
|
||||||
final ByteBuffer bb = ByteBuffer.wrap(bytes);
|
long high = bb.getLong();
|
||||||
final long high = bb.getLong();
|
long low = bb.getLong();
|
||||||
final long low = bb.getLong();
|
helper = new UUID(high, low);
|
||||||
helper = new UUID(high, low);
|
} catch (Exception e) {
|
||||||
} catch (final Exception e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
helper = UUID.nameUUIDFromBytes(bytes);
|
||||||
helper = UUID.nameUUIDFromBytes(bytes);
|
|
||||||
}
|
|
||||||
UUIDHandler.add(new StringWrapper(name), helper);
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
UUIDHandler.add(new StringWrapper(name), helper);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
@ -249,16 +249,17 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r.close();
|
resultSet.close();
|
||||||
stmt.close();
|
statement.close();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException ignored) {
|
||||||
|
//ignored
|
||||||
}
|
}
|
||||||
return plots;
|
return plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accepts(final String version) {
|
public boolean accepts(String version) {
|
||||||
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get().canUpdate("0.999.999", version);
|
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get().canUpdate("0.999.999", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,12 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a flag is removed from a plot
|
* Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
@ -34,56 +33,57 @@ import com.intellectualcrafters.plot.object.PlotCluster;
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final PlotCluster cluster;
|
private final PlotCluster cluster;
|
||||||
private final Flag flag;
|
private final Flag flag;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
* @param flag Flag that was removed
|
* @param flag Flag that was removed
|
||||||
* @param cluster PlotCluster from which the flag was removed
|
* @param cluster PlotCluster from which the flag was removed
|
||||||
*/
|
*/
|
||||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
public ClusterFlagRemoveEvent(Flag flag, PlotCluster cluster) {
|
||||||
this.cluster = cluster;
|
this.cluster = cluster;
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cluster involved
|
* Get the cluster involved
|
||||||
*
|
*
|
||||||
* @return PlotCluster
|
* @return PlotCluster
|
||||||
*/
|
*/
|
||||||
public PlotCluster getCluster() {
|
public PlotCluster getCluster() {
|
||||||
return cluster;
|
return this.cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the flag involved
|
* Get the flag involved
|
||||||
*
|
*
|
||||||
* @return Flag
|
* @return Flag
|
||||||
*/
|
*/
|
||||||
public Flag getFlag() {
|
public Flag getFlag() {
|
||||||
return flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(boolean b) {
|
||||||
cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,65 +20,67 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private final boolean auto;
|
private final boolean auto;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerClaimPlotEvent: Called when a plot is claimed
|
* PlayerClaimPlotEvent: Called when a plot is claimed
|
||||||
*
|
*
|
||||||
* @param player Player that claimed the plot
|
* @param player Player that claimed the plot
|
||||||
* @param plot Plot that was claimed
|
* @param plot Plot that was claimed
|
||||||
*/
|
*/
|
||||||
public PlayerClaimPlotEvent(final Player player, final Plot plot, final boolean auto) {
|
public PlayerClaimPlotEvent(Player player, Plot plot, boolean auto) {
|
||||||
super(player);
|
super(player);
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
this.auto = auto;
|
this.auto = auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plot involved
|
* Get the plot involved
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot() {
|
public Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if it was an automated claim, else false
|
* @return true if it was an automated claim, else false
|
||||||
*/
|
*/
|
||||||
public boolean wasAuto() {
|
public boolean wasAuto() {
|
||||||
return auto;
|
return this.auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(boolean b) {
|
||||||
cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,42 +20,44 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerEnterPlotEvent extends PlayerEvent {
|
public class PlayerEnterPlotEvent extends PlayerEvent {
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
* PlayerEnterPlotEvent: Called when a player leaves a plot
|
||||||
*
|
*
|
||||||
* @param player Player that entered the plot
|
* @param player Player that entered the plot
|
||||||
* @param plot Plot that was entered
|
* @param plot Plot that was entered
|
||||||
*/
|
*/
|
||||||
public PlayerEnterPlotEvent(final Player player, final Plot plot) {
|
public PlayerEnterPlotEvent(Player player, Plot plot) {
|
||||||
super(player);
|
super(player);
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plot involved
|
* Get the plot involved
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot() {
|
public Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -20,43 +20,44 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
* PlayerLeavePlotEvent: Called when a player leaves a plot
|
||||||
*
|
*
|
||||||
* @param player Player that left the plot
|
* @param player Player that left the plot
|
||||||
* @param plot Plot that was left
|
* @param plot Plot that was left
|
||||||
*/
|
*/
|
||||||
public PlayerLeavePlotEvent(final Player player, final Plot plot) {
|
public PlayerLeavePlotEvent(Player player, Plot plot) {
|
||||||
super(player);
|
super(player);
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plot involved
|
* Get the plot involved
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot() {
|
public Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -20,22 +20,23 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerPlotDeniedEvent extends PlotEvent {
|
public class PlayerPlotDeniedEvent extends PlotEvent {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
|
||||||
*
|
*
|
||||||
@ -44,44 +45,44 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
|||||||
* @param player Player that was denied/un-denied
|
* @param player Player that was denied/un-denied
|
||||||
* @param added true of add to deny list, false if removed
|
* @param added true of add to deny list, false if removed
|
||||||
*/
|
*/
|
||||||
public PlayerPlotDeniedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
public PlayerPlotDeniedEvent(Player initiator, Plot plot, UUID player, boolean added) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
this.added = added;
|
this.added = added;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a user was added
|
* If a user was added
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean wasAdded() {
|
public boolean wasAdded() {
|
||||||
return added;
|
return this.added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player added/removed
|
* The player added/removed
|
||||||
*
|
*
|
||||||
* @return UUID
|
* @return UUID
|
||||||
*/
|
*/
|
||||||
public UUID getPlayer() {
|
public UUID getPlayer() {
|
||||||
return player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player initiating the action
|
* The player initiating the action
|
||||||
*
|
*
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public Player getInitiator() {
|
public Player getInitiator() {
|
||||||
return initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -20,22 +20,23 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerPlotHelperEvent extends PlotEvent {
|
public class PlayerPlotHelperEvent extends PlotEvent {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
|
||||||
*
|
*
|
||||||
@ -44,44 +45,44 @@ public class PlayerPlotHelperEvent extends PlotEvent {
|
|||||||
* @param player Player that was added/removed from the helper list
|
* @param player Player that was added/removed from the helper list
|
||||||
* @param added true of the player was added, false if the player was removed
|
* @param added true of the player was added, false if the player was removed
|
||||||
*/
|
*/
|
||||||
public PlayerPlotHelperEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
public PlayerPlotHelperEvent(Player initiator, Plot plot, UUID player, boolean added) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
this.added = added;
|
this.added = added;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a player was added
|
* If a player was added
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean wasAdded() {
|
public boolean wasAdded() {
|
||||||
return added;
|
return this.added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The UUID added/removed
|
* The UUID added/removed
|
||||||
*
|
*
|
||||||
* @return UUID
|
* @return UUID
|
||||||
*/
|
*/
|
||||||
public UUID getPlayer() {
|
public UUID getPlayer() {
|
||||||
return player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player initiating the action
|
* The player initiating the action
|
||||||
*
|
*
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public Player getInitiator() {
|
public Player getInitiator() {
|
||||||
return initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -20,22 +20,23 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlayerPlotTrustedEvent extends PlotEvent {
|
public class PlayerPlotTrustedEvent extends PlotEvent {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player initiator;
|
private final Player initiator;
|
||||||
private final boolean added;
|
private final boolean added;
|
||||||
private final UUID player;
|
private final UUID player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
* PlayerPlotTrustedEvent: Called when a plot trusted user is added/removed
|
||||||
*
|
*
|
||||||
@ -44,44 +45,44 @@ public class PlayerPlotTrustedEvent extends PlotEvent {
|
|||||||
* @param player Player that was added/removed from the trusted list
|
* @param player Player that was added/removed from the trusted list
|
||||||
* @param added true of the player was added, false if the player was removed
|
* @param added true of the player was added, false if the player was removed
|
||||||
*/
|
*/
|
||||||
public PlayerPlotTrustedEvent(final Player initiator, final Plot plot, final UUID player, final boolean added) {
|
public PlayerPlotTrustedEvent(Player initiator, Plot plot, UUID player, boolean added) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
this.added = added;
|
this.added = added;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a player was added
|
* If a player was added
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public boolean wasAdded() {
|
public boolean wasAdded() {
|
||||||
return added;
|
return this.added;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The UUID added/removed
|
* The UUID added/removed
|
||||||
*
|
*
|
||||||
* @return UUID
|
* @return UUID
|
||||||
*/
|
*/
|
||||||
public UUID getPlayer() {
|
public UUID getPlayer() {
|
||||||
return player;
|
return this.player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player initiating the action
|
* The player initiating the action
|
||||||
*
|
*
|
||||||
* @return Player
|
* @return Player
|
||||||
*/
|
*/
|
||||||
public Player getInitiator() {
|
public Player getInitiator() {
|
||||||
return initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -20,24 +20,26 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player teleports to a plot
|
* Called when a player teleports to a plot
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Location from;
|
private final Location from;
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
|
||||||
*
|
*
|
||||||
@ -45,46 +47,46 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
|||||||
* @param from Start location
|
* @param from Start location
|
||||||
* @param plot Plot to which the player was teleported
|
* @param plot Plot to which the player was teleported
|
||||||
*/
|
*/
|
||||||
public PlayerTeleportToPlotEvent(final Player player, final Location from, final Plot plot) {
|
public PlayerTeleportToPlotEvent(Player player, Location from, Plot plot) {
|
||||||
super(player);
|
super(player);
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the from location
|
* Get the from location
|
||||||
*
|
*
|
||||||
* @return Location
|
* @return Location
|
||||||
*/
|
*/
|
||||||
public Location getFrom() {
|
public Location getFrom() {
|
||||||
return from;
|
return this.from;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plot involved
|
* Get the plot involved
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot() {
|
public Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,28 +20,29 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot is cleared
|
* Called when a plot is cleared
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
public class PlotClearEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled;
|
||||||
public PlotClearEvent(Plot plot) {
|
public PlotClearEvent(Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotId
|
* Get the PlotId
|
||||||
*
|
*
|
||||||
@ -50,7 +51,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
|||||||
public PlotId getPlotId() {
|
public PlotId getPlotId() {
|
||||||
return getPlot().getId();
|
return getPlot().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the world name
|
* Get the world name
|
||||||
*
|
*
|
||||||
@ -59,19 +60,19 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
|||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return getPlot().getArea().worldname;
|
return getPlot().getArea().worldname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(boolean b) {
|
||||||
cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,26 +20,28 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot is deleted
|
* Called when a plot is deleted
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlotDeleteEvent extends PlotEvent {
|
public class PlotDeleteEvent extends PlotEvent {
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
public PlotDeleteEvent(Plot plot) {
|
public PlotDeleteEvent(Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the PlotId
|
* Get the PlotId
|
||||||
*
|
*
|
||||||
@ -48,7 +50,7 @@ public class PlotDeleteEvent extends PlotEvent {
|
|||||||
public PlotId getPlotId() {
|
public PlotId getPlotId() {
|
||||||
return getPlot().getId();
|
return getPlot().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the world name
|
* Get the world name
|
||||||
*
|
*
|
||||||
@ -57,7 +59,7 @@ public class PlotDeleteEvent extends PlotEvent {
|
|||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return getPlot().getArea().worldname;
|
return getPlot().getArea().worldname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
|
|
||||||
public abstract class PlotEvent extends Event {
|
public abstract class PlotEvent extends Event {
|
||||||
|
|
||||||
private final Plot plot;
|
private final Plot plot;
|
||||||
|
|
||||||
public PlotEvent(final Plot plot) {
|
public PlotEvent(Plot plot) {
|
||||||
this.plot = plot;
|
this.plot = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Plot getPlot() {
|
public final Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,58 +20,59 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a Flag is added to a plot
|
* Called when a Flag is added to a plot
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Flag flag;
|
private final Flag flag;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
* PlotFlagAddEvent: Called when a Flag is added to a plot
|
||||||
*
|
*
|
||||||
* @param flag Flag that was added
|
* @param flag Flag that was added
|
||||||
* @param plot Plot to which the flag was added
|
* @param plot Plot to which the flag was added
|
||||||
*/
|
*/
|
||||||
public PlotFlagAddEvent(final Flag flag, final Plot plot) {
|
public PlotFlagAddEvent(Flag flag, Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the flag involved
|
* Get the flag involved
|
||||||
*
|
*
|
||||||
* @return Flag
|
* @return Flag
|
||||||
*/
|
*/
|
||||||
public Flag getFlag() {
|
public Flag getFlag() {
|
||||||
return flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isCancelled() {
|
public final boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setCancelled(final boolean cancelled) {
|
public final void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,58 +20,59 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a flag is removed from a plot
|
* Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Flag flag;
|
private final Flag flag;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
* @param flag Flag that was removed
|
* @param flag Flag that was removed
|
||||||
* @param plot Plot from which the flag was removed
|
* @param plot Plot from which the flag was removed
|
||||||
*/
|
*/
|
||||||
public PlotFlagRemoveEvent(final Flag flag, final Plot plot) {
|
public PlotFlagRemoveEvent(Flag flag, Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the flag involved
|
* Get the flag involved
|
||||||
*
|
*
|
||||||
* @return Flag
|
* @return Flag
|
||||||
*/
|
*/
|
||||||
public Flag getFlag() {
|
public Flag getFlag() {
|
||||||
return flag;
|
return this.flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isCancelled() {
|
public final boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setCancelled(final boolean cancelled) {
|
public final void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,25 +20,26 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
|
/**
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlotMergeEvent extends Event implements Cancellable {
|
public class PlotMergeEvent extends Event implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final ArrayList<PlotId> plots;
|
private final ArrayList<PlotId> plots;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
private Plot plot;
|
private Plot plot;
|
||||||
private World world;
|
private World world;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotMergeEvent: Called when plots are merged
|
* PlotMergeEvent: Called when plots are merged
|
||||||
*
|
*
|
||||||
@ -46,48 +47,48 @@ public class PlotMergeEvent extends Event implements Cancellable {
|
|||||||
* @param plot Plot that was merged
|
* @param plot Plot that was merged
|
||||||
* @param plots A list of plots involved in the event
|
* @param plots A list of plots involved in the event
|
||||||
*/
|
*/
|
||||||
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) {
|
public PlotMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
|
||||||
this.plots = plots;
|
this.plots = plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plots being added;
|
* Get the plots being added;
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public ArrayList<PlotId> getPlots() {
|
public ArrayList<PlotId> getPlots() {
|
||||||
return plots;
|
return this.plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the main plot
|
* Get the main plot
|
||||||
*
|
*
|
||||||
* @return Plot
|
* @return Plot
|
||||||
*/
|
*/
|
||||||
public Plot getPlot() {
|
public Plot getPlot() {
|
||||||
return plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return this.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(boolean b) {
|
||||||
cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,46 +1,46 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.Rating;
|
import com.intellectualcrafters.plot.object.Rating;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2015-07-13 for PlotSquaredGit
|
* Created 2015-07-13 for PlotSquaredGit
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class PlotRateEvent extends PlotEvent {
|
public class PlotRateEvent extends PlotEvent {
|
||||||
|
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final PlotPlayer rater;
|
private final PlotPlayer rater;
|
||||||
private Rating rating;
|
private Rating rating;
|
||||||
|
|
||||||
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
|
public PlotRateEvent(PlotPlayer rater, Rating rating, Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.rater = rater;
|
this.rater = rater;
|
||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotPlayer getRater() {
|
public PlotPlayer getRater() {
|
||||||
return rater;
|
return this.rater;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRating(final Rating rating) {
|
public Rating getRating() {
|
||||||
|
return this.rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRating(Rating rating) {
|
||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rating getRating() {
|
|
||||||
return rating;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,70 +20,71 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import java.util.ArrayList;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
|
/**
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
*/
|
||||||
public class PlotUnlinkEvent extends Event implements Cancellable {
|
public class PlotUnlinkEvent extends Event implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final ArrayList<PlotId> plots;
|
private final ArrayList<PlotId> plots;
|
||||||
private final World world;
|
private final World world;
|
||||||
private boolean cancelled;
|
|
||||||
private final PlotArea area;
|
private final PlotArea area;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a mega-plot is unlinked.
|
* Called when a mega-plot is unlinked.
|
||||||
*
|
*
|
||||||
* @param world World in which the event occurred
|
* @param world World in which the event occurred
|
||||||
* @param plots Plots that are involved in the event
|
* @param plots Plots that are involved in the event
|
||||||
*/
|
*/
|
||||||
public PlotUnlinkEvent(final World world, PlotArea area, final ArrayList<PlotId> plots) {
|
public PlotUnlinkEvent(World world, PlotArea area, ArrayList<PlotId> plots) {
|
||||||
this.plots = plots;
|
this.plots = plots;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.area = area;
|
this.area = area;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plots involved
|
* Get the plots involved
|
||||||
*
|
*
|
||||||
* @return PlotId
|
* @return PlotId
|
||||||
*/
|
*/
|
||||||
public ArrayList<PlotId> getPlots() {
|
public ArrayList<PlotId> getPlots() {
|
||||||
return plots;
|
return this.plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return this.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotArea getArea() {
|
public PlotArea getArea() {
|
||||||
return area;
|
return this.area;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(boolean b) {
|
||||||
cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ import java.util.Random;
|
|||||||
public class BukkitAugmentedGenerator extends BlockPopulator {
|
public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||||
|
|
||||||
private static BukkitAugmentedGenerator generator;
|
private static BukkitAugmentedGenerator generator;
|
||||||
|
|
||||||
private BukkitAugmentedGenerator() {}
|
|
||||||
|
|
||||||
public static BukkitAugmentedGenerator get(World world) {
|
public static BukkitAugmentedGenerator get(World world) {
|
||||||
for (BlockPopulator populator : world.getPopulators()) {
|
for (BlockPopulator populator : world.getPopulators()) {
|
||||||
@ -27,7 +25,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void populate(final World world, Random r, final Chunk chunk) {
|
public void populate(World world, Random r, Chunk chunk) {
|
||||||
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
||||||
this.plotGenerator = generator;
|
this.plotGenerator = generator;
|
||||||
this.platformGenerator = this;
|
this.platformGenerator = this;
|
||||||
populators.add(new BlockPopulator() {
|
this.populators.add(new BlockPopulator() {
|
||||||
@Override
|
@Override
|
||||||
public void populate(World world, Random r, Chunk c) {
|
public void populate(World world, Random r, Chunk c) {
|
||||||
GenChunk result = (GenChunk) chunkSetter;
|
GenChunk result = (GenChunk) BukkitPlotGenerator.this.chunkSetter;
|
||||||
if (result.result_data != null) {
|
if (result.result_data != null) {
|
||||||
for (int i = 0; i < result.result_data.length; i++) {
|
for (int i = 0; i < result.result_data.length; i++) {
|
||||||
byte[] section = result.result_data[i];
|
byte[] section = result.result_data[i];
|
||||||
@ -79,7 +79,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
chunkSetter = new GenChunk(null, null);
|
this.chunkSetter = new GenChunk(null, null);
|
||||||
this.full = true;
|
this.full = true;
|
||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
@ -90,8 +90,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
this.full = false;
|
this.full = false;
|
||||||
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
||||||
platformGenerator = cg;
|
this.platformGenerator = cg;
|
||||||
plotGenerator = new IndependentPlotGenerator() {
|
this.plotGenerator = new IndependentPlotGenerator() {
|
||||||
@Override
|
@Override
|
||||||
public void processSetup(SetupObject setup) {}
|
public void processSetup(SetupObject setup) {}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(final PlotChunk<?> result, final PlotArea settings, final PseudoRandom random) {
|
public void generateChunk(final PlotChunk<?> result, PlotArea settings, PseudoRandom random) {
|
||||||
World w = BukkitUtil.getWorld(world);
|
World w = BukkitUtil.getWorld(world);
|
||||||
Random r = new Random(result.getChunkWrapper().hashCode());
|
Random r = new Random(result.getChunkWrapper().hashCode());
|
||||||
BiomeGrid grid = new BiomeGrid() {
|
BiomeGrid grid = new BiomeGrid() {
|
||||||
@ -134,8 +134,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
//ignored
|
||||||
}
|
}
|
||||||
catch (Throwable e) {}
|
|
||||||
// Populator spillage
|
// Populator spillage
|
||||||
short[][] tmp = cg.generateExtBlockSections(w, r, result.getX(), result.getZ(), grid);
|
short[][] tmp = cg.generateExtBlockSections(w, r, result.getX(), result.getZ(), grid);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
@ -166,9 +167,9 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
chunkSetter = new GenChunk(null, SetQueue.IMP.new ChunkWrapper(world, 0, 0));
|
this.chunkSetter = new GenChunk(null, SetQueue.IMP.new ChunkWrapper(world, 0, 0));
|
||||||
if (cg != null) {
|
if (cg != null) {
|
||||||
populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world)));
|
this.populators.addAll(cg.getDefaultPopulators(BukkitUtil.getWorld(world)));
|
||||||
}
|
}
|
||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
@ -180,24 +181,24 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFull() {
|
public boolean isFull() {
|
||||||
return full;
|
return this.full;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndependentPlotGenerator getPlotGenerator() {
|
public IndependentPlotGenerator getPlotGenerator() {
|
||||||
return plotGenerator;
|
return this.plotGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkGenerator getPlatformGenerator() {
|
public ChunkGenerator getPlatformGenerator() {
|
||||||
return platformGenerator;
|
return this.platformGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
try {
|
try {
|
||||||
if (!loaded) {
|
if (!this.loaded) {
|
||||||
final String name = world.getName();
|
String name = world.getName();
|
||||||
PS.get().loadWorld(name, this);
|
PS.get().loadWorld(name, this);
|
||||||
Set<PlotArea> areas = PS.get().getPlotAreas(name);
|
Set<PlotArea> areas = PS.get().getPlotAreas(name);
|
||||||
if (!areas.isEmpty()) {
|
if (!areas.isEmpty()) {
|
||||||
@ -218,17 +219,17 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
world.setWaterAnimalSpawnLimit(-1);
|
world.setWaterAnimalSpawnLimit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return populators;
|
return this.populators;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
|
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
|
||||||
GenChunk result = (GenChunk) chunkSetter;
|
GenChunk result = (GenChunk) this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
||||||
// Set the result data
|
// Set the result data
|
||||||
@ -239,8 +240,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
// Catch any exceptions (as exceptions usually thrown
|
// Catch any exceptions (as exceptions usually thrown
|
||||||
try {
|
try {
|
||||||
// Fill the result data if necessary
|
// Fill the result data if necessary
|
||||||
if (platformGenerator != this) {
|
if (this.platformGenerator != this) {
|
||||||
return platformGenerator.generateChunkData(world, random, cx, cz, grid);
|
return this.platformGenerator.generateChunkData(world, random, cx, cz, grid);
|
||||||
} else {
|
} else {
|
||||||
generate(world, cx, cz, result);
|
generate(world, cx, cz, result);
|
||||||
}
|
}
|
||||||
@ -253,10 +254,10 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
public void generate(World world, int cx, int cz, GenChunk result) {
|
public void generate(World world, int cx, int cz, GenChunk result) {
|
||||||
// Load if improperly loaded
|
// Load if improperly loaded
|
||||||
if (!loaded) {
|
if (!this.loaded) {
|
||||||
final String name = world.getName();
|
String name = world.getName();
|
||||||
PS.get().loadWorld(name, this);
|
PS.get().loadWorld(name, this);
|
||||||
loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
// Set random seed
|
// Set random seed
|
||||||
this.random.state = cx << 16 | cz & 0xFFFF;
|
this.random.state = cx << 16 | cz & 0xFFFF;
|
||||||
@ -265,13 +266,13 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
||||||
plotGenerator.generateChunk(chunkSetter, area, this.random);
|
this.plotGenerator.generateChunk(this.chunkSetter, area, this.random);
|
||||||
ChunkManager.postProcessChunk(result);
|
ChunkManager.postProcessChunk(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid grid) {
|
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid grid) {
|
||||||
GenChunk result = (GenChunk) chunkSetter;
|
GenChunk result = (GenChunk) this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
result.setChunkWrapper(SetQueue.IMP.new ChunkWrapper(world.getName(), cx, cz));
|
||||||
// Set the result data
|
// Set the result data
|
||||||
@ -282,8 +283,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
// Catch any exceptions (as exceptions usually thrown
|
// Catch any exceptions (as exceptions usually thrown
|
||||||
try {
|
try {
|
||||||
// Fill the result data
|
// Fill the result data
|
||||||
if (platformGenerator != this) {
|
if (this.platformGenerator != this) {
|
||||||
return platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
|
return this.platformGenerator.generateExtBlockSections(world, r, cx, cz, grid);
|
||||||
} else {
|
} else {
|
||||||
generate(world, cx, cz, result);
|
generate(world, cx, cz, result);
|
||||||
}
|
}
|
||||||
@ -295,19 +296,27 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow spawning everywhere
|
* Allow spawning everywhere.
|
||||||
|
* @param world Ignored
|
||||||
|
* @param x Ignored
|
||||||
|
* @param z Ignored
|
||||||
|
* @return always true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean canSpawn(final World world, final int x, final int z) {
|
public boolean canSpawn(World world, int x, int z) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (platformGenerator == this) {
|
if (this.platformGenerator == this) {
|
||||||
return "" + plotGenerator;
|
return "" + this.plotGenerator;
|
||||||
|
}
|
||||||
|
if (this.platformGenerator == null) {
|
||||||
|
return "null";
|
||||||
|
} else {
|
||||||
|
return this.platformGenerator.getClass().getName();
|
||||||
}
|
}
|
||||||
return platformGenerator == null ? "null" : platformGenerator.getClass().getName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
@ -33,13 +35,9 @@ import java.util.ArrayDeque;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
public class ChunkListener implements Listener {
|
public class ChunkListener implements Listener {
|
||||||
|
|
||||||
private RefMethod methodGetHandleChunk;
|
private RefMethod methodGetHandleChunk;
|
||||||
private RefClass classChunk;
|
|
||||||
private RefClass classCraftChunk;
|
|
||||||
private RefField mustSave;
|
private RefField mustSave;
|
||||||
private Chunk lastChunk;
|
private Chunk lastChunk;
|
||||||
|
|
||||||
@ -47,8 +45,8 @@ public class ChunkListener implements Listener {
|
|||||||
public ChunkListener() {
|
public ChunkListener() {
|
||||||
if (Settings.CHUNK_PROCESSOR_GC || Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE) {
|
if (Settings.CHUNK_PROCESSOR_GC || Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE) {
|
||||||
try {
|
try {
|
||||||
this.classChunk = getRefClass("{nms}.Chunk");
|
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
this.classCraftChunk = getRefClass("{cb}.CraftChunk");
|
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
this.mustSave = classChunk.getField("mustSave");
|
this.mustSave = classChunk.getField("mustSave");
|
||||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -63,12 +61,12 @@ public class ChunkListener implements Listener {
|
|||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final int distance = Bukkit.getViewDistance() + 2;
|
int distance = Bukkit.getViewDistance() + 2;
|
||||||
final HashMap<String, HashMap<ChunkLoc, Integer>> players = new HashMap<>();
|
HashMap<String, HashMap<ChunkLoc, Integer>> players = new HashMap<>();
|
||||||
for (final Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||||
final PlotPlayer pp = entry.getValue();
|
PlotPlayer pp = entry.getValue();
|
||||||
final Location loc = pp.getLocation();
|
Location location = pp.getLocation();
|
||||||
final String world = loc.getWorld();
|
String world = location.getWorld();
|
||||||
if (!PS.get().hasPlotArea(world)) {
|
if (!PS.get().hasPlotArea(world)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -77,7 +75,7 @@ public class ChunkListener implements Listener {
|
|||||||
map = new HashMap<>();
|
map = new HashMap<>();
|
||||||
players.put(world, map);
|
players.put(world, map);
|
||||||
}
|
}
|
||||||
final ChunkLoc origin = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
ChunkLoc origin = new ChunkLoc(location.getX() >> 4, location.getZ() >> 4);
|
||||||
Integer val = map.get(origin);
|
Integer val = map.get(origin);
|
||||||
int check;
|
int check;
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
@ -97,8 +95,8 @@ public class ChunkListener implements Listener {
|
|||||||
if (z >= check || -z >= check) {
|
if (z >= check || -z >= check) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int weight = distance - Math.max(Math.abs(x), Math.abs(z));
|
int weight = distance - Math.max(Math.abs(x), Math.abs(z));
|
||||||
final ChunkLoc chunk = new ChunkLoc(x + origin.x, z + origin.z);
|
ChunkLoc chunk = new ChunkLoc(x + origin.x, z + origin.z);
|
||||||
val = map.get(chunk);
|
val = map.get(chunk);
|
||||||
if (val == null || val < weight) {
|
if (val == null || val < weight) {
|
||||||
map.put(chunk, weight);
|
map.put(chunk, weight);
|
||||||
@ -108,24 +106,24 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int time = 300;
|
int time = 300;
|
||||||
for (final World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
final String name = world.getName();
|
String name = world.getName();
|
||||||
if (!PS.get().hasPlotArea(name)) {
|
if (!PS.get().hasPlotArea(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final boolean autosave = world.isAutoSave();
|
boolean autosave = world.isAutoSave();
|
||||||
if (autosave) {
|
if (autosave) {
|
||||||
world.setAutoSave(false);
|
world.setAutoSave(false);
|
||||||
}
|
}
|
||||||
final HashMap<ChunkLoc, Integer> map = players.get(name);
|
HashMap<ChunkLoc, Integer> map = players.get(name);
|
||||||
if (map == null || map.isEmpty()) {
|
if (map == null || map.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Chunk[] chunks = world.getLoadedChunks();
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
ArrayDeque<Chunk> toUnload = new ArrayDeque<>();
|
ArrayDeque<Chunk> toUnload = new ArrayDeque<>();
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
final int x = chunk.getX();
|
int x = chunk.getX();
|
||||||
final int z = chunk.getZ();
|
int z = chunk.getZ();
|
||||||
if (!map.containsKey(new ChunkLoc(x, z))) {
|
if (!map.containsKey(new ChunkLoc(x, z))) {
|
||||||
toUnload.add(chunk);
|
toUnload.add(chunk);
|
||||||
}
|
}
|
||||||
@ -152,14 +150,14 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean unloadChunk(final String world, final Chunk chunk) {
|
public boolean unloadChunk(String world, Chunk chunk) {
|
||||||
final int X = chunk.getX();
|
int X = chunk.getX();
|
||||||
final int Z = chunk.getZ();
|
int Z = chunk.getZ();
|
||||||
final int x = X << 4;
|
int x = X << 4;
|
||||||
final int z = Z << 4;
|
int z = Z << 4;
|
||||||
final int x2 = x + 15;
|
int x2 = x + 15;
|
||||||
final int z2 = z + 15;
|
int z2 = z + 15;
|
||||||
Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
|
Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
|
||||||
if (plot != null && plot.hasOwner()) {
|
if (plot != null && plot.hasOwner()) {
|
||||||
return false;
|
return false;
|
||||||
@ -180,8 +178,8 @@ public class ChunkListener implements Listener {
|
|||||||
if (plot != null && plot.hasOwner()) {
|
if (plot != null && plot.hasOwner()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||||
mustSave.of(c).set(false);
|
this.mustSave.of(c).set(false);
|
||||||
if (chunk.isLoaded()) {
|
if (chunk.isLoaded()) {
|
||||||
chunk.unload(false, false);
|
chunk.unload(false, false);
|
||||||
}
|
}
|
||||||
@ -189,10 +187,10 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkUnload(final ChunkUnloadEvent event) {
|
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
if (Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE) {
|
if (Settings.CHUNK_PROCESSOR_TRIM_ON_SAVE) {
|
||||||
final Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
final String world = chunk.getWorld().getName();
|
String world = chunk.getWorld().getName();
|
||||||
if (PS.get().hasPlotArea(world)) {
|
if (PS.get().hasPlotArea(world)) {
|
||||||
if (unloadChunk(world, chunk)) {
|
if (unloadChunk(world, chunk)) {
|
||||||
return;
|
return;
|
||||||
@ -205,15 +203,15 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkLoad(final ChunkLoadEvent event) {
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
processChunk(event.getChunk(), false);
|
processChunk(event.getChunk(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onItemSpawn(final ItemSpawnEvent event) {
|
public void onItemSpawn(ItemSpawnEvent event) {
|
||||||
final Item entity = event.getEntity();
|
Item entity = event.getEntity();
|
||||||
final Chunk chunk = entity.getLocation().getChunk();
|
Chunk chunk = entity.getLocation().getChunk();
|
||||||
if (chunk == lastChunk) {
|
if (chunk == this.lastChunk) {
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -221,28 +219,28 @@ public class ChunkListener implements Listener {
|
|||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
lastChunk = chunk;
|
this.lastChunk = chunk;
|
||||||
} else {
|
} else {
|
||||||
lastChunk = null;
|
this.lastChunk = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBlockPhysics(final BlockPhysicsEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
if (Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS) {
|
if (Settings.CHUNK_PROCESSOR_DISABLE_PHYSICS) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onEntitySpawn(final CreatureSpawnEvent event) {
|
public void onEntitySpawn(CreatureSpawnEvent event) {
|
||||||
final LivingEntity entity = event.getEntity();
|
LivingEntity entity = event.getEntity();
|
||||||
final Chunk chunk = entity.getLocation().getChunk();
|
Chunk chunk = entity.getLocation().getChunk();
|
||||||
if (chunk == lastChunk) {
|
if (chunk == this.lastChunk) {
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
@ -250,20 +248,20 @@ public class ChunkListener implements Listener {
|
|||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||||
event.getEntity().remove();
|
event.getEntity().remove();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
lastChunk = chunk;
|
this.lastChunk = chunk;
|
||||||
} else {
|
} else {
|
||||||
lastChunk = null;
|
this.lastChunk = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cleanChunk(final Chunk chunk) {
|
public void cleanChunk(final Chunk chunk) {
|
||||||
TaskManager.index.incrementAndGet();
|
TaskManager.index.incrementAndGet();
|
||||||
final Integer currentIndex = TaskManager.index.get();
|
final Integer currentIndex = TaskManager.index.get();
|
||||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
@ -273,7 +271,7 @@ public class ChunkListener implements Listener {
|
|||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BlockState[] tiles = chunk.getTileEntities();
|
BlockState[] tiles = chunk.getTileEntities();
|
||||||
if (tiles.length == 0) {
|
if (tiles.length == 0) {
|
||||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||||
TaskManager.tasks.remove(currentIndex);
|
TaskManager.tasks.remove(currentIndex);
|
||||||
@ -281,7 +279,7 @@ public class ChunkListener implements Listener {
|
|||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (System.currentTimeMillis() - start < 250) {
|
while (System.currentTimeMillis() - start < 250) {
|
||||||
if (i >= tiles.length) {
|
if (i >= tiles.length) {
|
||||||
@ -298,15 +296,15 @@ public class ChunkListener implements Listener {
|
|||||||
}, 5);
|
}, 5);
|
||||||
TaskManager.tasks.put(currentIndex, task);
|
TaskManager.tasks.put(currentIndex, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean processChunk(final Chunk chunk, final boolean unload) {
|
public boolean processChunk(Chunk chunk, boolean unload) {
|
||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
final BlockState[] tiles = chunk.getTileEntities();
|
BlockState[] tiles = chunk.getTileEntities();
|
||||||
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||||
for (final Entity ent : entities) {
|
for (Entity ent : entities) {
|
||||||
if (!(ent instanceof Player)) {
|
if (!(ent instanceof Player)) {
|
||||||
ent.remove();
|
ent.remove();
|
||||||
}
|
}
|
||||||
@ -319,7 +317,7 @@ public class ChunkListener implements Listener {
|
|||||||
cleanChunk(chunk);
|
cleanChunk(chunk);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (final BlockState tile : tiles) {
|
for (BlockState tile : tiles) {
|
||||||
tile.getBlock().setType(Material.AIR, false);
|
tile.getBlock().setType(Material.AIR, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,12 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
*/
|
|
||||||
public class ForceFieldListener implements Listener {
|
public class ForceFieldListener implements Listener {
|
||||||
private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) {
|
|
||||||
final Set<PlotPlayer> players = new HashSet<>();
|
private Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||||
PlotPlayer pp;
|
Set<PlotPlayer> players = new HashSet<>();
|
||||||
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
||||||
|
PlotPlayer pp;
|
||||||
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -54,10 +52,10 @@ public class ForceFieldListener implements Listener {
|
|||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlotPlayer hasNearbyPermitted(final Player player, final Plot plot) {
|
private PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
||||||
PlotPlayer pp;
|
for (Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
||||||
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
|
PlotPlayer pp;
|
||||||
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -67,12 +65,16 @@ public class ForceFieldListener implements Listener {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector calculateVelocity(final PlotPlayer pp, final PlotPlayer e) {
|
public Vector calculateVelocity(PlotPlayer pp, PlotPlayer e) {
|
||||||
Location playerLocation = pp.getLocationFull();
|
Location playerLocation = pp.getLocationFull();
|
||||||
Location oPlayerLocation = e.getLocation();
|
Location oPlayerLocation = e.getLocation();
|
||||||
final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation
|
double playerX = playerLocation.getX();
|
||||||
.getZ();
|
double playerY = playerLocation.getY();
|
||||||
|
double playerZ = playerLocation.getZ();
|
||||||
|
double oPlayerX = oPlayerLocation.getX();
|
||||||
|
double oPlayerY = oPlayerLocation.getY();
|
||||||
|
double oPlayerZ = oPlayerLocation.getZ();
|
||||||
double x = 0d;
|
double x = 0d;
|
||||||
if (playerX < oPlayerX) {
|
if (playerX < oPlayerX) {
|
||||||
x = 1.0d;
|
x = 1.0d;
|
||||||
@ -93,25 +95,25 @@ public class ForceFieldListener implements Listener {
|
|||||||
}
|
}
|
||||||
return new Vector(x, y, z);
|
return new Vector(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlotEntry(final PlayerEnterPlotEvent event) {
|
public void onPlotEntry(PlayerEnterPlotEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
final Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) {
|
if ((FlagManager.getPlotFlagRaw(plot, "forcefield") != null) && FlagManager.getPlotFlagRaw(plot, "forcefield").getValue().equals("true")) {
|
||||||
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) {
|
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) {
|
||||||
final UUID uuid = pp.getUUID();
|
UUID uuid = pp.getUUID();
|
||||||
if (plot.isAdded(uuid)) {
|
if (plot.isAdded(uuid)) {
|
||||||
final Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||||
for (final PlotPlayer oPlayer : players) {
|
for (PlotPlayer oPlayer : players) {
|
||||||
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer));
|
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
|
PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
|
||||||
if (oPlayer == null) {
|
if (oPlayer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,18 +14,18 @@ import org.bukkit.event.block.BlockExplodeEvent;
|
|||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class PlayerEvents_1_8_3 implements Listener {
|
public class PlayerEvents183 implements Listener {
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onBigBoom(final BlockExplodeEvent event) {
|
public void onBigBoom(BlockExplodeEvent event) {
|
||||||
final Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
Location loc = BukkitUtil.getLocation(block.getLocation());
|
Location loc = BukkitUtil.getLocation(block.getLocation());
|
||||||
final String world = loc.getWorld();
|
String world = loc.getWorld();
|
||||||
if (!PS.get().hasPlotArea(world)) {
|
if (!PS.get().hasPlotArea(world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlotArea area = loc.getPlotArea();
|
PlotArea area = loc.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
final Iterator<Block> iter = event.blockList().iterator();
|
Iterator<Block> iter = event.blockList().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
loc = BukkitUtil.getLocation(iter.next().getLocation());
|
loc = BukkitUtil.getLocation(iter.next().getLocation());
|
||||||
if (loc.getPlotArea() != null) {
|
if (loc.getPlotArea() != null) {
|
||||||
@ -38,9 +38,9 @@ public class PlayerEvents_1_8_3 implements Listener {
|
|||||||
if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) {
|
if (plot == null || !FlagManager.isPlotFlagTrue(plot, "explosion")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
final Iterator<Block> iter = event.blockList().iterator();
|
Iterator<Block> iter = event.blockList().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
final Block b = iter.next();
|
Block b = iter.next();
|
||||||
if (!plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation())))) {
|
if (!plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation())))) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
@ -1,9 +1,15 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import java.util.List;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.plotsquared.listener.PlotListener;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
@ -20,48 +26,41 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import java.util.HashSet;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import java.util.List;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import java.util.UUID;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import com.plotsquared.listener.PlotListener;
|
|
||||||
|
|
||||||
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onInventoryClick(final InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event.isShiftClick()) {
|
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event.isShiftClick()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HumanEntity entity = event.getWhoClicked();
|
HumanEntity entity = event.getWhoClicked();
|
||||||
if (!(entity instanceof Player) || !PS.get().hasPlotArea(entity.getWorld().getName())) {
|
if (!(entity instanceof Player) || !PS.get().hasPlotArea(entity.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
final PlayerInventory inv = player.getInventory();
|
PlayerInventory inv = player.getInventory();
|
||||||
final int slot = inv.getHeldItemSlot();
|
int slot = inv.getHeldItemSlot();
|
||||||
if ((slot != event.getSlot()) || (slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
|
if ((slot != event.getSlot()) || (slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ItemStack current = inv.getItemInHand();
|
ItemStack current = inv.getItemInHand();
|
||||||
final ItemStack newItem = event.getCursor();
|
ItemStack newItem = event.getCursor();
|
||||||
final ItemMeta newMeta = newItem.getItemMeta();
|
ItemMeta newMeta = newItem.getItemMeta();
|
||||||
final ItemMeta oldMeta = newItem.getItemMeta();
|
ItemMeta oldMeta = newItem.getItemMeta();
|
||||||
String newLore = "";
|
String newLore = "";
|
||||||
if (newMeta != null) {
|
if (newMeta != null) {
|
||||||
final List<String> lore = newMeta.getLore();
|
List<String> lore = newMeta.getLore();
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
newLore = lore.toString();
|
newLore = lore.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String oldLore = "";
|
String oldLore = "";
|
||||||
if (oldMeta != null) {
|
if (oldMeta != null) {
|
||||||
final List<String> lore = oldMeta.getLore();
|
List<String> lore = oldMeta.getLore();
|
||||||
if (lore != null) {
|
if (lore != null) {
|
||||||
oldLore = lore.toString();
|
oldLore = lore.toString();
|
||||||
}
|
}
|
||||||
@ -69,86 +68,82 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
|||||||
if (!newLore.equals("[(+NBT)]") || (current.equals(newItem) && newLore.equals(oldLore))) {
|
if (!newLore.equals("[(+NBT)]") || (current.equals(newItem) && newLore.equals(oldLore))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final HashSet<Byte> blocks = null;
|
HashSet<Byte> blocks = null;
|
||||||
final Block block = player.getTargetBlock(blocks, 7);
|
Block block = player.getTargetBlock(blocks, 7);
|
||||||
final BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state.getType() != newItem.getType()) {
|
if (state.getType() != newItem.getType()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location l = BukkitUtil.getLocation(state.getLocation());
|
Location l = BukkitUtil.getLocation(state.getLocation());
|
||||||
PlotArea area = l.getPlotArea();
|
PlotArea area = l.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = area.getPlotAbs(l);
|
Plot plot = area.getPlotAbs(l);
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
} else if (!plot.hasOwner()) {
|
||||||
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||||
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
||||||
|
cancelled = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!plot.hasOwner()) {
|
UUID uuid = pp.getUUID();
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
if (!plot.isAdded(uuid)) {
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
||||||
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
final UUID uuid = pp.getUUID();
|
|
||||||
if (!plot.isAdded(uuid)) {
|
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
|
||||||
cancelled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
if ((current.getTypeId() == newItem.getTypeId()) && (current.getDurability() == newItem.getDurability())) {
|
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem.getDurability())) {
|
||||||
event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability()));
|
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setCursor(new ItemStack(newItem.getTypeId(), newItem.getAmount(), newItem.getDurability()));
|
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onInteract(final PlayerInteractAtEntityEvent e) {
|
public void onInteract(PlayerInteractAtEntityEvent e) {
|
||||||
final Entity entity = e.getRightClicked();
|
Entity entity = e.getRightClicked();
|
||||||
if (!(entity instanceof ArmorStand)) {
|
if (!(entity instanceof ArmorStand)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
||||||
final PlotArea area = l.getPlotArea();
|
PlotArea area = l.getPlotArea();
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = area.getPlotAbs(l);
|
Plot plot = area.getPlotAbs(l);
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
} else if (!plot.hasOwner()) {
|
||||||
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
||||||
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!plot.hasOwner()) {
|
UUID uuid = pp.getUUID();
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
|
if (!plot.isAdded(uuid)) {
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
|
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
||||||
|
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
final UUID uuid = pp.getUUID();
|
|
||||||
if (!plot.isAdded(uuid)) {
|
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,40 +45,33 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created 2014-10-30 for PlotSquared
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class PlotPlusListener extends PlotListener implements Listener {
|
public class PlotPlusListener extends PlotListener implements Listener {
|
||||||
private final static HashMap<String, Interval> feedRunnable = new HashMap<>();
|
|
||||||
private final static HashMap<String, Interval> healRunnable = new HashMap<>();
|
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
|
||||||
|
private static final HashMap<String, Interval> healRunnable = new HashMap<>();
|
||||||
public static void startRunnable(final JavaPlugin plugin) {
|
|
||||||
|
public static void startRunnable(JavaPlugin plugin) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!healRunnable.isEmpty()) {
|
if (!healRunnable.isEmpty()) {
|
||||||
for (final Iterator<Entry<String, Interval>> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
|
for (Iterator<Entry<String, Interval>> iter = healRunnable.entrySet().iterator(); iter.hasNext(); ) {
|
||||||
final Entry<String, Interval> entry = iter.next();
|
Entry<String, Interval> entry = iter.next();
|
||||||
final Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
Player player = Bukkit.getPlayer(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final double level = player.getHealth();
|
double level = player.getHealth();
|
||||||
if (level != value.max) {
|
if (level != value.max) {
|
||||||
player.setHealth(Math.min(level + value.amount, value.max));
|
player.setHealth(Math.min(level + value.amount, value.max));
|
||||||
}
|
}
|
||||||
@ -86,18 +79,18 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!feedRunnable.isEmpty()) {
|
if (!feedRunnable.isEmpty()) {
|
||||||
for (final Iterator<Entry<String, Interval>> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
|
for (Iterator<Entry<String, Interval>> iter = feedRunnable.entrySet().iterator(); iter.hasNext(); ) {
|
||||||
final Entry<String, Interval> entry = iter.next();
|
Entry<String, Interval> entry = iter.next();
|
||||||
final Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
Player player = Bukkit.getPlayer(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int level = player.getFoodLevel();
|
int level = player.getFoodLevel();
|
||||||
if (level != value.max) {
|
if (level != value.max) {
|
||||||
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
||||||
}
|
}
|
||||||
@ -105,17 +98,17 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0l, 20l);
|
}, 0L, 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onMelt(final BlockFadeEvent event) {
|
public void onMelt(BlockFadeEvent event) {
|
||||||
final BlockState state = event.getNewState();
|
BlockState state = event.getNewState();
|
||||||
|
|
||||||
if (state.getType() != Material.WATER && state.getType() != Material.STATIONARY_WATER) {
|
if (state.getType() != Material.WATER && state.getType() != Material.STATIONARY_WATER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = BukkitUtil.getLocation(state.getLocation()).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(state.getLocation()).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,12 +121,12 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onInteract(final BlockDamageEvent event) {
|
public void onInteract(BlockDamageEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,12 +136,12 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onDamage(final EntityDamageEvent event) {
|
public void onDamage(EntityDamageEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = (Player) event.getEntity();
|
Player player = (Player) event.getEntity();
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,115 +151,82 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemPickup(final PlayerPickupItemEvent event) {
|
public void onItemPickup(PlayerPickupItemEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final UUID uuid = pp.getUUID();
|
UUID uuid = pp.getUUID();
|
||||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
|
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemDrop(final PlayerDropItemEvent event) {
|
public void onItemDrop(PlayerDropItemEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final UUID uuid = pp.getUUID();
|
UUID uuid = pp.getUUID();
|
||||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
|
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlotEnter(final PlayerEnterPlotEvent event) {
|
public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
final Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
||||||
if (feed != null) {
|
if (feed != null) {
|
||||||
final Integer[] value = (Integer[]) feed.getValue();
|
Integer[] value = (Integer[]) feed.getValue();
|
||||||
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
||||||
if (heal != null) {
|
if (heal != null) {
|
||||||
final Integer[] value = (Integer[]) heal.getValue();
|
Integer[] value = (Integer[]) heal.getValue();
|
||||||
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
final Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
final String name = player.getName();
|
String name = player.getName();
|
||||||
feedRunnable.remove(name);
|
feedRunnable.remove(name);
|
||||||
healRunnable.remove(name);
|
healRunnable.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlotLeave(final PlayerLeavePlotEvent event) {
|
public void onPlotLeave(PlayerLeavePlotEvent event) {
|
||||||
final Player leaver = event.getPlayer();
|
Player leaver = event.getPlayer();
|
||||||
final Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BukkitUtil.getPlayer(leaver);
|
BukkitUtil.getPlayer(leaver);
|
||||||
final String name = leaver.getName();
|
String name = leaver.getName();
|
||||||
feedRunnable.remove(name);
|
feedRunnable.remove(name);
|
||||||
healRunnable.remove(name);
|
healRunnable.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Interval {
|
private static class Interval {
|
||||||
public final int interval;
|
|
||||||
public final int amount;
|
final int interval;
|
||||||
public final int max;
|
final int amount;
|
||||||
|
final int max;
|
||||||
public int count = 0;
|
public int count = 0;
|
||||||
|
|
||||||
public Interval(final int interval, final int amount, final int max) {
|
Interval(int interval, int amount, int max) {
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Meta Class
|
|
||||||
*
|
|
||||||
|
|
||||||
*/
|
|
||||||
public static class RecordMeta {
|
|
||||||
public final static List<RecordMeta> metaList = new ArrayList<>();
|
|
||||||
static {
|
|
||||||
for (int x = 3; x < 12; x++) {
|
|
||||||
metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private final String name;
|
|
||||||
private final Material material;
|
|
||||||
|
|
||||||
public RecordMeta(final String name, final Material material) {
|
|
||||||
this.name = name;
|
|
||||||
this.material = material;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return name.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PS;
|
||||||
|
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
||||||
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -7,17 +10,13 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.world.WorldInitEvent;
|
import org.bukkit.event.world.WorldInitEvent;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
|
||||||
|
|
||||||
public class WorldEvents implements Listener {
|
public class WorldEvents implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onWorldInit(final WorldInitEvent event) {
|
public void onWorldInit(WorldInitEvent event) {
|
||||||
final World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
final String name = world.getName();
|
String name = world.getName();
|
||||||
final ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen instanceof GeneratorWrapper) {
|
if (gen instanceof GeneratorWrapper) {
|
||||||
PS.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
PS.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,19 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.listeners.worldedit;
|
package com.plotsquared.bukkit.listeners.worldedit;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
@ -29,6 +15,18 @@ import com.plotsquared.listener.WEManager;
|
|||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.bukkit.selections.Selection;
|
import com.sk89q.worldedit.bukkit.selections.Selection;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class WEListener implements Listener {
|
public class WEListener implements Listener {
|
||||||
|
|
||||||
@ -43,21 +41,10 @@ public class WEListener implements Listener {
|
|||||||
public final HashSet<String> region = new HashSet<>(Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr",
|
public final HashSet<String> region = new HashSet<>(Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr",
|
||||||
"regen", "copy", "cut", "green", "setbiome"));
|
"regen", "copy", "cut", "green", "setbiome"));
|
||||||
public final HashSet<String> regionExtend = new HashSet<>(Collections.singletonList("stack"));
|
public final HashSet<String> regionExtend = new HashSet<>(Collections.singletonList("stack"));
|
||||||
public final HashSet<String> unregioned = new HashSet<>(Arrays.asList("paste", "redo", "undo", "rotate", "flip", "generate", "schematic", "schem"));
|
|
||||||
public final HashSet<String> unsafe1 = new HashSet<>(Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks"));
|
|
||||||
public final HashSet<String> restricted = new HashSet<>(Collections.singletonList("up"));
|
public final HashSet<String> restricted = new HashSet<>(Collections.singletonList("up"));
|
||||||
public final HashSet<String> other = new HashSet<>(Arrays.asList("undo", "redo"));
|
public final HashSet<String> other = new HashSet<>(Arrays.asList("undo", "redo"));
|
||||||
|
|
||||||
public boolean checkCommand(final List<String> list, final String cmd) {
|
public String reduceCmd(String cmd, boolean single) {
|
||||||
for (final String identifier : list) {
|
|
||||||
if (("/" + identifier).equals(cmd) || ("//" + identifier).equals(cmd) || ("/worldedit:/" + identifier).equals(cmd) || ("/worldedit:" + identifier).equals(cmd)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String reduceCmd(final String cmd, final boolean single) {
|
|
||||||
if (cmd.startsWith("/worldedit:/")) {
|
if (cmd.startsWith("/worldedit:/")) {
|
||||||
return cmd.substring(12);
|
return cmd.substring(12);
|
||||||
}
|
}
|
||||||
@ -72,24 +59,24 @@ public class WEListener implements Listener {
|
|||||||
}
|
}
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(final String s) {
|
public int getInt(String s) {
|
||||||
try {
|
try {
|
||||||
int max = 0;
|
int max = 0;
|
||||||
final String[] split = s.split(",");
|
String[] split = s.split(",");
|
||||||
for (final String rad : split) {
|
for (String rad : split) {
|
||||||
final int val = Integer.parseInt(rad);
|
int val = Integer.parseInt(rad);
|
||||||
if (val > max) {
|
if (val > max) {
|
||||||
max = val;
|
max = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max;
|
return max;
|
||||||
} catch (final NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkVolume(final PlotPlayer player, final long volume, final long max, final Cancellable e) {
|
public boolean checkVolume(PlotPlayer player, long volume, long max, Cancellable e) {
|
||||||
if (volume > max) {
|
if (volume > max) {
|
||||||
MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", volume + "").replaceAll("%max%", max + ""));
|
MainUtil.sendMessage(player, C.WORLDEDIT_VOLUME.s().replaceAll("%current%", volume + "").replaceAll("%max%", max + ""));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -99,16 +86,16 @@ public class WEListener implements Listener {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkSelection(final Player p, final PlotPlayer pp, final int modifier, final long max, final Cancellable e) {
|
public boolean checkSelection(Player p, PlotPlayer pp, int modifier, long max, Cancellable e) {
|
||||||
final Selection selection = BukkitMain.worldEdit.getSelection(p);
|
Selection selection = BukkitMain.worldEdit.getSelection(p);
|
||||||
if (selection == null) {
|
if (selection == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector();
|
BlockVector pos1 = selection.getNativeMinimumPoint().toBlockVector();
|
||||||
final BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector();
|
BlockVector pos2 = selection.getNativeMaximumPoint().toBlockVector();
|
||||||
final HashSet<RegionWrapper> mask = WEManager.getMask(pp);
|
HashSet<RegionWrapper> mask = WEManager.getMask(pp);
|
||||||
final RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
|
RegionWrapper region = new RegionWrapper(pos1.getBlockX(), pos2.getBlockX(), pos1.getBlockZ(), pos2.getBlockZ());
|
||||||
if (Settings.REQUIRE_SELECTION) {
|
if (Settings.REQUIRE_SELECTION) {
|
||||||
String arg = null;
|
String arg = null;
|
||||||
if (!WEManager.regionContains(region, mask)) {
|
if (!WEManager.regionContains(region, mask)) {
|
||||||
@ -135,15 +122,16 @@ public class WEListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final long volume = Math.abs((pos1.getBlockX() - pos2.getBlockX()) * (pos1.getBlockY() - pos2.getBlockY()) * (pos1.getBlockZ() - pos2.getBlockZ())) * modifier;
|
long volume = Math.abs((pos1.getBlockX() - pos2.getBlockX()) * (pos1.getBlockY() - pos2.getBlockY()) * (pos1.getBlockZ() - pos2.getBlockZ()))
|
||||||
|
* modifier;
|
||||||
return checkVolume(pp, volume, max, e);
|
return checkVolume(pp, volume, max, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean delay(final Player player, final String command, final boolean delayed) {
|
public boolean delay(final Player player, final String command, boolean delayed) {
|
||||||
if (!Settings.QUEUE_COMMANDS || !Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
if (!Settings.QUEUE_COMMANDS || !Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final boolean free = SetQueue.IMP.addTask(null);
|
boolean free = SetQueue.IMP.addTask(null);
|
||||||
if (free) {
|
if (free) {
|
||||||
if (delayed) {
|
if (delayed) {
|
||||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.WORLDEDIT_RUN, command);
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.WORLDEDIT_RUN, command);
|
||||||
@ -166,80 +154,80 @@ public class WEListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public boolean onPlayerCommand(final PlayerCommandPreprocessEvent e) {
|
public boolean onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||||
final WorldEditPlugin worldedit = BukkitMain.worldEdit;
|
WorldEditPlugin worldedit = BukkitMain.worldEdit;
|
||||||
if (worldedit == null) {
|
if (worldedit == null) {
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(p);
|
PlotPlayer pp = BukkitUtil.getPlayer(p);
|
||||||
if (!PS.get().hasPlotArea(p.getWorld().getName())) {
|
if (!PS.get().hasPlotArea(p.getWorld().getName())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final String message = e.getMessage();
|
String message = e.getMessage();
|
||||||
final String cmd = message.toLowerCase();
|
String cmd = message.toLowerCase();
|
||||||
final boolean single = true;
|
String[] split = cmd.split(" ");
|
||||||
final String[] split = cmd.split(" ");
|
|
||||||
|
long maxVolume = Settings.WE_MAX_VOLUME;
|
||||||
final long maxVolume = Settings.WE_MAX_VOLUME;
|
long maxIterations = Settings.WE_MAX_ITERATIONS;
|
||||||
final long maxIterations = Settings.WE_MAX_ITERATIONS;
|
|
||||||
if (pp.getAttribute("worldedit")) {
|
if (pp.getAttribute("worldedit")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
boolean single = true;
|
||||||
if (split.length >= 2) {
|
if (split.length >= 2) {
|
||||||
final String reduced = reduceCmd(split[0], single);
|
String reduced = reduceCmd(split[0], single);
|
||||||
final String reduced2 = reduceCmd(split[0] + " " + split[1], single);
|
String reduced2 = reduceCmd(split[0] + " " + split[1], single);
|
||||||
if (rad1.contains(reduced)) {
|
if (this.rad1.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final long volume = getInt(split[1]) * 256;
|
long volume = getInt(split[1]) * 256;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
if (rad2.contains(reduced)) {
|
if (this.rad2.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (split.length >= 3) {
|
if (split.length >= 3) {
|
||||||
final long volume = getInt(split[2]) * 256;
|
long volume = getInt(split[2]) * 256;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rad2_1.contains(reduced)) {
|
if (this.rad2_1.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (split.length >= 4) {
|
if (split.length >= 4) {
|
||||||
final long volume = getInt(split[2]) * getInt(split[3]);
|
long volume = getInt(split[2]) * getInt(split[3]);
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rad2_2.contains(reduced)) {
|
if (this.rad2_2.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (split.length >= 3) {
|
if (split.length >= 3) {
|
||||||
final long radius = getInt(split[2]);
|
long radius = getInt(split[2]);
|
||||||
final long volume = radius * radius;
|
long volume = radius * radius;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rad2_3.contains(reduced2)) {
|
if (this.rad2_3.contains(reduced2)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (split.length >= 3) {
|
if (split.length >= 3) {
|
||||||
if (split.length == 4) {
|
if (split.length == 4) {
|
||||||
final int iterations = getInt(split[3]);
|
int iterations = getInt(split[3]);
|
||||||
if (iterations > maxIterations) {
|
if (iterations > maxIterations) {
|
||||||
MainUtil.sendMessage(pp, C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", iterations + "").replaceAll("%max%", maxIterations + ""));
|
MainUtil.sendMessage(pp, C.WORLDEDIT_ITERATIONS.s().replaceAll("%current%", iterations + "").replaceAll("%max%", maxIterations + ""));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -249,13 +237,13 @@ public class WEListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final long radius = getInt(split[2]);
|
long radius = getInt(split[2]);
|
||||||
final long volume = radius * radius;
|
long volume = radius * radius;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rad3_1.contains(reduced2)) {
|
if (this.rad3_1.contains(reduced2)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
@ -265,13 +253,13 @@ public class WEListener implements Listener {
|
|||||||
if (split[i].equalsIgnoreCase("-h")) {
|
if (split[i].equalsIgnoreCase("-h")) {
|
||||||
i = 3;
|
i = 3;
|
||||||
}
|
}
|
||||||
final long radius = getInt(split[i]);
|
long radius = getInt(split[i]);
|
||||||
final long volume = radius * radius;
|
long volume = radius * radius;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rad3_2.contains(reduced2)) {
|
if (this.rad3_2.contains(reduced2)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
@ -281,13 +269,13 @@ public class WEListener implements Listener {
|
|||||||
if (split[i].equalsIgnoreCase("-h")) {
|
if (split[i].equalsIgnoreCase("-h")) {
|
||||||
i = 4;
|
i = 4;
|
||||||
}
|
}
|
||||||
final long radius = getInt(split[i]);
|
long radius = getInt(split[i]);
|
||||||
final long volume = radius * radius;
|
long volume = radius * radius;
|
||||||
return checkVolume(pp, volume, maxVolume, e);
|
return checkVolume(pp, volume, maxVolume, e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (regionExtend.contains(reduced)) {
|
if (this.regionExtend.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
@ -295,7 +283,7 @@ public class WEListener implements Listener {
|
|||||||
return checkSelection(p, pp, getInt(split[1]), maxVolume, e);
|
return checkSelection(p, pp, getInt(split[1]), maxVolume, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String reduced = reduceCmd(split[0], single);
|
String reduced = reduceCmd(split[0], single);
|
||||||
if (Settings.WE_BLACKLIST.contains(reduced)) {
|
if (Settings.WE_BLACKLIST.contains(reduced)) {
|
||||||
MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE);
|
MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -303,8 +291,8 @@ public class WEListener implements Listener {
|
|||||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (restricted.contains(reduced)) {
|
if (this.restricted.contains(reduced)) {
|
||||||
final Plot plot = pp.getCurrentPlot();
|
Plot plot = pp.getCurrentPlot();
|
||||||
if ((plot != null) && plot.isAdded(pp.getUUID())) {
|
if ((plot != null) && plot.isAdded(pp.getUUID())) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
@ -319,14 +307,14 @@ public class WEListener implements Listener {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (region.contains(reduced)) {
|
if (this.region.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return checkSelection(p, pp, 1, maxVolume, e);
|
return checkSelection(p, pp, 1, maxVolume, e);
|
||||||
}
|
}
|
||||||
if (other.contains(reduced)) {
|
if (this.other.contains(reduced)) {
|
||||||
if (delay(p, message, false)) {
|
if (delay(p, message, false)) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,40 +1,39 @@
|
|||||||
package com.plotsquared.bukkit.object;
|
package com.plotsquared.bukkit.object;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.LazyBlock;
|
import com.intellectualcrafters.plot.object.LazyBlock;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
public class BukkitLazyBlock extends LazyBlock {
|
public class BukkitLazyBlock extends LazyBlock {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private Block block;
|
private Block block;
|
||||||
private PlotBlock pb;
|
private PlotBlock pb;
|
||||||
|
|
||||||
public BukkitLazyBlock(final int id, final Block block) {
|
public BukkitLazyBlock(int id, Block block) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitLazyBlock(final PlotBlock pb) {
|
public BukkitLazyBlock(PlotBlock pb) {
|
||||||
id = pb.id;
|
this.id = pb.id;
|
||||||
this.pb = pb;
|
this.pb = pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitLazyBlock(final Block block) {
|
public BukkitLazyBlock(Block block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotBlock getPlotBlock() {
|
public PlotBlock getPlotBlock() {
|
||||||
if (pb != null) {
|
if (this.pb != null) {
|
||||||
return pb;
|
return this.pb;
|
||||||
}
|
}
|
||||||
if (id == 0) {
|
if (this.id == 0) {
|
||||||
id = block.getTypeId();
|
this.id = this.block.getTypeId();
|
||||||
}
|
}
|
||||||
byte data;
|
byte data;
|
||||||
switch (id) {
|
switch (this.id) {
|
||||||
case 0:
|
case 0:
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
@ -120,20 +119,20 @@ public class BukkitLazyBlock extends LazyBlock {
|
|||||||
data = 0;
|
data = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
data = block.getData();
|
data = this.block.getData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pb = new PlotBlock((short) id, data);
|
this.pb = new PlotBlock((short) this.id, data);
|
||||||
return pb;
|
return this.pb;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
if (id == 0) {
|
if (this.id == 0) {
|
||||||
id = block.getTypeId();
|
this.id = this.block.getTypeId();
|
||||||
}
|
}
|
||||||
return id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.plotsquared.bukkit.object;
|
package com.plotsquared.bukkit.object;
|
||||||
|
|
||||||
import java.util.UUID;
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||||
|
|
||||||
@ -14,27 +13,27 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
|||||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public BukkitOfflinePlayer(final OfflinePlayer player) {
|
public BukkitOfflinePlayer(OfflinePlayer player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
return player.getUniqueId();
|
return this.player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLastPlayed() {
|
public long getLastPlayed() {
|
||||||
return player.getLastPlayed();
|
return this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
return player.isOnline();
|
return this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return player.getName();
|
return this.player.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import com.intellectualcrafters.plot.config.C;
|
|||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
import com.intellectualcrafters.plot.util.PlotGameMode;
|
||||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
@ -31,12 +31,12 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer(final Player player) {
|
public BukkitPlayer(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
super.populatePersistentMetaMap();
|
super.populatePersistentMetaMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitPlayer(final Player player, final boolean offline) {
|
public BukkitPlayer(Player player, boolean offline) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.offline = offline;
|
this.offline = offline;
|
||||||
super.populatePersistentMetaMap();
|
super.populatePersistentMetaMap();
|
||||||
@ -44,45 +44,45 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getPreviousLogin() {
|
public long getPreviousLogin() {
|
||||||
if (last == 0) {
|
if (this.last == 0) {
|
||||||
last = player.getLastPlayed();
|
this.last = this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
return last;
|
return this.last;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
final Location loc = super.getLocation();
|
Location location = super.getLocation();
|
||||||
return loc == null ? BukkitUtil.getLocation(player) : loc;
|
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
if (uuid == null) {
|
if (this.uuid == null) {
|
||||||
uuid = UUIDHandler.getUUID(this);
|
this.uuid = UUIDHandler.getUUID(this);
|
||||||
}
|
}
|
||||||
return uuid;
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final String node) {
|
public boolean hasPermission(String permission) {
|
||||||
if (offline && EconHandler.manager != null) {
|
if (this.offline && EconHandler.manager != null) {
|
||||||
return EconHandler.manager.hasPermission(getName(), node);
|
return EconHandler.manager.hasPermission(getName(), permission);
|
||||||
}
|
}
|
||||||
return player.hasPermission(node);
|
return this.player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permission getPermission(final String node) {
|
public Permission getPermission(String node) {
|
||||||
final PluginManager manager = Bukkit.getPluginManager();
|
PluginManager manager = Bukkit.getPluginManager();
|
||||||
Permission perm = manager.getPermission(node);
|
Permission perm = manager.getPermission(node);
|
||||||
if (perm == null) {
|
if (perm == null) {
|
||||||
final String[] nodes = node.split("\\.");
|
String[] nodes = node.split("\\.");
|
||||||
perm = new Permission(node);
|
perm = new Permission(node);
|
||||||
final StringBuilder n = new StringBuilder();
|
StringBuilder n = new StringBuilder();
|
||||||
for (int i = 0; i < nodes.length - 1; i++) {
|
for (int i = 0; i < nodes.length - 1; i++) {
|
||||||
n.append(nodes[i]).append(".");
|
n.append(nodes[i]).append(".");
|
||||||
if (!node.equals(n + C.PERMISSION_STAR.s())) {
|
if (!node.equals(n + C.PERMISSION_STAR.s())) {
|
||||||
final Permission parent = getPermission(n + C.PERMISSION_STAR.s());
|
Permission parent = getPermission(n + C.PERMISSION_STAR.s());
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
perm.addParent(parent, true);
|
perm.addParent(parent, true);
|
||||||
}
|
}
|
||||||
@ -96,134 +96,125 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(final String message) {
|
public void sendMessage(String message) {
|
||||||
player.sendMessage(message);
|
this.player.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void teleport(final Location loc) {
|
public void teleport(Location location) {
|
||||||
if (Math.abs(loc.getX()) >= 30000000 || Math.abs(loc.getZ()) >= 30000000) {
|
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()), TeleportCause.COMMAND);
|
this.player.teleport(
|
||||||
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, location.getY(), location.getZ() + 0.5,
|
||||||
|
location.getYaw(), location.getPitch()), TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (name == null) {
|
if (this.name == null) {
|
||||||
name = player.getName();
|
this.name = this.player.getName();
|
||||||
}
|
}
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
return !offline && player.isOnline();
|
return !this.offline && this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompassTarget(final Location loc) {
|
public void setCompassTarget(Location location) {
|
||||||
player.setCompassTarget(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
this.player.setCompassTarget(
|
||||||
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getLocationFull() {
|
public Location getLocationFull() {
|
||||||
return BukkitUtil.getLocationFull(player);
|
return BukkitUtil.getLocationFull(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadData() {
|
public void setWeather(PlotWeather weather) {
|
||||||
if (!player.isOnline()) {
|
|
||||||
player.loadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveData() {
|
|
||||||
player.saveData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWeather(final PlotWeather weather) {
|
|
||||||
switch (weather) {
|
switch (weather) {
|
||||||
case CLEAR:
|
case CLEAR:
|
||||||
player.setPlayerWeather(WeatherType.CLEAR);
|
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||||
return;
|
return;
|
||||||
case RAIN:
|
case RAIN:
|
||||||
player.setPlayerWeather(WeatherType.DOWNFALL);
|
this.player.setPlayerWeather(WeatherType.DOWNFALL);
|
||||||
return;
|
return;
|
||||||
case RESET:
|
case RESET:
|
||||||
player.resetPlayerWeather();
|
this.player.resetPlayerWeather();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotGamemode getGamemode() {
|
public PlotGameMode getGameMode() {
|
||||||
switch (player.getGameMode()) {
|
switch (this.player.getGameMode()) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return PlotGamemode.ADVENTURE;
|
return PlotGameMode.ADVENTURE;
|
||||||
case CREATIVE:
|
case CREATIVE:
|
||||||
return PlotGamemode.CREATIVE;
|
return PlotGameMode.CREATIVE;
|
||||||
case SPECTATOR:
|
case SPECTATOR:
|
||||||
return PlotGamemode.SPECTATOR;
|
return PlotGameMode.SPECTATOR;
|
||||||
case SURVIVAL:
|
case SURVIVAL:
|
||||||
return PlotGamemode.SURVIVAL;
|
return PlotGameMode.SURVIVAL;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGamemode(final PlotGamemode gamemode) {
|
public void setGameMode(PlotGameMode gameMode) {
|
||||||
switch (gamemode) {
|
switch (gameMode) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
this.player.setGameMode(GameMode.ADVENTURE);
|
||||||
return;
|
return;
|
||||||
case CREATIVE:
|
case CREATIVE:
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
this.player.setGameMode(GameMode.CREATIVE);
|
||||||
return;
|
return;
|
||||||
case SPECTATOR:
|
case SPECTATOR:
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
this.player.setGameMode(GameMode.SPECTATOR);
|
||||||
return;
|
return;
|
||||||
case SURVIVAL:
|
case SURVIVAL:
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
this.player.setGameMode(GameMode.SURVIVAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTime(final long time) {
|
public void setTime(long time) {
|
||||||
if (time != Long.MAX_VALUE) {
|
if (time != Long.MAX_VALUE) {
|
||||||
player.setPlayerTime(time, false);
|
this.player.setPlayerTime(time, false);
|
||||||
} else {
|
} else {
|
||||||
player.resetPlayerTime();
|
this.player.resetPlayerTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFlight(final boolean fly) {
|
public void setFlight(boolean fly) {
|
||||||
player.setAllowFlight(fly);
|
this.player.setAllowFlight(fly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playMusic(final Location loc, final int id) {
|
public void playMusic(Location location, int id) {
|
||||||
player.playEffect(BukkitUtil.getLocation(loc), Effect.RECORD_PLAY, id);
|
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kick(final String message) {
|
public void kick(String message) {
|
||||||
player.kickPlayer(message);
|
this.player.kickPlayer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void stopSpectating() {
|
@Override public void stopSpectating() {
|
||||||
if (getGamemode() == PlotGamemode.SPECTATOR) {
|
if (getGameMode() == PlotGameMode.SPECTATOR) {
|
||||||
player.setSpectatorTarget(null);
|
this.player.setSpectatorTarget(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBanned() {
|
public boolean isBanned() {
|
||||||
return player.isBanned();
|
return this.player.isBanned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,31 +56,31 @@ public class EntityWrapper {
|
|||||||
private ArmorStandStats stand;
|
private ArmorStandStats stand;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public EntityWrapper(final org.bukkit.entity.Entity entity, final short depth) {
|
public EntityWrapper(org.bukkit.entity.Entity entity, short depth) {
|
||||||
hash = entity.getEntityId();
|
this.hash = entity.getEntityId();
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
final Location loc = entity.getLocation();
|
Location loc = entity.getLocation();
|
||||||
yaw = loc.getYaw();
|
this.yaw = loc.getYaw();
|
||||||
pitch = loc.getPitch();
|
this.pitch = loc.getPitch();
|
||||||
x = loc.getX();
|
this.x = loc.getX();
|
||||||
y = loc.getY();
|
this.y = loc.getY();
|
||||||
z = loc.getZ();
|
this.z = loc.getZ();
|
||||||
type = entity.getType();
|
this.type = entity.getType();
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
base = new EntityBaseStats();
|
this.base = new EntityBaseStats();
|
||||||
final Entity p = entity.getPassenger();
|
Entity p = entity.getPassenger();
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
base.passenger = new EntityWrapper(p, depth);
|
this.base.passenger = new EntityWrapper(p, depth);
|
||||||
}
|
}
|
||||||
base.fall = entity.getFallDistance();
|
this.base.fall = entity.getFallDistance();
|
||||||
base.fire = (short) entity.getFireTicks();
|
this.base.fire = (short) entity.getFireTicks();
|
||||||
base.age = entity.getTicksLived();
|
this.base.age = entity.getTicksLived();
|
||||||
final Vector velocity = entity.getVelocity();
|
Vector velocity = entity.getVelocity();
|
||||||
base.v_x = velocity.getX();
|
this.base.v_x = velocity.getX();
|
||||||
base.v_y = velocity.getY();
|
this.base.v_y = velocity.getY();
|
||||||
base.v_z = velocity.getZ();
|
this.base.v_z = velocity.getZ();
|
||||||
if (depth == 1) {
|
if (depth == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,31 +123,31 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// MISC //
|
// MISC //
|
||||||
case DROPPED_ITEM: {
|
case DROPPED_ITEM: {
|
||||||
final Item item = (Item) entity;
|
Item item = (Item) entity;
|
||||||
stack = item.getItemStack();
|
this.stack = item.getItemStack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case ITEM_FRAME: {
|
case ITEM_FRAME: {
|
||||||
final ItemFrame itemframe = (ItemFrame) entity;
|
ItemFrame itemframe = (ItemFrame) entity;
|
||||||
x = Math.floor(x);
|
this.x = Math.floor(this.x);
|
||||||
y = Math.floor(y);
|
this.y = Math.floor(this.y);
|
||||||
z = Math.floor(z);
|
this.z = Math.floor(this.z);
|
||||||
dataByte = getOrdinal(Rotation.values(), itemframe.getRotation());
|
this.dataByte = getOrdinal(Rotation.values(), itemframe.getRotation());
|
||||||
stack = itemframe.getItem().clone();
|
this.stack = itemframe.getItem().clone();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case PAINTING: {
|
case PAINTING: {
|
||||||
final Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
x = Math.floor(x);
|
this.x = Math.floor(this.x);
|
||||||
y = Math.floor(y);
|
this.y = Math.floor(this.y);
|
||||||
z = Math.floor(z);
|
this.z = Math.floor(this.z);
|
||||||
final Art a = painting.getArt();
|
Art a = painting.getArt();
|
||||||
dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
this.dataByte = getOrdinal(BlockFace.values(), painting.getFacing());
|
||||||
final int h = a.getBlockHeight();
|
int h = a.getBlockHeight();
|
||||||
if ((h % 2) == 0) {
|
if ((h % 2) == 0) {
|
||||||
y -= 1;
|
this.y -= 1;
|
||||||
}
|
}
|
||||||
dataString = a.name();
|
this.dataString = a.name();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// END MISC //
|
// END MISC //
|
||||||
@ -161,7 +161,7 @@ public class EntityWrapper {
|
|||||||
// START AGEABLE //
|
// START AGEABLE //
|
||||||
// START TAMEABLE //
|
// START TAMEABLE //
|
||||||
case HORSE: {
|
case HORSE: {
|
||||||
final Horse horse = (Horse) entity;
|
Horse horse = (Horse) entity;
|
||||||
this.horse = new HorseStats();
|
this.horse = new HorseStats();
|
||||||
this.horse.jump = horse.getJumpStrength();
|
this.horse.jump = horse.getJumpStrength();
|
||||||
this.horse.chest = horse.isCarryingChest();
|
this.horse.chest = horse.isCarryingChest();
|
||||||
@ -184,9 +184,9 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// END AMEABLE //
|
// END AMEABLE //
|
||||||
case SHEEP: {
|
case SHEEP: {
|
||||||
final Sheep sheep = (Sheep) entity;
|
Sheep sheep = (Sheep) entity;
|
||||||
dataByte = (byte) ((sheep).isSheared() ? 1 : 0);
|
this.dataByte = (byte) (sheep.isSheared() ? 1 : 0);
|
||||||
dataByte2 = sheep.getColor().getDyeData();
|
this.dataByte2 = sheep.getColor().getDyeData();
|
||||||
storeAgeable((Ageable) entity);
|
storeAgeable((Ageable) entity);
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
@ -202,54 +202,55 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// END AGEABLE //
|
// END AGEABLE //
|
||||||
case RABBIT: { // NEW
|
case RABBIT: { // NEW
|
||||||
dataByte = getOrdinal(Type.values(), ((Rabbit) entity).getRabbitType());
|
this.dataByte = getOrdinal(Type.values(), ((Rabbit) entity).getRabbitType());
|
||||||
storeAgeable((Ageable) entity);
|
storeAgeable((Ageable) entity);
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case GUARDIAN: { // NEW
|
case GUARDIAN: { // NEW
|
||||||
dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
|
this.dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case SKELETON: { // NEW
|
case SKELETON: { // NEW
|
||||||
dataByte = (byte) ((Skeleton) entity).getSkeletonType().getId();
|
this.dataByte = (byte) ((Skeleton) entity).getSkeletonType().getId();
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case ARMOR_STAND: { // NEW
|
case ARMOR_STAND: { // NEW
|
||||||
// CHECK positions
|
// CHECK positions
|
||||||
final ArmorStand stand = (ArmorStand) entity;
|
ArmorStand stand = (ArmorStand) entity;
|
||||||
inventory = new ItemStack[] { stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(), stand.getLeggings().clone(), stand.getBoots().clone() };
|
this.inventory = new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(),
|
||||||
|
stand.getLeggings().clone(), stand.getBoots().clone()};
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
this.stand = new ArmorStandStats();
|
this.stand = new ArmorStandStats();
|
||||||
|
|
||||||
final EulerAngle head = stand.getHeadPose();
|
EulerAngle head = stand.getHeadPose();
|
||||||
this.stand.head[0] = (float) head.getX();
|
this.stand.head[0] = (float) head.getX();
|
||||||
this.stand.head[1] = (float) head.getY();
|
this.stand.head[1] = (float) head.getY();
|
||||||
this.stand.head[2] = (float) head.getZ();
|
this.stand.head[2] = (float) head.getZ();
|
||||||
|
|
||||||
final EulerAngle body = stand.getBodyPose();
|
EulerAngle body = stand.getBodyPose();
|
||||||
this.stand.body[0] = (float) body.getX();
|
this.stand.body[0] = (float) body.getX();
|
||||||
this.stand.body[1] = (float) body.getY();
|
this.stand.body[1] = (float) body.getY();
|
||||||
this.stand.body[2] = (float) body.getZ();
|
this.stand.body[2] = (float) body.getZ();
|
||||||
|
|
||||||
final EulerAngle leftLeg = stand.getLeftLegPose();
|
EulerAngle leftLeg = stand.getLeftLegPose();
|
||||||
this.stand.leftLeg[0] = (float) leftLeg.getX();
|
this.stand.leftLeg[0] = (float) leftLeg.getX();
|
||||||
this.stand.leftLeg[1] = (float) leftLeg.getY();
|
this.stand.leftLeg[1] = (float) leftLeg.getY();
|
||||||
this.stand.leftLeg[2] = (float) leftLeg.getZ();
|
this.stand.leftLeg[2] = (float) leftLeg.getZ();
|
||||||
|
|
||||||
final EulerAngle rightLeg = stand.getRightLegPose();
|
EulerAngle rightLeg = stand.getRightLegPose();
|
||||||
this.stand.rightLeg[0] = (float) rightLeg.getX();
|
this.stand.rightLeg[0] = (float) rightLeg.getX();
|
||||||
this.stand.rightLeg[1] = (float) rightLeg.getY();
|
this.stand.rightLeg[1] = (float) rightLeg.getY();
|
||||||
this.stand.rightLeg[2] = (float) rightLeg.getZ();
|
this.stand.rightLeg[2] = (float) rightLeg.getZ();
|
||||||
|
|
||||||
final EulerAngle leftArm = stand.getLeftArmPose();
|
EulerAngle leftArm = stand.getLeftArmPose();
|
||||||
this.stand.leftArm[0] = (float) leftArm.getX();
|
this.stand.leftArm[0] = (float) leftArm.getX();
|
||||||
this.stand.leftArm[1] = (float) leftArm.getY();
|
this.stand.leftArm[1] = (float) leftArm.getY();
|
||||||
this.stand.leftArm[2] = (float) leftArm.getZ();
|
this.stand.leftArm[2] = (float) leftArm.getZ();
|
||||||
|
|
||||||
final EulerAngle rightArm = stand.getRightArmPose();
|
EulerAngle rightArm = stand.getRightArmPose();
|
||||||
this.stand.rightArm[0] = (float) rightArm.getX();
|
this.stand.rightArm[0] = (float) rightArm.getX();
|
||||||
this.stand.rightArm[1] = (float) rightArm.getY();
|
this.stand.rightArm[1] = (float) rightArm.getY();
|
||||||
this.stand.rightArm[2] = (float) rightArm.getZ();
|
this.stand.rightArm[2] = (float) rightArm.getZ();
|
||||||
@ -298,39 +299,39 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return hash == obj.hashCode();
|
return this.hash == obj.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeInventory(final InventoryHolder held) {
|
public void storeInventory(InventoryHolder held) {
|
||||||
inventory = held.getInventory().getContents().clone();
|
this.inventory = held.getInventory().getContents().clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreLiving(final LivingEntity entity) {
|
private void restoreLiving(LivingEntity entity) {
|
||||||
entity.setCanPickupItems(lived.loot);
|
entity.setCanPickupItems(this.lived.loot);
|
||||||
if (lived.name != null) {
|
if (this.lived.name != null) {
|
||||||
entity.setCustomName(lived.name);
|
entity.setCustomName(this.lived.name);
|
||||||
entity.setCustomNameVisible(lived.visible);
|
entity.setCustomNameVisible(this.lived.visible);
|
||||||
}
|
}
|
||||||
if ((lived.potions != null) && (!lived.potions.isEmpty())) {
|
if ((this.lived.potions != null) && !this.lived.potions.isEmpty()) {
|
||||||
entity.addPotionEffects(lived.potions);
|
entity.addPotionEffects(this.lived.potions);
|
||||||
}
|
}
|
||||||
entity.setRemainingAir(lived.air);
|
entity.setRemainingAir(this.lived.air);
|
||||||
entity.setRemoveWhenFarAway(lived.persistent);
|
entity.setRemoveWhenFarAway(this.lived.persistent);
|
||||||
if (lived.equipped) {
|
if (this.lived.equipped) {
|
||||||
final EntityEquipment equipment = entity.getEquipment();
|
EntityEquipment equipment = entity.getEquipment();
|
||||||
equipment.setItemInHand(lived.hands);
|
equipment.setItemInHand(this.lived.hands);
|
||||||
equipment.setHelmet(lived.helmet);
|
equipment.setHelmet(this.lived.helmet);
|
||||||
equipment.setChestplate(lived.chestplate);
|
equipment.setChestplate(this.lived.chestplate);
|
||||||
equipment.setLeggings(lived.leggings);
|
equipment.setLeggings(this.lived.leggings);
|
||||||
equipment.setBoots(lived.boots);
|
equipment.setBoots(this.lived.boots);
|
||||||
}
|
}
|
||||||
if (lived.leashed) {
|
if (this.lived.leashed) {
|
||||||
// TODO leashes
|
// TODO leashes
|
||||||
// World world = entity.getWorld();
|
// World world = entity.getWorld();
|
||||||
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leash_x, Math.floor(y) + lived.leash_y, Math
|
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leash_x, Math.floor(y) + lived.leash_y, Math
|
||||||
@ -339,11 +340,11 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreInventory(final InventoryHolder entity) {
|
private void restoreInventory(InventoryHolder entity) {
|
||||||
entity.getInventory().setContents(inventory);
|
entity.getInventory().setContents(this.inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeLiving(final LivingEntity lived) {
|
public void storeLiving(LivingEntity lived) {
|
||||||
this.lived = new LivingEntityStats();
|
this.lived = new LivingEntityStats();
|
||||||
this.lived.potions = lived.getActivePotionEffects();
|
this.lived.potions = lived.getActivePotionEffects();
|
||||||
this.lived.loot = lived.getCanPickupItems();
|
this.lived.loot = lived.getCanPickupItems();
|
||||||
@ -354,12 +355,12 @@ public class EntityWrapper {
|
|||||||
this.lived.persistent = lived.getRemoveWhenFarAway();
|
this.lived.persistent = lived.getRemoveWhenFarAway();
|
||||||
this.lived.leashed = lived.isLeashed();
|
this.lived.leashed = lived.isLeashed();
|
||||||
if (this.lived.leashed) {
|
if (this.lived.leashed) {
|
||||||
final Location loc = lived.getLeashHolder().getLocation();
|
Location loc = lived.getLeashHolder().getLocation();
|
||||||
this.lived.leash_x = (short) (x - loc.getBlockX());
|
this.lived.leash_x = (short) (this.x - loc.getBlockX());
|
||||||
this.lived.leash_y = (short) (y - loc.getBlockY());
|
this.lived.leash_y = (short) (this.y - loc.getBlockY());
|
||||||
this.lived.leash_z = (short) (z - loc.getBlockZ());
|
this.lived.leash_z = (short) (this.z - loc.getBlockZ());
|
||||||
}
|
}
|
||||||
final EntityEquipment equipment = lived.getEquipment();
|
EntityEquipment equipment = lived.getEquipment();
|
||||||
this.lived.equipped = equipment != null;
|
this.lived.equipped = equipment != null;
|
||||||
if (this.lived.equipped) {
|
if (this.lived.equipped) {
|
||||||
this.lived.hands = equipment.getItemInHand().clone();
|
this.lived.hands = equipment.getItemInHand().clone();
|
||||||
@ -370,50 +371,50 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreTameable(final Tameable entity) {
|
private void restoreTameable(Tameable entity) {
|
||||||
if (tamed.tamed) {
|
if (this.tamed.tamed) {
|
||||||
if (tamed.owner != null) {
|
if (this.tamed.owner != null) {
|
||||||
entity.setTamed(true);
|
entity.setTamed(true);
|
||||||
entity.setOwner(tamed.owner);
|
entity.setOwner(this.tamed.owner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreAgeable(final Ageable entity) {
|
private void restoreAgeable(Ageable entity) {
|
||||||
if (!aged.adult) {
|
if (!this.aged.adult) {
|
||||||
entity.setBaby();
|
entity.setBaby();
|
||||||
}
|
}
|
||||||
entity.setAgeLock(aged.locked);
|
entity.setAgeLock(this.aged.locked);
|
||||||
if (aged.age > 0) {
|
if (this.aged.age > 0) {
|
||||||
entity.setAge(aged.age);
|
entity.setAge(this.aged.age);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeAgeable(final Ageable aged) {
|
public void storeAgeable(Ageable aged) {
|
||||||
this.aged = new AgeableStats();
|
this.aged = new AgeableStats();
|
||||||
this.aged.age = aged.getAge();
|
this.aged.age = aged.getAge();
|
||||||
this.aged.locked = aged.getAgeLock();
|
this.aged.locked = aged.getAgeLock();
|
||||||
this.aged.adult = aged.isAdult();
|
this.aged.adult = aged.isAdult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void storeTameable(final Tameable tamed) {
|
public void storeTameable(Tameable tamed) {
|
||||||
this.tamed = new TameableStats();
|
this.tamed = new TameableStats();
|
||||||
this.tamed.owner = tamed.getOwner();
|
this.tamed.owner = tamed.getOwner();
|
||||||
this.tamed.tamed = tamed.isTamed();
|
this.tamed.tamed = tamed.isTamed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public Entity spawn(final World world, final int x_offset, final int z_offset) {
|
public Entity spawn(World world, int x_offset, int z_offset) {
|
||||||
final Location loc = new Location(world, x + x_offset, y, z + z_offset);
|
Location loc = new Location(world, this.x + x_offset, this.y, this.z + z_offset);
|
||||||
loc.setYaw(yaw);
|
loc.setYaw(this.yaw);
|
||||||
loc.setPitch(pitch);
|
loc.setPitch(this.pitch);
|
||||||
if (type.isSpawnable()) {
|
if (this.type.isSpawnable()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Entity entity;
|
Entity entity;
|
||||||
switch (type) {
|
switch (this.type) {
|
||||||
case DROPPED_ITEM: {
|
case DROPPED_ITEM: {
|
||||||
return world.dropItem(loc, stack);
|
return world.dropItem(loc, this.stack);
|
||||||
}
|
}
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
case LEASH_HITCH: {
|
case LEASH_HITCH: {
|
||||||
@ -428,28 +429,29 @@ public class EntityWrapper {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
entity = world.spawnEntity(loc, type);
|
entity = world.spawnEntity(loc, this.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (depth == 0) {
|
if (this.depth == 0) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
if (base.passenger != null) {
|
if (this.base.passenger != null) {
|
||||||
try {
|
try {
|
||||||
entity.setPassenger(base.passenger.spawn(world, x_offset, z_offset));
|
entity.setPassenger(this.base.passenger.spawn(world, x_offset, z_offset));
|
||||||
} catch (final Exception e) {}
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (base.fall != 0) {
|
if (this.base.fall != 0) {
|
||||||
entity.setFallDistance(base.fall);
|
entity.setFallDistance(this.base.fall);
|
||||||
}
|
}
|
||||||
if (base.fire != 0) {
|
if (this.base.fire != 0) {
|
||||||
entity.setFireTicks(base.fire);
|
entity.setFireTicks(this.base.fire);
|
||||||
}
|
}
|
||||||
if (base.age != 0) {
|
if (this.base.age != 0) {
|
||||||
entity.setTicksLived(base.age);
|
entity.setTicksLived(this.base.age);
|
||||||
}
|
}
|
||||||
entity.setVelocity(new Vector(base.v_x, base.v_y, base.v_z));
|
entity.setVelocity(new Vector(this.base.v_x, this.base.v_y, this.base.v_z));
|
||||||
if (depth == 1) {
|
if (this.depth == 1) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
@ -491,15 +493,15 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// MISC //
|
// MISC //
|
||||||
case ITEM_FRAME: {
|
case ITEM_FRAME: {
|
||||||
final ItemFrame itemframe = (ItemFrame) entity;
|
ItemFrame itemframe = (ItemFrame) entity;
|
||||||
itemframe.setRotation(Rotation.values()[dataByte]);
|
itemframe.setRotation(Rotation.values()[this.dataByte]);
|
||||||
itemframe.setItem(stack);
|
itemframe.setItem(this.stack);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
case PAINTING: {
|
case PAINTING: {
|
||||||
final Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
painting.setFacingDirection(BlockFace.values()[dataByte], true);
|
painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
|
||||||
painting.setArt(Art.getByName(dataString), true);
|
painting.setArt(Art.getByName(this.dataString), true);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
// END MISC //
|
// END MISC //
|
||||||
@ -513,7 +515,7 @@ public class EntityWrapper {
|
|||||||
// START AGEABLE //
|
// START AGEABLE //
|
||||||
// START TAMEABLE //
|
// START TAMEABLE //
|
||||||
case HORSE: {
|
case HORSE: {
|
||||||
final Horse horse = (Horse) entity;
|
Horse horse = (Horse) entity;
|
||||||
horse.setJumpStrength(this.horse.jump);
|
horse.setJumpStrength(this.horse.jump);
|
||||||
horse.setCarryingChest(this.horse.chest);
|
horse.setCarryingChest(this.horse.chest);
|
||||||
horse.setVariant(Variant.values()[this.horse.variant]);
|
horse.setVariant(Variant.values()[this.horse.variant]);
|
||||||
@ -535,12 +537,12 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// END AGEABLE //
|
// END AGEABLE //
|
||||||
case SHEEP: {
|
case SHEEP: {
|
||||||
final Sheep sheep = (Sheep) entity;
|
Sheep sheep = (Sheep) entity;
|
||||||
if (dataByte == 1) {
|
if (this.dataByte == 1) {
|
||||||
sheep.setSheared(true);
|
sheep.setSheared(true);
|
||||||
}
|
}
|
||||||
if (dataByte2 != 0) {
|
if (this.dataByte2 != 0) {
|
||||||
sheep.setColor(DyeColor.getByDyeData(dataByte2));
|
sheep.setColor(DyeColor.getByDyeData(this.dataByte2));
|
||||||
}
|
}
|
||||||
restoreAgeable((Ageable) entity);
|
restoreAgeable((Ageable) entity);
|
||||||
restoreLiving((LivingEntity) entity);
|
restoreLiving((LivingEntity) entity);
|
||||||
@ -557,67 +559,67 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
// END AGEABLE //
|
// END AGEABLE //
|
||||||
case RABBIT: { // NEW
|
case RABBIT: { // NEW
|
||||||
if (dataByte != 0) {
|
if (this.dataByte != 0) {
|
||||||
((Rabbit) entity).setRabbitType(Type.values()[dataByte]);
|
((Rabbit) entity).setRabbitType(Type.values()[this.dataByte]);
|
||||||
}
|
}
|
||||||
restoreAgeable((Ageable) entity);
|
restoreAgeable((Ageable) entity);
|
||||||
restoreLiving((LivingEntity) entity);
|
restoreLiving((LivingEntity) entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
case GUARDIAN: { // NEW
|
case GUARDIAN: { // NEW
|
||||||
if (dataByte != 0) {
|
if (this.dataByte != 0) {
|
||||||
((Guardian) entity).setElder(true);
|
((Guardian) entity).setElder(true);
|
||||||
}
|
}
|
||||||
restoreLiving((LivingEntity) entity);
|
restoreLiving((LivingEntity) entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
case SKELETON: { // NEW
|
case SKELETON: { // NEW
|
||||||
if (dataByte != 0) {
|
if (this.dataByte != 0) {
|
||||||
((Skeleton) entity).setSkeletonType(SkeletonType.values()[dataByte]);
|
((Skeleton) entity).setSkeletonType(SkeletonType.values()[this.dataByte]);
|
||||||
}
|
}
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
case ARMOR_STAND: { // NEW
|
case ARMOR_STAND: { // NEW
|
||||||
// CHECK positions
|
// CHECK positions
|
||||||
final ArmorStand stand = (ArmorStand) entity;
|
ArmorStand stand = (ArmorStand) entity;
|
||||||
if (inventory[0] != null) {
|
if (this.inventory[0] != null) {
|
||||||
stand.setItemInHand(inventory[0]);
|
stand.setItemInHand(this.inventory[0]);
|
||||||
}
|
}
|
||||||
if (inventory[1] != null) {
|
if (this.inventory[1] != null) {
|
||||||
stand.setHelmet(inventory[1]);
|
stand.setHelmet(this.inventory[1]);
|
||||||
}
|
}
|
||||||
if (inventory[2] != null) {
|
if (this.inventory[2] != null) {
|
||||||
stand.setChestplate(inventory[2]);
|
stand.setChestplate(this.inventory[2]);
|
||||||
}
|
}
|
||||||
if (inventory[3] != null) {
|
if (this.inventory[3] != null) {
|
||||||
stand.setLeggings(inventory[3]);
|
stand.setLeggings(this.inventory[3]);
|
||||||
}
|
}
|
||||||
if (inventory[4] != null) {
|
if (this.inventory[4] != null) {
|
||||||
stand.setBoots(inventory[4]);
|
stand.setBoots(this.inventory[4]);
|
||||||
}
|
}
|
||||||
if ((this.stand.head[0] != 0) || (this.stand.head[1] != 0) || (this.stand.head[2] != 0)) {
|
if ((this.stand.head[0] != 0) || (this.stand.head[1] != 0) || (this.stand.head[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
EulerAngle pose = new EulerAngle(this.stand.head[0], this.stand.head[1], this.stand.head[2]);
|
||||||
stand.setHeadPose(pose);
|
stand.setHeadPose(pose);
|
||||||
}
|
}
|
||||||
if ((this.stand.body[0] != 0) || (this.stand.body[1] != 0) || (this.stand.body[2] != 0)) {
|
if ((this.stand.body[0] != 0) || (this.stand.body[1] != 0) || (this.stand.body[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
EulerAngle pose = new EulerAngle(this.stand.body[0], this.stand.body[1], this.stand.body[2]);
|
||||||
stand.setBodyPose(pose);
|
stand.setBodyPose(pose);
|
||||||
}
|
}
|
||||||
if ((this.stand.leftLeg[0] != 0) || (this.stand.leftLeg[1] != 0) || (this.stand.leftLeg[2] != 0)) {
|
if ((this.stand.leftLeg[0] != 0) || (this.stand.leftLeg[1] != 0) || (this.stand.leftLeg[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
|
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
|
||||||
stand.setLeftLegPose(pose);
|
stand.setLeftLegPose(pose);
|
||||||
}
|
}
|
||||||
if ((this.stand.rightLeg[0] != 0) || (this.stand.rightLeg[1] != 0) || (this.stand.rightLeg[2] != 0)) {
|
if ((this.stand.rightLeg[0] != 0) || (this.stand.rightLeg[1] != 0) || (this.stand.rightLeg[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
|
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
|
||||||
stand.setRightLegPose(pose);
|
stand.setRightLegPose(pose);
|
||||||
}
|
}
|
||||||
if ((this.stand.leftArm[0] != 0) || (this.stand.leftArm[1] != 0) || (this.stand.leftArm[2] != 0)) {
|
if ((this.stand.leftArm[0] != 0) || (this.stand.leftArm[1] != 0) || (this.stand.leftArm[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
|
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
|
||||||
stand.setLeftArmPose(pose);
|
stand.setLeftArmPose(pose);
|
||||||
}
|
}
|
||||||
if ((this.stand.rightArm[0] != 0) || (this.stand.rightArm[1] != 0) || (this.stand.rightArm[2] != 0)) {
|
if ((this.stand.rightArm[0] != 0) || (this.stand.rightArm[1] != 0) || (this.stand.rightArm[2] != 0)) {
|
||||||
final EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
|
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
|
||||||
stand.setRightArmPose(pose);
|
stand.setRightArmPose(pose);
|
||||||
}
|
}
|
||||||
if (this.stand.invisible) {
|
if (this.stand.invisible) {
|
||||||
@ -663,8 +665,8 @@ public class EntityWrapper {
|
|||||||
// END LIVING //
|
// END LIVING //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte getOrdinal(final Object[] list, final Object value) {
|
private byte getOrdinal(Object[] list, Object value) {
|
||||||
for (byte i = 0; i < list.length; i++) {
|
for (byte i = 0; i < list.length; i++) {
|
||||||
if (list[i].equals(value)) {
|
if (list[i].equals(value)) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -11,12 +11,14 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minecraft 1.8 Title
|
* Minecraft 1.8 Title.
|
||||||
*
|
*
|
||||||
* @version 1.0.4
|
* @version 1.0.4
|
||||||
* @author Maxim Van de Wynckel
|
* @author Maxim Van de Wynckel
|
||||||
*/
|
*/
|
||||||
public class HackTitleManager {
|
public class HackTitleManager {
|
||||||
|
|
||||||
|
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||||
/* Title packet */
|
/* Title packet */
|
||||||
private Class<?> packetTitle;
|
private Class<?> packetTitle;
|
||||||
/* Title packet actions ENUM */
|
/* Title packet actions ENUM */
|
||||||
@ -29,76 +31,66 @@ public class HackTitleManager {
|
|||||||
/* Subtitle text and color */
|
/* Subtitle text and color */
|
||||||
private String subtitle = "";
|
private String subtitle = "";
|
||||||
private ChatColor subtitleColor = ChatColor.WHITE;
|
private ChatColor subtitleColor = ChatColor.WHITE;
|
||||||
/* Title timings */
|
/* Title timings. */
|
||||||
private int fadeInTime = -1;
|
private int fadeInTime = -1;
|
||||||
private int stayTime = -1;
|
private int stayTime = -1;
|
||||||
private int fadeOutTime = -1;
|
private int fadeOutTime = -1;
|
||||||
private boolean ticks = false;
|
private boolean ticks = false;
|
||||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new 1.8 title
|
* Create a new 1.8 title.
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title Title
|
||||||
* Title
|
* @throws ClassNotFoundException NMS Error.
|
||||||
* @throws ClassNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public HackTitleManager(final String title) throws ClassNotFoundException {
|
public HackTitleManager(String title) throws ClassNotFoundException {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new 1.8 title
|
* Create a new 1.8 title.
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title Title text
|
||||||
* Title text
|
* @param subtitle Subtitle text
|
||||||
* @param subtitle
|
* @throws ClassNotFoundException NMS Error
|
||||||
* Subtitle text
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public HackTitleManager(final String title, final String subtitle) throws ClassNotFoundException {
|
public HackTitleManager(String title, String subtitle) throws ClassNotFoundException {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.subtitle = subtitle;
|
this.subtitle = subtitle;
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy 1.8 title
|
* Copy 1.8 title.
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title Title
|
||||||
* Title
|
* @throws ClassNotFoundException NMS Error
|
||||||
* @throws ClassNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public HackTitleManager(final HackTitleManager title) throws ClassNotFoundException {
|
public HackTitleManager(HackTitleManager title) throws ClassNotFoundException {
|
||||||
// Copy title
|
// Copy title
|
||||||
this.title = title.title;
|
this.title = title.title;
|
||||||
subtitle = title.subtitle;
|
this.subtitle = title.subtitle;
|
||||||
titleColor = title.titleColor;
|
this.titleColor = title.titleColor;
|
||||||
subtitleColor = title.subtitleColor;
|
this.subtitleColor = title.subtitleColor;
|
||||||
fadeInTime = title.fadeInTime;
|
this.fadeInTime = title.fadeInTime;
|
||||||
fadeOutTime = title.fadeOutTime;
|
this.fadeOutTime = title.fadeOutTime;
|
||||||
stayTime = title.stayTime;
|
this.stayTime = title.stayTime;
|
||||||
ticks = title.ticks;
|
this.ticks = title.ticks;
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new 1.8 title
|
* Create a new 1.8 title.
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title Title text
|
||||||
* Title text
|
* @param subtitle Subtitle text
|
||||||
* @param subtitle
|
* @param fadeInTime Fade in time
|
||||||
* Subtitle text
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeInTime
|
* @param fadeOutTime Fade out time
|
||||||
* Fade in time
|
* @throws ClassNotFoundException NMS error
|
||||||
* @param stayTime
|
|
||||||
* Stay on screen time
|
|
||||||
* @param fadeOutTime
|
|
||||||
* Fade out time
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public HackTitleManager(final String title, final String subtitle, final int fadeInTime, final int stayTime, final int fadeOutTime) throws ClassNotFoundException {
|
public HackTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) throws ClassNotFoundException {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.subtitle = subtitle;
|
this.subtitle = subtitle;
|
||||||
this.fadeInTime = fadeInTime;
|
this.fadeInTime = fadeInTime;
|
||||||
@ -106,265 +98,8 @@ public class HackTitleManager {
|
|||||||
this.fadeOutTime = fadeOutTime;
|
this.fadeOutTime = fadeOutTime;
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||||
* Load spigot and NMS classes
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
*/
|
|
||||||
private void loadClasses() throws ClassNotFoundException {
|
|
||||||
packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
|
||||||
packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
|
||||||
nmsChatSerializer = getNMSClass("ChatSerializer");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title text
|
|
||||||
*
|
|
||||||
* @param title
|
|
||||||
* Title
|
|
||||||
*/
|
|
||||||
public void setTitle(final String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get title text
|
|
||||||
*
|
|
||||||
* @return Title text
|
|
||||||
*/
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set subtitle text
|
|
||||||
*
|
|
||||||
* @param subtitle
|
|
||||||
* Subtitle text
|
|
||||||
*/
|
|
||||||
public void setSubtitle(final String subtitle) {
|
|
||||||
this.subtitle = subtitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get subtitle text
|
|
||||||
*
|
|
||||||
* @return Subtitle text
|
|
||||||
*/
|
|
||||||
public String getSubtitle() {
|
|
||||||
return subtitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the title color
|
|
||||||
*
|
|
||||||
* @param color
|
|
||||||
* Chat color
|
|
||||||
*/
|
|
||||||
public void setTitleColor(final ChatColor color) {
|
|
||||||
titleColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the subtitle color
|
|
||||||
*
|
|
||||||
* @param color
|
|
||||||
* Chat color
|
|
||||||
*/
|
|
||||||
public void setSubtitleColor(final ChatColor color) {
|
|
||||||
subtitleColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title fade in time
|
|
||||||
*
|
|
||||||
* @param time
|
|
||||||
* Time
|
|
||||||
*/
|
|
||||||
public void setFadeInTime(final int time) {
|
|
||||||
fadeInTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title fade out time
|
|
||||||
*
|
|
||||||
* @param time
|
|
||||||
* Time
|
|
||||||
*/
|
|
||||||
public void setFadeOutTime(final int time) {
|
|
||||||
fadeOutTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title stay time
|
|
||||||
*
|
|
||||||
* @param time
|
|
||||||
* Time
|
|
||||||
*/
|
|
||||||
public void setStayTime(final int time) {
|
|
||||||
stayTime = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set timings to ticks
|
|
||||||
*/
|
|
||||||
public void setTimingsToTicks() {
|
|
||||||
ticks = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set timings to seconds
|
|
||||||
*/
|
|
||||||
public void setTimingsToSeconds() {
|
|
||||||
ticks = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the title to a player
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* Player
|
|
||||||
*/
|
|
||||||
public void send(final Player player) throws Exception {
|
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot() && (packetTitle != null)) {
|
|
||||||
// First reset previous settings
|
|
||||||
resetTitle(player);
|
|
||||||
// Send timings first
|
|
||||||
final Object handle = getHandle(player);
|
|
||||||
final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
final Object[] actions = packetActions.getEnumConstants();
|
|
||||||
final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
|
||||||
Object packet = packetTitle.getConstructor(packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2], fadeInTime * (ticks ? 1 : 20), stayTime * (ticks ? 1 : 20),
|
|
||||||
fadeOutTime * (ticks ? 1 : 20));
|
|
||||||
// Send if set
|
|
||||||
if ((fadeInTime != -1) && (fadeOutTime != -1) && (stayTime != -1)) {
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
}
|
|
||||||
// Send title
|
|
||||||
Object serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
|
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', title) + "\",color:" + titleColor.name().toLowerCase() + "}");
|
|
||||||
packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
if (!subtitle.isEmpty()) {
|
|
||||||
// Send subtitle if present
|
|
||||||
serialized = getMethod(nmsChatSerializer, "a", String.class).invoke(null,
|
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', subtitle) + "\",color:" + subtitleColor.name().toLowerCase() + "}");
|
|
||||||
packet = packetTitle.getConstructor(packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast the title to all players
|
|
||||||
*/
|
|
||||||
public void broadcast() throws Exception {
|
|
||||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
send(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the title
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* Player
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void clearTitle(final Player player) throws Exception {
|
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
|
||||||
// Send timings first
|
|
||||||
final Object handle = getHandle(player);
|
|
||||||
final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
final Object[] actions = packetActions.getEnumConstants();
|
|
||||||
final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
|
||||||
final Object packet = packetTitle.getConstructor(packetActions).newInstance(actions[3]);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the title settings
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* Player
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public void resetTitle(final Player player) throws Exception {
|
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
|
||||||
// Send timings first
|
|
||||||
final Object handle = getHandle(player);
|
|
||||||
final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
final Object[] actions = packetActions.getEnumConstants();
|
|
||||||
final Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
|
||||||
final Object packet = packetTitle.getConstructor(packetActions).newInstance(actions[4]);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the protocol version of the player
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* Player
|
|
||||||
* @return Protocol version
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private int getProtocolVersion(final Player player) throws Exception {
|
|
||||||
final Object handle = getHandle(player);
|
|
||||||
final Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
|
||||||
final Object networkManager = getValue("networkManager", connection);
|
|
||||||
return (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if running spigot
|
|
||||||
*
|
|
||||||
* @return Spigot
|
|
||||||
*/
|
|
||||||
private boolean isSpigot() {
|
|
||||||
return Bukkit.getVersion().contains("Spigot");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get class by url
|
|
||||||
*
|
|
||||||
* @param namespace
|
|
||||||
* Namespace url
|
|
||||||
* @return Class
|
|
||||||
*/
|
|
||||||
private Class<?> getClass(final String namespace) {
|
|
||||||
try {
|
|
||||||
return Class.forName(namespace);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Field getField(final String name, final Class<?> clazz) throws Exception {
|
|
||||||
return clazz.getDeclaredField(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getValue(final String name, final Object obj) throws Exception {
|
|
||||||
final Field f = getField(name, obj.getClass());
|
|
||||||
f.setAccessible(true);
|
|
||||||
return f.get(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Class<?> getPrimitiveType(final Class<?> clazz) {
|
|
||||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Class<?>[] toPrimitiveTypeArray(final Class<?>[] classes) {
|
|
||||||
final int a = classes != null ? classes.length : 0;
|
|
||||||
final Class<?>[] types = new Class<?>[a];
|
|
||||||
for (int i = 0; i < a; i++) {
|
|
||||||
types[i] = getPrimitiveType(classes[i]);
|
|
||||||
}
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean equalsTypeArray(final Class<?>[] a, final Class<?>[] o) {
|
|
||||||
if (a.length != o.length) {
|
if (a.length != o.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -375,8 +110,258 @@ public class HackTitleManager {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getHandle(final Object obj) {
|
/**
|
||||||
|
* Load spigot and NMS classes.
|
||||||
|
* @throws ClassNotFoundException Spigot Error.
|
||||||
|
*/
|
||||||
|
private void loadClasses() throws ClassNotFoundException {
|
||||||
|
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||||
|
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||||
|
this.nmsChatSerializer = getNMSClass("ChatSerializer");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get title text.
|
||||||
|
*
|
||||||
|
* @return Title text
|
||||||
|
*/
|
||||||
|
public String getTitle() {
|
||||||
|
return this.title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title text.
|
||||||
|
*
|
||||||
|
* @param title Title
|
||||||
|
*/
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get subtitle text.
|
||||||
|
*
|
||||||
|
* @return Subtitle text
|
||||||
|
*/
|
||||||
|
public String getSubtitle() {
|
||||||
|
return this.subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set subtitle text.
|
||||||
|
*
|
||||||
|
* @param subtitle Subtitle text
|
||||||
|
*/
|
||||||
|
public void setSubtitle(String subtitle) {
|
||||||
|
this.subtitle = subtitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the title color.
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setTitleColor(ChatColor color) {
|
||||||
|
this.titleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subtitle color.
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setSubtitleColor(ChatColor color) {
|
||||||
|
this.subtitleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade in time.
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeInTime(int time) {
|
||||||
|
this.fadeInTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade out time.
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeOutTime(int time) {
|
||||||
|
this.fadeOutTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title stay time.
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setStayTime(int time) {
|
||||||
|
this.stayTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set timings to ticks.
|
||||||
|
*/
|
||||||
|
public void setTimingsToTicks() {
|
||||||
|
this.ticks = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set timings to seconds.
|
||||||
|
*/
|
||||||
|
public void setTimingsToSeconds() {
|
||||||
|
this.ticks = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the title to a player.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @throws Exception on NMS error
|
||||||
|
*/
|
||||||
|
public void send(Player player) throws Exception {
|
||||||
|
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
||||||
|
// First reset previous settings
|
||||||
|
resetTitle(player);
|
||||||
|
// Send timings first
|
||||||
|
Object handle = getHandle(player);
|
||||||
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
|
Object packet = this.packetTitle.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2],
|
||||||
|
this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
|
// Send if set
|
||||||
|
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
}
|
||||||
|
// Send title
|
||||||
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.title) + "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||||
|
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[0], serialized);
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
if (!this.subtitle.isEmpty()) {
|
||||||
|
// Send subtitle if present
|
||||||
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.subtitle) + "\",color:" + this.subtitleColor.name()
|
||||||
|
.toLowerCase() + "}");
|
||||||
|
packet = this.packetTitle.getConstructor(this.packetActions, getNMSClass("IChatBaseComponent")).newInstance(actions[1], serialized);
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast the title to all players.
|
||||||
|
* @throws Exception on NMS Error
|
||||||
|
*/
|
||||||
|
public void broadcast() throws Exception {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
send(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the title.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @throws Exception on NMS Error
|
||||||
|
*/
|
||||||
|
public void clearTitle(Player player) throws Exception {
|
||||||
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
|
// Send timings first
|
||||||
|
Object handle = getHandle(player);
|
||||||
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
|
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the title settings.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @throws Exception on NMS error.
|
||||||
|
*/
|
||||||
|
public void resetTitle(Player player) throws Exception {
|
||||||
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
|
// Send timings first
|
||||||
|
Object handle = getHandle(player);
|
||||||
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
|
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
||||||
|
sendPacket.invoke(connection, packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the protocol version of the player.
|
||||||
|
*
|
||||||
|
* @param player Player
|
||||||
|
* @return Protocol version
|
||||||
|
* @throws Exception on NMS Error
|
||||||
|
*/
|
||||||
|
private int getProtocolVersion(Player player) throws Exception {
|
||||||
|
Object handle = getHandle(player);
|
||||||
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Object networkManager = getValue("networkManager", connection);
|
||||||
|
return (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if running spigot.
|
||||||
|
*
|
||||||
|
* @return Spigot
|
||||||
|
*/
|
||||||
|
private boolean isSpigot() {
|
||||||
|
return Bukkit.getVersion().contains("Spigot");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get class by url.
|
||||||
|
*
|
||||||
|
* @param namespace Namespace url
|
||||||
|
* @return Class
|
||||||
|
*/
|
||||||
|
private Class<?> getClass(String namespace) {
|
||||||
|
try {
|
||||||
|
return Class.forName(namespace);
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Field getField(String name, Class<?> clazz) throws Exception {
|
||||||
|
return clazz.getDeclaredField(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getValue(String name, Object obj) throws Exception {
|
||||||
|
Field f = getField(name, obj.getClass());
|
||||||
|
f.setAccessible(true);
|
||||||
|
return f.get(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||||
|
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||||
|
int a = classes != null ? classes.length : 0;
|
||||||
|
Class<?>[] types = new Class<?>[a];
|
||||||
|
for (int i = 0; i < a; i++) {
|
||||||
|
types[i] = getPrimitiveType(classes[i]);
|
||||||
|
}
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getHandle(Object obj) {
|
||||||
try {
|
try {
|
||||||
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
||||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
@ -384,31 +369,31 @@ public class HackTitleManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getMethod(final String name, final Class<?> clazz, final Class<?>... paramTypes) {
|
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||||
final Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||||
for (final Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
final Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||||
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
|
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getVersion() {
|
private String getVersion() {
|
||||||
final String name = Bukkit.getServer().getClass().getPackage().getName();
|
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class<?> getNMSClass(final String className) throws ClassNotFoundException {
|
private Class<?> getNMSClass(String className) throws ClassNotFoundException {
|
||||||
final String fullName = "net.minecraft.server." + getVersion() + className;
|
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||||
return Class.forName(fullName);
|
return Class.forName(fullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(final Class<?> clazz, final String name) {
|
private Field getField(Class<?> clazz, String name) {
|
||||||
try {
|
try {
|
||||||
final Field field = clazz.getDeclaredField(name);
|
Field field = clazz.getDeclaredField(name);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
} catch (SecurityException | NoSuchFieldException e) {
|
} catch (SecurityException | NoSuchFieldException e) {
|
||||||
@ -416,18 +401,18 @@ public class HackTitleManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getMethod(final Class<?> clazz, final String name, final Class<?>... args) {
|
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (final Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
if (m.getName().equals(name) && ((args.length == 0) || ClassListEqual(args, m.getParameterTypes()))) {
|
if (m.getName().equals(name) && ((args.length == 0) || classListEqual(args, m.getParameterTypes()))) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ClassListEqual(final Class<?>[] l1, final Class<?>[] l2) {
|
private boolean classListEqual(Class<?>[] l1, Class<?>[] l2) {
|
||||||
if (l1.length != l2.length) {
|
if (l1.length != l2.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -20,31 +20,31 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)));
|
m.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||||
final List<FancyMessage> lines = new ArrayList<>();
|
List<FancyMessage> lines = new ArrayList<>();
|
||||||
for (final PlotMessage tooltip : tooltips) {
|
for (PlotMessage tooltip : tooltips) {
|
||||||
lines.add(tooltip.$(this));
|
lines.add(tooltip.$(this));
|
||||||
}
|
}
|
||||||
m.$(this).formattedTooltip(lines);
|
m.$(this).formattedTooltip(lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void command(final PlotMessage m, final String command) {
|
public void command(PlotMessage m, String command) {
|
||||||
m.$(this).command(command);
|
m.$(this).command(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void text(final PlotMessage m, final String text) {
|
public void text(PlotMessage m, String text) {
|
||||||
m.$(this).then(ChatColor.stripColor(text));
|
m.$(this).then(ChatColor.stripColor(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
public void send(PlotMessage m, PlotPlayer player) {
|
||||||
if (ConsolePlayer.isConsole(player)) {
|
if (ConsolePlayer.isConsole(player)) {
|
||||||
player.sendMessage(m.$(this).toOldMessageFormat());
|
player.sendMessage(m.$(this).toOldMessageFormat());
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +53,7 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggest(final PlotMessage m, final String command) {
|
public void suggest(PlotMessage m, String command) {
|
||||||
m.$(this).suggest(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
|
@Override
|
||||||
public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
|
public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel,
|
||||||
final String[] args) {
|
String[] args) {
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String perm) {
|
public boolean hasPermission(String permission) {
|
||||||
return commandSender.hasPermission(commandLabel);
|
return commandSender.hasPermission(commandLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +66,12 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
|
public List<String> onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String s,
|
||||||
final String[] strings) {
|
String[] strings) {
|
||||||
if (!(commandSender instanceof Player)) {
|
if (!(commandSender instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||||
if (strings.length < 1) {
|
if (strings.length < 1) {
|
||||||
if (strings.length == 0 || "plots".startsWith(s)) {
|
if (strings.length == 0 || "plots".startsWith(s)) {
|
||||||
return Collections.singletonList("plots");
|
return Collections.singletonList("plots");
|
||||||
@ -80,11 +80,11 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (strings.length > 1) {
|
if (strings.length > 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Set<String> tabOptions = new HashSet<>();
|
Set<String> tabOptions = new HashSet<>();
|
||||||
final String arg = strings[0].toLowerCase();
|
String arg = strings[0].toLowerCase();
|
||||||
ArrayList<String> labels = new ArrayList<>();
|
ArrayList<String> labels = new ArrayList<>();
|
||||||
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
for (Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||||
final String label = cmd.getCommand();
|
String label = cmd.getCommand();
|
||||||
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
||||||
aliases.add(label);
|
aliases.add(label);
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
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.OfflinePlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
import com.intellectualcrafters.plot.util.EconHandler;
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
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 {
|
public class BukkitEconHandler extends EconHandler {
|
||||||
|
|
||||||
@ -19,80 +17,80 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
|
|
||||||
public Economy getEconomy() {
|
public Economy getEconomy() {
|
||||||
init();
|
init();
|
||||||
return econ;
|
return this.econ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Permission getPermissions() {
|
public Permission getPermissions() {
|
||||||
init();
|
init();
|
||||||
return perms;
|
return this.perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean init() {
|
public boolean init() {
|
||||||
if (econ == null || perms == null) {
|
if (this.econ == null || this.perms == null) {
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
}
|
}
|
||||||
return econ != null && perms != null;
|
return this.econ != null && this.perms != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupPermissions() {
|
private boolean setupPermissions() {
|
||||||
final RegisteredServiceProvider<Permission> permissionProvider =
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
perms = permissionProvider.getProvider();
|
this.perms = permissionProvider.getProvider();
|
||||||
}
|
}
|
||||||
return perms != null;
|
return this.perms != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupEconomy() {
|
private boolean setupEconomy() {
|
||||||
final RegisteredServiceProvider<Economy> economyProvider =
|
RegisteredServiceProvider<Economy> economyProvider =
|
||||||
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
econ = economyProvider.getProvider();
|
this.econ = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
return econ != null;
|
return this.econ != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMoney(final PlotPlayer player) {
|
public double getMoney(PlotPlayer player) {
|
||||||
final double bal = super.getMoney(player);
|
double bal = super.getMoney(player);
|
||||||
if (Double.isNaN(bal)) {
|
if (Double.isNaN(bal)) {
|
||||||
return econ.getBalance(((BukkitPlayer) player).player);
|
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||||
}
|
}
|
||||||
return bal;
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void withdrawMoney(final PlotPlayer player, final double amount) {
|
public void withdrawMoney(PlotPlayer player, double amount) {
|
||||||
econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void depositMoney(final PlotPlayer player, final double amount) {
|
public void depositMoney(PlotPlayer player, double amount) {
|
||||||
econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void depositMoney(final OfflinePlotPlayer player, final double amount) {
|
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||||
econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (value) {
|
||||||
perms.playerAdd(world, player, perm);
|
this.perms.playerAdd(world, player, perm);
|
||||||
} else {
|
} else {
|
||||||
perms.playerRemove(world, player, perm);
|
this.perms.playerRemove(world, player, perm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(final String world, final String player, final String perm) {
|
public boolean hasPermission(String world, String player, String perm) {
|
||||||
return perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getBalance(PlotPlayer player) {
|
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 class BukkitEventUtil extends EventUtil {
|
||||||
|
|
||||||
public Player getPlayer(final PlotPlayer player) {
|
public Player getPlayer(PlotPlayer player) {
|
||||||
if (player instanceof BukkitPlayer) {
|
if (player instanceof BukkitPlayer) {
|
||||||
return ((BukkitPlayer) player).player;
|
return ((BukkitPlayer) player).player;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean callEvent(final Event event) {
|
public boolean callEvent(Event event) {
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean callClear(final Plot plot) {
|
public boolean callClear(Plot plot) {
|
||||||
return callEvent(new PlotClearEvent(plot));
|
return callEvent(new PlotClearEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void callDelete(final Plot plot) {
|
public void callDelete(Plot plot) {
|
||||||
callEvent(new PlotDeleteEvent(plot));
|
callEvent(new PlotDeleteEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean callFlagAdd(final Flag flag, final Plot plot) {
|
public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean callFlagRemove(final Flag flag, final Plot plot) {
|
public boolean callFlagRemove(Flag flag, Plot plot) {
|
||||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getArea().worldname), plot, plots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void callEntry(final PlotPlayer player, final Plot plot) {
|
public void callEntry(PlotPlayer player, Plot plot) {
|
||||||
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void callLeave(final PlotPlayer player, final Plot plot) {
|
public void callLeave(PlotPlayer player, Plot plot) {
|
||||||
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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));
|
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean callFlagRemove(final Flag flag, final PlotCluster cluster) {
|
public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
|
||||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating) {
|
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||||
final PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
return event.getRating();
|
return event.getRating();
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
}
|
}
|
||||||
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(final int a, final int b, final Biome c) {
|
public void setBiome(int a, int b, Biome c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Biome getBiome(final int a, final int b) {
|
public Biome getBiome(int a, int b) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -76,8 +76,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
|
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
final short[][][] oldblocks = new short[256][width][length];
|
final short[][][] oldBlocks = new short[256][width][length];
|
||||||
final short[][][] newblocks = new short[256][width][length];
|
final short[][][] newBlocks = new short[256][width][length];
|
||||||
|
|
||||||
final Runnable run = new Runnable() {
|
final Runnable run = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -86,38 +86,38 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
@Override
|
@Override
|
||||||
public void run(int[] value) {
|
public void run(int[] value) {
|
||||||
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
|
||||||
final int X = value[0];
|
int X = value[0];
|
||||||
final int Z = value[1];
|
int Z = value[1];
|
||||||
final short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
||||||
final int xb = (X << 4) - bx;
|
int xb = (X << 4) - bx;
|
||||||
final int zb = (Z << 4) - bz;
|
int zb = (Z << 4) - bz;
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
if (result[i] == null) {
|
if (result[i] == null) {
|
||||||
for (int j = 0; j < 4096; j++) {
|
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) {
|
if (x < 0 || x >= width) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int z = MainUtil.z_loc[i][j] + zb;
|
int z = MainUtil.z_loc[i][j] + zb;
|
||||||
if (z < 0 || z >= length) {
|
if (z < 0 || z >= length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
oldblocks[y][x][z] = 0;
|
oldBlocks[y][x][z] = 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < result[i].length; j++) {
|
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) {
|
if (x < 0 || x >= width) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int z = MainUtil.z_loc[i][j] + zb;
|
int z = MainUtil.z_loc[i][j] + zb;
|
||||||
if (z < 0 || z >= length) {
|
if (z < 0 || z >= length) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
oldblocks[y][x][z] = result[i][j];
|
oldBlocks[y][x][z] = result[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,19 +128,19 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final int size = width * length;
|
int size = width * length;
|
||||||
final int[] changes = new int[size];
|
int[] changes = new int[size];
|
||||||
final int[] faces = new int[size];
|
int[] faces = new int[size];
|
||||||
final int[] data = new int[size];
|
int[] data = new int[size];
|
||||||
final int[] air = new int[size];
|
int[] air = new int[size];
|
||||||
final int[] variety = new int[size];
|
int[] variety = new int[size];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int z = 0; z < length; z++) {
|
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++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
final short old = oldblocks[y][x][z];
|
short old = oldBlocks[y][x][z];
|
||||||
final short now = newblocks[y][x][z];
|
short now = newBlocks[y][x][z];
|
||||||
if (old != now) {
|
if (old != now) {
|
||||||
changes[i]++;
|
changes[i]++;
|
||||||
}
|
}
|
||||||
@ -150,28 +150,28 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
// check vertices
|
// check vertices
|
||||||
// modifications_adjacent
|
// modifications_adjacent
|
||||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
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]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
if (newblocks[y][x - 1][z] == 0) {
|
if (newBlocks[y][x - 1][z] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
if (newblocks[y][x][z - 1] == 0) {
|
if (newBlocks[y][x][z - 1] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
if (newblocks[y + 1][x][z] == 0) {
|
if (newBlocks[y + 1][x][z] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
if (newblocks[y][x + 1][z] == 0) {
|
if (newBlocks[y][x + 1][z] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
if (newblocks[y][x][z + 1] == 0) {
|
if (newBlocks[y][x][z + 1] == 0) {
|
||||||
faces[i]++;
|
faces[i]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Material material = Material.getMaterial(now);
|
Material material = Material.getMaterial(now);
|
||||||
final Class<? extends MaterialData> md = material.getData();
|
Class<? extends MaterialData> md = material.getData();
|
||||||
if (md.equals(Directional.class)) {
|
if (md.equals(Directional.class)) {
|
||||||
data[i] += 8;
|
data[i] += 8;
|
||||||
} else if (!md.equals(MaterialData.class)) {
|
} else if (!md.equals(MaterialData.class)) {
|
||||||
@ -188,7 +188,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
// put in analysis obj
|
// put in analysis obj
|
||||||
|
|
||||||
// run whenDone
|
// run whenDone
|
||||||
final PlotAnalysis analysis = new PlotAnalysis();
|
PlotAnalysis analysis = new PlotAnalysis();
|
||||||
analysis.changes = (int) (MathMan.getMean(changes) * 100);
|
analysis.changes = (int) (MathMan.getMean(changes) * 100);
|
||||||
analysis.faces = (int) (MathMan.getMean(faces) * 100);
|
analysis.faces = (int) (MathMan.getMean(faces) * 100);
|
||||||
analysis.data = (int) (MathMan.getMean(data) * 100);
|
analysis.data = (int) (MathMan.getMean(data) * 100);
|
||||||
@ -217,8 +217,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(int[] value) {
|
public void run(int[] value) {
|
||||||
final int X = value[0];
|
int X = value[0];
|
||||||
final int Z = value[1];
|
int Z = value[1];
|
||||||
worldObj.loadChunk(X, Z);
|
worldObj.loadChunk(X, Z);
|
||||||
int minX;
|
int minX;
|
||||||
if (X == cbx) {
|
if (X == cbx) {
|
||||||
@ -245,20 +245,20 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
maxZ = 16;
|
maxZ = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int cbx = X << 4;
|
int cbx = X << 4;
|
||||||
final int cbz = Z << 4;
|
int cbz = Z << 4;
|
||||||
|
|
||||||
final int xb = cbx - bx;
|
int xb = cbx - bx;
|
||||||
final int zb = cbz - bz;
|
int zb = cbz - bz;
|
||||||
for (int x = minX; x <= maxX; x++) {
|
for (int x = minX; x <= maxX; x++) {
|
||||||
final int xx = cbx + x;
|
int xx = cbx + x;
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
final int zz = cbz + z;
|
int zz = cbz + z;
|
||||||
for (int y = 0; y < 256; y++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
final Block block = worldObj.getBlockAt(xx, y, zz);
|
Block block = worldObj.getBlockAt(xx, y, zz);
|
||||||
final int xr = xb + x;
|
int xr = xb + x;
|
||||||
final int zr = zb + z;
|
int zr = zb + z;
|
||||||
newblocks[y][xr][zr] = (short) block.getTypeId();
|
newBlocks[y][xr][zr] = (short) block.getTypeId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,17 +275,17 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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,
|
public int checkModified(String worldname, int x1, int x2, int y1, int y2, int z1, int z2,
|
||||||
final PlotBlock[] blocks) {
|
PlotBlock[] blocks) {
|
||||||
final World world = BukkitUtil.getWorld(worldname);
|
World world = BukkitUtil.getWorld(worldname);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int y = y1; y <= y2; y++) {
|
for (int y = y1; y <= y2; y++) {
|
||||||
for (int x = x1; x <= x2; x++) {
|
for (int x = x1; x <= x2; x++) {
|
||||||
for (int z = z1; z <= z2; z++) {
|
for (int z = z1; z <= z2; z++) {
|
||||||
final Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
final int id = block.getTypeId();
|
int id = block.getTypeId();
|
||||||
boolean same = false;
|
boolean same = false;
|
||||||
for (final PlotBlock p : blocks) {
|
for (PlotBlock p : blocks) {
|
||||||
if (id == p.id) {
|
if (id == p.id) {
|
||||||
same = true;
|
same = true;
|
||||||
break;
|
break;
|
||||||
@ -301,15 +301,15 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
public int get_ey(String worldname, int sx, int ex, int sz, int ez, int sy) {
|
||||||
final World world = BukkitUtil.getWorld(worldname);
|
World world = BukkitUtil.getWorld(worldname);
|
||||||
final int maxY = world.getMaxHeight();
|
int maxY = world.getMaxHeight();
|
||||||
int ey = sy;
|
int ey = sy;
|
||||||
for (int x = sx; x <= ex; x++) {
|
for (int x = sx; x <= ex; x++) {
|
||||||
for (int z = sz; z <= ez; z++) {
|
for (int z = sz; z <= ez; z++) {
|
||||||
for (int y = sy; y < maxY; y++) {
|
for (int y = sy; y < maxY; y++) {
|
||||||
if (y > ey) {
|
if (y > ey) {
|
||||||
final Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
if (!block.getType().equals(Material.AIR)) {
|
if (!block.getType().equals(Material.AIR)) {
|
||||||
ey = y;
|
ey = y;
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BukkitInventoryUtil extends InventoryUtil {
|
public class BukkitInventoryUtil extends InventoryUtil {
|
||||||
|
|
||||||
public static ItemStack getItem(final PlotItemStack item) {
|
public static ItemStack getItem(PlotItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return 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;
|
ItemMeta meta = null;
|
||||||
if (item.name != null) {
|
if (item.name != null) {
|
||||||
meta = stack.getItemMeta();
|
meta = stack.getItemMeta();
|
||||||
@ -33,8 +33,8 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
meta = stack.getItemMeta();
|
meta = stack.getItemMeta();
|
||||||
}
|
}
|
||||||
final List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
for (final String entry : item.lore) {
|
for (String entry : item.lore) {
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
@ -46,12 +46,12 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open(final PlotInventory inv) {
|
public void open(PlotInventory inv) {
|
||||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
final Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||||
final PlotItemStack[] items = inv.getItems();
|
PlotItemStack[] items = inv.getItems();
|
||||||
for (int i = 0; i < inv.size * 9; i++) {
|
for (int i = 0; i < inv.size * 9; i++) {
|
||||||
final PlotItemStack item = items[i];
|
PlotItemStack item = items[i];
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
inventory.setItem(i, getItem(item));
|
inventory.setItem(i, getItem(item));
|
||||||
}
|
}
|
||||||
@ -61,19 +61,19 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(final PlotInventory inv) {
|
public void close(PlotInventory inv) {
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inv.player.deleteMeta("inventory");
|
inv.player.deleteMeta("inventory");
|
||||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
bp.player.closeInventory();
|
bp.player.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItem(final PlotInventory inv, final int index, final PlotItemStack item) {
|
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
final InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,22 +81,22 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
bp.player.updateInventory();
|
bp.player.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotItemStack getItem(final ItemStack item) {
|
public PlotItemStack getItem(ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final int id = item.getTypeId();
|
int id = item.getTypeId();
|
||||||
final short data = item.getDurability();
|
short data = item.getDurability();
|
||||||
final int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
String name = null;
|
String name = null;
|
||||||
String[] lore = null;
|
String[] lore = null;
|
||||||
if (item.hasItemMeta()) {
|
if (item.hasItemMeta()) {
|
||||||
final ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (meta.hasDisplayName()) {
|
if (meta.hasDisplayName()) {
|
||||||
name = meta.getDisplayName();
|
name = meta.getDisplayName();
|
||||||
}
|
}
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
final List<String> itemLore = meta.getLore();
|
List<String> itemLore = meta.getLore();
|
||||||
lore = itemLore.toArray(new String[itemLore.size()]);
|
lore = itemLore.toArray(new String[itemLore.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,10 +104,10 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotItemStack[] getItems(final PlotPlayer player) {
|
public PlotItemStack[] getItems(PlotPlayer player) {
|
||||||
final BukkitPlayer bp = (BukkitPlayer) player;
|
BukkitPlayer bp = (BukkitPlayer) player;
|
||||||
final PlayerInventory inv = bp.player.getInventory();
|
PlayerInventory inv = bp.player.getInventory();
|
||||||
final PlotItemStack[] items = new PlotItemStack[36];
|
PlotItemStack[] items = new PlotItemStack[36];
|
||||||
for (int i = 0; i < 36; i++) {
|
for (int i = 0; i < 36; i++) {
|
||||||
items[i] = getItem(inv.getItem(i));
|
items[i] = getItem(inv.getItem(i));
|
||||||
}
|
}
|
||||||
@ -115,12 +115,12 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpen(final PlotInventory inv) {
|
public boolean isOpen(PlotInventory inv) {
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
final InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING && opened.getTitle() == null;
|
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING && opened.getTitle() == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,35 +16,35 @@ public class BukkitPlainChatManager extends ChatManager<List<StringBuilder>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void color(final PlotMessage m, final String color) {
|
public void color(PlotMessage m, String color) {
|
||||||
final List<StringBuilder> parts = m.$(this);
|
List<StringBuilder> parts = m.$(this);
|
||||||
parts.get(parts.size() - 1).insert(0, color);
|
parts.get(parts.size() - 1).insert(0, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tooltip(final PlotMessage m, final PlotMessage... tooltips) {
|
public void tooltip(PlotMessage m, PlotMessage... tooltips) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void command(final PlotMessage m, final String command) {
|
public void command(PlotMessage m, String command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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)));
|
m.$(this).add(new StringBuilder(ChatColor.stripColor(text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(final PlotMessage m, final PlotPlayer player) {
|
public void send(PlotMessage m, PlotPlayer player) {
|
||||||
final StringBuilder built = new StringBuilder();
|
StringBuilder built = new StringBuilder();
|
||||||
for (final StringBuilder sb : m.$(this)) {
|
for (StringBuilder sb : m.$(this)) {
|
||||||
built.append(sb);
|
built.append(sb);
|
||||||
}
|
}
|
||||||
player.sendMessage(built.toString());
|
player.sendMessage(built.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler
|
* Schematic Handler.
|
||||||
*
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class BukkitSchematicHandler extends SchematicHandler {
|
public class BukkitSchematicHandler extends SchematicHandler {
|
||||||
|
|
||||||
@ -66,10 +63,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
// Main positions
|
// Main positions
|
||||||
Location[] corners = MainUtil.getCorners(world, regions);
|
Location[] corners = MainUtil.getCorners(world, regions);
|
||||||
final Location bot = corners[0];
|
final Location bot = corners[0];
|
||||||
final Location top = corners[1];
|
Location top = corners[1];
|
||||||
|
|
||||||
final int width = (top.getX() - bot.getX()) + 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;
|
final int length = (top.getZ() - bot.getZ()) + 1;
|
||||||
// Main Schematic tag
|
// Main Schematic tag
|
||||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||||
@ -136,16 +133,16 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) {
|
while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) {
|
||||||
// save schematics
|
// save schematics
|
||||||
final ChunkLoc chunk = chunks.remove(0);
|
ChunkLoc chunk = chunks.remove(0);
|
||||||
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||||
if (!bc.load(false)) {
|
if (!bc.load(false)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int X = chunk.x;
|
int X = chunk.x;
|
||||||
final int Z = chunk.z;
|
int Z = chunk.z;
|
||||||
int xxb = X << 4;
|
int xxb = X << 4;
|
||||||
int zzb = Z << 4;
|
int zzb = Z << 4;
|
||||||
int xxt = xxb + 15;
|
int xxt = xxb + 15;
|
||||||
@ -164,16 +161,16 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
zzt = p2z;
|
zzt = p2z;
|
||||||
}
|
}
|
||||||
for (int y = sy; y <= Math.min(255, ey); y++) {
|
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||||
final int ry = y - sy;
|
int ry = y - sy;
|
||||||
final int i1 = ry * width * length;
|
int i1 = ry * width * length;
|
||||||
for (int z = zzb; z <= zzt; z++) {
|
for (int z = zzb; z <= zzt; z++) {
|
||||||
final int rz = z - bz;
|
int rz = z - bz;
|
||||||
final int i2 = i1 + (rz * width);
|
int i2 = i1 + (rz * width);
|
||||||
for (int x = xxb; x <= xxt; x++) {
|
for (int x = xxb; x <= xxt; x++) {
|
||||||
final int rx = x - bx;
|
int rx = x - bx;
|
||||||
final int index = i2 + rx;
|
int index = i2 + rx;
|
||||||
final Block block = worldObj.getBlockAt(x, y, z);
|
Block block = worldObj.getBlockAt(x, y, z);
|
||||||
final int id = block.getTypeId();
|
int id = block.getTypeId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
case 2:
|
case 2:
|
||||||
@ -281,13 +278,13 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
|||||||
case 151:
|
case 151:
|
||||||
case 178: {
|
case 178: {
|
||||||
// TODO implement fully
|
// TODO implement fully
|
||||||
final BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
final StateWrapper wrapper = new StateWrapper(state);
|
StateWrapper wrapper = new StateWrapper(state);
|
||||||
final CompoundTag rawTag = wrapper.getTag();
|
CompoundTag rawTag = wrapper.getTag();
|
||||||
if (rawTag != null) {
|
if (rawTag != null) {
|
||||||
final Map<String, Tag> values = new HashMap<>();
|
Map<String, Tag> values = new HashMap<>();
|
||||||
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
for (Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
||||||
values.put(entry.getKey(), entry.getValue());
|
values.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
values.put("id", new StringTag("id", wrapper.getId()));
|
values.put("id", new StringTag("id", wrapper.getId()));
|
||||||
|
@ -29,13 +29,13 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
if (!SetupUtils.generators.isEmpty()) {
|
if (!SetupUtils.generators.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String testWorld = "CheckingPlotSquaredGenerator";
|
String testWorld = "CheckingPlotSquaredGenerator";
|
||||||
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
final ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
||||||
if (generator != null) {
|
if (generator != null) {
|
||||||
PS.get().removePlotAreas(testWorld);
|
PS.get().removePlotAreas(testWorld);
|
||||||
final String name = plugin.getDescription().getName();
|
String name = plugin.getDescription().getName();
|
||||||
GeneratorWrapper<?> wrapped;
|
GeneratorWrapper<?> wrapped;
|
||||||
if (generator instanceof GeneratorWrapper<?>) {
|
if (generator instanceof GeneratorWrapper<?>) {
|
||||||
wrapped = (GeneratorWrapper<?>) generator;
|
wrapped = (GeneratorWrapper<?>) generator;
|
||||||
@ -49,10 +49,10 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String setupWorld(final SetupObject object) {
|
public String setupWorld(SetupObject object) {
|
||||||
SetupUtils.manager.updateGenerators();
|
SetupUtils.manager.updateGenerators();
|
||||||
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
|
||||||
final String world = object.world;
|
String world = object.world;
|
||||||
int type = object.type;
|
int type = object.type;
|
||||||
String worldPath = "worlds." + object.world;
|
String worldPath = "worlds." + object.world;
|
||||||
if (!PS.get().config.contains(worldPath)) {
|
if (!PS.get().config.contains(worldPath)) {
|
||||||
@ -69,7 +69,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
||||||
HashMap<String, Object> options = new HashMap<>();
|
HashMap<String, Object> options = new HashMap<>();
|
||||||
for (final ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
options.put(step.getConstant(), step.getValue());
|
options.put(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
options.put("generator.type", object.type);
|
options.put("generator.type", object.type);
|
||||||
@ -98,7 +98,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
for (final ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
PS.get().config.set("worlds." + world + "." + "generator.type", object.type);
|
||||||
@ -114,7 +114,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 0: {
|
case 0: {
|
||||||
for (final ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -122,7 +122,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
PS.get().config.save(PS.get().configFile);
|
PS.get().config.save(PS.get().configFile);
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (object.setupGenerator != null) {
|
if (object.setupGenerator != null) {
|
||||||
@ -142,7 +142,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final WorldCreator wc = new WorldCreator(object.world);
|
WorldCreator wc = new WorldCreator(object.world);
|
||||||
wc.generator(object.setupGenerator);
|
wc.generator(object.setupGenerator);
|
||||||
wc.environment(Environment.NORMAL);
|
wc.environment(Environment.NORMAL);
|
||||||
Bukkit.createWorld(wc);
|
Bukkit.createWorld(wc);
|
||||||
@ -166,34 +166,34 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
return object.world;
|
return object.world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGenerator(final String world, final String generator) {
|
public void setGenerator(String world, String generator) {
|
||||||
if ((Bukkit.getWorlds().isEmpty()) || !Bukkit.getWorlds().get(0).getName().equals(world)) {
|
if (Bukkit.getWorlds().isEmpty() || !Bukkit.getWorlds().get(0).getName().equals(world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final File file = new File("bukkit.yml").getAbsoluteFile();
|
File file = new File("bukkit.yml").getAbsoluteFile();
|
||||||
final YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||||
yml.set("worlds." + world + ".generator", generator);
|
yml.set("worlds." + world + ".generator", generator);
|
||||||
try {
|
try {
|
||||||
yml.save(file);
|
yml.save(file);
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGenerator(final PlotArea plotworld) {
|
public String getGenerator(PlotArea plotworld) {
|
||||||
if (SetupUtils.generators.isEmpty()) {
|
if (SetupUtils.generators.isEmpty()) {
|
||||||
updateGenerators();
|
updateGenerators();
|
||||||
}
|
}
|
||||||
final World world = Bukkit.getWorld(plotworld.worldname);
|
World world = Bukkit.getWorld(plotworld.worldname);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final ChunkGenerator generator = world.getGenerator();
|
ChunkGenerator generator = world.getGenerator();
|
||||||
if (!(generator instanceof BukkitPlotGenerator)) {
|
if (!(generator instanceof BukkitPlotGenerator)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (final Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
|
for (Entry<String, GeneratorWrapper<?>> entry : generators.entrySet()) {
|
||||||
GeneratorWrapper<?> current = entry.getValue();
|
GeneratorWrapper<?> current = entry.getValue();
|
||||||
if (current.equals(generator)) {
|
if (current.equals(generator)) {
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
|
@ -7,37 +7,38 @@ import org.bukkit.Bukkit;
|
|||||||
public class BukkitTaskManager extends TaskManager {
|
public class BukkitTaskManager extends TaskManager {
|
||||||
|
|
||||||
@Override
|
@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);
|
return BukkitMain.THIS.getServer().getScheduler().scheduleSyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") @Override
|
@SuppressWarnings("deprecation")
|
||||||
public int taskRepeatAsync(final Runnable r, final int interval) {
|
@Override
|
||||||
|
public int taskRepeatAsync(Runnable r, int interval) {
|
||||||
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
return BukkitMain.THIS.getServer().getScheduler().scheduleAsyncRepeatingTask(BukkitMain.THIS, r, interval, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void taskAsync(final Runnable r) {
|
public void taskAsync(Runnable r) {
|
||||||
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
|
BukkitMain.THIS.getServer().getScheduler().runTaskAsynchronously(BukkitMain.THIS, r).getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void task(final Runnable r) {
|
public void task(Runnable r) {
|
||||||
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
|
BukkitMain.THIS.getServer().getScheduler().runTask(BukkitMain.THIS, r).getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
BukkitMain.THIS.getServer().getScheduler().runTaskLater(BukkitMain.THIS, r, delay).getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
BukkitMain.THIS.getServer().getScheduler().runTaskLaterAsynchronously(BukkitMain.THIS, r, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelTask(final int task) {
|
public void cancelTask(int task) {
|
||||||
if (task != -1) {
|
if (task != -1) {
|
||||||
Bukkit.getScheduler().cancelTask(task);
|
Bukkit.getScheduler().cancelTask(task);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import org.bukkit.material.Step;
|
|||||||
import org.bukkit.material.Tree;
|
import org.bukkit.material.Tree;
|
||||||
import org.bukkit.material.WoodenStep;
|
import org.bukkit.material.WoodenStep;
|
||||||
import org.bukkit.material.Wool;
|
import org.bukkit.material.Wool;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -42,26 +43,26 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
private static Player lastPlayer = null;
|
private static Player lastPlayer = null;
|
||||||
private static PlotPlayer lastPlotPlayer = null;
|
private static PlotPlayer lastPlotPlayer = null;
|
||||||
|
|
||||||
public static void removePlayer(final String plr) {
|
public static void removePlayer(String plr) {
|
||||||
lastPlayer = null;
|
lastPlayer = null;
|
||||||
lastPlotPlayer = null;
|
lastPlotPlayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotPlayer getPlayer(final OfflinePlayer op) {
|
public static PlotPlayer getPlayer(OfflinePlayer op) {
|
||||||
if (op.isOnline()) {
|
if (op.isOnline()) {
|
||||||
return getPlayer(op.getPlayer());
|
return getPlayer(op.getPlayer());
|
||||||
}
|
}
|
||||||
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||||
player.loadData();
|
player.loadData();
|
||||||
return new BukkitPlayer(player, true);
|
return new BukkitPlayer(player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlotPlayer getPlayer(final Player player) {
|
public static PlotPlayer getPlayer(Player player) {
|
||||||
if (player == lastPlayer) {
|
if (player == lastPlayer) {
|
||||||
return lastPlotPlayer;
|
return lastPlotPlayer;
|
||||||
}
|
}
|
||||||
final String name = player.getName();
|
String name = player.getName();
|
||||||
final PlotPlayer pp = UUIDHandler.getPlayer(name);
|
PlotPlayer pp = UUIDHandler.getPlayer(name);
|
||||||
if (pp != null) {
|
if (pp != null) {
|
||||||
return pp;
|
return pp;
|
||||||
}
|
}
|
||||||
@ -71,63 +72,64 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
return lastPlotPlayer;
|
return lastPlotPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocation(final org.bukkit.Location loc) {
|
public static Location getLocation(org.bukkit.Location location) {
|
||||||
return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()));
|
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) {
|
public static org.bukkit.Location getLocation(Location location) {
|
||||||
return new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ());
|
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 (StringMan.isEqual(string, lastString)) {
|
||||||
if (lastWorld != null) {
|
if (lastWorld != null) {
|
||||||
return lastWorld;
|
return lastWorld;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final World world = Bukkit.getWorld(string);
|
World world = Bukkit.getWorld(string);
|
||||||
lastString = string;
|
lastString = string;
|
||||||
lastWorld = world;
|
lastWorld = world;
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getWorld(final Entity entity) {
|
public static String getWorld(Entity entity) {
|
||||||
return entity.getWorld().getName();
|
return entity.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Entity> getEntities(final String worldname) {
|
public static List<Entity> getEntities(String worldname) {
|
||||||
return getWorld(worldname).getEntities();
|
return getWorld(worldname).getEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocation(final Entity entity) {
|
public static Location getLocation(Entity entity) {
|
||||||
final org.bukkit.Location loc = entity.getLocation();
|
org.bukkit.Location loc = entity.getLocation();
|
||||||
final String world = loc.getWorld().getName();
|
String world = loc.getWorld().getName();
|
||||||
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Location getLocationFull(final Entity entity) {
|
public static Location getLocationFull(Entity entity) {
|
||||||
final org.bukkit.Location loc = entity.getLocation();
|
org.bukkit.Location loc = entity.getLocation();
|
||||||
return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()),
|
return new Location(loc.getWorld().getName(), MathMan.roundInt(loc.getX()), MathMan.roundInt(loc.getY()), MathMan.roundInt(loc.getZ()),
|
||||||
loc.getYaw(), loc.getPitch());
|
loc.getYaw(), loc.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWorld(final String world) {
|
public boolean isWorld(String world) {
|
||||||
return getWorld(world) != null;
|
return getWorld(world) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
return getWorld(world).getBiome(x, z).name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSign(final String worldname, final int x, final int y, final int z, final String[] lines) {
|
public void setSign(String worldname, int x, int y, int z, String[] lines) {
|
||||||
final World world = getWorld(worldname);
|
World world = getWorld(worldname);
|
||||||
final Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
// block.setType(Material.AIR);
|
// block.setType(Material.AIR);
|
||||||
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
|
block.setTypeIdAndData(Material.WALL_SIGN.getId(), (byte) 2, false);
|
||||||
final BlockState blockstate = block.getState();
|
BlockState blockstate = block.getState();
|
||||||
if (blockstate instanceof Sign) {
|
if (blockstate instanceof Sign) {
|
||||||
final Sign sign = (Sign) blockstate;
|
final Sign sign = (Sign) blockstate;
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
@ -144,11 +146,11 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSign(final Location loc) {
|
public String[] getSign(Location location) {
|
||||||
final Block block = getWorld(loc.getWorld()).getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
Block block = getWorld(location.getWorld()).getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
if (block.getState() instanceof Sign) {
|
if (block.getState() instanceof Sign) {
|
||||||
final Sign sign = (Sign) block.getState();
|
Sign sign = (Sign) block.getState();
|
||||||
return sign.getLines();
|
return sign.getLines();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,16 +158,16 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Location getSpawn(final String world) {
|
public Location getSpawn(String world) {
|
||||||
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||||
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(), temp.getYaw(), temp.getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSpawn(Location loc) {
|
public void setSpawn(Location location) {
|
||||||
World world = getWorld(loc.getWorld());
|
World world = getWorld(location.getWorld());
|
||||||
if (world != null) {
|
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
|
@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();
|
return getWorld(world).getHighestBlockAt(x, z).getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBiomeFromString(final String biomeStr) {
|
public int getBiomeFromString(String biomeStr) {
|
||||||
try {
|
try {
|
||||||
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||||
return Arrays.asList(Biome.values()).indexOf(biome);
|
return Arrays.asList(Biome.values()).indexOf(biome);
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getBiomeList() {
|
public String[] getBiomeList() {
|
||||||
final Biome[] biomes = Biome.values();
|
Biome[] biomes = Biome.values();
|
||||||
final String[] list = new String[biomes.length];
|
String[] list = new String[biomes.length];
|
||||||
for (int i = 0; i < biomes.length; i++) {
|
for (int i = 0; i < biomes.length; i++) {
|
||||||
list[i] = biomes[i].name();
|
list[i] = biomes[i].name();
|
||||||
}
|
}
|
||||||
@ -203,18 +205,18 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addItems(final String worldname, final PlotItem items) {
|
public boolean addItems(String worldName, PlotItem items) {
|
||||||
final World world = getWorld(worldname);
|
World world = getWorld(worldName);
|
||||||
final Block block = world.getBlockAt(items.x, items.y, items.z);
|
Block block = world.getBlockAt(items.x, items.y, items.z);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof InventoryHolder) {
|
if (state instanceof InventoryHolder) {
|
||||||
final InventoryHolder holder = (InventoryHolder) state;
|
InventoryHolder holder = (InventoryHolder) state;
|
||||||
final Inventory inv = holder.getInventory();
|
Inventory inv = holder.getInventory();
|
||||||
for (int i = 0; i < items.id.length; i++) {
|
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);
|
inv.addItem(item);
|
||||||
}
|
}
|
||||||
state.update(true);
|
state.update(true);
|
||||||
@ -224,11 +226,11 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBlockSolid(final PlotBlock block) {
|
public boolean isBlockSolid(PlotBlock block) {
|
||||||
try {
|
try {
|
||||||
final Material material = Material.getMaterial(block.id);
|
Material material = Material.getMaterial(block.id);
|
||||||
if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
|
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()
|
if (data.equals(MaterialData.class) && !material.isTransparent() && material.isOccluding()
|
||||||
|| data.equals(Tree.class)
|
|| data.equals(Tree.class)
|
||||||
|| data.equals(Sandstone.class)
|
|| data.equals(Sandstone.class)
|
||||||
@ -245,16 +247,16 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClosestMatchingName(final PlotBlock block) {
|
public String getClosestMatchingName(PlotBlock block) {
|
||||||
try {
|
try {
|
||||||
return Material.getMaterial(block.id).name();
|
return Material.getMaterial(block.id).name();
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,13 +264,14 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
@Override
|
@Override
|
||||||
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||||
try {
|
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));
|
return new StringComparison<PlotBlock>().new ComparisonResult(0, new PlotBlock((short) material.getId(), (byte) 0));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
//ignored
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
byte data;
|
byte data;
|
||||||
final String[] split = name.split(":");
|
String[] split = name.split(":");
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
data = Byte.parseByte(split[1]);
|
data = Byte.parseByte(split[1]);
|
||||||
name = split[0];
|
name = split[0];
|
||||||
@ -281,23 +284,24 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
id = Short.parseShort(split[0]);
|
id = Short.parseShort(split[0]);
|
||||||
match = 0;
|
match = 0;
|
||||||
} else {
|
} 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;
|
match = comparison.match;
|
||||||
id = (short) comparison.best.getId();
|
id = (short) comparison.best.getId();
|
||||||
}
|
}
|
||||||
final PlotBlock block = new PlotBlock(id, data);
|
PlotBlock block = new PlotBlock(id, data);
|
||||||
final StringComparison<PlotBlock> outer = new StringComparison<>();
|
StringComparison<PlotBlock> outer = new StringComparison<>();
|
||||||
return outer.new ComparisonResult(match, block);
|
return outer.new ComparisonResult(match, block);
|
||||||
|
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
//ignored
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiomes(final String worldname, RegionWrapper region, final String biomeStr) {
|
public void setBiomes(String worldName, RegionWrapper region, String biomeStr) {
|
||||||
final World world = getWorld(worldname);
|
World world = getWorld(worldName);
|
||||||
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||||
for (int x = region.minX; x <= region.maxX; x++) {
|
for (int x = region.minX; x <= region.maxX; x++) {
|
||||||
for (int z = region.minZ; z <= region.maxZ; z++) {
|
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||||
world.setBiome(x, z, biome);
|
world.setBiome(x, z, biome);
|
||||||
@ -306,9 +310,9 @@ public class BukkitUtil extends WorldUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotBlock getBlock(final Location loc) {
|
public PlotBlock getBlock(Location location) {
|
||||||
final World world = getWorld(loc.getWorld());
|
World world = getWorld(location.getWorld());
|
||||||
final Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
return PlotBlock.EVERYTHING;
|
return PlotBlock.EVERYTHING;
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,24 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
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.lang.reflect.InvocationTargetException;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
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.logging.Level;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
@ -76,13 +87,13 @@ public class Metrics {
|
|||||||
*/
|
*/
|
||||||
private volatile BukkitTask task = null;
|
private volatile BukkitTask task = null;
|
||||||
|
|
||||||
public Metrics(final Plugin plugin) throws IOException {
|
public Metrics(Plugin plugin) throws IOException {
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw new IllegalArgumentException("Plugin cannot be null");
|
throw new IllegalArgumentException("Plugin cannot be null");
|
||||||
}
|
}
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
guid = UUID.randomUUID().toString();
|
this.guid = UUID.randomUUID().toString();
|
||||||
debug = false;
|
this.debug = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,19 +103,19 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return byte[] the file as a byte array
|
* @return byte[] the file as a byte array
|
||||||
*/
|
*/
|
||||||
public static byte[] gzip(final String input) {
|
public static byte[] gzip(String input) {
|
||||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
GZIPOutputStream gzos = null;
|
GZIPOutputStream gzos = null;
|
||||||
try {
|
try {
|
||||||
gzos = new GZIPOutputStream(baos);
|
gzos = new GZIPOutputStream(baos);
|
||||||
gzos.write(input.getBytes("UTF-8"));
|
gzos.write(input.getBytes("UTF-8"));
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
if (gzos != null) {
|
if (gzos != null) {
|
||||||
try {
|
try {
|
||||||
gzos.close();
|
gzos.close();
|
||||||
} catch (final IOException ignore) {
|
} catch (IOException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,14 +131,14 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @throws UnsupportedEncodingException
|
* @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;
|
boolean isValueNumeric = false;
|
||||||
try {
|
try {
|
||||||
if (value.equals("0") || !value.endsWith("0")) {
|
if (value.equals("0") || !value.endsWith("0")) {
|
||||||
Double.parseDouble(value);
|
Double.parseDouble(value);
|
||||||
isValueNumeric = true;
|
isValueNumeric = true;
|
||||||
}
|
}
|
||||||
} catch (final NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
isValueNumeric = false;
|
isValueNumeric = false;
|
||||||
}
|
}
|
||||||
if (json.charAt(json.length() - 1) != '{') {
|
if (json.charAt(json.length() - 1) != '{') {
|
||||||
@ -149,11 +160,11 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private static String escapeJSON(final String text) {
|
private static String escapeJSON(String text) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append('"');
|
builder.append('"');
|
||||||
for (int index = 0; index < text.length(); index++) {
|
for (int index = 0; index < text.length(); index++) {
|
||||||
final char chr = text.charAt(index);
|
char chr = text.charAt(index);
|
||||||
switch (chr) {
|
switch (chr) {
|
||||||
case '"':
|
case '"':
|
||||||
case '\\':
|
case '\\':
|
||||||
@ -174,7 +185,7 @@ public class Metrics {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (chr < ' ') {
|
if (chr < ' ') {
|
||||||
final String t = "000" + Integer.toHexString(chr);
|
String t = "000" + Integer.toHexString(chr);
|
||||||
builder.append("\\u" + t.substring(t.length() - 4));
|
builder.append("\\u" + t.substring(t.length() - 4));
|
||||||
} else {
|
} else {
|
||||||
builder.append(chr);
|
builder.append(chr);
|
||||||
@ -193,7 +204,7 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @return the encoded text, as UTF-8
|
* @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");
|
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
|
* @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) {
|
if (name == null) {
|
||||||
throw new IllegalArgumentException("Graph name cannot be null");
|
throw new IllegalArgumentException("Graph name cannot be null");
|
||||||
}
|
}
|
||||||
// Construct the graph object
|
// Construct the graph object
|
||||||
final Graph graph = new Graph(name);
|
Graph graph = new Graph(name);
|
||||||
// Now we can add our graph
|
// Now we can add our graph
|
||||||
graphs.add(graph);
|
this.graphs.add(graph);
|
||||||
// and return back
|
// and return back
|
||||||
return graph;
|
return graph;
|
||||||
}
|
}
|
||||||
@ -222,11 +233,11 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param graph The name of the graph
|
* @param graph The name of the graph
|
||||||
*/
|
*/
|
||||||
public void addGraph(final Graph graph) {
|
public void addGraph(Graph graph) {
|
||||||
if (graph == null) {
|
if (graph == null) {
|
||||||
throw new IllegalArgumentException("Graph cannot be 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() {
|
public boolean start() {
|
||||||
// Is metrics already running?
|
// Is metrics already running?
|
||||||
if (task != null) {
|
if (this.task != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Begin hitting the server with glorious data
|
// 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;
|
private boolean firstPost = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
postPlugin(!firstPost);
|
postPlugin(!this.firstPost);
|
||||||
// After the first post we set firstPost to
|
// After the first post we set firstPost to
|
||||||
// false
|
// false
|
||||||
// Each post thereafter will be a ping
|
// Each post thereafter will be a ping
|
||||||
firstPost = false;
|
this.firstPost = false;
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (debug) {
|
if (Metrics.this.debug) {
|
||||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,7 +282,7 @@ public class Metrics {
|
|||||||
*/
|
*/
|
||||||
public void enable() throws IOException {
|
public void enable() throws IOException {
|
||||||
// Enable Task, if it is not running
|
// Enable Task, if it is not running
|
||||||
if (task == null) {
|
if (this.task == null) {
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,9 +294,9 @@ public class Metrics {
|
|||||||
*/
|
*/
|
||||||
public void disable() throws IOException {
|
public void disable() throws IOException {
|
||||||
// Disable Task, if it is running
|
// Disable Task, if it is running
|
||||||
if (task != null) {
|
if (this.task != null) {
|
||||||
task.cancel();
|
this.task.cancel();
|
||||||
task = null;
|
this.task = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +312,7 @@ public class Metrics {
|
|||||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||||
// pluginsFolder => base/plugins/
|
// pluginsFolder => base/plugins/
|
||||||
// The base is not necessarily relative to the startup directory.
|
// 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 => base/plugins/PluginMetrics/config.yml
|
||||||
return new File(new File(pluginsFolder, "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
|
* 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
|
// Server software specific section
|
||||||
final PluginDescriptionFile description = plugin.getDescription();
|
PluginDescriptionFile description = this.plugin.getDescription();
|
||||||
final String pluginName = description.getName();
|
String pluginName = description.getName();
|
||||||
final boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE
|
boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
|
||||||
// if
|
String pluginVersion = description.getVersion();
|
||||||
// online
|
String serverVersion = Bukkit.getVersion();
|
||||||
// mode
|
|
||||||
// is
|
|
||||||
// enabled
|
|
||||||
final String pluginVersion = description.getVersion();
|
|
||||||
final String serverVersion = Bukkit.getVersion();
|
|
||||||
int playersOnline = 0;
|
int playersOnline = 0;
|
||||||
try {
|
try {
|
||||||
if (Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).getReturnType() == Collection.class) {
|
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
|
// END server software specific section -- all code below does not use
|
||||||
// any code outside of this class / Java
|
// any code outside of this class / Java
|
||||||
// Construct the post data
|
// Construct the post data
|
||||||
final StringBuilder json = new StringBuilder(1024);
|
StringBuilder json = new StringBuilder(1024);
|
||||||
json.append('{');
|
json.append('{');
|
||||||
// The plugin's description file containg all of the plugin data such as
|
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||||
// name, version, author, etc
|
appendJSONPair(json, "guid", this.guid);
|
||||||
appendJSONPair(json, "guid", guid);
|
|
||||||
appendJSONPair(json, "plugin_version", pluginVersion);
|
appendJSONPair(json, "plugin_version", pluginVersion);
|
||||||
appendJSONPair(json, "server_version", serverVersion);
|
appendJSONPair(json, "server_version", serverVersion);
|
||||||
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
appendJSONPair(json, "players_online", Integer.toString(playersOnline));
|
||||||
// New data as of R6
|
// New data as of R6
|
||||||
final String osname = System.getProperty("os.name");
|
String osname = System.getProperty("os.name");
|
||||||
String osarch = System.getProperty("os.arch");
|
String osarch = System.getProperty("os.arch");
|
||||||
final String osversion = System.getProperty("os.version");
|
String osversion = System.getProperty("os.version");
|
||||||
final String java_version = System.getProperty("java.version");
|
String java_version = System.getProperty("java.version");
|
||||||
final int coreCount = Runtime.getRuntime().availableProcessors();
|
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||||
// normalize os arch .. amd64 -> x86_64
|
// normalize os arch .. amd64 -> x86_64
|
||||||
if (osarch.equals("amd64")) {
|
if (osarch.equals("amd64")) {
|
||||||
osarch = "x86_64";
|
osarch = "x86_64";
|
||||||
@ -362,8 +367,8 @@ public class Metrics {
|
|||||||
if (isPing) {
|
if (isPing) {
|
||||||
appendJSONPair(json, "ping", "1");
|
appendJSONPair(json, "ping", "1");
|
||||||
}
|
}
|
||||||
if (!graphs.isEmpty()) {
|
if (!this.graphs.isEmpty()) {
|
||||||
synchronized (graphs) {
|
synchronized (this.graphs) {
|
||||||
json.append(',');
|
json.append(',');
|
||||||
json.append('"');
|
json.append('"');
|
||||||
json.append("graphs");
|
json.append("graphs");
|
||||||
@ -371,10 +376,10 @@ public class Metrics {
|
|||||||
json.append(':');
|
json.append(':');
|
||||||
json.append('{');
|
json.append('{');
|
||||||
boolean firstGraph = true;
|
boolean firstGraph = true;
|
||||||
for (final Graph graph : graphs) {
|
for (Graph graph : this.graphs) {
|
||||||
final StringBuilder graphJson = new StringBuilder();
|
StringBuilder graphJson = new StringBuilder();
|
||||||
graphJson.append('{');
|
graphJson.append('{');
|
||||||
for (final Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
|
||||||
}
|
}
|
||||||
graphJson.append('}');
|
graphJson.append('}');
|
||||||
@ -392,7 +397,7 @@ public class Metrics {
|
|||||||
// close json
|
// close json
|
||||||
json.append('}');
|
json.append('}');
|
||||||
// Create the url
|
// 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
|
// Connect to the website
|
||||||
URLConnection connection;
|
URLConnection connection;
|
||||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||||
@ -402,8 +407,8 @@ public class Metrics {
|
|||||||
} else {
|
} else {
|
||||||
connection = url.openConnection();
|
connection = url.openConnection();
|
||||||
}
|
}
|
||||||
final byte[] uncompressed = json.toString().getBytes();
|
byte[] uncompressed = json.toString().getBytes();
|
||||||
final byte[] compressed = gzip(json.toString());
|
byte[] compressed = gzip(json.toString());
|
||||||
// Headers
|
// Headers
|
||||||
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
|
||||||
connection.addRequestProperty("Content-Type", "application/json");
|
connection.addRequestProperty("Content-Type", "application/json");
|
||||||
@ -412,7 +417,7 @@ public class Metrics {
|
|||||||
connection.addRequestProperty("Accept", "application/json");
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
connection.addRequestProperty("Connection", "close");
|
connection.addRequestProperty("Connection", "close");
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
if (debug) {
|
if (this.debug) {
|
||||||
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -423,7 +428,7 @@ public class Metrics {
|
|||||||
String response;
|
String response;
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
response = reader.readLine();
|
response = reader.readLine();
|
||||||
if (debug) {
|
if (this.debug) {
|
||||||
PS.debug("[Metrics] Response for " + pluginName + ": " + response);
|
PS.debug("[Metrics] Response for " + pluginName + ": " + response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,18 +442,17 @@ public class Metrics {
|
|||||||
} else {
|
} else {
|
||||||
// Is this the first update this hour?
|
// Is this the first update this hour?
|
||||||
if ("1".equals(response) || response.contains("This is your first update this hour")) {
|
if ("1".equals(response) || response.contains("This is your first update this hour")) {
|
||||||
synchronized (graphs) {
|
synchronized (this.graphs) {
|
||||||
for (final Graph graph : graphs) {
|
for (Graph graph : this.graphs) {
|
||||||
for (final Plotter plotter : graph.getPlotters()) {
|
for (Plotter plotter : graph.getPlotters()) {
|
||||||
plotter.reset();
|
plotter.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
if (this.debug) {
|
||||||
if (debug) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -483,7 +487,7 @@ public class Metrics {
|
|||||||
*/
|
*/
|
||||||
private final Set<Plotter> plotters = new LinkedHashSet<>();
|
private final Set<Plotter> plotters = new LinkedHashSet<>();
|
||||||
|
|
||||||
private Graph(final String name) {
|
private Graph(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,7 +497,7 @@ public class Metrics {
|
|||||||
* @return the Graph's name
|
* @return the Graph's name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,8 +505,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plotter the plotter to add to the graph
|
* @param plotter the plotter to add to the graph
|
||||||
*/
|
*/
|
||||||
public void addPlotter(final Plotter plotter) {
|
public void addPlotter(Plotter plotter) {
|
||||||
plotters.add(plotter);
|
this.plotters.add(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -510,8 +514,8 @@ public class Metrics {
|
|||||||
*
|
*
|
||||||
* @param plotter the plotter to remove from the graph
|
* @param plotter the plotter to remove from the graph
|
||||||
*/
|
*/
|
||||||
public void removePlotter(final Plotter plotter) {
|
public void removePlotter(Plotter plotter) {
|
||||||
plotters.remove(plotter);
|
this.plotters.remove(plotter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -520,21 +524,21 @@ public class Metrics {
|
|||||||
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
* @return an unmodifiable {@link java.util.Set} of the plotter objects
|
||||||
*/
|
*/
|
||||||
public Set<Plotter> getPlotters() {
|
public Set<Plotter> getPlotters() {
|
||||||
return Collections.unmodifiableSet(plotters);
|
return Collections.unmodifiableSet(this.plotters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return name.hashCode();
|
return this.name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object) {
|
public boolean equals(Object object) {
|
||||||
if (!(object instanceof Graph)) {
|
if (!(object instanceof Graph)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Graph graph = (Graph) object;
|
Graph graph = (Graph) object;
|
||||||
return graph.name.equals(name);
|
return graph.name.equals(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -547,7 +551,7 @@ public class Metrics {
|
|||||||
/**
|
/**
|
||||||
* Interface used to collect custom data for a plugin
|
* Interface used to collect custom data for a plugin
|
||||||
*/
|
*/
|
||||||
public static abstract class Plotter {
|
public abstract static class Plotter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plot's name
|
* 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
|
* @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;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,7 +589,7 @@ public class Metrics {
|
|||||||
* @return the plotted point's column name
|
* @return the plotted point's column name
|
||||||
*/
|
*/
|
||||||
public String getColumnName() {
|
public String getColumnName() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -600,12 +604,12 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object object) {
|
public boolean equals(Object object) {
|
||||||
if (!(object instanceof Plotter)) {
|
if (!(object instanceof Plotter)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Plotter plotter = (Plotter) object;
|
Plotter plotter = (Plotter) object;
|
||||||
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
return plotter.name.equals(this.name) && plotter.getValue() == getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,12 +15,27 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
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.concurrent.ConcurrentMap;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
@ -48,39 +63,43 @@ public class NbtFactory {
|
|||||||
// Loading/saving compounds
|
// Loading/saving compounds
|
||||||
private LoadCompoundMethod LOAD_COMPOUND;
|
private LoadCompoundMethod LOAD_COMPOUND;
|
||||||
private Method SAVE_COMPOUND;
|
private Method SAVE_COMPOUND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an instance of the NBT factory by deducing the class of NBTBase.
|
* Construct an instance of the NBT factory by deducing the class of NBTBase.
|
||||||
*/
|
*/
|
||||||
private NbtFactory() {
|
private NbtFactory() {
|
||||||
if (BASE_CLASS == null) {
|
if (this.BASE_CLASS == null) {
|
||||||
try {
|
try {
|
||||||
// Keep in mind that I do use hard-coded field names - but it's okay as long as we're dealing
|
// 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.
|
// 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();
|
String packageName = getPackageName();
|
||||||
final Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
||||||
|
|
||||||
// Prepare NBT
|
// Prepare NBT
|
||||||
COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
this.COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
||||||
BASE_CLASS = COMPOUND_CLASS.getSuperclass();
|
this.BASE_CLASS = this.COMPOUND_CLASS.getSuperclass();
|
||||||
NBT_GET_TYPE = getMethod(0, Modifier.STATIC, BASE_CLASS, "getTypeId");
|
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
||||||
NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, BASE_CLASS, "createTag", byte.class);
|
this.NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
||||||
|
|
||||||
// Prepare CraftItemStack
|
// Prepare CraftItemStack
|
||||||
CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
||||||
CRAFT_HANDLE = getField(null, CRAFT_STACK, "handle");
|
this.CRAFT_HANDLE = getField(null, this.CRAFT_STACK, "handle");
|
||||||
STACK_TAG = getField(null, CRAFT_HANDLE.getType(), "tag");
|
this.STACK_TAG = getField(null, this.CRAFT_HANDLE.getType(), "tag");
|
||||||
|
|
||||||
// Loading/saving
|
// Loading/saving
|
||||||
final String nmsPackage = BASE_CLASS.getPackage().getName();
|
String nmsPackage = this.BASE_CLASS.getPackage().getName();
|
||||||
initializeNMS(loader, nmsPackage);
|
initializeNMS(loader, nmsPackage);
|
||||||
|
|
||||||
LOAD_COMPOUND = READ_LIMITER_CLASS != null ? new LoadMethodSkinUpdate(STREAM_TOOLS, READ_LIMITER_CLASS) :
|
if (this.READ_LIMITER_CLASS != null) {
|
||||||
new LoadMethodWorldUpdate(STREAM_TOOLS);
|
this.LOAD_COMPOUND = new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
||||||
SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, STREAM_TOOLS, null, BASE_CLASS, DataOutput.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);
|
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.
|
* Construct a new NBT list of an unspecified type.
|
||||||
* @return The NBT list.
|
* @return The NBT list.
|
||||||
*/
|
*/
|
||||||
public static NbtList createList(final Object... content) {
|
public static NbtList createList(Object... content) {
|
||||||
return createList(Arrays.asList(content));
|
return createList(Arrays.asList(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,11 +128,11 @@ public class NbtFactory {
|
|||||||
* Construct a new NBT list of an unspecified type.
|
* Construct a new NBT list of an unspecified type.
|
||||||
* @return The NBT list.
|
* @return The NBT list.
|
||||||
*/
|
*/
|
||||||
public static NbtList createList(final Iterable<? extends Object> iterable) {
|
public static NbtList createList(Iterable<? extends Object> iterable) {
|
||||||
final NbtList list = get().new NbtList(INSTANCE.createNbtTag(NbtType.TAG_LIST, null));
|
NbtList list = get().new NbtList(INSTANCE.createNbtTag(NbtType.TAG_LIST, null));
|
||||||
|
|
||||||
// Add the content as well
|
// Add the content as well
|
||||||
for (final Object obj : iterable) {
|
for (Object obj : iterable) {
|
||||||
list.add(obj);
|
list.add(obj);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@ -121,7 +140,6 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT compound.
|
* Construct a new NBT compound.
|
||||||
* <p>
|
|
||||||
*
|
*
|
||||||
* @return The NBT compound.
|
* @return The NBT compound.
|
||||||
*/
|
*/
|
||||||
@ -134,29 +152,33 @@ public class NbtFactory {
|
|||||||
* @param nmsList - the NBT list.
|
* @param nmsList - the NBT list.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
public static NbtList fromList(final Object nmsList) {
|
public static NbtList fromList(Object nmsList) {
|
||||||
return get().new NbtList(nmsList);
|
return get().new NbtList(nmsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the content of a file from a stream.
|
* Load the content of a file from a stream.
|
||||||
* <p>
|
*
|
||||||
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
|
* Use {@link Files#newInputStreamSupplier(java.io.File)} to provide a stream from a file.
|
||||||
* @param stream - the stream supplier.
|
* @param stream - the stream supplier.
|
||||||
* @param option - whether or not to decompress the input stream.
|
* @param option - whether or not to decompress the input stream.
|
||||||
* @return The decoded NBT compound.
|
* @return The decoded NBT compound.
|
||||||
* @throws IOException If anything went wrong.
|
* @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;
|
InputStream input = null;
|
||||||
DataInputStream data = null;
|
DataInputStream data = null;
|
||||||
boolean suppress = true;
|
boolean suppress = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
input = stream.getInput();
|
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;
|
suppress = false;
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
@ -171,14 +193,14 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the content of a NBT compound to a stream.
|
* 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.
|
* Use {@link Files#newOutputStreamSupplier(java.io.File)} to provide a stream supplier to a file.
|
||||||
* @param source - the NBT compound to save.
|
* @param source - the NBT compound to save.
|
||||||
* @param stream - the stream.
|
* @param stream - the stream.
|
||||||
* @param option - whether or not to compress the output.
|
* @param option - whether or not to compress the output.
|
||||||
* @throws IOException If anything went wrong.
|
* @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;
|
OutputStream output = null;
|
||||||
DataOutputStream data = null;
|
DataOutputStream data = null;
|
||||||
boolean suppress = true;
|
boolean suppress = true;
|
||||||
@ -204,7 +226,7 @@ public class NbtFactory {
|
|||||||
* @param nmsCompound - the NBT compund.
|
* @param nmsCompound - the NBT compund.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
public static NbtCompound fromCompound(final Object nmsCompound) {
|
public static NbtCompound fromCompound(Object nmsCompound) {
|
||||||
return get().new NbtCompound(nmsCompound);
|
return get().new NbtCompound(nmsCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,9 +237,9 @@ public class NbtFactory {
|
|||||||
* @param compound - the new NBT compound, or NULL to remove it.
|
* @param compound - the new NBT compound, or NULL to remove it.
|
||||||
* @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
|
* @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);
|
checkItemStack(stack);
|
||||||
final Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||||
|
|
||||||
// Now update the tag compound
|
// Now update the tag compound
|
||||||
setFieldValue(get().STACK_TAG, nms, compound.getHandle());
|
setFieldValue(get().STACK_TAG, nms, compound.getHandle());
|
||||||
@ -232,14 +254,14 @@ public class NbtFactory {
|
|||||||
* @param stack - the item stack.
|
* @param stack - the item stack.
|
||||||
* @return A wrapper for its NBT tag.
|
* @return A wrapper for its NBT tag.
|
||||||
*/
|
*/
|
||||||
public static NbtCompound fromItemTag(final ItemStack stack) {
|
public static NbtCompound fromItemTag(ItemStack stack) {
|
||||||
checkItemStack(stack);
|
checkItemStack(stack);
|
||||||
final Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
Object nms = getFieldValue(get().CRAFT_HANDLE, stack);
|
||||||
final Object tag = getFieldValue(get().STACK_TAG, nms);
|
Object tag = getFieldValue(get().STACK_TAG, nms);
|
||||||
|
|
||||||
// Create the tag if it doesn't exist
|
// Create the tag if it doesn't exist
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
final NbtCompound compound = createCompound();
|
NbtCompound compound = createCompound();
|
||||||
setItemTag(stack, compound);
|
setItemTag(stack, compound);
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
@ -251,17 +273,17 @@ public class NbtFactory {
|
|||||||
* @param stack - the stack to convert.
|
* @param stack - the stack to convert.
|
||||||
* @return The CraftItemStack version.
|
* @return The CraftItemStack version.
|
||||||
*/
|
*/
|
||||||
public static ItemStack getCraftItemStack(final ItemStack stack) {
|
public static ItemStack getCraftItemStack(ItemStack stack) {
|
||||||
// Any need to convert?
|
// Any need to convert?
|
||||||
if ((stack == null) || get().CRAFT_STACK.isAssignableFrom(stack.getClass())) {
|
if ((stack == null) || get().CRAFT_STACK.isAssignableFrom(stack.getClass())) {
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Call the private constructor
|
// Call the private constructor
|
||||||
final Constructor<?> caller = INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
|
Constructor<?> caller = INSTANCE.CRAFT_STACK.getDeclaredConstructor(ItemStack.class);
|
||||||
caller.setAccessible(true);
|
caller.setAccessible(true);
|
||||||
return (ItemStack) caller.newInstance(stack);
|
return (ItemStack) caller.newInstance(stack);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException("Unable to convert " + stack + " + to a CraftItemStack.");
|
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.
|
* Ensure that the given stack can store arbitrary NBT information.
|
||||||
* @param stack - the stack to check.
|
* @param stack - the stack to check.
|
||||||
*/
|
*/
|
||||||
private static void checkItemStack(final ItemStack stack) {
|
private static void checkItemStack(ItemStack stack) {
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
throw new IllegalArgumentException("Stack cannot be NULL.");
|
throw new IllegalArgumentException("Stack cannot be NULL.");
|
||||||
}
|
}
|
||||||
@ -289,26 +311,26 @@ public class NbtFactory {
|
|||||||
* @param params - the parameters to supply.
|
* @param params - the parameters to supply.
|
||||||
* @return The result of the method.
|
* @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 {
|
try {
|
||||||
return method.invoke(target, params);
|
return method.invoke(target, params);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unable to invoke method " + method + " for " + target, 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 {
|
try {
|
||||||
field.set(target, value);
|
field.set(target, value);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unable to set " + field + " for " + target, 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 {
|
try {
|
||||||
return field.get(target);
|
return field.get(target);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Unable to retrieve " + field + " for " + target, 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.
|
* @return The first method by this name.
|
||||||
* @throws IllegalStateException If we cannot find this method.
|
* @throws IllegalStateException If we cannot find this method.
|
||||||
*/
|
*/
|
||||||
private static Method getMethod(final int requireMod, final int bannedMod, final Class<?> clazz, final String methodName,
|
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz, String methodName,
|
||||||
final Class<?>... params) {
|
Class<?>... params) {
|
||||||
for (final Method method : clazz.getDeclaredMethods()) {
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
// Limitation: Doesn't handle overloads
|
// Limitation: Doesn't handle overloads
|
||||||
if (((method.getModifiers() & requireMod) == requireMod)
|
if (((method.getModifiers() & requireMod) == requireMod)
|
||||||
&& ((method.getModifiers() & bannedMod) == 0)
|
&& ((method.getModifiers() & bannedMod) == 0)
|
||||||
@ -351,12 +373,12 @@ public class NbtFactory {
|
|||||||
* @return The first field by this name.
|
* @return The first field by this name.
|
||||||
* @throws IllegalStateException If we cannot find this field.
|
* @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) {
|
if (clazz == null) {
|
||||||
clazz = instance.getClass();
|
clazz = instance.getClass();
|
||||||
}
|
}
|
||||||
// Ignore access rules
|
// Ignore access rules
|
||||||
for (final Field field : clazz.getDeclaredFields()) {
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
if (field.getName().equals(fieldName)) {
|
if (field.getName().equals(fieldName)) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
@ -369,18 +391,18 @@ public class NbtFactory {
|
|||||||
throw new IllegalStateException("Unable to find field " + fieldName + " in " + instance);
|
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 {
|
try {
|
||||||
STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
||||||
READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
||||||
} catch (final ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
// Ignore - we will detect this later
|
// Ignore - we will detect this later
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageName() {
|
private String getPackageName() {
|
||||||
final Server server = Bukkit.getServer();
|
Server server = Bukkit.getServer();
|
||||||
final String name = server != null ? server.getClass().getPackage().getName() : null;
|
String name = server != null ? server.getClass().getPackage().getName() : null;
|
||||||
|
|
||||||
if ((name != null) && name.contains("craftbukkit")) {
|
if ((name != null) && name.contains("craftbukkit")) {
|
||||||
return name;
|
return name;
|
||||||
@ -391,12 +413,12 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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);
|
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle), handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@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);
|
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.
|
* @param value - the value of the element to create. Can be a List or a Map.
|
||||||
* @return The NBT element.
|
* @return The NBT element.
|
||||||
*/
|
*/
|
||||||
private Object unwrapValue(final Object value) {
|
private Object unwrapValue(Object value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -430,13 +452,13 @@ public class NbtFactory {
|
|||||||
* @param nms - the NBT element.
|
* @param nms - the NBT element.
|
||||||
* @return The wrapper equivalent.
|
* @return The wrapper equivalent.
|
||||||
*/
|
*/
|
||||||
private Object wrapNative(final Object nms) {
|
private Object wrapNative(Object nms) {
|
||||||
if (nms == null) {
|
if (nms == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BASE_CLASS.isAssignableFrom(nms.getClass())) {
|
if (this.BASE_CLASS.isAssignableFrom(nms.getClass())) {
|
||||||
final NbtType type = getNbtType(nms);
|
NbtType type = getNbtType(nms);
|
||||||
|
|
||||||
// Handle the different types
|
// Handle the different types
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -457,8 +479,8 @@ public class NbtFactory {
|
|||||||
* @param value - the value, or NULL to keep the original value.
|
* @param value - the value, or NULL to keep the original value.
|
||||||
* @return The created tag.
|
* @return The created tag.
|
||||||
*/
|
*/
|
||||||
private Object createNbtTag(final NbtType type, final Object value) {
|
private Object createNbtTag(NbtType type, Object value) {
|
||||||
final Object tag = invokeMethod(NBT_CREATE_TAG, null, (byte) type.id);
|
Object tag = invokeMethod(this.NBT_CREATE_TAG, null, (byte) type.id);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
setFieldValue(getDataField(type, tag), tag, value);
|
setFieldValue(getDataField(type, tag), tag, value);
|
||||||
@ -472,11 +494,11 @@ public class NbtFactory {
|
|||||||
* @param nms - the NBT class instance.
|
* @param nms - the NBT class instance.
|
||||||
* @return The corresponding field.
|
* @return The corresponding field.
|
||||||
*/
|
*/
|
||||||
private Field getDataField(final NbtType type, final Object nms) {
|
private Field getDataField(NbtType type, Object nms) {
|
||||||
if (DATA_FIELD[type.id] == null) {
|
if (this.DATA_FIELD[type.id] == null) {
|
||||||
DATA_FIELD[type.id] = getField(nms, null, type.getFieldName());
|
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.
|
* @param nms - the native NBT tag.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
private NbtType getNbtType(final Object nms) {
|
private NbtType getNbtType(Object nms) {
|
||||||
final int type = (Byte) invokeMethod(NBT_GET_TYPE, nms);
|
int type = (Byte) invokeMethod(this.NBT_GET_TYPE, nms);
|
||||||
return NBT_ENUM.get(type);
|
return NBT_ENUM.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,8 +516,8 @@ public class NbtFactory {
|
|||||||
* @param primitive - the primitive type.
|
* @param primitive - the primitive type.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
private NbtType getPrimitiveType(final Object primitive) {
|
private NbtType getPrimitiveType(Object primitive) {
|
||||||
final NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
NbtType type = NBT_ENUM.get(NBT_CLASS.inverse().get(Primitives.unwrap(primitive.getClass())));
|
||||||
|
|
||||||
// Display the illegal value at least
|
// Display the illegal value at least
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
@ -529,7 +551,7 @@ public class NbtFactory {
|
|||||||
// Unique NBT type
|
// Unique NBT type
|
||||||
public final int id;
|
public final int id;
|
||||||
|
|
||||||
NbtType(final int id, final Class<?> type) {
|
NbtType(int id, Class<?> type) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
NBT_CLASS.put(id, type);
|
NBT_CLASS.put(id, type);
|
||||||
NBT_ENUM.put(id, this);
|
NBT_ENUM.put(id, this);
|
||||||
@ -567,9 +589,9 @@ public class NbtFactory {
|
|||||||
|
|
||||||
protected Method staticMethod;
|
protected Method staticMethod;
|
||||||
|
|
||||||
protected void setMethod(final Method method) {
|
protected void setMethod(Method method) {
|
||||||
staticMethod = method;
|
this.staticMethod = method;
|
||||||
staticMethod.setAccessible(true);
|
this.staticMethod.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -577,7 +599,7 @@ public class NbtFactory {
|
|||||||
* @param input - the input stream.
|
* @param input - the input stream.
|
||||||
* @return The loaded NBT compound.
|
* @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 {
|
private static class LoadMethodWorldUpdate extends LoadCompoundMethod {
|
||||||
|
|
||||||
public LoadMethodWorldUpdate(final Class<?> streamClass) {
|
public LoadMethodWorldUpdate(Class<?> streamClass) {
|
||||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object loadNbt(final DataInput input) {
|
public Object loadNbt(DataInput input) {
|
||||||
return invokeMethod(staticMethod, null, input);
|
return invokeMethod(this.staticMethod, null, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,15 +624,15 @@ public class NbtFactory {
|
|||||||
|
|
||||||
private Object readLimiter;
|
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));
|
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class, readLimiterClass));
|
||||||
|
|
||||||
// Find the unlimited read limiter
|
// Find the unlimited read limiter
|
||||||
for (final Field field : readLimiterClass.getDeclaredFields()) {
|
for (Field field : readLimiterClass.getDeclaredFields()) {
|
||||||
if (readLimiterClass.isAssignableFrom(field.getType())) {
|
if (readLimiterClass.isAssignableFrom(field.getType())) {
|
||||||
try {
|
try {
|
||||||
readLimiter = field.get(null);
|
this.readLimiter = field.get(null);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Cannot retrieve read limiter.", e);
|
throw new RuntimeException("Cannot retrieve read limiter.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -618,8 +640,8 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object loadNbt(final DataInput input) {
|
public Object loadNbt(DataInput input) {
|
||||||
return invokeMethod(staticMethod, null, input, readLimiter);
|
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -643,44 +665,44 @@ public class NbtFactory {
|
|||||||
*/
|
*/
|
||||||
public final class NbtCompound extends ConvertedMap {
|
public final class NbtCompound extends ConvertedMap {
|
||||||
|
|
||||||
private NbtCompound(final Object handle) {
|
private NbtCompound(Object handle) {
|
||||||
super(handle, getDataMap(handle));
|
super(handle, getDataMap(handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simplifiying access to each value
|
// 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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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.
|
* @param createNew - whether or not to create a new list if its missing.
|
||||||
* @return An existing list, a new list or NULL.
|
* @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);
|
NbtList list = (NbtList) get(key);
|
||||||
|
|
||||||
if ((list == null) && createNew) {
|
if ((list == null) && createNew) {
|
||||||
@ -705,7 +727,7 @@ public class NbtFactory {
|
|||||||
* @param createNew - whether or not to create a new map if its missing.
|
* @param createNew - whether or not to create a new map if its missing.
|
||||||
* @return An existing map, a new map or NULL.
|
* @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);
|
return getMap(Collections.singletonList(key), createNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,9 +742,9 @@ public class NbtFactory {
|
|||||||
* @param value - the new value of this entry.
|
* @param value - the new value of this entry.
|
||||||
* @return This compound, for chaining.
|
* @return This compound, for chaining.
|
||||||
*/
|
*/
|
||||||
public NbtCompound putPath(final String path, final Object value) {
|
public NbtCompound putPath(String path, Object value) {
|
||||||
final List<String> entries = getPathElements(path);
|
List<String> entries = getPathElements(path);
|
||||||
final Map<String, Object> map = getMap(entries.subList(0, entries.size() - 1), true);
|
Map<String, Object> map = getMap(entries.subList(0, entries.size() - 1), true);
|
||||||
|
|
||||||
map.put(entries.get(entries.size() - 1), value);
|
map.put(entries.get(entries.size() - 1), value);
|
||||||
return this;
|
return this;
|
||||||
@ -737,9 +759,9 @@ public class NbtFactory {
|
|||||||
* @return The value, or NULL if not found.
|
* @return The value, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T getPath(final String path) {
|
public <T> T getPath(String path) {
|
||||||
final List<String> entries = getPathElements(path);
|
List<String> entries = getPathElements(path);
|
||||||
final NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
||||||
|
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
return (T) map.get(entries.get(entries.size() - 1));
|
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.
|
* @param option - whether or not to compress the output.
|
||||||
* @throws IOException If anything went wrong.
|
* @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);
|
saveStream(this, stream, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -765,10 +787,10 @@ public class NbtFactory {
|
|||||||
* @param createNew - whether or not to create new compounds on the way.
|
* @param createNew - whether or not to create new compounds on the way.
|
||||||
* @return The map at this location.
|
* @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;
|
NbtCompound current = this;
|
||||||
|
|
||||||
for (final String entry : path) {
|
for (String entry : path) {
|
||||||
NbtCompound child = (NbtCompound) current.get(entry);
|
NbtCompound child = (NbtCompound) current.get(entry);
|
||||||
|
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
@ -787,7 +809,7 @@ public class NbtFactory {
|
|||||||
* @param path - the path to split.
|
* @param path - the path to split.
|
||||||
* @return The elements.
|
* @return The elements.
|
||||||
*/
|
*/
|
||||||
private List<String> getPathElements(final String path) {
|
private List<String> getPathElements(String path) {
|
||||||
return Lists.newArrayList(Splitter.on(".").omitEmptyStrings().split(path));
|
return Lists.newArrayList(Splitter.on(".").omitEmptyStrings().split(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -803,7 +825,7 @@ public class NbtFactory {
|
|||||||
*/
|
*/
|
||||||
public final class NbtList extends ConvertedList {
|
public final class NbtList extends ConvertedList {
|
||||||
|
|
||||||
private NbtList(final Object handle) {
|
private NbtList(Object handle) {
|
||||||
super(handle, getDataList(handle));
|
super(handle, getDataList(handle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -817,15 +839,15 @@ public class NbtFactory {
|
|||||||
// Don't recreate wrapper objects
|
// Don't recreate wrapper objects
|
||||||
private final ConcurrentMap<Object, Object> cache = new MapMaker().weakKeys().makeMap();
|
private final ConcurrentMap<Object, Object> cache = new MapMaker().weakKeys().makeMap();
|
||||||
|
|
||||||
public Object wrap(final Object value) {
|
public Object wrap(Object value) {
|
||||||
Object current = cache.get(value);
|
Object current = this.cache.get(value);
|
||||||
|
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
current = wrapNative(value);
|
current = wrapNative(value);
|
||||||
|
|
||||||
// Only cache composite objects
|
// Only cache composite objects
|
||||||
if ((current instanceof ConvertedMap) || (current instanceof ConvertedList)) {
|
if ((current instanceof ConvertedMap) || (current instanceof ConvertedList)) {
|
||||||
cache.put(value, current);
|
this.cache.put(value, current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
@ -844,57 +866,57 @@ public class NbtFactory {
|
|||||||
|
|
||||||
private final CachedNativeWrapper cache = new CachedNativeWrapper();
|
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.handle = handle;
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For converting back and forth
|
// For converting back and forth
|
||||||
protected Object wrapOutgoing(final Object value) {
|
protected Object wrapOutgoing(Object value) {
|
||||||
return cache.wrap(value);
|
return this.cache.wrap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object unwrapIncoming(final Object wrapped) {
|
protected Object unwrapIncoming(Object wrapped) {
|
||||||
return unwrapValue(wrapped);
|
return unwrapValue(wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modification
|
// Modification
|
||||||
@Override
|
@Override
|
||||||
public Object put(final String key, final Object value) {
|
public Object put(String key, Object value) {
|
||||||
return wrapOutgoing(original.put(key, unwrapIncoming(value)));
|
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Performance
|
// Performance
|
||||||
@Override
|
@Override
|
||||||
public Object get(final Object key) {
|
public Object get(Object key) {
|
||||||
return wrapOutgoing(original.get(key));
|
return wrapOutgoing(this.original.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object remove(final Object key) {
|
public Object remove(Object key) {
|
||||||
return wrapOutgoing(original.remove(key));
|
return wrapOutgoing(this.original.remove(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(final Object key) {
|
public boolean containsKey(Object key) {
|
||||||
return original.containsKey(key);
|
return this.original.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Entry<String, Object>> entrySet() {
|
public Set<Entry<String, Object>> entrySet() {
|
||||||
return new AbstractSet<Entry<String, Object>>() {
|
return new AbstractSet<Entry<String, Object>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean add(final Entry<String, Object> e) {
|
public boolean add(Entry<String, Object> e) {
|
||||||
final String key = e.getKey();
|
String key = e.getKey();
|
||||||
final Object value = e.getValue();
|
Object value = e.getValue();
|
||||||
|
|
||||||
original.put(key, unwrapIncoming(value));
|
ConvertedMap.this.original.put(key, unwrapIncoming(value));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return original.size();
|
return ConvertedMap.this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -905,7 +927,7 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Iterator<Entry<String, Object>> iterator() {
|
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>>() {
|
return new Iterator<Entry<String, Object>>() {
|
||||||
@Override
|
@Override
|
||||||
@ -915,7 +937,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entry<String, Object> next() {
|
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()));
|
return new SimpleEntry<String, Object>(entry.getKey(), wrapOutgoing(entry.getValue()));
|
||||||
}
|
}
|
||||||
@ -929,7 +951,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandle() {
|
public Object getHandle() {
|
||||||
return handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,61 +967,61 @@ public class NbtFactory {
|
|||||||
private final List<Object> original;
|
private final List<Object> original;
|
||||||
private final CachedNativeWrapper cache = new CachedNativeWrapper();
|
private final CachedNativeWrapper cache = new CachedNativeWrapper();
|
||||||
|
|
||||||
public ConvertedList(final Object handle, final List<Object> original) {
|
public ConvertedList(Object handle, List<Object> original) {
|
||||||
if (NBT_LIST_TYPE == null) {
|
if (NbtFactory.this.NBT_LIST_TYPE == null) {
|
||||||
NBT_LIST_TYPE = getField(handle, null, "type");
|
NbtFactory.this.NBT_LIST_TYPE = getField(handle, null, "type");
|
||||||
}
|
}
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object wrapOutgoing(final Object value) {
|
protected Object wrapOutgoing(Object value) {
|
||||||
return cache.wrap(value);
|
return this.cache.wrap(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object unwrapIncoming(final Object wrapped) {
|
protected Object unwrapIncoming(Object wrapped) {
|
||||||
return unwrapValue(wrapped);
|
return unwrapValue(wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object get(final int index) {
|
public Object get(int index) {
|
||||||
return wrapOutgoing(original.get(index));
|
return wrapOutgoing(this.original.get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return original.size();
|
return this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object set(final int index, final Object element) {
|
public Object set(int index, Object element) {
|
||||||
return wrapOutgoing(original.set(index, unwrapIncoming(element)));
|
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(final int index, final Object element) {
|
public void add(int index, Object element) {
|
||||||
final Object nbt = unwrapIncoming(element);
|
Object nbt = unwrapIncoming(element);
|
||||||
|
|
||||||
// Set the list type if its the first element
|
// Set the list type if its the first element
|
||||||
if (size() == 0) {
|
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
|
@Override
|
||||||
public Object remove(final int index) {
|
public Object remove(int index) {
|
||||||
return wrapOutgoing(original.remove(index));
|
return wrapOutgoing(this.original.remove(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(final Object o) {
|
public boolean remove(Object o) {
|
||||||
return original.remove(unwrapIncoming(o));
|
return this.original.remove(unwrapIncoming(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getHandle() {
|
public Object getHandle() {
|
||||||
return handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,15 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class OfflinePlayerUtil {
|
public class OfflinePlayerUtil {
|
||||||
|
|
||||||
public static Player loadPlayer(final String name) {
|
public static Player loadPlayer(String name) {
|
||||||
return loadPlayer(Bukkit.getOfflinePlayer(name));
|
return loadPlayer(Bukkit.getOfflinePlayer(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player loadPlayer(final UUID id) {
|
public static Player loadPlayer(UUID id) {
|
||||||
return loadPlayer(Bukkit.getOfflinePlayer(id));
|
return loadPlayer(Bukkit.getOfflinePlayer(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player loadPlayer(final OfflinePlayer player) {
|
public static Player loadPlayer(OfflinePlayer player) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -37,21 +37,21 @@ public class OfflinePlayerUtil {
|
|||||||
return loadPlayer(player.getUniqueId(), player.getName());
|
return loadPlayer(player.getUniqueId(), player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Player loadPlayer(final UUID id, final String name) {
|
private static Player loadPlayer(UUID id, String name) {
|
||||||
final Object server = getMinecraftServer();
|
Object server = getMinecraftServer();
|
||||||
final Object interactManager = newPlayerInteractManager();
|
Object interactManager = newPlayerInteractManager();
|
||||||
final Object worldServer = getWorldServer();
|
Object worldServer = getWorldServer();
|
||||||
final Object profile = newGameProfile(id, name);
|
Object profile = newGameProfile(id, name);
|
||||||
final Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||||
final Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||||
getUtilClass("com.mojang.authlib.GameProfile"),
|
getUtilClass("com.mojang.authlib.GameProfile"),
|
||||||
getNmsClass("PlayerInteractManager"));
|
getNmsClass("PlayerInteractManager"));
|
||||||
final Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||||
return (Player) getBukkitEntity(entityPlayer);
|
return (Player) getBukkitEntity(entityPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object newGameProfile(final UUID id, final String name) {
|
private static Object newGameProfile(UUID id, String name) {
|
||||||
final Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
Class<?> gameProfileClass = getUtilClass("com.mojang.authlib.GameProfile");
|
||||||
if (gameProfileClass == null) { //Before uuids
|
if (gameProfileClass == null) { //Before uuids
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -65,17 +65,17 @@ public class OfflinePlayerUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Object newPlayerInteractManager() {
|
private static Object newPlayerInteractManager() {
|
||||||
final Object worldServer = getWorldServer();
|
Object worldServer = getWorldServer();
|
||||||
final Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
Class<?> playerInteractClass = getNmsClass("PlayerInteractManager");
|
||||||
final Class<?> worldClass = getNmsClass("World");
|
Class<?> worldClass = getNmsClass("World");
|
||||||
final Constructor c = makeConstructor(playerInteractClass, worldClass);
|
Constructor c = makeConstructor(playerInteractClass, worldClass);
|
||||||
return callConstructor(c, worldServer);
|
return callConstructor(c, worldServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object getWorldServer() {
|
private static Object getWorldServer() {
|
||||||
final Object server = getMinecraftServer();
|
Object server = getMinecraftServer();
|
||||||
final Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
Class<?> minecraftServerClass = getNmsClass("MinecraftServer");
|
||||||
final Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
Method getWorldServer = makeMethod(minecraftServerClass, "getWorldServer", int.class);
|
||||||
return callMethod(getWorldServer, server, 0);
|
return callMethod(getWorldServer, server, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ public class OfflinePlayerUtil {
|
|||||||
return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
|
return callMethod(makeMethod(getCbClass("CraftServer"), "getServer"), Bukkit.getServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity getBukkitEntity(final Object o) {
|
private static Entity getBukkitEntity(Object o) {
|
||||||
final Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
Method getBukkitEntity = makeMethod(o.getClass(), "getBukkitEntity");
|
||||||
return callMethod(getBukkitEntity, o);
|
return callMethod(getBukkitEntity, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
@ -17,11 +19,12 @@ import org.bukkit.Chunk;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
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 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)
|
* 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 {
|
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 methodGetHandlePlayer;
|
||||||
private final RefMethod methodGetHandleChunk;
|
private final RefMethod methodGetHandleChunk;
|
||||||
private final RefConstructor MapChunk;
|
private final RefConstructor mapChunk;
|
||||||
private final RefField connection;
|
private final RefField connection;
|
||||||
private final RefMethod send;
|
private final RefMethod send;
|
||||||
private final RefMethod methodInitLighting;
|
private final RefMethod methodInitLighting;
|
||||||
@ -48,32 +43,39 @@ public class SendChunk {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SendChunk() {
|
public SendChunk() {
|
||||||
methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
connection = classEntityPlayer.getField("playerConnection");
|
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
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) {
|
public void sendChunk(Collection<Chunk> input) {
|
||||||
final HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
||||||
final HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||||
final int view = Bukkit.getServer().getViewDistance();
|
int view = Bukkit.getServer().getViewDistance();
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
final String world = chunk.getWorld().getName();
|
String world = chunk.getWorld().getName();
|
||||||
ArrayList<Chunk> list = map.get(world);
|
ArrayList<Chunk> list = map.get(world);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
map.put(world, list);
|
map.put(world, list);
|
||||||
}
|
}
|
||||||
list.add(chunk);
|
list.add(chunk);
|
||||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||||
methodInitLighting.of(c).call();
|
this.methodInitLighting.of(c).call();
|
||||||
}
|
}
|
||||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||||
PlotPlayer pp = entry.getValue();
|
PlotPlayer pp = entry.getValue();
|
||||||
final Plot plot = pp.getCurrentPlot();
|
Plot plot = pp.getCurrentPlot();
|
||||||
Location loc = null;
|
Location loc = null;
|
||||||
String world;
|
String world;
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
@ -82,29 +84,29 @@ public class SendChunk {
|
|||||||
loc = pp.getLocation();
|
loc = pp.getLocation();
|
||||||
world = loc.getWorld();
|
world = loc.getWorld();
|
||||||
}
|
}
|
||||||
final ArrayList<Chunk> list = map.get(world);
|
ArrayList<Chunk> list = map.get(world);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
loc = pp.getLocation();
|
loc = pp.getLocation();
|
||||||
}
|
}
|
||||||
final int cx = loc.getX() >> 4;
|
int cx = loc.getX() >> 4;
|
||||||
final int cz = loc.getZ() >> 4;
|
int cz = loc.getZ() >> 4;
|
||||||
final Player player = ((BukkitPlayer) pp).player;
|
Player player = ((BukkitPlayer) pp).player;
|
||||||
final Object entity = methodGetHandlePlayer.of(player).call();
|
Object entity = this.methodGetHandlePlayer.of(player).call();
|
||||||
|
|
||||||
for (final Chunk chunk : list) {
|
for (Chunk chunk : list) {
|
||||||
final int dx = Math.abs(cx - chunk.getX());
|
int dx = Math.abs(cx - chunk.getX());
|
||||||
final int dz = Math.abs(cz - chunk.getZ());
|
int dz = Math.abs(cz - chunk.getZ());
|
||||||
if ((dx > view) || (dz > view)) {
|
if ((dx > view) || (dz > view)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||||
chunks.remove(chunk);
|
chunks.remove(chunk);
|
||||||
final Object con = connection.of(entity).get();
|
Object con = this.connection.of(entity).get();
|
||||||
final Object packet = MapChunk.create(c, true, 65535);
|
Object packet = this.mapChunk.create(c, true, 65535);
|
||||||
send.of(con).call(packet);
|
this.send.of(con).call(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final Chunk chunk : chunks) {
|
for (final Chunk chunk : chunks) {
|
||||||
@ -113,8 +115,8 @@ public class SendChunk {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
final String worldname = chunk.getWorld().getName();
|
String worldname = chunk.getWorld().getName();
|
||||||
PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
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 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname
|
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) {
|
public void sendChunk(String worldname, Collection<ChunkLoc> locs) {
|
||||||
final World myworld = Bukkit.getWorld(worldname);
|
World myworld = Bukkit.getWorld(worldname);
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
for (final ChunkLoc loc : locs) {
|
for (ChunkLoc loc : locs) {
|
||||||
if (myworld.isChunkLoaded(loc.x, loc.z)) {
|
if (myworld.isChunkLoaded(loc.x, loc.z)) {
|
||||||
chunks.add(myworld.getChunkAt(loc.x, loc.z));
|
chunks.add(myworld.getChunkAt(loc.x, loc.z));
|
||||||
}
|
}
|
||||||
|
@ -14,24 +14,24 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
public class SetGenCB {
|
public class SetGenCB {
|
||||||
|
|
||||||
public static void setGenerator(final World world) throws Exception {
|
public static void setGenerator(World world) throws Exception {
|
||||||
SetupUtils.manager.updateGenerators();
|
SetupUtils.manager.updateGenerators();
|
||||||
PS.get().removePlotAreas(world.getName());
|
PS.get().removePlotAreas(world.getName());
|
||||||
final ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen == null) {
|
if (gen == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String name = gen.getClass().getCanonicalName();
|
String name = gen.getClass().getCanonicalName();
|
||||||
boolean set = false;
|
boolean set = false;
|
||||||
for (final GeneratorWrapper<?> wrapper : SetupUtils.generators.values()) {
|
for (GeneratorWrapper<?> wrapper : SetupUtils.generators.values()) {
|
||||||
ChunkGenerator newGen = (ChunkGenerator) wrapper.getPlatformGenerator();
|
ChunkGenerator newGen = (ChunkGenerator) wrapper.getPlatformGenerator();
|
||||||
if (newGen == null) {
|
if (newGen == null) {
|
||||||
newGen = (ChunkGenerator) wrapper;
|
newGen = (ChunkGenerator) wrapper;
|
||||||
}
|
}
|
||||||
if (newGen.getClass().getCanonicalName().equals(name)) {
|
if (newGen.getClass().getCanonicalName().equals(name)) {
|
||||||
// set generator
|
// set generator
|
||||||
final Field generator = world.getClass().getDeclaredField("generator");
|
Field generator = world.getClass().getDeclaredField("generator");
|
||||||
final Field populators = world.getClass().getDeclaredField("populators");
|
Field populators = world.getClass().getDeclaredField("populators");
|
||||||
generator.setAccessible(true);
|
generator.setAccessible(true);
|
||||||
populators.setAccessible(true);
|
populators.setAccessible(true);
|
||||||
// Set populators (just in case)
|
// Set populators (just in case)
|
||||||
@ -45,7 +45,7 @@ public class SetGenCB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!set) {
|
if (!set) {
|
||||||
final Iterator<BlockPopulator> iter = world.getPopulators().iterator();
|
Iterator<BlockPopulator> iter = world.getPopulators().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
if (iter.next() instanceof BukkitAugmentedGenerator) {
|
if (iter.next() instanceof BukkitAugmentedGenerator) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
|
@ -17,12 +17,13 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
public short[] relight;
|
public short[] relight;
|
||||||
public int[][] biomes;
|
public int[][] biomes;
|
||||||
public Chunk chunk;
|
public Chunk chunk;
|
||||||
public FastChunk_1_8_3(final ChunkWrapper chunk) {
|
|
||||||
|
public FastChunk_1_8_3(ChunkWrapper chunk) {
|
||||||
super(chunk);
|
super(chunk);
|
||||||
ids = new char[16][];
|
this.ids = new char[16][];
|
||||||
count = new short[16];
|
this.count = new short[16];
|
||||||
air = new short[16];
|
this.air = new short[16];
|
||||||
relight = new short[16];
|
this.relight = new short[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,17 +34,17 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
if (chunk == null) {
|
if (this.chunk == null) {
|
||||||
final ChunkWrapper cl = getChunkWrapper();
|
ChunkWrapper cl = getChunkWrapper();
|
||||||
chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
this.chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||||
}
|
}
|
||||||
return chunk;
|
return this.chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChunkWrapper(final ChunkWrapper loc) {
|
public void setChunkWrapper(ChunkWrapper loc) {
|
||||||
super.setChunkWrapper(loc);
|
super.setChunkWrapper(loc);
|
||||||
chunk = null;
|
this.chunk = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,44 +52,44 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getCount(final int i) {
|
public int getCount(int i) {
|
||||||
return count[i];
|
return this.count[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAir(final int i) {
|
public int getAir(int i) {
|
||||||
return air[i];
|
return this.air[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCount(int i, short value) {
|
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
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getRelight(final int i) {
|
public int getRelight(int i) {
|
||||||
return relight[i];
|
return this.relight[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalCount() {
|
public int getTotalCount() {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
total += count[i];
|
total += this.count[i];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalRelight() {
|
public int getTotalRelight() {
|
||||||
if (getTotalCount() == 0) {
|
if (getTotalCount() == 0) {
|
||||||
Arrays.fill(count, (short) 1);
|
Arrays.fill(this.count, (short) 1);
|
||||||
Arrays.fill(relight, Short.MAX_VALUE);
|
Arrays.fill(this.relight, Short.MAX_VALUE);
|
||||||
return Short.MAX_VALUE;
|
return Short.MAX_VALUE;
|
||||||
}
|
}
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
total += relight[i];
|
total += this.relight[i];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@ -98,24 +99,24 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public char[] getIdArray(final int i) {
|
public char[] getIdArray(int i) {
|
||||||
return ids[i];
|
return this.ids[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlock(final int x, final int y, final int z, final int id, byte data) {
|
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||||
final int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
final int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
char[] vs = ids[i];
|
char[] vs = this.ids[i];
|
||||||
if (vs == null) {
|
if (vs == null) {
|
||||||
vs = ids[i] = new char[4096];
|
vs = this.ids[i] = new char[4096];
|
||||||
count[i]++;
|
this.count[i]++;
|
||||||
} else if (vs[j] == 0) {
|
} else if (vs[j] == 0) {
|
||||||
count[i]++;
|
this.count[i]++;
|
||||||
}
|
}
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
air[i]++;
|
this.air[i]++;
|
||||||
vs[j] = (char) 1;
|
vs[j] = (char) 1;
|
||||||
return;
|
return;
|
||||||
case 10:
|
case 10:
|
||||||
@ -129,7 +130,7 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
case 124:
|
case 124:
|
||||||
case 138:
|
case 138:
|
||||||
case 169:
|
case 169:
|
||||||
relight[i]++;
|
this.relight[i]++;
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
case 13:
|
case 13:
|
||||||
@ -193,7 +194,7 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
case 130:
|
case 130:
|
||||||
case 76:
|
case 76:
|
||||||
case 62:
|
case 62:
|
||||||
relight[i]++;
|
this.relight[i]++;
|
||||||
case 54:
|
case 54:
|
||||||
case 146:
|
case 146:
|
||||||
case 61:
|
case 61:
|
||||||
@ -212,12 +213,12 @@ public class FastChunk_1_8_3 extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public PlotChunk clone() {
|
public PlotChunk clone() {
|
||||||
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
||||||
toReturn.air = air.clone();
|
toReturn.air = this.air.clone();
|
||||||
toReturn.count = count.clone();
|
toReturn.count = this.count.clone();
|
||||||
toReturn.relight = relight.clone();
|
toReturn.relight = this.relight.clone();
|
||||||
toReturn.ids = new char[ids.length][];
|
toReturn.ids = new char[this.ids.length][];
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < this.ids.length; i++) {
|
||||||
char[] matrix = ids[i];
|
char[] matrix = this.ids[i];
|
||||||
if (matrix != null) {
|
if (matrix != null) {
|
||||||
toReturn.ids[i] = new char[matrix.length];
|
toReturn.ids[i] = new char[matrix.length];
|
||||||
System.arraycopy(matrix, 0, toReturn.ids[i], 0, 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
|
@Override
|
||||||
public PlotChunk shallowClone() {
|
public PlotChunk shallowClone() {
|
||||||
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
FastChunk_1_8_3 toReturn = new FastChunk_1_8_3(getChunkWrapper());
|
||||||
toReturn.air = air;
|
toReturn.air = this.air;
|
||||||
toReturn.count = count;
|
toReturn.count = this.count;
|
||||||
toReturn.relight = relight;
|
toReturn.relight = this.relight;
|
||||||
toReturn.ids = ids;
|
toReturn.ids = this.ids;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(int x, int z, int biome) {
|
public void setBiome(int x, int z, int biome) {
|
||||||
if (biomes == null) {
|
if (this.biomes == null) {
|
||||||
biomes = new int[16][16];
|
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 short[] relight;
|
||||||
public int[][] biomes;
|
public int[][] biomes;
|
||||||
public Chunk chunk;
|
public Chunk chunk;
|
||||||
public FastChunk_1_9(final ChunkWrapper chunk) {
|
|
||||||
|
public FastChunk_1_9(ChunkWrapper chunk) {
|
||||||
super(chunk);
|
super(chunk);
|
||||||
ids = new int[16][];
|
this.ids = new int[16][];
|
||||||
count = new short[16];
|
this.count = new short[16];
|
||||||
air = new short[16];
|
this.air = new short[16];
|
||||||
relight = new short[16];
|
this.relight = new short[16];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,17 +34,17 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
if (chunk == null) {
|
if (this.chunk == null) {
|
||||||
final ChunkWrapper cl = getChunkWrapper();
|
ChunkWrapper cl = getChunkWrapper();
|
||||||
chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
this.chunk = Bukkit.getWorld(cl.world).getChunkAt(cl.x, cl.z);
|
||||||
}
|
}
|
||||||
return chunk;
|
return this.chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChunkWrapper(final ChunkWrapper loc) {
|
public void setChunkWrapper(ChunkWrapper loc) {
|
||||||
super.setChunkWrapper(loc);
|
super.setChunkWrapper(loc);
|
||||||
chunk = null;
|
this.chunk = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,16 +52,16 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getCount(final int i) {
|
public int getCount(int i) {
|
||||||
return count[i];
|
return this.count[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAir(final int i) {
|
public int getAir(int i) {
|
||||||
return air[i];
|
return this.air[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCount(int i, short value) {
|
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
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getRelight(final int i) {
|
public int getRelight(int i) {
|
||||||
return relight[i];
|
return this.relight[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalCount() {
|
public int getTotalCount() {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
total += count[i];
|
total += this.count[i];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalRelight() {
|
public int getTotalRelight() {
|
||||||
if (getTotalCount() == 0) {
|
if (getTotalCount() == 0) {
|
||||||
Arrays.fill(count, (short) 1);
|
Arrays.fill(this.count, (short) 1);
|
||||||
Arrays.fill(relight, Short.MAX_VALUE);
|
Arrays.fill(this.relight, Short.MAX_VALUE);
|
||||||
return Short.MAX_VALUE;
|
return Short.MAX_VALUE;
|
||||||
}
|
}
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
total += relight[i];
|
total += this.relight[i];
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
@ -98,28 +99,28 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
* @param i
|
* @param i
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int[] getIdArray(final int i) {
|
public int[] getIdArray(int i) {
|
||||||
return ids[i];
|
return this.ids[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][] getIdArrays() {
|
public int[][] getIdArrays() {
|
||||||
return ids;
|
return this.ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlock(final int x, final int y, final int z, final int id, byte data) {
|
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||||
final int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
final int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
int[] vs = ids[i];
|
int[] vs = this.ids[i];
|
||||||
if (vs == null) {
|
if (vs == null) {
|
||||||
vs = ids[i] = new int[4096];
|
vs = this.ids[i] = new int[4096];
|
||||||
count[i]++;
|
this.count[i]++;
|
||||||
} else if (vs[j] == 0) {
|
} else if (vs[j] == 0) {
|
||||||
count[i]++;
|
this.count[i]++;
|
||||||
}
|
}
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
air[i]++;
|
this.air[i]++;
|
||||||
vs[j] = -1;
|
vs[j] = -1;
|
||||||
return;
|
return;
|
||||||
case 10:
|
case 10:
|
||||||
@ -133,7 +134,7 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
case 124:
|
case 124:
|
||||||
case 138:
|
case 138:
|
||||||
case 169:
|
case 169:
|
||||||
relight[i]++;
|
this.relight[i]++;
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
case 13:
|
case 13:
|
||||||
@ -192,12 +193,12 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
case 190:
|
case 190:
|
||||||
case 191:
|
case 191:
|
||||||
case 192:
|
case 192:
|
||||||
vs[j] = (id);
|
vs[j] = id;
|
||||||
return;
|
return;
|
||||||
case 130:
|
case 130:
|
||||||
case 76:
|
case 76:
|
||||||
case 62:
|
case 62:
|
||||||
relight[i]++;
|
this.relight[i]++;
|
||||||
case 54:
|
case 54:
|
||||||
case 146:
|
case 146:
|
||||||
case 61:
|
case 61:
|
||||||
@ -216,12 +217,12 @@ public class FastChunk_1_9 extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public PlotChunk clone() {
|
public PlotChunk clone() {
|
||||||
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
||||||
toReturn.air = air.clone();
|
toReturn.air = this.air.clone();
|
||||||
toReturn.count = count.clone();
|
toReturn.count = this.count.clone();
|
||||||
toReturn.relight = relight.clone();
|
toReturn.relight = this.relight.clone();
|
||||||
toReturn.ids = new int[ids.length][];
|
toReturn.ids = new int[this.ids.length][];
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < this.ids.length; i++) {
|
||||||
int[] matrix = ids[i];
|
int[] matrix = this.ids[i];
|
||||||
if (matrix != null) {
|
if (matrix != null) {
|
||||||
toReturn.ids[i] = new int[matrix.length];
|
toReturn.ids[i] = new int[matrix.length];
|
||||||
System.arraycopy(matrix, 0, toReturn.ids[i], 0, 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
|
@Override
|
||||||
public PlotChunk shallowClone() {
|
public PlotChunk shallowClone() {
|
||||||
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
FastChunk_1_9 toReturn = new FastChunk_1_9(getChunkWrapper());
|
||||||
toReturn.air = air;
|
toReturn.air = this.air;
|
||||||
toReturn.count = count;
|
toReturn.count = this.count;
|
||||||
toReturn.relight = relight;
|
toReturn.relight = this.relight;
|
||||||
toReturn.ids = ids;
|
toReturn.ids = this.ids;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(int x, int z, int biome) {
|
public void setBiome(int x, int z, int biome) {
|
||||||
if (biomes == null) {
|
if (this.biomes == null) {
|
||||||
biomes = new int[16][16];
|
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;
|
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.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@ -21,8 +23,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
public class FastQueue_1_7 extends SlowQueue {
|
public class FastQueue_1_7 extends SlowQueue {
|
||||||
|
|
||||||
private final RefClass classBlock = getRefClass("{nms}.Block");
|
private final RefClass classBlock = getRefClass("{nms}.Block");
|
||||||
@ -37,24 +37,24 @@ public class FastQueue_1_7 extends SlowQueue {
|
|||||||
|
|
||||||
private final SendChunk chunksender;
|
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 {
|
public FastQueue_1_7() throws NoSuchMethodException, RuntimeException {
|
||||||
methodGetHandle = classCraftWorld.getMethod("getHandle");
|
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||||
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
|
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||||
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class);
|
this.methodA = this.classChunk.getMethod("a", int.class, int.class, int.class, this.classBlock, int.class);
|
||||||
methodGetById = classBlock.getMethod("getById", int.class);
|
this.methodGetById = this.classBlock.getMethod("getById", int.class);
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||||
chunksender = new SendChunk();
|
this.chunksender = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (toUpdate.isEmpty()) {
|
if (FastQueue_1_7.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_7.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && (count < 128)) {
|
while (i.hasNext() && (count < 128)) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -69,12 +69,12 @@ public class FastQueue_1_7 extends SlowQueue {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final Collection<Chunk> chunks) {
|
public void update(Collection<Chunk> chunks) {
|
||||||
if (chunks.isEmpty()) {
|
if (chunks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!MainUtil.canSendChunk) {
|
if (!MainUtil.canSendChunk) {
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
chunk.load();
|
chunk.load();
|
||||||
@ -82,8 +82,8 @@ public class FastQueue_1_7 extends SlowQueue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
chunksender.sendChunk(chunks);
|
this.chunksender.sendChunk(chunks);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
@ -91,36 +91,36 @@ public class FastQueue_1_7 extends SlowQueue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues
|
||||||
* @param pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(PlotChunk<Chunk> pc) {
|
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||||
SlowChunk sc = (SlowChunk) pc;
|
SlowChunk sc = (SlowChunk) plotChunk;
|
||||||
Chunk chunk = pc.getChunk();
|
Chunk chunk = plotChunk.getChunk();
|
||||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||||
if (!toUpdate.containsKey(wrapper)) {
|
if (!this.toUpdate.containsKey(wrapper)) {
|
||||||
toUpdate.put(wrapper, chunk);
|
this.toUpdate.put(wrapper, chunk);
|
||||||
}
|
}
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
final Object w = methodGetHandle.of(world).call();
|
Object w = this.methodGetHandle.of(world).call();
|
||||||
final Object c = methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
Object c = this.methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||||
for (int i = 0; i < sc.result.length; i++) {
|
for (int i = 0; i < sc.result.length; i++) {
|
||||||
PlotBlock[] result2 = sc.result[i];
|
PlotBlock[] result2 = sc.result[i];
|
||||||
if (result2 == null) {
|
if (result2 == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < 4096; j++) {
|
for (int j = 0; j < 4096; j++) {
|
||||||
final int x = MainUtil.x_loc[i][j];
|
int x = MainUtil.x_loc[i][j];
|
||||||
final int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
final int z = MainUtil.z_loc[i][j];
|
int z = MainUtil.z_loc[i][j];
|
||||||
PlotBlock newBlock = result2[j];
|
PlotBlock newBlock = result2[j];
|
||||||
if (newBlock.id == -1) {
|
if (newBlock.id == -1) {
|
||||||
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object block = methodGetById.call(newBlock.id);
|
Object block = this.methodGetById.call(newBlock.id);
|
||||||
methodA.of(c).call(x, y, z, block, newBlock.data);
|
this.methodA.of(c).call(x, y, z, block, newBlock.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[][] biomes = sc.biomes;
|
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 chunk
|
||||||
* @param fixAll
|
* @param fixAll
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
||||||
Object c = methodGetHandle.of(chunk.getChunk()).call();
|
Object c = this.methodGetHandle.of(chunk.getChunk()).call();
|
||||||
methodInitLighting.of(c).call();
|
this.methodInitLighting.of(c).call();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues
|
||||||
* @param world
|
* @param world
|
||||||
* @param locs
|
* @param locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||||
World worldObj = BukkitUtil.getWorld(world);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
for (ChunkLoc loc : locs) {
|
for (ChunkLoc loc : locations) {
|
||||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
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;
|
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.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
@ -23,8 +25,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
public class FastQueue_1_8 extends SlowQueue {
|
public class FastQueue_1_8 extends SlowQueue {
|
||||||
|
|
||||||
private final RefMethod methodInitLighting;
|
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 classChunk = getRefClass("{nms}.Chunk");
|
||||||
private final RefClass classWorld = getRefClass("{nms}.World");
|
private final RefClass classWorld = getRefClass("{nms}.World");
|
||||||
private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
private final RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||||
private HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||||
private RefMethod methodGetHandle;
|
private final RefMethod methodGetHandle;
|
||||||
private RefMethod methodGetChunkAt;
|
private final RefMethod methodGetChunkAt;
|
||||||
private RefMethod methodA;
|
private final RefMethod methodA;
|
||||||
private RefMethod methodGetByCombinedId;
|
private final RefMethod methodGetByCombinedId;
|
||||||
private RefConstructor constructorBlockPosition;
|
private final RefConstructor constructorBlockPosition;
|
||||||
private SendChunk chunksender;
|
private final SendChunk chunksender;
|
||||||
|
|
||||||
public FastQueue_1_8() throws NoSuchMethodException, RuntimeException {
|
public FastQueue_1_8() throws NoSuchMethodException, RuntimeException {
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = this.classChunk.getMethod("initLighting");
|
||||||
constructorBlockPosition = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
this.constructorBlockPosition = this.classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||||
methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
this.methodGetByCombinedId = this.classBlock.getMethod("getByCombinedId", int.class);
|
||||||
methodGetHandle = classCraftWorld.getMethod("getHandle");
|
this.methodGetHandle = this.classCraftWorld.getMethod("getHandle");
|
||||||
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
|
this.methodGetChunkAt = this.classWorld.getMethod("getChunkAt", int.class, int.class);
|
||||||
methodA = classChunk.getMethod("a", classBlockPosition, classIBlockData);
|
this.methodA = this.classChunk.getMethod("a", this.classBlockPosition, this.classIBlockData);
|
||||||
chunksender = new SendChunk();
|
this.chunksender = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (toUpdate.isEmpty()) {
|
if (FastQueue_1_8.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
||||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_8.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && (count < 128)) {
|
while (i.hasNext() && (count < 128)) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -73,12 +73,12 @@ public class FastQueue_1_8 extends SlowQueue {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final Collection<Chunk> chunks) {
|
public void update(Collection<Chunk> chunks) {
|
||||||
if (chunks.isEmpty()) {
|
if (chunks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!MainUtil.canSendChunk) {
|
if (!MainUtil.canSendChunk) {
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
chunk.load();
|
chunk.load();
|
||||||
@ -86,38 +86,38 @@ public class FastQueue_1_8 extends SlowQueue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
chunksender.sendChunk(chunks);
|
this.chunksender.sendChunk(chunks);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overriden by any specialized queues
|
* This should be overridden by any specialized queues.
|
||||||
* @param pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(PlotChunk<Chunk> pc) {
|
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||||
SlowChunk sc = (SlowChunk) pc;
|
SlowChunk sc = (SlowChunk) plotChunk;
|
||||||
Chunk chunk = pc.getChunk();
|
Chunk chunk = plotChunk.getChunk();
|
||||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||||
if (!toUpdate.containsKey(wrapper)) {
|
if (!this.toUpdate.containsKey(wrapper)) {
|
||||||
toUpdate.put(wrapper, chunk);
|
this.toUpdate.put(wrapper, chunk);
|
||||||
}
|
}
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
final Object w = methodGetHandle.of(world).call();
|
Object w = this.methodGetHandle.of(world).call();
|
||||||
final Object c = methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
Object c = this.methodGetChunkAt.of(w).call(wrapper.x, wrapper.z);
|
||||||
for (int i = 0; i < sc.result.length; i++) {
|
for (int i = 0; i < sc.result.length; i++) {
|
||||||
PlotBlock[] result2 = sc.result[i];
|
PlotBlock[] result2 = sc.result[i];
|
||||||
if (result2 == null) {
|
if (result2 == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < 4096; j++) {
|
for (int j = 0; j < 4096; j++) {
|
||||||
final int x = MainUtil.x_loc[i][j];
|
int x = MainUtil.x_loc[i][j];
|
||||||
final int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
final int z = MainUtil.z_loc[i][j];
|
int z = MainUtil.z_loc[i][j];
|
||||||
PlotBlock newBlock = result2[j];
|
PlotBlock newBlock = result2[j];
|
||||||
if (newBlock.id == -1) {
|
if (newBlock.id == -1) {
|
||||||
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
chunk.getBlock(x, y, z).setData(newBlock.data, false);
|
||||||
@ -162,7 +162,7 @@ public class FastQueue_1_8 extends SlowQueue {
|
|||||||
case 33:
|
case 33:
|
||||||
case 151:
|
case 151:
|
||||||
case 178: {
|
case 178: {
|
||||||
final Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
if (block.getData() == newBlock.data) {
|
if (block.getData() == newBlock.data) {
|
||||||
if (block.getTypeId() != newBlock.id) {
|
if (block.getTypeId() != newBlock.id) {
|
||||||
block.setTypeId(newBlock.id, false);
|
block.setTypeId(newBlock.id, false);
|
||||||
@ -179,8 +179,8 @@ public class FastQueue_1_8 extends SlowQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start data value shortcut
|
// Start data value shortcut
|
||||||
final Block block = world.getBlockAt(x, y, z);
|
Block block = world.getBlockAt(x, y, z);
|
||||||
final int currentId = block.getTypeId();
|
int currentId = block.getTypeId();
|
||||||
if (currentId == newBlock.id) {
|
if (currentId == newBlock.id) {
|
||||||
switch (newBlock.id) {
|
switch (newBlock.id) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -323,9 +323,9 @@ public class FastQueue_1_8 extends SlowQueue {
|
|||||||
// End blockstate workaround //
|
// End blockstate workaround //
|
||||||
|
|
||||||
// check sign
|
// check sign
|
||||||
final Object pos = constructorBlockPosition.create(x, y, z);
|
Object pos = this.constructorBlockPosition.create(x, y, z);
|
||||||
final Object combined = methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
Object combined = this.methodGetByCombinedId.call(newBlock.id + (newBlock.data << 12));
|
||||||
methodA.of(chunk).call(pos, combined);
|
this.methodA.of(chunk).call(pos, combined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[][] biomes = sc.biomes;
|
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
|
* @param wrap
|
||||||
*/
|
*/
|
||||||
@Override
|
@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
|
* @param fixAll
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
public boolean fixLighting(PlotChunk<Chunk> chunk, boolean fixAll) {
|
||||||
Object c = methodGetHandle.of(chunk.getChunk()).call();
|
Object c = this.methodGetHandle.of(chunk.getChunk()).call();
|
||||||
methodInitLighting.of(c).call();
|
this.methodInitLighting.of(c).call();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues.
|
||||||
* @param locs
|
* @param locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||||
World worldObj = BukkitUtil.getWorld(world);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
for (ChunkLoc loc : locs) {
|
for (ChunkLoc loc : locations) {
|
||||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
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;
|
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.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
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.RefClass;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod.RefExecutor;
|
||||||
|
import com.intellectualcrafters.plot.util.SetQueue;
|
||||||
import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper;
|
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 com.plotsquared.bukkit.util.SendChunk;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -20,59 +25,57 @@ import org.bukkit.block.Biome;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
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 java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
|
||||||
|
|
||||||
public class FastQueue_1_8_3 extends SlowQueue {
|
public class FastQueue_1_8_3 extends SlowQueue {
|
||||||
|
|
||||||
private final SendChunk chunksender;
|
private final SendChunk chunksender;
|
||||||
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||||
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
private final RefMethod methodGetHandleChunk;
|
||||||
private final RefClass classPacket = getRefClass("{nms}.Packet");
|
private final RefConstructor MapChunk;
|
||||||
private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
private final RefMethod methodInitLighting;
|
||||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
private final RefConstructor classBlockPositionConstructor;
|
||||||
private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
private final RefConstructor classChunkSectionConstructor;
|
||||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
private final RefMethod methodX;
|
||||||
private final RefClass classWorld = getRefClass("{nms}.World");
|
private final RefMethod methodAreNeighborsLoaded;
|
||||||
private final RefField mustSave = classChunk.getField("mustSave");
|
private final RefField fieldSections;
|
||||||
private final RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
private final RefField fieldWorld;
|
||||||
private final RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
private final RefMethod methodGetIdArray;
|
||||||
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;
|
|
||||||
|
|
||||||
public FastQueue_1_8_3() throws NoSuchMethodException, RuntimeException {
|
public FastQueue_1_8_3() throws NoSuchMethodException, RuntimeException {
|
||||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||||
fieldSections = classChunk.getField("sections");
|
this.MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||||
fieldWorld = classChunk.getField("world");
|
RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
||||||
methodGetIdArray = classChunkSection.getMethod("getIdArray");
|
this.classBlockPositionConstructor = classBlockPosition.getConstructor(int.class, int.class, int.class);
|
||||||
methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
RefClass classWorld = getRefClass("{nms}.World");
|
||||||
classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
this.methodX = classWorld.getMethod("x", classBlockPosition.getRealClass());
|
||||||
chunksender = new SendChunk();
|
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() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (toUpdate.isEmpty()) {
|
if (FastQueue_1_8_3.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_8_3.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && (count < 128)) {
|
while (i.hasNext() && count < 128) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
count++;
|
count++;
|
||||||
@ -86,12 +89,12 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final Collection<Chunk> chunks) {
|
public void update(Collection<Chunk> chunks) {
|
||||||
if (chunks.isEmpty()) {
|
if (chunks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!MainUtil.canSendChunk) {
|
if (!MainUtil.canSendChunk) {
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
chunk.load();
|
chunk.load();
|
||||||
@ -99,70 +102,70 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
chunksender.sendChunk(chunks);
|
this.chunksender.sendChunk(chunks);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues.
|
||||||
* @param pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(PlotChunk<Chunk> pc) {
|
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||||
FastChunk_1_8_3 fs = (FastChunk_1_8_3) pc;
|
FastChunk_1_8_3 fs = (FastChunk_1_8_3) plotChunk;
|
||||||
Chunk chunk = pc.getChunk();
|
Chunk chunk = plotChunk.getChunk();
|
||||||
final World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||||
if (!toUpdate.containsKey(wrapper)) {
|
if (!this.toUpdate.containsKey(wrapper)) {
|
||||||
toUpdate.put(wrapper, chunk);
|
this.toUpdate.put(wrapper, chunk);
|
||||||
}
|
}
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
try {
|
try {
|
||||||
final boolean flag = world.getEnvironment() == Environment.NORMAL;
|
boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||||
|
|
||||||
// Sections
|
// Sections
|
||||||
final Method getHandele = chunk.getClass().getDeclaredMethod("getHandle");
|
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||||
final Object c = getHandele.invoke(chunk);
|
Object c = getHandle.invoke(chunk);
|
||||||
final Class<? extends Object> clazz = c.getClass();
|
Class<? extends Object> clazz = c.getClass();
|
||||||
final Field sf = clazz.getDeclaredField("sections");
|
Field sections1 = clazz.getDeclaredField("sections");
|
||||||
sf.setAccessible(true);
|
sections1.setAccessible(true);
|
||||||
final Field tf = clazz.getDeclaredField("tileEntities");
|
Field tileEntities = clazz.getDeclaredField("tileEntities");
|
||||||
final Field ef = clazz.getDeclaredField("entitySlices");
|
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||||
|
|
||||||
final Object[] sections = (Object[]) sf.get(c);
|
Object[] sections = (Object[]) sections1.get(c);
|
||||||
final HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
HashMap<?, ?> tiles = (HashMap<?, ?>) tileEntities.get(c);
|
||||||
final List<?>[] entities = (List<?>[]) ef.get(c);
|
List<?>[] entities = (List<?>[]) entitySlices.get(c);
|
||||||
|
|
||||||
Method xm = null;
|
Method getX = null;
|
||||||
Method ym = null;
|
Method getY = null;
|
||||||
Method zm = null;
|
Method getZ = null;
|
||||||
|
|
||||||
// Trim tiles
|
// Trim tiles
|
||||||
final Set<Entry<?, ?>> entryset = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
Set<Entry<?, ?>> entrySet = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||||
final Iterator<Entry<?, ?>> iter = entryset.iterator();
|
Iterator<Entry<?, ?>> iterator = entrySet.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Entry<?, ?> tile = iter.next();
|
Entry<?, ?> tile = iterator.next();
|
||||||
final Object pos = tile.getKey();
|
Object pos = tile.getKey();
|
||||||
if (xm == null) {
|
if (getX == null) {
|
||||||
final Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||||
xm = clazz2.getDeclaredMethod("getX");
|
getX = clazz2.getDeclaredMethod("getX");
|
||||||
ym = clazz2.getDeclaredMethod("getY");
|
getY = clazz2.getDeclaredMethod("getY");
|
||||||
zm = clazz2.getDeclaredMethod("getZ");
|
getZ = clazz2.getDeclaredMethod("getZ");
|
||||||
}
|
}
|
||||||
final int lx = (int) xm.invoke(pos) & 15;
|
int lx = (int) getX.invoke(pos) & 15;
|
||||||
final int ly = (int) ym.invoke(pos);
|
int ly = (int) getY.invoke(pos);
|
||||||
final int lz = (int) zm.invoke(pos) & 15;
|
int lz = (int) getZ.invoke(pos) & 15;
|
||||||
final int j = MainUtil.CACHE_I[ly][lx][lz];
|
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||||
final int k = MainUtil.CACHE_J[ly][lx][lz];
|
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||||
final char[] array = fs.getIdArray(j);
|
char[] array = fs.getIdArray(j);
|
||||||
if (array == null) {
|
if (array == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (array[k] != 0) {
|
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) {
|
if (fs.getCount(j) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final char[] newArray = fs.getIdArray(j);
|
char[] newArray = fs.getIdArray(j);
|
||||||
if (newArray == null) {
|
if (newArray == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -187,10 +190,10 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
section = sections[j] = newChunkSection(j << 4, flag, newArray);
|
section = sections[j] = newChunkSection(j << 4, flag, newArray);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final char[] currentArray = getIdArray(section);
|
char[] currentArray = getIdArray(section);
|
||||||
boolean fill = true;
|
boolean fill = true;
|
||||||
for (int k = 0; k < newArray.length; k++) {
|
for (int k = 0; k < newArray.length; k++) {
|
||||||
final char n = newArray[k];
|
char n = newArray[k];
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0:
|
case 0:
|
||||||
fill = false;
|
fill = false;
|
||||||
@ -209,8 +212,8 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Clear
|
// Clear
|
||||||
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException |
|
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException
|
||||||
NoSuchFieldException e) {
|
| NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
int[][] biomes = fs.biomes;
|
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) {
|
public Object newChunkSection(int i, boolean flag, char[] ids) {
|
||||||
return classChunkSectionConstructor.create(i, flag, ids);
|
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public char[] getIdArray(final Object obj) {
|
public char[] getIdArray(Object obj) {
|
||||||
return (char[]) methodGetIdArray.of(obj).call();
|
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
|
* @param wrap
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -251,13 +254,13 @@ 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 pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
|
public boolean fixLighting(PlotChunk<Chunk> plotChunk, boolean fixAll) {
|
||||||
try {
|
try {
|
||||||
FastChunk_1_8_3 bc = (FastChunk_1_8_3) pc;
|
FastChunk_1_8_3 bc = (FastChunk_1_8_3) plotChunk;
|
||||||
final Chunk chunk = bc.getChunk();
|
Chunk chunk = bc.getChunk();
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
chunk.load(false);
|
chunk.load(false);
|
||||||
} else {
|
} else {
|
||||||
@ -266,12 +269,12 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize lighting
|
// 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();
|
World world = chunk.getWorld();
|
||||||
ChunkWrapper wrapper = bc.getChunkWrapper();
|
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 x = wrapper.x - 1; x <= wrapper.x + 1; x++) {
|
||||||
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
|
for (int z = wrapper.z - 1; z <= wrapper.z + 1; z++) {
|
||||||
if (x != 0 && z != 0) {
|
if (x != 0 && z != 0) {
|
||||||
@ -279,44 +282,46 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
while (!other.isLoaded()) {
|
while (!other.isLoaded()) {
|
||||||
other.load(true);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object[] sections = (Object[]) fieldSections.of(c).get();
|
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||||
final Object w = fieldWorld.of(c).get();
|
Object w = this.fieldWorld.of(c).get();
|
||||||
|
|
||||||
final int X = chunk.getX() << 4;
|
int X = chunk.getX() << 4;
|
||||||
final int Z = chunk.getZ() << 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++) {
|
for (int j = 0; j < sections.length; j++) {
|
||||||
final Object section = sections[j];
|
Object section = sections[j];
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
if ((bc.getRelight(j) == 0 && !fixAll) || bc.getCount(j) == 0 || (bc.getCount(j) >= 4096 && bc.getAir(j) == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final char[] array = getIdArray(section);
|
char[] array = getIdArray(section);
|
||||||
int l = PseudoRandom.random.random(2);
|
int l = PseudoRandom.random.random(2);
|
||||||
for (int k = 0; k < array.length; k++) {
|
for (int k = 0; k < array.length; k++) {
|
||||||
final int i = array[k];
|
int i = array[k];
|
||||||
if (i < 16) {
|
if (i < 16) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final short id = (short) (i >> 4);
|
short id = (short) (i >> 4);
|
||||||
switch (id) { // Lighting
|
switch (id) { // Lighting
|
||||||
default:
|
default:
|
||||||
if (!fixAll) {
|
if (!fixAll) {
|
||||||
@ -341,19 +346,19 @@ public class FastQueue_1_8_3 extends SlowQueue {
|
|||||||
case 130:
|
case 130:
|
||||||
case 138:
|
case 138:
|
||||||
case 169:
|
case 169:
|
||||||
final int x = MainUtil.x_loc[j][k];
|
int x = MainUtil.x_loc[j][k];
|
||||||
final int y = MainUtil.y_loc[j][k];
|
int y = MainUtil.y_loc[j][k];
|
||||||
final int z = MainUtil.z_loc[j][k];
|
int z = MainUtil.z_loc[j][k];
|
||||||
if (isSurrounded(sections, x, y, z)) {
|
if (isSurrounded(sections, x, y, z)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object pos = classBlockPositionConstructor.create(X + x, y, Z + z);
|
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||||
relight.call(pos);
|
relight.call(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
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 world
|
||||||
* @param locs
|
* @param locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@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 : locations) {
|
||||||
for (ChunkLoc loc : locs) {
|
|
||||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
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 {
|
public class FastQueue_1_9 extends SlowQueue {
|
||||||
|
|
||||||
private final Object air;
|
private final Object air;
|
||||||
private final SendChunk chunksender;
|
private final SendChunk chunkSender;
|
||||||
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
private final HashMap<ChunkWrapper, Chunk> toUpdate = new HashMap<>();
|
||||||
private final RefMethod methodGetHandleChunk;
|
private final RefMethod methodGetHandleChunk;
|
||||||
private final RefMethod methodInitLighting;
|
private final RefMethod methodInitLighting;
|
||||||
@ -55,36 +55,36 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
|
|
||||||
public FastQueue_1_9() throws RuntimeException {
|
public FastQueue_1_9() throws RuntimeException {
|
||||||
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
RefClass classBlockPosition = getRefClass("{nms}.BlockPosition");
|
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");
|
RefClass classWorld = getRefClass("{nms}.World");
|
||||||
methodW = classWorld.getMethod("w", classBlockPosition.getRealClass());
|
this.methodW = classWorld.getMethod("w", classBlockPosition.getRealClass());
|
||||||
fieldSections = classChunk.getField("sections");
|
this.fieldSections = classChunk.getField("sections");
|
||||||
fieldWorld = classChunk.getField("world");
|
this.fieldWorld = classChunk.getField("world");
|
||||||
RefClass classBlock = getRefClass("{nms}.Block");
|
RefClass classBlock = getRefClass("{nms}.Block");
|
||||||
RefClass classIBlockData = getRefClass("{nms}.IBlockData");
|
RefClass classIBlockData = getRefClass("{nms}.IBlockData");
|
||||||
methodGetCombinedId = classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
this.methodGetCombinedId = classBlock.getMethod("getCombinedId", classIBlockData.getRealClass());
|
||||||
methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
this.methodGetByCombinedId = classBlock.getMethod("getByCombinedId", int.class);
|
||||||
RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
RefClass classChunkSection = getRefClass("{nms}.ChunkSection");
|
||||||
methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
this.methodGetBlocks = classChunkSection.getMethod("getBlocks");
|
||||||
methodGetType = classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
this.methodGetType = classChunkSection.getMethod("getType", int.class, int.class, int.class);
|
||||||
methodSetType = classChunkSection.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
this.methodSetType = classChunkSection.getMethod("setType", int.class, int.class, int.class, classIBlockData.getRealClass());
|
||||||
methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
this.methodAreNeighborsLoaded = classChunk.getMethod("areNeighborsLoaded", int.class);
|
||||||
classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
this.classChunkSectionConstructor = classChunkSection.getConstructor(int.class, boolean.class, char[].class);
|
||||||
air = methodGetByCombinedId.call(0);
|
this.air = this.methodGetByCombinedId.call(0);
|
||||||
chunksender = new SendChunk();
|
this.chunkSender = new SendChunk();
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (toUpdate.isEmpty()) {
|
if (FastQueue_1_9.this.toUpdate.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
final Iterator<Entry<ChunkWrapper, Chunk>> i = toUpdate.entrySet().iterator();
|
Iterator<Entry<ChunkWrapper, Chunk>> i = FastQueue_1_9.this.toUpdate.entrySet().iterator();
|
||||||
while (i.hasNext() && count < 128) {
|
while (i.hasNext() && count < 128) {
|
||||||
chunks.add(i.next().getValue());
|
chunks.add(i.next().getValue());
|
||||||
i.remove();
|
i.remove();
|
||||||
@ -99,12 +99,12 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(final Collection<Chunk> chunks) {
|
public void update(Collection<Chunk> chunks) {
|
||||||
if (chunks.isEmpty()) {
|
if (chunks.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!MainUtil.canSendChunk) {
|
if (!MainUtil.canSendChunk) {
|
||||||
for (final Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
chunk.load();
|
chunk.load();
|
||||||
@ -112,8 +112,8 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
chunksender.sendChunk(chunks);
|
this.chunkSender.sendChunk(chunks);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
@ -121,60 +121,60 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues
|
||||||
* @param pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(PlotChunk<Chunk> pc) {
|
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||||
FastChunk_1_9 fs = (FastChunk_1_9) pc;
|
FastChunk_1_9 fs = (FastChunk_1_9) plotChunk;
|
||||||
Chunk chunk = pc.getChunk();
|
Chunk chunk = plotChunk.getChunk();
|
||||||
final World world = chunk.getWorld();
|
World world = chunk.getWorld();
|
||||||
ChunkWrapper wrapper = pc.getChunkWrapper();
|
ChunkWrapper wrapper = plotChunk.getChunkWrapper();
|
||||||
if (!toUpdate.containsKey(wrapper)) {
|
if (!this.toUpdate.containsKey(wrapper)) {
|
||||||
toUpdate.put(wrapper, chunk);
|
this.toUpdate.put(wrapper, chunk);
|
||||||
}
|
}
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
try {
|
try {
|
||||||
final boolean flag = world.getEnvironment() == Environment.NORMAL;
|
boolean flag = world.getEnvironment() == Environment.NORMAL;
|
||||||
|
|
||||||
// Sections
|
// Sections
|
||||||
final Method getHandele = chunk.getClass().getDeclaredMethod("getHandle");
|
Method getHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||||
final Object c = getHandele.invoke(chunk);
|
Object c = getHandle.invoke(chunk);
|
||||||
final Class<? extends Object> clazz = c.getClass();
|
Class<? extends Object> clazz = c.getClass();
|
||||||
final Field sf = clazz.getDeclaredField("sections");
|
Field sf = clazz.getDeclaredField("sections");
|
||||||
sf.setAccessible(true);
|
sf.setAccessible(true);
|
||||||
final Field tf = clazz.getDeclaredField("tileEntities");
|
Field tf = clazz.getDeclaredField("tileEntities");
|
||||||
final Field entitySlices = clazz.getDeclaredField("entitySlices");
|
Field entitySlices = clazz.getDeclaredField("entitySlices");
|
||||||
|
|
||||||
final Object[] sections = (Object[]) sf.get(c);
|
Object[] sections = (Object[]) sf.get(c);
|
||||||
final HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
HashMap<?, ?> tiles = (HashMap<?, ?>) tf.get(c);
|
||||||
final Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
Collection<?>[] entities = (Collection<?>[]) entitySlices.get(c);
|
||||||
|
|
||||||
Method xm = null;
|
Method xm = null;
|
||||||
Method ym = null;
|
Method ym = null;
|
||||||
Method zm = null;
|
Method zm = null;
|
||||||
// Trim tiles
|
// Trim tiles
|
||||||
final Set<Entry<?, ?>> entryset = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
Set<Entry<?, ?>> entrySet = (Set<Entry<?, ?>>) (Set<?>) tiles.entrySet();
|
||||||
final Iterator<Entry<?, ?>> iter = entryset.iterator();
|
Iterator<Entry<?, ?>> iterator = entrySet.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final Entry<?, ?> tile = iter.next();
|
Entry<?, ?> tile = iterator.next();
|
||||||
final Object pos = tile.getKey();
|
Object pos = tile.getKey();
|
||||||
if (xm == null) {
|
if (xm == null) {
|
||||||
final Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
Class<? extends Object> clazz2 = pos.getClass().getSuperclass();
|
||||||
xm = clazz2.getDeclaredMethod("getX");
|
xm = clazz2.getDeclaredMethod("getX");
|
||||||
ym = clazz2.getDeclaredMethod("getY");
|
ym = clazz2.getDeclaredMethod("getY");
|
||||||
zm = clazz2.getDeclaredMethod("getZ");
|
zm = clazz2.getDeclaredMethod("getZ");
|
||||||
}
|
}
|
||||||
final int lx = (int) xm.invoke(pos) & 15;
|
int lx = (int) xm.invoke(pos) & 15;
|
||||||
final int ly = (int) ym.invoke(pos);
|
int ly = (int) ym.invoke(pos);
|
||||||
final int lz = (int) zm.invoke(pos) & 15;
|
int lz = (int) zm.invoke(pos) & 15;
|
||||||
final int j = MainUtil.CACHE_I[ly][lx][lz];
|
int j = MainUtil.CACHE_I[ly][lx][lz];
|
||||||
final int k = MainUtil.CACHE_J[ly][lx][lz];
|
int k = MainUtil.CACHE_J[ly][lx][lz];
|
||||||
final int[] array = fs.getIdArray(j);
|
int[] array = fs.getIdArray(j);
|
||||||
if (array == null) {
|
if (array == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (array[k] != 0) {
|
if (array[k] != 0) {
|
||||||
iter.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
if (fs.getCount(j) == 0) {
|
if (fs.getCount(j) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int[] newArray = fs.getIdArray(j);
|
int[] newArray = fs.getIdArray(j);
|
||||||
if (newArray == null) {
|
if (newArray == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -206,11 +206,11 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
section = sections[j] = newChunkSection(j << 4, flag, array);
|
section = sections[j] = newChunkSection(j << 4, flag, array);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object currentArray = getBlocks(section);
|
Object currentArray = getBlocks(section);
|
||||||
RefExecutor setType = methodSetType.of(section);
|
RefExecutor setType = this.methodSetType.of(section);
|
||||||
boolean fill = true;
|
boolean fill = true;
|
||||||
for (int k = 0; k < newArray.length; k++) {
|
for (int k = 0; k < newArray.length; k++) {
|
||||||
final int n = newArray[k];
|
int n = newArray[k];
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 0:
|
case 0:
|
||||||
fill = false;
|
fill = false;
|
||||||
@ -220,15 +220,15 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
int x = MainUtil.x_loc[j][k];
|
int x = MainUtil.x_loc[j][k];
|
||||||
int y = MainUtil.y_loc[j][k];
|
int y = MainUtil.y_loc[j][k];
|
||||||
int z = MainUtil.z_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;
|
continue;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
int x = MainUtil.x_loc[j][k];
|
int x = MainUtil.x_loc[j][k];
|
||||||
int y = MainUtil.y_loc[j][k];
|
int y = MainUtil.y_loc[j][k];
|
||||||
int z = MainUtil.z_loc[j][k];
|
int z = MainUtil.z_loc[j][k];
|
||||||
Object iblock = methodGetByCombinedId.call((int) n);
|
Object iBlock = this.methodGetByCombinedId.call((int) n);
|
||||||
setType.call(x, y & 15, z, iblock);
|
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) {
|
public Object newChunkSection(int i, boolean flag, char[] ids) {
|
||||||
return classChunkSectionConstructor.create(i, flag, ids);
|
return this.classChunkSectionConstructor.create(i, flag, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getBlocks(final Object obj) {
|
public Object getBlocks(Object obj) {
|
||||||
return methodGetBlocks.of(obj).call();
|
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) {
|
public boolean fixLighting(PlotChunk<Chunk> pc, boolean fixAll) {
|
||||||
try {
|
try {
|
||||||
FastChunk_1_9 bc = (FastChunk_1_9) pc;
|
FastChunk_1_9 bc = (FastChunk_1_9) pc;
|
||||||
final Chunk chunk = bc.getChunk();
|
Chunk chunk = bc.getChunk();
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
chunk.load(false);
|
chunk.load(false);
|
||||||
} else {
|
} else {
|
||||||
@ -294,9 +294,9 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize lighting
|
// 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();
|
World world = chunk.getWorld();
|
||||||
ChunkWrapper wrapper = bc.getChunkWrapper();
|
ChunkWrapper wrapper = bc.getChunkWrapper();
|
||||||
String worldname = wrapper.world;
|
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) {
|
if (bc.getTotalRelight() == 0 && !fixAll) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object[] sections = (Object[]) fieldSections.of(c).get();
|
Object[] sections = (Object[]) this.fieldSections.of(c).get();
|
||||||
final Object w = fieldWorld.of(c).get();
|
Object w = this.fieldWorld.of(c).get();
|
||||||
|
|
||||||
final int X = chunk.getX() << 4;
|
int X = chunk.getX() << 4;
|
||||||
final int Z = chunk.getZ() << 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++) {
|
for (int j = 0; j < sections.length; j++) {
|
||||||
final Object section = sections[j];
|
Object section = sections[j];
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
|
if (bc.getRelight(j) == 0 && !fixAll || bc.getCount(j) == 0 || bc.getCount(j) >= 4096 && bc.getAir(j) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int[] array = bc.getIdArray(j);
|
int[] array = bc.getIdArray(j);
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
int l = PseudoRandom.random.random(2);
|
int l = PseudoRandom.random.random(2);
|
||||||
for (int k = 0; k < array.length; k++) {
|
for (int k = 0; k < array.length; k++) {
|
||||||
final int i = array[k];
|
int i = array[k];
|
||||||
if (i < 16) {
|
if (i < 16) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final short id = (short) (i >> 4);
|
short id = (short) (i >> 4);
|
||||||
switch (id) { // Lighting
|
switch (id) { // Lighting
|
||||||
default:
|
default:
|
||||||
if (!fixAll) {
|
if (!fixAll) {
|
||||||
@ -367,20 +367,20 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
case 130:
|
case 130:
|
||||||
case 138:
|
case 138:
|
||||||
case 169:
|
case 169:
|
||||||
final int x = MainUtil.x_loc[j][k];
|
int x = MainUtil.x_loc[j][k];
|
||||||
final int y = MainUtil.y_loc[j][k];
|
int y = MainUtil.y_loc[j][k];
|
||||||
final int z = MainUtil.z_loc[j][k];
|
int z = MainUtil.z_loc[j][k];
|
||||||
if (isSurrounded(bc.getIdArrays(), x, y, z)) {
|
if (isSurrounded(bc.getIdArrays(), x, y, z)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object pos = classBlockPositionConstructor.create(X + x, y, Z + z);
|
Object pos = this.classBlockPositionConstructor.create(X + x, y, Z + z);
|
||||||
relight.call(pos);
|
relight.call(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -397,7 +397,7 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
public boolean isSolid(int i) {
|
public boolean isSolid(int i) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
Material material = Material.getMaterial(i);
|
Material material = Material.getMaterial(i);
|
||||||
return material != null && Material.getMaterial(i).isOccluding();
|
return material != null && Material.getMaterial(i).isOccluding();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -420,8 +420,8 @@ public class FastQueue_1_9 extends SlowQueue {
|
|||||||
|
|
||||||
public int getId(Object section, int x, int y, int z) {
|
public int getId(Object section, int x, int y, int z) {
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
Object iblock = methodGetType.of(section).call(x, y & 15, z);
|
Object iBlock = this.methodGetType.of(section).call(x, y & 15, z);
|
||||||
return (int) methodGetCombinedId.call(iblock);
|
return (int) this.methodGetCombinedId.call(iBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId(Object[] sections, int x, int y, int z) {
|
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) {
|
if (section == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// Object array = getBlocks(section);
|
// Object array = getBlocks(section);
|
||||||
return getId(section, x, y, z);
|
return getId(section, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overridden by any specialized queues
|
* This should be overridden by any specialized queues
|
||||||
* @param world
|
* @param world
|
||||||
* @param locs
|
* @param locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@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);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
for (ChunkLoc loc : locs) {
|
for (ChunkLoc loc : locations) {
|
||||||
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
ChunkWrapper wrapper = SetQueue.IMP.new ChunkWrapper(world, loc.x, loc.z);
|
||||||
toUpdate.remove(wrapper);
|
this.toUpdate.remove(wrapper);
|
||||||
}
|
}
|
||||||
TaskManager.runTaskLater(new Runnable() {
|
TaskManager.runTaskLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
chunksender.sendChunk(world, locs);
|
FastQueue_1_9.this.chunkSender.sendChunk(world, locations);
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
@ -33,40 +33,40 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public Chunk getChunkAbs() {
|
public Chunk getChunkAbs() {
|
||||||
ChunkWrapper wrap = getChunkWrapper();
|
ChunkWrapper wrap = getChunkWrapper();
|
||||||
if (chunk == null || wrap.x != chunk.getX() || wrap.z != chunk.getZ()) {
|
if (this.chunk == null || wrap.x != this.chunk.getX() || wrap.z != this.chunk.getZ()) {
|
||||||
chunk = BukkitUtil.getWorld(wrap.world).getChunkAt(wrap.x, wrap.z);
|
this.chunk = BukkitUtil.getWorld(wrap.world).getChunkAt(wrap.x, wrap.z);
|
||||||
}
|
}
|
||||||
return chunk;
|
return this.chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(int x, int z, int biome) {
|
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) {
|
public void setBiome(int x, int z, Biome biome) {
|
||||||
if (grid != null) {
|
if (this.grid != null) {
|
||||||
grid.setBiome(x, z, biome);
|
this.grid.setBiome(x, z, biome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||||
if (result == null) {
|
if (this.result == null) {
|
||||||
cd.setBlock(x, y, z, id, data);
|
this.cd.setBlock(x, y, z, id, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
short[] v = result[i];
|
short[] v = this.result[i];
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
result[i] = v = new short[4096];
|
this.result[i] = v = new short[4096];
|
||||||
}
|
}
|
||||||
int j = MainUtil.CACHE_J[y][x][z];
|
int j = MainUtil.CACHE_J[y][x][z];
|
||||||
v[j] = (short) id;
|
v[j] = (short) id;
|
||||||
if (data != 0) {
|
if (data != 0) {
|
||||||
byte[] vd = result_data[i];
|
byte[] vd = this.result_data[i];
|
||||||
if (vd == null) {
|
if (vd == null) {
|
||||||
result_data[i] = vd = new byte[4096];
|
this.result_data[i] = vd = new byte[4096];
|
||||||
}
|
}
|
||||||
vd[j] = data;
|
vd[j] = data;
|
||||||
}
|
}
|
||||||
@ -75,32 +75,32 @@ public class GenChunk extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public PlotChunk clone() {
|
public PlotChunk clone() {
|
||||||
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
||||||
if (result != null) {
|
if (this.result != null) {
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < this.result.length; i++) {
|
||||||
short[] matrix = result[i];
|
short[] matrix = this.result[i];
|
||||||
if (matrix != null) {
|
if (matrix != null) {
|
||||||
toReturn.result[i] = new short[matrix.length];
|
toReturn.result[i] = new short[matrix.length];
|
||||||
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < result_data.length; i++) {
|
for (int i = 0; i < this.result_data.length; i++) {
|
||||||
byte[] matrix = result_data[i];
|
byte[] matrix = this.result_data[i];
|
||||||
if (matrix != null) {
|
if (matrix != null) {
|
||||||
toReturn.result_data[i] = new byte[matrix.length];
|
toReturn.result_data[i] = new byte[matrix.length];
|
||||||
System.arraycopy(matrix, 0, toReturn.result_data[i], 0, matrix.length);
|
System.arraycopy(matrix, 0, toReturn.result_data[i], 0, matrix.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toReturn.cd = cd;
|
toReturn.cd = this.cd;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotChunk shallowClone() {
|
public PlotChunk shallowClone() {
|
||||||
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
GenChunk toReturn = new GenChunk(getChunkAbs(), getChunkWrapper());
|
||||||
toReturn.result = result;
|
toReturn.result = this.result;
|
||||||
toReturn.result_data = result_data;
|
toReturn.result_data = this.result_data;
|
||||||
toReturn.cd = cd;
|
toReturn.cd = this.cd;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
|||||||
|
|
||||||
public PlotBlock[][] result = new PlotBlock[16][];
|
public PlotBlock[][] result = new PlotBlock[16][];
|
||||||
public int[][] biomes;
|
public int[][] biomes;
|
||||||
|
|
||||||
public SlowChunk(ChunkWrapper chunk) {
|
public SlowChunk(ChunkWrapper chunk) {
|
||||||
super(chunk);
|
super(chunk);
|
||||||
}
|
}
|
||||||
@ -23,25 +24,25 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBiome(int x, int z, int biome) {
|
public void setBiome(int x, int z, int biome) {
|
||||||
if (biomes == null) {
|
if (this.biomes == null) {
|
||||||
biomes = new int[16][16];
|
this.biomes = new int[16][16];
|
||||||
}
|
}
|
||||||
biomes[x][z] = biome;
|
this.biomes[x][z] = biome;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBlock(int x, int y, int z, int id, byte data) {
|
public void setBlock(int x, int y, int z, int id, byte data) {
|
||||||
if (result[y >> 4] == null) {
|
if (this.result[y >> 4] == null) {
|
||||||
result[y >> 4] = new PlotBlock[4096];
|
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
|
@Override
|
||||||
public PlotChunk clone() {
|
public PlotChunk clone() {
|
||||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < this.result.length; i++) {
|
||||||
PlotBlock[] matrix = result[i];
|
PlotBlock[] matrix = this.result[i];
|
||||||
if (matrix != null) {
|
if (matrix != null) {
|
||||||
toReturn.result[i] = new PlotBlock[matrix.length];
|
toReturn.result[i] = new PlotBlock[matrix.length];
|
||||||
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
System.arraycopy(matrix, 0, toReturn.result[i], 0, matrix.length);
|
||||||
@ -53,7 +54,7 @@ public class SlowChunk extends PlotChunk<Chunk> {
|
|||||||
@Override
|
@Override
|
||||||
public PlotChunk shallowClone() {
|
public PlotChunk shallowClone() {
|
||||||
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
SlowChunk toReturn = new SlowChunk(getChunkWrapper());
|
||||||
toReturn.result = result;
|
toReturn.result = this.result;
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,18 +30,18 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
if (y > 255 || y < 0) {
|
if (y > 255 || y < 0) {
|
||||||
return false;
|
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;
|
x = x & 15;
|
||||||
z = z & 15;
|
z = z & 15;
|
||||||
PlotChunk<Chunk> result = blocks.get(wrap);
|
PlotChunk<Chunk> result = this.blocks.get(wrap);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = getChunk(wrap);
|
result = getChunk(wrap);
|
||||||
result.setBlock(x, y, z, id, data);
|
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) {
|
if (previous == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
blocks.put(wrap, previous);
|
this.blocks.put(wrap, previous);
|
||||||
result = previous;
|
result = previous;
|
||||||
}
|
}
|
||||||
result.setBlock(x, y, z, id, data);
|
result.setBlock(x, y, z, id, data);
|
||||||
@ -50,7 +50,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChunk(PlotChunk<Chunk> chunk) {
|
public void setChunk(PlotChunk<Chunk> chunk) {
|
||||||
blocks.put(chunk.getChunkWrapper(), chunk);
|
this.blocks.put(chunk.getChunkWrapper(), chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,11 +59,11 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
throw new IllegalStateException("Must be called from main thread!");
|
throw new IllegalStateException("Must be called from main thread!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (blocks.isEmpty()) {
|
if (this.blocks.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = blocks.entrySet().iterator();
|
Iterator<Entry<ChunkWrapper, PlotChunk<Chunk>>> iter = this.blocks.entrySet().iterator();
|
||||||
final PlotChunk<Chunk> toReturn = iter.next().getValue();
|
PlotChunk<Chunk> toReturn = iter.next().getValue();
|
||||||
if (SetQueue.IMP.isWaiting()) {
|
if (SetQueue.IMP.isWaiting()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
execute(toReturn);
|
execute(toReturn);
|
||||||
fixLighting(toReturn, true);
|
fixLighting(toReturn, true);
|
||||||
return toReturn;
|
return toReturn;
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -83,17 +83,17 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
throw new IllegalStateException("Must be called from main thread!");
|
throw new IllegalStateException("Must be called from main thread!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (blocks.isEmpty()) {
|
if (this.blocks.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final PlotChunk<Chunk> toReturn = blocks.remove(wrap);
|
PlotChunk<Chunk> toReturn = this.blocks.remove(wrap);
|
||||||
if (toReturn == null) {
|
if (toReturn == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
execute(toReturn);
|
execute(toReturn);
|
||||||
fixLighting(toReturn, fixLighting);
|
fixLighting(toReturn, fixLighting);
|
||||||
return toReturn;
|
return toReturn;
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -101,16 +101,16 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
blocks.clear();
|
this.blocks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overriden by any specialized queues
|
* This should be overridden by any specialized queues.
|
||||||
* @param pc
|
* @param plotChunk
|
||||||
*/
|
*/
|
||||||
public void execute(PlotChunk<Chunk> pc) {
|
public void execute(PlotChunk<Chunk> plotChunk) {
|
||||||
SlowChunk sc = (SlowChunk) pc;
|
SlowChunk sc = (SlowChunk) plotChunk;
|
||||||
Chunk chunk = pc.getChunk();
|
Chunk chunk = plotChunk.getChunk();
|
||||||
chunk.load(true);
|
chunk.load(true);
|
||||||
for (int i = 0; i < sc.result.length; i++) {
|
for (int i = 0; i < sc.result.length; i++) {
|
||||||
PlotBlock[] result2 = sc.result[i];
|
PlotBlock[] result2 = sc.result[i];
|
||||||
@ -118,9 +118,9 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < 4096; j++) {
|
for (int j = 0; j < 4096; j++) {
|
||||||
final int x = MainUtil.x_loc[i][j];
|
int x = MainUtil.x_loc[i][j];
|
||||||
final int y = MainUtil.y_loc[i][j];
|
int y = MainUtil.y_loc[i][j];
|
||||||
final int z = MainUtil.z_loc[i][j];
|
int z = MainUtil.z_loc[i][j];
|
||||||
Block block = chunk.getBlock(x, y, z);
|
Block block = chunk.getBlock(x, y, z);
|
||||||
PlotBlock newBlock = result2[j];
|
PlotBlock newBlock = result2[j];
|
||||||
if (newBlock == null) {
|
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
|
* @param wrap
|
||||||
*/
|
*/
|
||||||
@Override
|
@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
|
* @param fixAll
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -271,11 +271,11 @@ public class SlowQueue implements PlotQueue<Chunk> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should be overriden by any specialized queues
|
* This should be overridden by any specialized queues.
|
||||||
* @param locs
|
* @param locations
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void sendChunk(String world, Collection<ChunkLoc> locs) {
|
public void sendChunk(String world, Collection<ChunkLoc> locations) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,41 +1,40 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DefaultUUIDWrapper extends UUIDWrapper {
|
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final PlotPlayer player) {
|
public UUID getUUID(PlotPlayer player) {
|
||||||
return ((BukkitPlayer) player).player.getUniqueId();
|
return ((BukkitPlayer) player).player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
return player.getUUID();
|
return player.getUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final String name) {
|
public UUID getUUID(String name) {
|
||||||
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
final OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
final BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
for (int i = 0; i < ops.length; i++) {
|
for (int i = 0; i < ops.length; i++) {
|
||||||
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|||||||
import com.plotsquared.bukkit.util.NbtFactory;
|
import com.plotsquared.bukkit.util.NbtFactory;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
@ -32,18 +33,18 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
public FileUUIDHandler(final UUIDWrapper wrapper) {
|
public FileUUIDHandler(UUIDWrapper wrapper) {
|
||||||
super(wrapper);
|
super(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean startCaching(final Runnable whenDone) {
|
public boolean startCaching(Runnable whenDone) {
|
||||||
return super.startCaching(whenDone) && cache(whenDone);
|
return super.startCaching(whenDone) && cache(whenDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cache(final Runnable whenDone) {
|
public boolean cache(final Runnable whenDone) {
|
||||||
final File container = Bukkit.getWorldContainer();
|
final File container = Bukkit.getWorldContainer();
|
||||||
final List<World> worlds = Bukkit.getWorlds();
|
List<World> worlds = Bukkit.getWorlds();
|
||||||
final String world;
|
final String world;
|
||||||
if (worlds.isEmpty()) {
|
if (worlds.isEmpty()) {
|
||||||
world = "world";
|
world = "world";
|
||||||
@ -54,10 +55,10 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
||||||
final File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (uuidfile.exists()) {
|
if (uuidfile.exists()) {
|
||||||
try {
|
try {
|
||||||
final List<String> lines = Files.readAllLines(uuidfile.toPath(), StandardCharsets.UTF_8);
|
List<String> lines = Files.readAllLines(uuidfile.toPath(), StandardCharsets.UTF_8);
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
try {
|
try {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
@ -65,55 +66,55 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
final String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
final String name = split[0];
|
String name = split[0];
|
||||||
if ((name.isEmpty()) || (name.length() > 16) || !StringMan.isAlphanumericUnd(name)) {
|
if (name.isEmpty() || (name.length() > 16) || !StringMan.isAlphanumericUnd(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final UUID uuid = uuidWrapper.getUUID(name);
|
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
UUIDHandler.add(new StringWrapper(name), uuid);
|
UUIDHandler.add(new StringWrapper(name), uuid);
|
||||||
} catch (final Exception e2) {
|
} catch (Exception e2) {
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.TWIN_MODE_UUID) {
|
if (Settings.TWIN_MODE_UUID) {
|
||||||
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
||||||
final HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||||
PS.debug("&aFast mode UUID caching enabled!");
|
PS.debug("&aFast mode UUID caching enabled!");
|
||||||
final File playerdataFolder = new File(container, world + File.separator + "playerdata");
|
File playerdataFolder = new File(container, world + File.separator + "playerdata");
|
||||||
final String[] dat = playerdataFolder.list(new FilenameFilter() {
|
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s) {
|
public boolean accept(File f, String s) {
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final boolean check = all.isEmpty();
|
boolean check = all.isEmpty();
|
||||||
if (dat != null) {
|
if (dat != null) {
|
||||||
for (final String current : dat) {
|
for (String current : dat) {
|
||||||
final String s = current.replaceAll(".dat$", "");
|
String s = current.replaceAll(".dat$", "");
|
||||||
try {
|
try {
|
||||||
final UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if (check || all.remove(uuid)) {
|
if (check || all.remove(uuid)) {
|
||||||
final File file = new File(playerdataFolder + File.separator + current);
|
File file = new File(playerdataFolder + File.separator + current);
|
||||||
final InputSupplier<FileInputStream> is = com.google.common.io.Files.newInputStreamSupplier(file);
|
InputSupplier<FileInputStream> is = com.google.common.io.Files.newInputStreamSupplier(file);
|
||||||
final NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
final NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
final String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
final long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
if (ExpireManager.IMP != null) {
|
if (ExpireManager.IMP != null) {
|
||||||
ExpireManager.IMP.storeDate(uuid, last);
|
ExpireManager.IMP.storeDate(uuid, last);
|
||||||
}
|
}
|
||||||
toAdd.put(new StringWrapper(name), uuid);
|
toAdd.put(new StringWrapper(name), uuid);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
|
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
|
||||||
}
|
}
|
||||||
@ -129,45 +130,45 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
PS.debug("Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
PS.debug("Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
toAdd.put(new StringWrapper("*"), DBFunc.everyone);
|
||||||
final HashSet<String> worlds = new HashSet<>();
|
HashSet<String> worlds = new HashSet<>();
|
||||||
worlds.add(world);
|
worlds.add(world);
|
||||||
worlds.add("world");
|
worlds.add("world");
|
||||||
final HashSet<UUID> uuids = new HashSet<>();
|
HashSet<UUID> uuids = new HashSet<>();
|
||||||
final HashSet<String> names = new HashSet<>();
|
HashSet<String> names = new HashSet<>();
|
||||||
File playerdataFolder = null;
|
File playerdataFolder = null;
|
||||||
for (final String worldname : worlds) {
|
for (String worldName : worlds) {
|
||||||
// Getting UUIDs
|
// Getting UUIDs
|
||||||
playerdataFolder = new File(container, worldname + File.separator + "playerdata");
|
playerdataFolder = new File(container, worldName + File.separator + "playerdata");
|
||||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s) {
|
public boolean accept(File f, String s) {
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ((dat != null) && (dat.length != 0)) {
|
if ((dat != null) && (dat.length != 0)) {
|
||||||
for (final String current : dat) {
|
for (String current : dat) {
|
||||||
final String s = current.replaceAll(".dat$", "");
|
String s = current.replaceAll(".dat$", "");
|
||||||
try {
|
try {
|
||||||
final UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
uuids.add(uuid);
|
uuids.add(uuid);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
|
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Getting names
|
// Getting names
|
||||||
final File playersFolder = new File(worldname + File.separator + "players");
|
File playersFolder = new File(worldName + File.separator + "players");
|
||||||
dat = playersFolder.list(new FilenameFilter() {
|
dat = playersFolder.list(new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(final File f, final String s) {
|
public boolean accept(File f, String s) {
|
||||||
return s.endsWith(".dat");
|
return s.endsWith(".dat");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ((dat != null) && (dat.length != 0)) {
|
if ((dat != null) && (dat.length != 0)) {
|
||||||
for (final String current : dat) {
|
for (String current : dat) {
|
||||||
names.add(current.replaceAll(".dat$", ""));
|
names.add(current.replaceAll(".dat$", ""));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -175,21 +176,21 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
try {
|
try {
|
||||||
final File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
|
File file = new File(playerdataFolder + File.separator + uuid.toString() + ".dat");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final ByteSource is = com.google.common.io.Files.asByteSource(file);
|
ByteSource is = com.google.common.io.Files.asByteSource(file);
|
||||||
final NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory.fromStream(is, NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
final NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
final String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
final long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
if (Settings.OFFLINE_MODE) {
|
if (Settings.OFFLINE_MODE) {
|
||||||
if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) {
|
if (Settings.UUID_LOWERCASE && !name.toLowerCase().equals(name)) {
|
||||||
uuid = uuidWrapper.getUUID(name);
|
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
} else {
|
} else {
|
||||||
final long most = (long) compound.get("UUIDMost");
|
long most = (long) compound.get("UUIDMost");
|
||||||
final long least = (long) compound.get("UUIDLeast");
|
long least = (long) compound.get("UUIDLeast");
|
||||||
uuid = new UUID(most, least);
|
uuid = new UUID(most, least);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,23 +198,23 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
ExpireManager.IMP.storeDate(uuid, last);
|
ExpireManager.IMP.storeDate(uuid, last);
|
||||||
}
|
}
|
||||||
toAdd.put(new StringWrapper(name), uuid);
|
toAdd.put(new StringWrapper(name), uuid);
|
||||||
} catch (final Throwable e) {
|
} catch (Throwable e) {
|
||||||
PS.debug(C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
PS.debug(C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final String name : names) {
|
for (String name : names) {
|
||||||
final UUID uuid = uuidWrapper.getUUID(name);
|
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
final StringWrapper nameWrap = new StringWrapper(name);
|
StringWrapper nameWrap = new StringWrapper(name);
|
||||||
toAdd.put(nameWrap, uuid);
|
toAdd.put(nameWrap, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getUUIDMap().isEmpty()) {
|
if (getUUIDMap().isEmpty()) {
|
||||||
for (final OfflinePlotPlayer op : uuidWrapper.getOfflinePlayers()) {
|
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper.getOfflinePlayers()) {
|
||||||
final long last = op.getLastPlayed();
|
long last = op.getLastPlayed();
|
||||||
if (last != 0) {
|
if (last != 0) {
|
||||||
final String name = op.getName();
|
String name = op.getName();
|
||||||
final StringWrapper wrap = new StringWrapper(name);
|
StringWrapper wrap = new StringWrapper(name);
|
||||||
final UUID uuid = uuidWrapper.getUUID(op);
|
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(op);
|
||||||
toAdd.put(wrap, uuid);
|
toAdd.put(wrap, uuid);
|
||||||
if (ExpireManager.IMP != null) {
|
if (ExpireManager.IMP != null) {
|
||||||
ExpireManager.IMP.storeDate(uuid, last);
|
ExpireManager.IMP.storeDate(uuid, last);
|
||||||
@ -235,7 +236,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ifFetch.value = uuidWrapper.getUUID(name);
|
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
TaskManager.runTask(ifFetch);
|
TaskManager.runTask(ifFetch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
@ -17,50 +8,58 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
||||||
private Method getOnline = null;
|
|
||||||
private final Object[] arg = new Object[0];
|
private final Object[] arg = new Object[0];
|
||||||
|
private Method getOnline = null;
|
||||||
|
|
||||||
public LowerOfflineUUIDWrapper() {
|
public LowerOfflineUUIDWrapper() {
|
||||||
try {
|
try {
|
||||||
getOnline = Server.class.getMethod("getOnlinePlayers");
|
this.getOnline = Server.class.getMethod("getOnlinePlayers");
|
||||||
} catch (final NoSuchMethodException | SecurityException e) {
|
} catch (NoSuchMethodException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final PlotPlayer player) {
|
public UUID getUUID(PlotPlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final OfflinePlayer player) {
|
public UUID getUUID(OfflinePlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||||
String name;
|
String name;
|
||||||
try {
|
try {
|
||||||
name = map.get(uuid).value;
|
name = map.get(uuid).value;
|
||||||
} catch (final NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
||||||
if (op.hasPlayedBefore()) {
|
if (op.hasPlayedBefore()) {
|
||||||
return new BukkitOfflinePlayer(op);
|
return new BukkitOfflinePlayer(op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (getUUID(player).equals(uuid)) {
|
if (getUUID(player).equals(uuid)) {
|
||||||
return new BukkitOfflinePlayer(player);
|
return new BukkitOfflinePlayer(player);
|
||||||
}
|
}
|
||||||
@ -70,36 +69,35 @@ public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Player[] getOnlinePlayers() {
|
public Player[] getOnlinePlayers() {
|
||||||
if (getOnline == null) {
|
if (this.getOnline == null) {
|
||||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Object players = getOnline.invoke(Bukkit.getServer(), arg);
|
Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
|
||||||
if (players instanceof Player[]) {
|
if (players instanceof Player[]) {
|
||||||
return (Player[]) players;
|
return (Player[]) players;
|
||||||
} else {
|
} else {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") Collection<? extends Player> p = (Collection<? extends Player>) players;
|
||||||
final Collection<? extends Player> p = (Collection<? extends Player>) players;
|
|
||||||
return p.toArray(new Player[p.size()]);
|
return p.toArray(new Player[p.size()]);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("Failed to resolve online players");
|
PS.debug("Failed to resolve online players");
|
||||||
getOnline = null;
|
this.getOnline = null;
|
||||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final String name) {
|
public UUID getUUID(String name) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
final OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
final BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
for (int i = 0; i < ops.length; i++) {
|
for (int i = 0; i < ops.length; i++) {
|
||||||
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
@ -18,49 +9,57 @@ import com.intellectualcrafters.plot.object.StringWrapper;
|
|||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class OfflineUUIDWrapper extends UUIDWrapper {
|
public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||||
private Method getOnline = null;
|
|
||||||
private final Object[] arg = new Object[0];
|
private final Object[] arg = new Object[0];
|
||||||
|
private Method getOnline = null;
|
||||||
|
|
||||||
public OfflineUUIDWrapper() {
|
public OfflineUUIDWrapper() {
|
||||||
try {
|
try {
|
||||||
getOnline = Server.class.getMethod("getOnlinePlayers");
|
this.getOnline = Server.class.getMethod("getOnlinePlayers");
|
||||||
} catch (final NoSuchMethodException | SecurityException e) {
|
} catch (NoSuchMethodException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final PlotPlayer player) {
|
public UUID getUUID(PlotPlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final OfflinePlotPlayer player) {
|
public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID(final OfflinePlayer player) {
|
public UUID getUUID(OfflinePlayer player) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer getOfflinePlayer(final UUID uuid) {
|
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
final BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||||
String name;
|
String name;
|
||||||
try {
|
try {
|
||||||
name = map.get(uuid).value;
|
name = map.get(uuid).value;
|
||||||
} catch (final NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
OfflinePlayer op = Bukkit.getOfflinePlayer(name);
|
||||||
if (op.hasPlayedBefore()) {
|
if (op.hasPlayedBefore()) {
|
||||||
return new BukkitOfflinePlayer(op);
|
return new BukkitOfflinePlayer(op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||||
if (getUUID(player).equals(uuid)) {
|
if (getUUID(player).equals(uuid)) {
|
||||||
return new BukkitOfflinePlayer(player);
|
return new BukkitOfflinePlayer(player);
|
||||||
}
|
}
|
||||||
@ -69,36 +68,35 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Player[] getOnlinePlayers() {
|
public Player[] getOnlinePlayers() {
|
||||||
if (getOnline == null) {
|
if (this.getOnline == null) {
|
||||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final Object players = getOnline.invoke(Bukkit.getServer(), arg);
|
Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
|
||||||
if (players instanceof Player[]) {
|
if (players instanceof Player[]) {
|
||||||
return (Player[]) players;
|
return (Player[]) players;
|
||||||
} else {
|
} else {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") Collection<? extends Player> p = (Collection<? extends Player>) players;
|
||||||
final Collection<? extends Player> p = (Collection<? extends Player>) players;
|
|
||||||
return p.toArray(new Player[p.size()]);
|
return p.toArray(new Player[p.size()]);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("Failed to resolve online players");
|
PS.debug("Failed to resolve online players");
|
||||||
getOnline = null;
|
this.getOnline = null;
|
||||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID(final String name) {
|
public UUID getUUID(String name) {
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OfflinePlotPlayer[] getOfflinePlayers() {
|
public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
final OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
final BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
for (int i = 0; i < ops.length; i++) {
|
for (int i = 0; i < ops.length; i++) {
|
||||||
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,9 @@ import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@ -31,35 +33,34 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
|
||||||
final int MAX_REQUESTS = 500;
|
final int MAX_REQUESTS = 500;
|
||||||
final int INTERVAL = 12000;
|
private final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
final JSONParser jsonParser = new JSONParser();
|
private final int INTERVAL = 12000;
|
||||||
private final SQLite _sqLite;
|
private final JSONParser jsonParser = new JSONParser();
|
||||||
|
private final SQLite sqlite;
|
||||||
|
|
||||||
public SQLUUIDHandler(final UUIDWrapper wrapper) {
|
public SQLUUIDHandler(UUIDWrapper wrapper) {
|
||||||
super(wrapper);
|
super(wrapper);
|
||||||
_sqLite = new SQLite("./plugins/PlotSquared/usercache.db");
|
this.sqlite = new SQLite("./plugins/PlotSquared/usercache.db");
|
||||||
try {
|
try {
|
||||||
_sqLite.openConnection();
|
this.sqlite.openConnection();
|
||||||
} catch (final Exception e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try (PreparedStatement stmt = getConnection().prepareStatement(
|
||||||
final PreparedStatement stmt = getConnection().prepareStatement(
|
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid, username)"
|
||||||
"CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid, username))");
|
+ ")")) {
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
stmt.close();
|
} catch (SQLException e) {
|
||||||
} catch (final SQLException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
startCaching(null);
|
startCaching(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection getConnection() {
|
private Connection getConnection() {
|
||||||
synchronized (_sqLite) {
|
synchronized (this.sqlite) {
|
||||||
return _sqLite.getConnection();
|
return this.sqlite.getConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +73,9 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
final PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||||
final ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
StringWrapper username = new StringWrapper(resultSet.getString("username"));
|
StringWrapper username = new StringWrapper(resultSet.getString("username"));
|
||||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||||
@ -86,7 +87,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
|
|
||||||
// This should be called as long as there are some unknown plots
|
// This should be called as long as there are some unknown plots
|
||||||
final ArrayDeque<UUID> toFetch = new ArrayDeque<>();
|
final ArrayDeque<UUID> toFetch = new ArrayDeque<>();
|
||||||
for (final UUID u : UUIDHandler.getAllUUIDS()) {
|
for (UUID u : UUIDHandler.getAllUUIDS()) {
|
||||||
if (!uuidExists(u)) {
|
if (!uuidExists(u)) {
|
||||||
toFetch.add(u);
|
toFetch.add(u);
|
||||||
}
|
}
|
||||||
@ -97,7 +98,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
||||||
fileHandler.startCaching(new Runnable() {
|
fileHandler.startCaching(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -122,70 +123,25 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
for (int i = 0; i < Math.min(500, toFetch.size()); i++) {
|
||||||
UUID uuid = toFetch.pop();
|
UUID uuid = toFetch.pop();
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(PROFILE_URL + uuid.toString().replace("-", "")).openConnection();
|
HttpURLConnection connection =
|
||||||
|
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
||||||
|
.openConnection();
|
||||||
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
|
InputStreamReader reader = new InputStreamReader(connection.getInputStream());
|
||||||
JSONObject response = (JSONObject) jsonParser.parse(reader);
|
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
|
||||||
String name = (String) response.get("name");
|
String name = (String) response.get("name");
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
add(new StringWrapper(name), uuid);
|
add(new StringWrapper(name), uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
TaskManager.runTaskLaterAsync(this, INTERVAL);
|
TaskManager.runTaskLaterAsync(this, SQLUUIDHandler.this.INTERVAL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
* This API is no longer accessible.
|
|
||||||
*/
|
|
||||||
// if (!Settings.OFFLINE_MODE) {
|
|
||||||
// PS.debug(C.PREFIX.s() + "&cWill fetch &6" + toFetch.size() + "&c from mojang!");
|
|
||||||
//
|
|
||||||
// int i = 0;
|
|
||||||
// final Iterator<UUID> iterator = toFetch.iterator();
|
|
||||||
// while (iterator.hasNext()) {
|
|
||||||
// final StringBuilder url = new StringBuilder("http://api.intellectualsites.com/uuid/?user=");
|
|
||||||
// final List<UUID> currentIteration = new ArrayList<>();
|
|
||||||
// while ((i++ <= 15) && iterator.hasNext()) {
|
|
||||||
// final UUID _uuid = iterator.next();
|
|
||||||
// url.append(_uuid.toString());
|
|
||||||
// if (iterator.hasNext()) {
|
|
||||||
// url.append(",");
|
|
||||||
// }
|
|
||||||
// currentIteration.add(_uuid);
|
|
||||||
// }
|
|
||||||
// PS.debug(C.PREFIX.s() + "&cWill attempt to fetch &6" + currentIteration.size() + "&c uuids from: &6" + url.toString());
|
|
||||||
// try {
|
|
||||||
// final HttpURLConnection connection = (HttpURLConnection) new URL(url.toString()).openConnection();
|
|
||||||
// connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
|
||||||
// final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
// String line;
|
|
||||||
// final StringBuilder rawJSON = new StringBuilder();
|
|
||||||
// while ((line = reader.readLine()) != null) {
|
|
||||||
// rawJSON.append(line);
|
|
||||||
// }
|
|
||||||
// reader.close();
|
|
||||||
// final JSONObject object = new JSONObject(rawJSON.toString());
|
|
||||||
// for (final UUID _u : currentIteration) {
|
|
||||||
// final Object o = object.getJSONObject(_u.toString().replace("-", "")).get("username");
|
|
||||||
// if ((o == null) || !(o instanceof String)) {
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
// add(new StringWrapper(o.toString()), _u);
|
|
||||||
// }
|
|
||||||
// } catch (final Exception e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// i = 0;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (whenDone != null) {
|
|
||||||
// whenDone.run();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (final SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SQLUUIDHandlerException("Couldn't select :s", e);
|
throw new SQLUUIDHandlerException("Couldn't select :s", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +159,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(PROFILE_URL);
|
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
@ -215,12 +171,14 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
stream.write(body.getBytes());
|
stream.write(body.getBytes());
|
||||||
stream.flush();
|
stream.flush();
|
||||||
stream.close();
|
stream.close();
|
||||||
JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||||
JSONObject jsonProfile = (JSONObject) array.get(0);
|
JSONObject jsonProfile = (JSONObject) array.get(0);
|
||||||
String id = (String) jsonProfile.get("id");
|
String id = (String) jsonProfile.get("id");
|
||||||
String name = (String) jsonProfile.get("name");
|
String name = (String) jsonProfile.get("name");
|
||||||
ifFetch.value = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
ifFetch.value = UUID.fromString(
|
||||||
} catch (Exception e) {
|
id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id
|
||||||
|
.substring(20, 32));
|
||||||
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
TaskManager.runTask(ifFetch);
|
TaskManager.runTask(ifFetch);
|
||||||
@ -233,7 +191,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
super.handleShutdown();
|
super.handleShutdown();
|
||||||
try {
|
try {
|
||||||
getConnection().close();
|
getConnection().close();
|
||||||
} catch (final SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new SQLUUIDHandlerException("Couldn't close database connection", e);
|
throw new SQLUUIDHandlerException("Couldn't close database connection", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,13 +203,12 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try (PreparedStatement statement = getConnection().prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
||||||
final PreparedStatement statement = getConnection().prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)");
|
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
statement.setString(2, name.toString());
|
statement.setString(2, name.toString());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
PS.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
PS.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
||||||
} catch (final SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,13 +227,12 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try (PreparedStatement statement = getConnection().prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
||||||
final PreparedStatement statement = getConnection().prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?");
|
|
||||||
statement.setString(1, name.value);
|
statement.setString(1, name.value);
|
||||||
statement.setString(2, uuid.toString());
|
statement.setString(2, uuid.toString());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
PS.debug(C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + "'");
|
PS.debug(C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + "'");
|
||||||
} catch (final SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,7 +241,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
|
|
||||||
private class SQLUUIDHandlerException extends RuntimeException {
|
private class SQLUUIDHandlerException extends RuntimeException {
|
||||||
|
|
||||||
SQLUUIDHandlerException(final String s, final Throwable c) {
|
SQLUUIDHandlerException(String s, Throwable c) {
|
||||||
super("SQLUUIDHandler caused an exception: " + s, c);
|
super("SQLUUIDHandler caused an exception: " + s, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,221 +21,225 @@ import java.io.File;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IPlotMain {
|
public interface IPlotMain {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message to console
|
* Log a message to console.
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
void log(final String message);
|
void log(String message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the `PlotSquared` directory (e.g. /plugins/PlotSquared or /mods/PlotSquared)
|
* Get the `PlotSquared` directory.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
File getDirectory();
|
File getDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the directory containing all the worlds
|
* Get the directory containing all the worlds.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
File getWorldContainer();
|
File getWorldContainer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap a player into a PlotPlayer object
|
* Wrap a player into a PlotPlayer object.
|
||||||
* @param obj
|
* @param player
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PlotPlayer wrapPlayer(final Object obj);
|
PlotPlayer wrapPlayer(Object player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable the implementation
|
* Disable the implementation.
|
||||||
* - If a full disable isn't feasibly, just disable what it can
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>If a full disable isn't feasibly, just disable what it can.</li>
|
||||||
|
* </ul>
|
||||||
*/
|
*/
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of the PlotSquared being used
|
* Get the version of the PlotSquared being used.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int[] getPluginVersion();
|
int[] getPluginVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of Minecraft that is running
|
* Get the version of Minecraft that is running.
|
||||||
* (used to check what protocols and such are supported)
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int[] getServerVersion();
|
int[] getServerVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the nms package prefix
|
* Get the nms package prefix.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getNMSPackage();
|
String getNMSPackage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the schematic handler
|
* Get the schematic handler.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SchematicHandler initSchematicHandler();
|
SchematicHandler initSchematicHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the schematic handler
|
* Get the schematic handler.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ChatManager initChatManager();
|
ChatManager initChatManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The task manager will run and manage minecraft tasks
|
* The task manager will run and manage Minecraft tasks.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
TaskManager getTaskManager();
|
TaskManager getTaskManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the task that will kill road mobs
|
* Run the task that will kill road mobs.
|
||||||
*/
|
*/
|
||||||
void runEntityTask();
|
void runEntityTask();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the implementation specific commands
|
* Register the implementation specific commands.
|
||||||
*/
|
*/
|
||||||
void registerCommands();
|
void registerCommands();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the protection system (used to protect blocks and such)
|
* Register the protection system.
|
||||||
*/
|
*/
|
||||||
void registerPlayerEvents();
|
void registerPlayerEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register inventory related events (used for inventory guis)
|
* Register inventory related events.
|
||||||
*/
|
*/
|
||||||
void registerInventoryEvents();
|
void registerInventoryEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register plot plus related events (whatever these are?)
|
* Register plot plus related events.
|
||||||
*/
|
*/
|
||||||
void registerPlotPlusEvents();
|
void registerPlotPlusEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register force field events (why is this a thing?)
|
* Register force field events.
|
||||||
*/
|
*/
|
||||||
void registerForceFieldEvents();
|
void registerForceFieldEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the WorldEdit hook
|
* Register the WorldEdit hook.
|
||||||
*/
|
*/
|
||||||
boolean initWorldEdit();
|
boolean initWorldEdit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the economy provider
|
* Get the economy provider.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
EconHandler getEconomyHandler();
|
EconHandler getEconomyHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Plot Queue class
|
* Get the {@link PlotQueue} class.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
PlotQueue initPlotQueue();
|
PlotQueue initPlotQueue();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the World Util class
|
* Get the {@link WorldUtil} class.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
WorldUtil initWorldUtil();
|
WorldUtil initWorldUtil();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the EventUtil class
|
* Get the EventUtil class.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
EventUtil initEventUtil();
|
EventUtil initEventUtil();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the chunk manager
|
* Get the chunk manager.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ChunkManager initChunkManager();
|
ChunkManager initChunkManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the setuputils class (used for world creation)
|
* Get the {@link SetupUtils} class.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SetupUtils initSetupUtils();
|
SetupUtils initSetupUtils();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get HybridUtils class (common functions useful for hybrid world generation)
|
* Get {@link HybridUtils} class.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
HybridUtils initHybridUtils();
|
HybridUtils initHybridUtils();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the metrics task
|
* Start Metrics.
|
||||||
*/
|
*/
|
||||||
void startMetrics();
|
void startMetrics();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a world is already loaded, set the generator (use NMS if required)
|
* If a world is already loaded, set the generator (use NMS if required).
|
||||||
* @param world
|
* @param world
|
||||||
*/
|
*/
|
||||||
void setGenerator(final String world);
|
void setGenerator(String world);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the UUIDHandlerImplementation which will cache and provide UUIDs
|
* Get the {@link UUIDHandlerImplementation} which will cache and provide UUIDs.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
UUIDHandlerImplementation initUUIDHandler();
|
UUIDHandlerImplementation initUUIDHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the InventoryUtil class (used for implementation specific inventory guis)
|
* Get the {@link InventoryUtil} class (used for implementation specific inventory guis).
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
InventoryUtil initInventoryUtil();
|
InventoryUtil initInventoryUtil();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the converter for the implementation (not necessarily PlotMe, just any plugin that we can convert from)
|
* Run the converter for the implementation (not necessarily PlotMe, just any plugin that we can convert from).
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean initPlotMeConverter();
|
boolean initPlotMeConverter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a PlotPlayer from cache e.g. if they have logged off
|
* Unregister a PlotPlayer from cache e.g. if they have logged off.
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
void unregister(final PlotPlayer player);
|
void unregister(PlotPlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the generator wrapper for a world (world) and generator (name)
|
* Get the generator wrapper for a world (world) and generator (name).
|
||||||
* @param world
|
* @param world
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
GeneratorWrapper<?> getGenerator(final String world, final String name);
|
GeneratorWrapper<?> getGenerator(String world, String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
* @param generator
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator);
|
GeneratorWrapper<?> wrapPlotGenerator(IndependentPlotGenerator generator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the chunk processor which will clean out chunks that have too many blockstates or entities
|
* Register the chunk processor which will clean out chunks that have too many blockstates or entities.
|
||||||
*/
|
*/
|
||||||
void registerChunkProcessor();
|
void registerChunkProcessor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the world initialization events (used to keep track of worlds being generated)
|
* Register the world initialization events (used to keep track of worlds being generated).
|
||||||
*/
|
*/
|
||||||
void registerWorldEvents();
|
void registerWorldEvents();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the server
|
* Get the name of the server.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getServerName();
|
String getServerName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the class that will manage player titles
|
* Get the class that will manage player titles.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
AbstractTitle initTitleManager();
|
AbstractTitle initTitleManager();
|
||||||
|
|
||||||
List<String> getPluginIds();
|
List<String> getPluginIds();
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,17 @@
|
|||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import static com.intellectualcrafters.plot.PS.log;
|
||||||
|
|
||||||
import com.intellectualcrafters.json.JSONArray;
|
import com.intellectualcrafters.json.JSONArray;
|
||||||
import com.intellectualcrafters.json.JSONObject;
|
import com.intellectualcrafters.json.JSONObject;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.PS.log;
|
|
||||||
|
|
||||||
public class Updater {
|
public class Updater {
|
||||||
|
|
||||||
private static String readUrl(String urlString) {
|
private static String readUrl(String urlString) {
|
||||||
@ -53,7 +53,12 @@ public class Updater {
|
|||||||
if (downloadURL.equals(name)) {
|
if (downloadURL.equals(name)) {
|
||||||
try {
|
try {
|
||||||
String[] split = release.getString("name").split("\\.");
|
String[] split = release.getString("name").split("\\.");
|
||||||
int[] version = new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), (split.length == 3) ? Integer.parseInt(split[2]) : 0 };
|
int[] version;
|
||||||
|
if (split.length == 3) {
|
||||||
|
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
|
||||||
|
} else {
|
||||||
|
version = new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), 0};
|
||||||
|
}
|
||||||
URL url = new URL(asset.getString("browser_download_url"));
|
URL url = new URL(asset.getString("browser_download_url"));
|
||||||
// If current version >= update
|
// If current version >= update
|
||||||
if (PS.get().checkVersion(PS.get().getVersion(), version)) {
|
if (PS.get().checkVersion(PS.get().getVersion(), version)) {
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
@ -34,24 +32,26 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
import com.plotsquared.general.commands.Argument;
|
import com.plotsquared.general.commands.Argument;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "add",
|
command = "add",
|
||||||
aliases = { "a" },
|
aliases = {"a"},
|
||||||
description = "Allow a user to build while you are online",
|
description = "Allow a user to build while you are online",
|
||||||
usage = "/plot add <player>",
|
usage = "/plot add <player>",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
permission = "plots.add",
|
permission = "plots.add",
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Add extends SubCommand {
|
public class Add extends SubCommand {
|
||||||
|
|
||||||
public Add() {
|
public Add() {
|
||||||
requiredArguments = new Argument[] { Argument.PlayerName };
|
this.requiredArguments = new Argument[]{Argument.PlayerName};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final Plot plot = loc.getPlotAbs();
|
Plot plot = loc.getPlotAbs();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ public class Add extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plot.getMembers().contains(uuid)) {
|
if (plot.getMembers().contains(uuid)) {
|
||||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||||
return false;
|
return false;
|
||||||
|
@ -31,17 +31,17 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "setalias",
|
command = "setalias",
|
||||||
permission = "plots.set.alias",
|
permission = "plots.set.alias",
|
||||||
description = "Set the plot name",
|
description = "Set the plot name",
|
||||||
usage = "/plot alias <alias>",
|
usage = "/plot alias <alias>",
|
||||||
aliases = { "alias", "sa", "name", "rename", "setname", "seta" },
|
aliases = {"alias", "sa", "name", "rename", "setname", "seta"},
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Alias extends SetCommand {
|
public class Alias extends SetCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean set(final PlotPlayer plr, final Plot plot, final String alias) {
|
public boolean set(PlotPlayer plr, Plot plot, String alias) {
|
||||||
if (alias.isEmpty()) {
|
if (alias.isEmpty()) {
|
||||||
C.COMMAND_SYNTAX.send(plr, getUsage());
|
C.COMMAND_SYNTAX.send(plr, getUsage());
|
||||||
return false;
|
return false;
|
||||||
@ -54,7 +54,7 @@ public class Alias extends SetCommand {
|
|||||||
C.NOT_VALID_VALUE.send(plr);
|
C.NOT_VALID_VALUE.send(plr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (final Plot p : PS.get().getPlots(plot.getArea())) {
|
for (Plot p : PS.get().getPlots(plot.getArea())) {
|
||||||
if (p.getAlias().equalsIgnoreCase(alias)) {
|
if (p.getAlias().equalsIgnoreCase(alias)) {
|
||||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
|
@ -26,18 +26,19 @@ import com.intellectualcrafters.plot.util.SetupUtils;
|
|||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@CommandDeclaration(command = "area",
|
@CommandDeclaration(command = "area",
|
||||||
permission = "plots.area",
|
permission = "plots.area",
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
description = "Create a new PlotArea",
|
description = "Create a new PlotArea",
|
||||||
aliases = "world",
|
aliases = "world",
|
||||||
usage = "/plot area <create|info|list|tp|regen>")
|
usage = "/plot area <create|info|list|tp|regen>")
|
||||||
public class Area extends SubCommand {
|
public class Area extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -71,7 +72,7 @@ public class Area extends SubCommand {
|
|||||||
plr.setMeta("area_pos1", loc);
|
plr.setMeta("area_pos1", loc);
|
||||||
C.SET_ATTRIBUTE.send(plr, "area_pos1", loc.getX() + "," + loc.getZ());
|
C.SET_ATTRIBUTE.send(plr, "area_pos1", loc.getX() + "," + loc.getZ());
|
||||||
MainUtil.sendMessage(plr, "You will now set pos2: /plot area create pos2"
|
MainUtil.sendMessage(plr, "You will now set pos2: /plot area create pos2"
|
||||||
+ "\nNote: The chosen plot size may result in the created area not exactly matching your second position.");
|
+ "\nNote: The chosen plot size may result in the created area not exactly matching your second position.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "pos2": { // Set position 2 and finish creation for type=2 (partial)
|
case "pos2": { // Set position 2 and finish creation for type=2 (partial)
|
||||||
@ -86,8 +87,8 @@ public class Area extends SubCommand {
|
|||||||
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
int dz = Math.abs(pos1.getZ() - pos2.getZ());
|
||||||
int numx = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
int numx = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||||
int numz = Math.max(1, (dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
int numz = Math.max(1, (dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE);
|
||||||
final int ddx = dx - (numx * area.SIZE - area.ROAD_WIDTH);
|
int ddx = dx - (numx * area.SIZE - area.ROAD_WIDTH);
|
||||||
final int ddz = dz - (numz * area.SIZE - area.ROAD_WIDTH);
|
int ddz = dz - (numz * area.SIZE - area.ROAD_WIDTH);
|
||||||
int bx = Math.min(pos1.getX(), pos2.getX()) + ddx;
|
int bx = Math.min(pos1.getX(), pos2.getX()) + ddx;
|
||||||
int bz = Math.min(pos1.getZ(), pos2.getZ()) + ddz;
|
int bz = Math.min(pos1.getZ(), pos2.getZ()) + ddz;
|
||||||
int tx = Math.max(pos1.getX(), pos2.getX()) - ddx;
|
int tx = Math.max(pos1.getX(), pos2.getX()) - ddx;
|
||||||
@ -129,7 +130,7 @@ public class Area extends SubCommand {
|
|||||||
if (area.TERRAIN != 3) {
|
if (area.TERRAIN != 3) {
|
||||||
ChunkManager.largeRegionTask(world, region, new RunnableVal<ChunkLoc>() {
|
ChunkManager.largeRegionTask(world, region, new RunnableVal<ChunkLoc>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(final ChunkLoc value) {
|
public void run(ChunkLoc value) {
|
||||||
AugmentedUtils.generate(world, value.x, value.z, null);
|
AugmentedUtils.generate(world, value.x, value.z, null);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
@ -326,13 +327,13 @@ public class Area extends SubCommand {
|
|||||||
region = "N/A";
|
region = "N/A";
|
||||||
}
|
}
|
||||||
String value = "&r$1NAME: " + name
|
String value = "&r$1NAME: " + name
|
||||||
+ "\n$1Type: $2" + area.TYPE
|
+ "\n$1Type: $2" + area.TYPE
|
||||||
+ "\n$1Terrain: $2" + area.TERRAIN
|
+ "\n$1Terrain: $2" + area.TERRAIN
|
||||||
+ "\n$1Usage: $2" + String.format("%.2f", percent) + "%"
|
+ "\n$1Usage: $2" + String.format("%.2f", percent) + "%"
|
||||||
+ "\n$1Claimed: $2" + claimed
|
+ "\n$1Claimed: $2" + claimed
|
||||||
+ "\n$1Clusters: $2" + clusters
|
+ "\n$1Clusters: $2" + clusters
|
||||||
+ "\n$1Region: $2" + region
|
+ "\n$1Region: $2" + region
|
||||||
+ "\n$1Generator: $2" + generator;
|
+ "\n$1Generator: $2" + generator;
|
||||||
MainUtil.sendMessage(plr, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
MainUtil.sendMessage(plr, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -379,19 +380,19 @@ public class Area extends SubCommand {
|
|||||||
region = "N/A";
|
region = "N/A";
|
||||||
}
|
}
|
||||||
PlotMessage tooltip = new PlotMessage()
|
PlotMessage tooltip = new PlotMessage()
|
||||||
.text("Claimed=").color("$1").text("" + claimed).color("$2")
|
.text("Claimed=").color("$1").text("" + claimed).color("$2")
|
||||||
.text("\nUsage=").color("$1").text(String.format("%.2f", percent) + "%").color("$2")
|
.text("\nUsage=").color("$1").text(String.format("%.2f", percent) + "%").color("$2")
|
||||||
.text("\nClusters=").color("$1").text("" + clusters).color("$2")
|
.text("\nClusters=").color("$1").text("" + clusters).color("$2")
|
||||||
.text("\nRegion=").color("$1").text(region).color("$2")
|
.text("\nRegion=").color("$1").text(region).color("$2")
|
||||||
.text("\nGenerator=").color("$1").text(generator).color("$2");
|
.text("\nGenerator=").color("$1").text(generator).color("$2");
|
||||||
|
|
||||||
// type / terrain
|
// type / terrain
|
||||||
String visit = "/plot area tp " + area.toString();
|
String visit = "/plot area tp " + area.toString();
|
||||||
message.text("[").color("$3")
|
message.text("[").color("$3")
|
||||||
.text(i + "").command(visit).tooltip(visit).color("$1")
|
.text(i + "").command(visit).tooltip(visit).color("$1")
|
||||||
.text("]").color("$3")
|
.text("]").color("$3")
|
||||||
.text(" " + name).tooltip(tooltip).command("/plot area info " + area).color("$1").text(" - ").color("$2")
|
.text(" " + name).tooltip(tooltip).command("/plot area info " + area).color("$1").text(" - ").color("$2")
|
||||||
.text(area.TYPE + ":" + area.TERRAIN).color("$3");
|
.text(area.TYPE + ":" + area.TERRAIN).color("$3");
|
||||||
}
|
}
|
||||||
}, "/plot area list", C.AREA_LIST_HEADER_PAGED.s());
|
}, "/plot area list", C.AREA_LIST_HEADER_PAGED.s());
|
||||||
return true;
|
return true;
|
||||||
@ -442,7 +443,8 @@ public class Area extends SubCommand {
|
|||||||
center = WorldUtil.IMP.getSpawn(area.worldname);
|
center = WorldUtil.IMP.getSpawn(area.worldname);
|
||||||
} else {
|
} else {
|
||||||
RegionWrapper region = area.getRegion();
|
RegionWrapper region = area.getRegion();
|
||||||
center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0, region.minZ + (region.maxZ - region.minZ) / 2);
|
center = new Location(area.worldname, region.minX + (region.maxX - region.minX) / 2, 0,
|
||||||
|
region.minZ + (region.maxZ - region.minZ) / 2);
|
||||||
center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ()));
|
center.setY(WorldUtil.IMP.getHighestBlock(area.worldname, center.getX(), center.getZ()));
|
||||||
}
|
}
|
||||||
plr.teleport(center);
|
plr.teleport(center);
|
||||||
@ -451,10 +453,10 @@ public class Area extends SubCommand {
|
|||||||
case "delete":
|
case "delete":
|
||||||
case "remove": {
|
case "remove": {
|
||||||
MainUtil.sendMessage(plr, "$1World creation settings may be stored in multiple locations:"
|
MainUtil.sendMessage(plr, "$1World creation settings may be stored in multiple locations:"
|
||||||
+ "\n$3 - $2Bukkit bukkit.yml"
|
+ "\n$3 - $2Bukkit bukkit.yml"
|
||||||
+ "\n$3 - $2PlotSquared settings.yml"
|
+ "\n$3 - $2PlotSquared settings.yml"
|
||||||
+ "\n$3 - $2Multiverse worlds.yml (or any world management plugin)"
|
+ "\n$3 - $2Multiverse worlds.yml (or any world management plugin)"
|
||||||
+ "\n$1Stop the server and delete it from these locations.");
|
+ "\n$1Stop the server and delete it from these locations.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,17 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "auto",
|
@CommandDeclaration(command = "auto",
|
||||||
permission = "plots.auto",
|
permission = "plots.auto",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
description = "Claim the nearest plot",
|
description = "Claim the nearest plot",
|
||||||
aliases = "a",
|
aliases = "a",
|
||||||
usage = "/plot auto [length,width]")
|
usage = "/plot auto [length,width]")
|
||||||
public class Auto extends SubCommand {
|
public class Auto extends SubCommand {
|
||||||
|
|
||||||
public static PlotId getNextPlotId(final PlotId id, final int step) {
|
public static PlotId getNextPlotId(PlotId id, int step) {
|
||||||
final int absX = Math.abs(id.x);
|
int absX = Math.abs(id.x);
|
||||||
final int absY = Math.abs(id.y);
|
int absY = Math.abs(id.y);
|
||||||
if (absX > absY) {
|
if (absX > absY) {
|
||||||
if (id.x > 0) {
|
if (id.x > 0) {
|
||||||
return new PlotId(id.x, id.y + 1);
|
return new PlotId(id.x, id.y + 1);
|
||||||
@ -71,7 +71,7 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
PlotArea plotarea = plr.getApplicablePlotArea();
|
PlotArea plotarea = plr.getApplicablePlotArea();
|
||||||
if (plotarea == null) {
|
if (plotarea == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
@ -83,7 +83,7 @@ public class Auto extends SubCommand {
|
|||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
|
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
|
||||||
try {
|
try {
|
||||||
final String[] split = args[0].split(",|;");
|
String[] split = args[0].split(",|;");
|
||||||
size_x = Integer.parseInt(split[0]);
|
size_x = Integer.parseInt(split[0]);
|
||||||
size_z = Integer.parseInt(split[1]);
|
size_z = Integer.parseInt(split[1]);
|
||||||
if (size_x < 1 || size_z < 1) {
|
if (size_x < 1 || size_z < 1) {
|
||||||
@ -110,8 +110,8 @@ public class Auto extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname);
|
int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname);
|
||||||
final int diff = currentPlots - plr.getAllowedPlots();
|
int diff = currentPlots - plr.getAllowedPlots();
|
||||||
if (diff + size_x * size_z > 0) {
|
if (diff + size_x * size_z > 0) {
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
|
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + "");
|
||||||
@ -159,15 +159,15 @@ public class Auto extends SubCommand {
|
|||||||
}
|
}
|
||||||
// TODO handle type 2 the same as normal worlds!
|
// TODO handle type 2 the same as normal worlds!
|
||||||
if (plotarea.TYPE == 2) {
|
if (plotarea.TYPE == 2) {
|
||||||
final PlotId bot = plotarea.getMin();
|
PlotId bot = plotarea.getMin();
|
||||||
final PlotId top = plotarea.getMax();
|
PlotId top = plotarea.getMax();
|
||||||
final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||||
PlotId id = new PlotId(0, 0);
|
PlotId id = new PlotId(0, 0);
|
||||||
final int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1);
|
int width = Math.max(top.x - bot.x + 1, top.y - bot.y + 1);
|
||||||
final int max = width * width;
|
int max = width * width;
|
||||||
//
|
//
|
||||||
for (int i = 0; i <= max; i++) {
|
for (int i = 0; i <= max; i++) {
|
||||||
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
|
||||||
Plot current = plotarea.getPlotAbs(currentId);
|
Plot current = plotarea.getPlotAbs(currentId);
|
||||||
if (current.canClaim(plr)) {
|
if (current.canClaim(plr)) {
|
||||||
current.claim(plr, true, null);
|
current.claim(plr, true, null);
|
||||||
@ -182,14 +182,14 @@ public class Auto extends SubCommand {
|
|||||||
plotarea.setMeta("lastPlot", new PlotId(0, 0));
|
plotarea.setMeta("lastPlot", new PlotId(0, 0));
|
||||||
boolean br = false;
|
boolean br = false;
|
||||||
while (true) {
|
while (true) {
|
||||||
final PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
|
PlotId start = getNextPlotId(getLastPlotId(plotarea), 1);
|
||||||
final PlotId end = new PlotId(start.x + size_x - 1, start.y + size_z - 1);
|
PlotId end = new PlotId(start.x + size_x - 1, start.y + size_z - 1);
|
||||||
plotarea.setMeta("lastPlot", start);
|
plotarea.setMeta("lastPlot", start);
|
||||||
if (plotarea.canClaim(plr, start, end)) {
|
if (plotarea.canClaim(plr, start, end)) {
|
||||||
for (int i = start.x; i <= end.x; i++) {
|
for (int i = start.x; i <= end.x; i++) {
|
||||||
for (int j = start.y; j <= end.y; j++) {
|
for (int j = start.y; j <= end.y; j++) {
|
||||||
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
|
Plot plot = plotarea.getPlotAbs(new PlotId(i, j));
|
||||||
final boolean teleport = i == end.x && j == end.y;
|
boolean teleport = i == end.x && j == end.y;
|
||||||
plot.claim(plr, teleport, null);
|
plot.claim(plr, teleport, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ public class Auto extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlotId getLastPlotId(final PlotArea area) {
|
public PlotId getLastPlotId(PlotArea area) {
|
||||||
PlotId value = (PlotId) area.getMeta("lastPlot");
|
PlotId value = (PlotId) area.getMeta("lastPlot");
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = new PlotId(0, 0);
|
value = new PlotId(0, 0);
|
||||||
|
@ -30,26 +30,26 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "bo3",
|
@CommandDeclaration(command = "bo3",
|
||||||
aliases = { "bo2" },
|
aliases = {"bo2"},
|
||||||
description = "Mark a plot as done",
|
description = "Mark a plot as done",
|
||||||
permission = "plots.bo3",
|
permission = "plots.bo3",
|
||||||
category = CommandCategory.SCHEMATIC,
|
category = CommandCategory.SCHEMATIC,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class BO3 extends SubCommand {
|
public class BO3 extends SubCommand {
|
||||||
|
|
||||||
public void noArgs(final PlotPlayer plr) {
|
public void noArgs(PlotPlayer plr) {
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
|
||||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
|
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final Plot plot = loc.getPlotAbs();
|
Plot plot = loc.getPlotAbs();
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3")) {
|
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.bo3")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -29,18 +29,18 @@ import com.intellectualcrafters.plot.util.WorldUtil;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "setbiome",
|
command = "setbiome",
|
||||||
permission = "plots.set.biome",
|
permission = "plots.set.biome",
|
||||||
description = "Set the plot biome",
|
description = "Set the plot biome",
|
||||||
usage = "/plot biome [biome]",
|
usage = "/plot biome [biome]",
|
||||||
aliases = { "biome", "sb", "setb", "b" },
|
aliases = {"biome", "sb", "setb", "b"},
|
||||||
category = CommandCategory.APPEARANCE,
|
category = CommandCategory.APPEARANCE,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Biome extends SetCommand {
|
public class Biome extends SetCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean set(final PlotPlayer plr, final Plot plot, final String value) {
|
public boolean set(final PlotPlayer plr, final Plot plot, final String value) {
|
||||||
final int biome = WorldUtil.IMP.getBiomeFromString(value);
|
int biome = WorldUtil.IMP.getBiomeFromString(value);
|
||||||
if (biome == -1) {
|
if (biome == -1) {
|
||||||
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s());
|
String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s());
|
||||||
C.NEED_BIOME.send(plr);
|
C.NEED_BIOME.send(plr);
|
||||||
|
@ -35,22 +35,22 @@ import com.plotsquared.general.commands.CommandDeclaration;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "buy",
|
command = "buy",
|
||||||
aliases = { "b" },
|
aliases = {"b"},
|
||||||
description = "Buy the plot you are standing on",
|
description = "Buy the plot you are standing on",
|
||||||
usage = "/plot buy",
|
usage = "/plot buy",
|
||||||
permission = "plots.buy",
|
permission = "plots.buy",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Buy extends SubCommand {
|
public class Buy extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(PlotPlayer plr, String... args) {
|
||||||
if (EconHandler.manager == null) {
|
if (EconHandler.manager == null) {
|
||||||
return sendMessage(plr, C.ECON_DISABLED);
|
return sendMessage(plr, C.ECON_DISABLED);
|
||||||
}
|
}
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final String world = loc.getWorld();
|
String world = loc.getWorld();
|
||||||
if (!PS.get().hasPlotArea(world)) {
|
if (!PS.get().hasPlotArea(world)) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ public class Buy extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
plots = plot.getConnectedPlots();
|
plots = plot.getConnectedPlots();
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -76,11 +76,11 @@ public class Buy extends SubCommand {
|
|||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return sendMessage(plr, C.PLOT_UNOWNED);
|
return sendMessage(plr, C.PLOT_UNOWNED);
|
||||||
}
|
}
|
||||||
final int currentPlots = plr.getPlotCount() + plots.size();
|
int currentPlots = plr.getPlotCount() + plots.size();
|
||||||
if (currentPlots > plr.getAllowedPlots()) {
|
if (currentPlots > plr.getAllowedPlots()) {
|
||||||
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
|
||||||
}
|
}
|
||||||
final Flag flag = FlagManager.getPlotFlagRaw(plot, "price");
|
Flag flag = FlagManager.getPlotFlagRaw(plot, "price");
|
||||||
if (flag == null) {
|
if (flag == null) {
|
||||||
return sendMessage(plr, C.NOT_FOR_SALE);
|
return sendMessage(plr, C.NOT_FOR_SALE);
|
||||||
}
|
}
|
||||||
@ -95,13 +95,13 @@ public class Buy extends SubCommand {
|
|||||||
EconHandler.manager.withdrawMoney(plr, price);
|
EconHandler.manager.withdrawMoney(plr, price);
|
||||||
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
||||||
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price);
|
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price);
|
||||||
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
||||||
if (owner != null) {
|
if (owner != null) {
|
||||||
sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + "");
|
sendMessage(plr, C.PLOT_SOLD, plot.getId() + "", plr.getName(), price + "");
|
||||||
}
|
}
|
||||||
FlagManager.removePlotFlag(plot, "price");
|
FlagManager.removePlotFlag(plot, "price");
|
||||||
}
|
}
|
||||||
for (final Plot current : plots) {
|
for (Plot current : plots) {
|
||||||
plot.setOwner(plr.getUUID());
|
plot.setOwner(plr.getUUID());
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, C.CLAIMED);
|
MainUtil.sendMessage(plr, C.CLAIMED);
|
||||||
|
@ -4,16 +4,16 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "chat",
|
command = "chat",
|
||||||
description = "Toggle plot chat on or off",
|
description = "Toggle plot chat on or off",
|
||||||
usage = "/plot chat [on|off]",
|
usage = "/plot chat [on|off]",
|
||||||
permission = "plots.chat",
|
permission = "plots.chat",
|
||||||
category = CommandCategory.CHAT,
|
category = CommandCategory.CHAT,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Chat extends SubCommand {
|
public class Chat extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args) {
|
public boolean onCommand(PlotPlayer player, String... args) {
|
||||||
return MainCommand.onCommand(player, "plot", "toggle", "chat");
|
return MainCommand.onCommand(player, "plot", "toggle", "chat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,24 +32,25 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "claim",
|
@CommandDeclaration(command = "claim",
|
||||||
aliases = "c",
|
aliases = "c",
|
||||||
description = "Claim the current plot you're standing on",
|
description = "Claim the current plot you're standing on",
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
requiredType = RequiredType.PLAYER,
|
requiredType = RequiredType.PLAYER,
|
||||||
permission = "plots.claim", usage = "/plot claim")
|
permission = "plots.claim", usage = "/plot claim")
|
||||||
public class Claim extends SubCommand {
|
public class Claim extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(PlotPlayer plr, String... args) {
|
||||||
String schematic = "";
|
String schematic = "";
|
||||||
if (args.length >= 1) {
|
if (args.length >= 1) {
|
||||||
schematic = args[0];
|
schematic = args[0];
|
||||||
}
|
}
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final Plot plot = loc.getPlotAbs();
|
Plot plot = loc.getPlotAbs();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return sendMessage(plr, C.NOT_IN_PLOT);
|
return sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld());
|
int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld());
|
||||||
int grants = 0;
|
int grants = 0;
|
||||||
if (currentPlots >= plr.getAllowedPlots()) {
|
if (currentPlots >= plr.getAllowedPlots()) {
|
||||||
if (plr.hasPersistentMeta("grantedPlots")) {
|
if (plr.hasPersistentMeta("grantedPlots")) {
|
||||||
@ -65,9 +66,9 @@ public class Claim extends SubCommand {
|
|||||||
if (!plot.canClaim(plr)) {
|
if (!plot.canClaim(plr)) {
|
||||||
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
return sendMessage(plr, C.PLOT_IS_CLAIMED);
|
||||||
}
|
}
|
||||||
final PlotArea world = plot.getArea();
|
PlotArea world = plot.getArea();
|
||||||
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
|
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
|
||||||
final double cost = world.PRICES.get("claim");
|
double cost = world.PRICES.get("claim");
|
||||||
if (cost > 0d) {
|
if (cost > 0d) {
|
||||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||||
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||||
|
@ -32,19 +32,20 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.intellectualcrafters.plot.util.SetQueue;
|
import com.intellectualcrafters.plot.util.SetQueue;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@CommandDeclaration(command = "clear",
|
@CommandDeclaration(command = "clear",
|
||||||
description = "Clear a plot",
|
description = "Clear a plot",
|
||||||
permission = "plots.clear",
|
permission = "plots.clear",
|
||||||
category = CommandCategory.APPEARANCE,
|
category = CommandCategory.APPEARANCE,
|
||||||
usage = "/plot clear [id]",
|
usage = "/plot clear [id]",
|
||||||
aliases = "reset")
|
aliases = "reset")
|
||||||
public class Clear extends SubCommand {
|
public class Clear extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(final PlotPlayer plr, String... args) {
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final Plot plot;
|
final Plot plot;
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
if (args[0].equalsIgnoreCase("mine")) {
|
if (args[0].equalsIgnoreCase("mine")) {
|
||||||
@ -81,15 +82,16 @@ public class Clear extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((FlagManager.getPlotFlagRaw(plot, "done") != null)
|
if ((FlagManager.getPlotFlagRaw(plot, "done") != null)
|
||||||
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())))) {
|
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr
|
||||||
|
.getPlotCount())))) {
|
||||||
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
final boolean result = plot.clear(true, false, new Runnable() {
|
boolean result = plot.clear(true, false, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
plot.unlink();
|
plot.unlink();
|
||||||
@ -111,13 +113,12 @@ public class Clear extends SubCommand {
|
|||||||
});
|
});
|
||||||
if (!result) {
|
if (!result) {
|
||||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
plot.addRunning();
|
plot.addRunning();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
if (Settings.CONFIRM_CLEAR && !Permissions.hasPermission(plr, "plots.confirm.bypass")) {
|
||||||
CmdConfirm.addPending(plr, "/plot clear " + plot.getId(), runnable);
|
CmdConfirm.addPending(plr, "/plot clear " + plot.getId(), runnable);
|
||||||
} else {
|
} else {
|
||||||
TaskManager.runTask(runnable);
|
TaskManager.runTask(runnable);
|
||||||
|
@ -35,21 +35,22 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(command = "cluster",
|
@CommandDeclaration(command = "cluster",
|
||||||
aliases = "clusters",
|
aliases = "clusters",
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.cluster",
|
permission = "plots.cluster",
|
||||||
description = "Manage a plot cluster")
|
description = "Manage a plot cluster")
|
||||||
public class Cluster extends SubCommand {
|
public class Cluster extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(PlotPlayer plr, String... args) {
|
||||||
|
|
||||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
@ -57,7 +58,7 @@ public class Cluster extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String sub = args[0].toLowerCase();
|
String sub = args[0].toLowerCase();
|
||||||
switch (sub) {
|
switch (sub) {
|
||||||
case "l":
|
case "l":
|
||||||
case "list": {
|
case "list": {
|
||||||
@ -70,11 +71,11 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlotArea area = plr.getApplicablePlotArea();
|
PlotArea area = plr.getApplicablePlotArea();
|
||||||
final Set<PlotCluster> clusters = area.getClusters();
|
Set<PlotCluster> clusters = area.getClusters();
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
|
||||||
for (final PlotCluster cluster : clusters) {
|
for (PlotCluster cluster : clusters) {
|
||||||
// Ignore unmanaged clusters
|
// Ignore unmanaged clusters
|
||||||
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
||||||
if (plr.getUUID().equals(cluster.owner)) {
|
if (plr.getUUID().equals(cluster.owner)) {
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
||||||
} else if (cluster.helpers.contains(plr.getUUID())) {
|
} else if (cluster.helpers.contains(plr.getUUID())) {
|
||||||
@ -110,7 +111,7 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// check if name is taken
|
// check if name is taken
|
||||||
final String name = args[1];
|
String name = args[1];
|
||||||
if (area.getCluster(name) != null) {
|
if (area.getCluster(name) != null) {
|
||||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||||
return false;
|
return false;
|
||||||
@ -127,11 +128,11 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if it occupies existing plots
|
// Check if it occupies existing plots
|
||||||
final Set<Plot> plots = area.getPlotSelectionOwned(pos1, pos2);
|
Set<Plot> plots = area.getPlotSelectionOwned(pos1, pos2);
|
||||||
if (!plots.isEmpty()) {
|
if (!plots.isEmpty()) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
|
||||||
final UUID uuid = plr.getUUID();
|
UUID uuid = plr.getUUID();
|
||||||
for (final Plot plot : plots) {
|
for (Plot plot : plots) {
|
||||||
if (!plot.isOwner(uuid)) {
|
if (!plot.isOwner(uuid)) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
|
||||||
return false;
|
return false;
|
||||||
@ -147,7 +148,7 @@ public class Cluster extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
|
current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
|
||||||
}
|
}
|
||||||
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
if (current + cluster.getArea() > allowed) {
|
if (current + cluster.getArea() > allowed) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
return false;
|
return false;
|
||||||
@ -157,7 +158,7 @@ public class Cluster extends SubCommand {
|
|||||||
area.addCluster(cluster);
|
area.addCluster(cluster);
|
||||||
DBFunc.createCluster(cluster);
|
DBFunc.createCluster(cluster);
|
||||||
// Add any existing plots to the current cluster
|
// Add any existing plots to the current cluster
|
||||||
for (final Plot plot : plots) {
|
for (Plot plot : plots) {
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
if (!cluster.isAdded(plot.owner)) {
|
if (!cluster.isAdded(plot.owner)) {
|
||||||
cluster.invited.add(plot.owner);
|
cluster.invited.add(plot.owner);
|
||||||
@ -235,7 +236,7 @@ public class Cluster extends SubCommand {
|
|||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(plr.getLocation());
|
PlotCluster cluster = area.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
@ -252,9 +253,9 @@ public class Cluster extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersect.getName());
|
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersect.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final HashSet<Plot> existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2());
|
HashSet<Plot> existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2());
|
||||||
final HashSet<Plot> newplots = area.getPlotSelectionOwned(pos1, pos2);
|
HashSet<Plot> newplots = area.getPlotSelectionOwned(pos1, pos2);
|
||||||
final HashSet<Plot> removed = (HashSet<Plot>) existing.clone();
|
HashSet<Plot> removed = (HashSet<Plot>) existing.clone();
|
||||||
removed.removeAll(newplots);
|
removed.removeAll(newplots);
|
||||||
// Check expand / shrink
|
// Check expand / shrink
|
||||||
if (!removed.isEmpty()) {
|
if (!removed.isEmpty()) {
|
||||||
@ -278,7 +279,7 @@ public class Cluster extends SubCommand {
|
|||||||
current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
|
current = plr.getPlayerClusterCount(plr.getLocation().getWorld());
|
||||||
}
|
}
|
||||||
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
|
||||||
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
|
||||||
if (current + cluster.getArea() > allowed) {
|
if (current + cluster.getArea() > allowed) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
|
||||||
return false;
|
return false;
|
||||||
@ -304,7 +305,7 @@ public class Cluster extends SubCommand {
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(plr.getLocation());
|
PlotCluster cluster = area.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
@ -316,7 +317,7 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check uuid
|
// check uuid
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||||
return false;
|
return false;
|
||||||
@ -325,7 +326,7 @@ public class Cluster extends SubCommand {
|
|||||||
// add the user if not added
|
// add the user if not added
|
||||||
cluster.invited.add(uuid);
|
cluster.invited.add(uuid);
|
||||||
DBFunc.setInvited(cluster, uuid);
|
DBFunc.setInvited(cluster, uuid);
|
||||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||||
}
|
}
|
||||||
@ -348,7 +349,7 @@ public class Cluster extends SubCommand {
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(plr.getLocation());
|
PlotCluster cluster = area.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
@ -360,7 +361,7 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check uuid
|
// check uuid
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
@ -376,12 +377,12 @@ public class Cluster extends SubCommand {
|
|||||||
}
|
}
|
||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
}
|
}
|
||||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
for (Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||||
final PlotCluster current = plot.getCluster();
|
PlotCluster current = plot.getCluster();
|
||||||
if (current != null && current.equals(cluster)) {
|
if (current != null && current.equals(cluster)) {
|
||||||
plot.unclaim();
|
plot.unclaim();
|
||||||
}
|
}
|
||||||
@ -417,7 +418,7 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final UUID uuid = plr.getUUID();
|
UUID uuid = plr.getUUID();
|
||||||
if (!cluster.isAdded(uuid)) {
|
if (!cluster.isAdded(uuid)) {
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
||||||
return false;
|
return false;
|
||||||
@ -433,8 +434,8 @@ public class Cluster extends SubCommand {
|
|||||||
cluster.invited.remove(uuid);
|
cluster.invited.remove(uuid);
|
||||||
DBFunc.removeInvited(cluster, uuid);
|
DBFunc.removeInvited(cluster, uuid);
|
||||||
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
||||||
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
for (Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
|
||||||
final PlotCluster current = plot.getCluster();
|
PlotCluster current = plot.getCluster();
|
||||||
if (current != null && current.equals(cluster)) {
|
if (current != null && current.equals(cluster)) {
|
||||||
plr.getLocation().getWorld();
|
plr.getLocation().getWorld();
|
||||||
plot.unclaim();
|
plot.unclaim();
|
||||||
@ -457,12 +458,12 @@ public class Cluster extends SubCommand {
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(plr.getLocation());
|
PlotCluster cluster = area.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[2], null);
|
UUID uuid = UUIDHandler.getUUID(args[2], null);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||||
return false;
|
return false;
|
||||||
@ -495,12 +496,12 @@ public class Cluster extends SubCommand {
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(args[1]);
|
PlotCluster cluster = area.getCluster(args[1]);
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final UUID uuid = plr.getUUID();
|
UUID uuid = plr.getUUID();
|
||||||
if (!cluster.isAdded(uuid)) {
|
if (!cluster.isAdded(uuid)) {
|
||||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
|
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
|
||||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
||||||
@ -540,14 +541,14 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String id = cluster.toString();
|
String id = cluster.toString();
|
||||||
String owner = UUIDHandler.getName(cluster.owner);
|
String owner = UUIDHandler.getName(cluster.owner);
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
owner = "unknown";
|
owner = "unknown";
|
||||||
}
|
}
|
||||||
final String name = cluster.getName();
|
String name = cluster.getName();
|
||||||
final String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (cluster.getP2().y - cluster.getP1().y + 1);
|
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (cluster.getP2().y - cluster.getP1().y + 1);
|
||||||
final String rights = cluster.isAdded(plr.getUUID()) + "";
|
String rights = cluster.isAdded(plr.getUUID()) + "";
|
||||||
String message = C.CLUSTER_INFO.s();
|
String message = C.CLUSTER_INFO.s();
|
||||||
message = message.replaceAll("%id%", id);
|
message = message.replaceAll("%id%", id);
|
||||||
message = message.replaceAll("%owner%", owner);
|
message = message.replaceAll("%owner%", owner);
|
||||||
@ -572,7 +573,7 @@ public class Cluster extends SubCommand {
|
|||||||
if (area == null) {
|
if (area == null) {
|
||||||
C.NOT_IN_PLOT_WORLD.send(plr);
|
C.NOT_IN_PLOT_WORLD.send(plr);
|
||||||
}
|
}
|
||||||
final PlotCluster cluster = area.getCluster(plr.getLocation());
|
PlotCluster cluster = area.getCluster(plr.getLocation());
|
||||||
if (cluster == null) {
|
if (cluster == null) {
|
||||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||||
return false;
|
return false;
|
||||||
@ -583,9 +584,9 @@ public class Cluster extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Location base = cluster.getClusterBottom();
|
Location base = cluster.getClusterBottom();
|
||||||
final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
|
Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||||
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||||
cluster.settings.setPosition(blockloc);
|
cluster.settings.setPosition(blockloc);
|
||||||
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||||
|
@ -2,7 +2,9 @@ package com.intellectualcrafters.plot.commands;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CommandCategory
|
* CommandCategory
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public enum CommandCategory {
|
public enum CommandCategory {
|
||||||
/**
|
/**
|
||||||
@ -54,18 +56,18 @@ public enum CommandCategory {
|
|||||||
* The category name (Readable)
|
* The category name (Readable)
|
||||||
*/
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param name readable name
|
* @param name readable name
|
||||||
*/
|
*/
|
||||||
CommandCategory(final String name) {
|
CommandCategory(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return this.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,27 +25,29 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Citymonstret on 2014-08-03.
|
* Created by Citymonstret on 2014-08-03.
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class CommandPermission {
|
public class CommandPermission {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Permission Node
|
* Permission Node
|
||||||
*/
|
*/
|
||||||
public final String permission;
|
public final String permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param permission Command Permission
|
* @param permission Command Permission
|
||||||
*/
|
*/
|
||||||
public CommandPermission(final String permission) {
|
public CommandPermission(String permission) {
|
||||||
this.permission = permission.toLowerCase();
|
this.permission = permission.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player Does the player have the permission?
|
* @param player Does the player have the permission?
|
||||||
*
|
*
|
||||||
* @return true of player has the required permission node
|
* @return true of player has the required permission node
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(final PlotPlayer player) {
|
public boolean hasPermission(PlotPlayer player) {
|
||||||
return Permissions.hasPermission(player, permission);
|
return Permissions.hasPermission(player, this.permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,30 +32,31 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.intellectualcrafters.plot.util.StringMan;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@CommandDeclaration(command = "comment",
|
@CommandDeclaration(command = "comment",
|
||||||
aliases = { "msg" },
|
aliases = {"msg"},
|
||||||
description = "Comment on a plot",
|
description = "Comment on a plot",
|
||||||
category = CommandCategory.CHAT,
|
category = CommandCategory.CHAT,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.comment")
|
permission = "plots.comment")
|
||||||
public class Comment extends SubCommand {
|
public class Comment extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String[] args) {
|
public boolean onCommand(PlotPlayer player, String[] args) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||||
if (inbox == null) {
|
if (inbox == null) {
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
final PlotId id = PlotId.fromString(args[1]);
|
PlotId id = PlotId.fromString(args[1]);
|
||||||
Plot plot = MainUtil.getPlotFromString(player, args[1], false);
|
Plot plot = MainUtil.getPlotFromString(player, args[1], false);
|
||||||
int index;
|
int index;
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
@ -72,9 +73,9 @@ public class Comment extends SubCommand {
|
|||||||
sendMessage(player, C.NO_PERM_INBOX, "");
|
sendMessage(player, C.NO_PERM_INBOX, "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
|
||||||
final PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
|
||||||
final boolean result = inbox.addComment(plot, comment);
|
boolean result = inbox.addComment(plot, comment);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
sendMessage(player, C.NO_PLOT_INBOX, "");
|
sendMessage(player, C.NO_PLOT_INBOX, "");
|
||||||
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
|
||||||
|
@ -30,6 +30,7 @@ import com.intellectualcrafters.plot.util.MathMan;
|
|||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
import com.intellectualcrafters.plot.util.WorldUtil;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -39,16 +40,16 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@CommandDeclaration(command = "condense",
|
@CommandDeclaration(command = "condense",
|
||||||
permission = "plots.admin",
|
permission = "plots.admin",
|
||||||
description = "Condense a plotworld",
|
description = "Condense a plotworld",
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
requiredType = RequiredType.CONSOLE)
|
requiredType = RequiredType.CONSOLE)
|
||||||
public class Condense extends SubCommand {
|
public class Condense extends SubCommand {
|
||||||
|
|
||||||
public static boolean TASK = false;
|
public static boolean TASK = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(final PlotPlayer plr, String... args) {
|
||||||
if ((args.length != 2) && (args.length != 3)) {
|
if ((args.length != 2) && (args.length != 3)) {
|
||||||
MainUtil.sendMessage(plr, "/plot condense <area> <start|stop|info> [radius]");
|
MainUtil.sendMessage(plr, "/plot condense <area> <start|stop|info> [radius]");
|
||||||
return false;
|
return false;
|
||||||
@ -72,7 +73,7 @@ public class Condense extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int radius = Integer.parseInt(args[2]);
|
int radius = Integer.parseInt(args[2]);
|
||||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots(area));
|
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots(area));
|
||||||
// remove non base plots
|
// remove non base plots
|
||||||
Iterator<Plot> iter = plots.iterator();
|
Iterator<Plot> iter = plots.iterator();
|
||||||
@ -109,23 +110,23 @@ public class Condense extends SubCommand {
|
|||||||
allPlots.addAll(array);
|
allPlots.addAll(array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int size = allPlots.size();
|
int size = allPlots.size();
|
||||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
int minimumRadius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||||
if (radius < minimum_radius) {
|
if (radius < minimumRadius) {
|
||||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final List<PlotId> to_move = new ArrayList<>(getPlots(allPlots, radius));
|
List<PlotId> toMove = new ArrayList<>(getPlots(allPlots, radius));
|
||||||
final List<PlotId> free = new ArrayList<>();
|
final List<PlotId> free = new ArrayList<>();
|
||||||
PlotId start = new PlotId(0, 0);
|
PlotId start = new PlotId(0, 0);
|
||||||
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
|
while ((start.x <= minimumRadius) && (start.y <= minimumRadius)) {
|
||||||
Plot plot = area.getPlotAbs(start);
|
Plot plot = area.getPlotAbs(start);
|
||||||
if (plot != null && !plot.hasOwner()) {
|
if (plot != null && !plot.hasOwner()) {
|
||||||
free.add(plot.getId());
|
free.add(plot.getId());
|
||||||
}
|
}
|
||||||
start = Auto.getNextPlotId(start, 1);
|
start = Auto.getNextPlotId(start, 1);
|
||||||
}
|
}
|
||||||
if ((free.isEmpty()) || (to_move.isEmpty())) {
|
if (free.isEmpty() || toMove.isEmpty()) {
|
||||||
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
|
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -197,22 +198,22 @@ public class Condense extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int radius = Integer.parseInt(args[2]);
|
int radius = Integer.parseInt(args[2]);
|
||||||
final Collection<Plot> plots = area.getPlots();
|
Collection<Plot> plots = area.getPlots();
|
||||||
final int size = plots.size();
|
int size = plots.size();
|
||||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
int minimumRadius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||||
if (radius < minimum_radius) {
|
if (radius < minimumRadius) {
|
||||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final int max_move = getPlots(plots, minimum_radius).size();
|
int maxMove = getPlots(plots, minimumRadius).size();
|
||||||
final int user_move = getPlots(plots, radius).size();
|
int userMove = getPlots(plots, radius).size();
|
||||||
MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
|
MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
|
||||||
MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
|
MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimumRadius);
|
||||||
MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
|
MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + maxMove);
|
||||||
MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
|
MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
|
||||||
MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
|
MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
|
||||||
MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + userMove);
|
||||||
MainUtil.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
MainUtil.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
||||||
MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
|
MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
|
||||||
return true;
|
return true;
|
||||||
@ -222,9 +223,9 @@ public class Condense extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
|
public Set<PlotId> getPlots(Collection<Plot> plots, int radius) {
|
||||||
final HashSet<PlotId> outside = new HashSet<>();
|
HashSet<PlotId> outside = new HashSet<>();
|
||||||
for (final Plot plot : plots) {
|
for (Plot plot : plots) {
|
||||||
if ((plot.getId().x > radius) || (plot.getId().x < -radius) || (plot.getId().y > radius) || (plot.getId().y < -radius)) {
|
if ((plot.getId().x > radius) || (plot.getId().x < -radius) || (plot.getId().y > radius) || (plot.getId().y < -radius)) {
|
||||||
outside.add(plot.getId());
|
outside.add(plot.getId());
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,14 @@ import com.intellectualcrafters.plot.util.TaskManager;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "confirm",
|
@CommandDeclaration(command = "confirm",
|
||||||
permission = "plots.use",
|
permission = "plots.use",
|
||||||
description = "Confirm an action",
|
description = "Confirm an action",
|
||||||
category = CommandCategory.INFO)
|
category = CommandCategory.INFO)
|
||||||
public class Confirm extends SubCommand {
|
public class Confirm extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(PlotPlayer plr, String... args) {
|
||||||
final CmdInstance command = CmdConfirm.getPending(plr);
|
CmdInstance command = CmdConfirm.getPending(plr);
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||||
return false;
|
return false;
|
||||||
|
@ -30,16 +30,16 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "continue",
|
command = "continue",
|
||||||
description = "Continue a plot that was previously marked as done",
|
description = "Continue a plot that was previously marked as done",
|
||||||
permission = "plots.continue",
|
permission = "plots.continue",
|
||||||
category = CommandCategory.SETTINGS,
|
category = CommandCategory.SETTINGS,
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Continue extends SubCommand {
|
public class Continue extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
final Plot plot = plr.getCurrentPlot();
|
Plot plot = plr.getCurrentPlot();
|
||||||
if ((plot == null) || !plot.hasOwner()) {
|
if ((plot == null) || !plot.hasOwner()) {
|
||||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,19 @@ import com.intellectualcrafters.plot.util.Permissions;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "copy",
|
command = "copy",
|
||||||
permission = "plots.copy",
|
permission = "plots.copy",
|
||||||
aliases = { "copypaste" },
|
aliases = {"copypaste"},
|
||||||
category = CommandCategory.CLAIMING,
|
category = CommandCategory.CLAIMING,
|
||||||
description = "Copy a plot",
|
description = "Copy a plot",
|
||||||
usage = "/plot copy <X;Z>",
|
usage = "/plot copy <X;Z>",
|
||||||
requiredType = RequiredType.NONE)
|
requiredType = RequiredType.NONE)
|
||||||
public class Copy extends SubCommand {
|
public class Copy extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(final PlotPlayer plr, String[] args) {
|
||||||
final Location loc = plr.getLocation();
|
Location loc = plr.getLocation();
|
||||||
final Plot plot1 = loc.getPlotAbs();
|
Plot plot1 = loc.getPlotAbs();
|
||||||
if (plot1 == null) {
|
if (plot1 == null) {
|
||||||
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
@ -53,8 +53,8 @@ public class Copy extends SubCommand {
|
|||||||
C.COMMAND_SYNTAX.send(plr, getUsage());
|
C.COMMAND_SYNTAX.send(plr, getUsage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final Plot plot2 = MainUtil.getPlotFromString(plr, args[0], true);
|
Plot plot2 = MainUtil.getPlotFromString(plr, args[0], true);
|
||||||
if ((plot2 == null)) {
|
if (plot2 == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (plot1.equals(plot2)) {
|
if (plot1.equals(plot2)) {
|
||||||
|
@ -30,19 +30,19 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "createroadschematic",
|
command = "createroadschematic",
|
||||||
aliases = { "crs" },
|
aliases = {"crs"},
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.createroadschematic",
|
permission = "plots.createroadschematic",
|
||||||
description = "Add a road schematic to your world using the roads around your current plot",
|
description = "Add a road schematic to your world using the roads around your current plot",
|
||||||
usage = "/plot createroadschematic")
|
usage = "/plot createroadschematic")
|
||||||
public class CreateRoadSchematic extends SubCommand {
|
public class CreateRoadSchematic extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args) {
|
public boolean onCommand(PlotPlayer player, String... args) {
|
||||||
final Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
final Plot plot = loc.getPlotAbs();
|
Plot plot = loc.getPlotAbs();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return sendMessage(player, C.NOT_IN_PLOT);
|
return sendMessage(player, C.NOT_IN_PLOT);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
|||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -20,13 +21,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "database",
|
command = "database",
|
||||||
aliases = { "convert" },
|
aliases = {"convert"},
|
||||||
category = CommandCategory.ADMINISTRATION,
|
category = CommandCategory.ADMINISTRATION,
|
||||||
permission = "plots.database",
|
permission = "plots.database",
|
||||||
description = "Convert/Backup Storage",
|
description = "Convert/Backup Storage",
|
||||||
requiredType = RequiredType.CONSOLE,
|
requiredType = RequiredType.CONSOLE,
|
||||||
usage = "/plots database [area] <sqlite|mysql|import>")
|
usage = "/plots database [area] <sqlite|mysql|import>")
|
||||||
public class Database extends SubCommand {
|
public class Database extends SubCommand {
|
||||||
|
|
||||||
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player) {
|
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player) {
|
||||||
@ -34,8 +35,8 @@ public class Database extends SubCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final ArrayList<Plot> ps = new ArrayList<>();
|
ArrayList<Plot> ps = new ArrayList<>();
|
||||||
for (final Plot p : plots) {
|
for (Plot p : plots) {
|
||||||
ps.add(p);
|
ps.add(p);
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "&6Starting...");
|
MainUtil.sendMessage(player, "&6Starting...");
|
||||||
@ -46,7 +47,7 @@ public class Database extends SubCommand {
|
|||||||
manager.close();
|
manager.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
|
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -89,15 +90,15 @@ public class Database extends SubCommand {
|
|||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "&6Starting...");
|
MainUtil.sendMessage(player, "&6Starting...");
|
||||||
implementation = new SQLite(file.getPath());
|
implementation = new SQLite(file.getPath());
|
||||||
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
|
SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
|
||||||
final HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
|
HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
|
||||||
plots = new ArrayList<>();
|
plots = new ArrayList<>();
|
||||||
for (final Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
|
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
|
||||||
String areaname = entry.getKey();
|
String areaname = entry.getKey();
|
||||||
PlotArea pa = PS.get().getPlotAreaByString(areaname);
|
PlotArea pa = PS.get().getPlotAreaByString(areaname);
|
||||||
if (pa != null) {
|
if (pa != null) {
|
||||||
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
final Plot plot = entry2.getValue();
|
Plot plot = entry2.getValue();
|
||||||
if (pa.getOwnedPlotAbs(plot.getId()) != null) {
|
if (pa.getOwnedPlotAbs(plot.getId()) != null) {
|
||||||
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
|
||||||
continue;
|
continue;
|
||||||
@ -126,11 +127,11 @@ public class Database extends SubCommand {
|
|||||||
if (args.length < 6) {
|
if (args.length < 6) {
|
||||||
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
|
||||||
}
|
}
|
||||||
final String host = args[1];
|
String host = args[1];
|
||||||
final String port = args[2];
|
String port = args[2];
|
||||||
final String username = args[3];
|
String username = args[3];
|
||||||
final String password = args[4];
|
String password = args[4];
|
||||||
final String database = args[5];
|
String database = args[5];
|
||||||
if (args.length > 6) {
|
if (args.length > 6) {
|
||||||
prefix = args[6];
|
prefix = args[6];
|
||||||
}
|
}
|
||||||
@ -146,7 +147,7 @@ public class Database extends SubCommand {
|
|||||||
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
|
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final SQLManager manager = new SQLManager(implementation, prefix, true);
|
SQLManager manager = new SQLManager(implementation, prefix, true);
|
||||||
insertPlots(manager, plots, player);
|
insertPlots(manager, plots, player);
|
||||||
return true;
|
return true;
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
@ -29,17 +29,17 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
|||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
@CommandDeclaration(command = "debug",
|
@CommandDeclaration(command = "debug",
|
||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
description = "Show debug information",
|
description = "Show debug information",
|
||||||
usage = "/plot debug [msg]",
|
usage = "/plot debug [msg]",
|
||||||
permission = "plots.admin")
|
permission = "plots.admin")
|
||||||
public class Debug extends SubCommand {
|
public class Debug extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
|
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
|
||||||
final StringBuilder msg = new StringBuilder();
|
StringBuilder msg = new StringBuilder();
|
||||||
for (final C c : C.values()) {
|
for (C c : C.values()) {
|
||||||
msg.append(c.s()).append("\n");
|
msg.append(c.s()).append("\n");
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, msg.toString());
|
MainUtil.sendMessage(plr, msg.toString());
|
||||||
@ -75,11 +75,11 @@ public class Debug extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSection(final String line, final String val) {
|
private String getSection(String line, String val) {
|
||||||
return line.replaceAll("%val%", val) + "\n";
|
return line.replaceAll("%val%", val) + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLine(final String line, final String var, final Object val) {
|
private String getLine(String line, String var, Object val) {
|
||||||
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,27 @@
|
|||||||
package com.intellectualcrafters.plot.commands;
|
package com.intellectualcrafters.plot.commands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "debugallowunsafe",
|
command = "debugallowunsafe",
|
||||||
description = "Allow unsafe actions until toggled off",
|
description = "Allow unsafe actions until toggled off",
|
||||||
usage = "/plot debugallowunsafe",
|
usage = "/plot debugallowunsafe",
|
||||||
category = CommandCategory.DEBUG,
|
category = CommandCategory.DEBUG,
|
||||||
requiredType = RequiredType.NONE,
|
requiredType = RequiredType.NONE,
|
||||||
permission = "plots.debugallowunsafe")
|
permission = "plots.debugallowunsafe")
|
||||||
public class DebugAllowUnsafe extends SubCommand {
|
public class DebugAllowUnsafe extends SubCommand {
|
||||||
|
|
||||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String... args) {
|
public boolean onCommand(PlotPlayer plr, String... args) {
|
||||||
|
|
||||||
if (unsafeAllowed.contains(plr.getUUID())) {
|
if (unsafeAllowed.contains(plr.getUUID())) {
|
||||||
unsafeAllowed.remove(plr.getUUID());
|
unsafeAllowed.remove(plr.getUUID());
|
||||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
||||||
@ -31,5 +31,5 @@ public class DebugAllowUnsafe extends SubCommand {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,14 @@ import com.google.common.collect.BiMap;
|
|||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.object.*;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
@ -36,20 +43,22 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(
|
||||||
command = "debugclaimtest",
|
command = "debugclaimtest",
|
||||||
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. Execution time may vary",
|
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
|
||||||
category = CommandCategory.DEBUG,
|
+ "Execution time may vary",
|
||||||
requiredType = RequiredType.CONSOLE,
|
category = CommandCategory.DEBUG,
|
||||||
permission = "plots.debugclaimtest")
|
requiredType = RequiredType.CONSOLE,
|
||||||
|
permission = "plots.debugclaimtest")
|
||||||
public class DebugClaimTest extends SubCommand {
|
public class DebugClaimTest extends SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(final PlotPlayer plr, String[] args) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
return !MainUtil
|
return !MainUtil
|
||||||
.sendMessage(
|
.sendMessage(
|
||||||
null,
|
null,
|
||||||
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the "
|
||||||
|
+ "plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
|
||||||
}
|
}
|
||||||
PlotArea area = PS.get().getPlotAreaByString(args[0]);
|
PlotArea area = PS.get().getPlotAreaByString(args[0]);
|
||||||
if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
|
if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) {
|
||||||
@ -62,35 +71,36 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
args[2].split(";");
|
args[2].split(";");
|
||||||
min = PlotId.fromString(args[1]);
|
min = PlotId.fromString(args[1]);
|
||||||
max = PlotId.fromString(args[2]);
|
max = PlotId.fromString(args[2]);
|
||||||
} catch (final Exception e) {
|
} catch (Exception e) {
|
||||||
return !MainUtil.sendMessage(plr,
|
return !MainUtil.sendMessage(plr,
|
||||||
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area.");
|
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion "
|
||||||
|
+ "will only check the plots in the selected area.");
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
|
||||||
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
|
||||||
final PlotManager manager = area.getPlotManager();
|
PlotManager manager = area.getPlotManager();
|
||||||
final ArrayList<Plot> plots = new ArrayList<>();
|
ArrayList<Plot> plots = new ArrayList<>();
|
||||||
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
for (PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
|
||||||
final Plot plot = area.getPlotAbs(id);
|
Plot plot = area.getPlotAbs(id);
|
||||||
if (plot.hasOwner()) {
|
if (plot.hasOwner()) {
|
||||||
MainUtil.sendMessage(plr, " - &cDB Already contains: " + plot.getId());
|
MainUtil.sendMessage(plr, " - &cDB Already contains: " + plot.getId());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Location loc = manager.getSignLoc(area, plot);
|
Location loc = manager.getSignLoc(area, plot);
|
||||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||||
final boolean result = ChunkManager.manager.loadChunk(area.worldname, chunk, false);
|
boolean result = ChunkManager.manager.loadChunk(area.worldname, chunk, false);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String[] lines = WorldUtil.IMP.getSign(loc);
|
String[] lines = WorldUtil.IMP.getSign(loc);
|
||||||
if (lines != null) {
|
if (lines != null) {
|
||||||
String line = lines[2];
|
String line = lines[2];
|
||||||
if (line != null && line.length() > 2) {
|
if (line != null && line.length() > 2) {
|
||||||
line = line.substring(2);
|
line = line.substring(2);
|
||||||
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
|
||||||
UUID uuid = map.get(new StringWrapper(line));
|
UUID uuid = map.get(new StringWrapper(line));
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
for (final Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map.entrySet()) {
|
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map.entrySet()) {
|
||||||
if (stringWrapperUUIDEntry.getKey().value.toLowerCase().startsWith(line.toLowerCase())) {
|
if (stringWrapperUUIDEntry.getKey().value.toLowerCase().startsWith(line.toLowerCase())) {
|
||||||
uuid = stringWrapperUUIDEntry.getValue();
|
uuid = stringWrapperUUIDEntry.getValue();
|
||||||
break;
|
break;
|
||||||
@ -118,7 +128,7 @@ public class DebugClaimTest extends SubCommand {
|
|||||||
MainUtil.sendMessage(plr, "&6Database update finished!");
|
MainUtil.sendMessage(plr, "&6Database update finished!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (final Plot plot : plots) {
|
for (Plot plot : plots) {
|
||||||
plot.create();
|
plot.create();
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||||
|
@ -54,6 +54,7 @@ import com.intellectualcrafters.plot.util.WorldUtil;
|
|||||||
import com.plotsquared.general.commands.Command;
|
import com.plotsquared.general.commands.Command;
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
import com.plotsquared.general.commands.CommandDeclaration;
|
||||||
import com.plotsquared.listener.WEManager;
|
import com.plotsquared.listener.WEManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -62,6 +63,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.script.Bindings;
|
import javax.script.Bindings;
|
||||||
import javax.script.ScriptContext;
|
import javax.script.ScriptContext;
|
||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
@ -70,111 +72,114 @@ import javax.script.ScriptException;
|
|||||||
import javax.script.SimpleScriptContext;
|
import javax.script.SimpleScriptContext;
|
||||||
|
|
||||||
@CommandDeclaration(command = "debugexec",
|
@CommandDeclaration(command = "debugexec",
|
||||||
permission = "plots.admin",
|
permission = "plots.admin",
|
||||||
description = "Mutli-purpose debug command",
|
description = "Mutli-purpose debug command",
|
||||||
aliases = "exec",
|
aliases = "exec",
|
||||||
category = CommandCategory.DEBUG)
|
category = CommandCategory.DEBUG)
|
||||||
public class DebugExec extends SubCommand {
|
public class DebugExec extends SubCommand {
|
||||||
|
|
||||||
private ScriptEngine engine;
|
private ScriptEngine engine;
|
||||||
private Bindings scope;
|
private Bindings scope;
|
||||||
|
|
||||||
public DebugExec() {
|
public DebugExec() {
|
||||||
try {
|
try {
|
||||||
if (PS.get() != null) {
|
if (PS.get() != null) {
|
||||||
final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
|
File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
init();
|
init();
|
||||||
final String script = StringMan.join(Files
|
String script = StringMan.join(Files
|
||||||
.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"),
|
.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"),
|
||||||
StandardCharsets.UTF_8),
|
StandardCharsets.UTF_8),
|
||||||
System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
scope.put("THIS", this);
|
this.scope.put("THIS", this);
|
||||||
scope.put("PlotPlayer", ConsolePlayer.getConsole());
|
this.scope.put("PlotPlayer", ConsolePlayer.getConsole());
|
||||||
engine.eval(script, scope);
|
this.engine.eval(script, this.scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException | ScriptException e) {}
|
} catch (IOException | ScriptException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptEngine getEngine() {
|
public ScriptEngine getEngine() {
|
||||||
return engine;
|
return this.engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bindings getScope() {
|
public Bindings getScope() {
|
||||||
return scope;
|
return this.scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
if (engine != null) {
|
if (this.engine != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
engine = new ScriptEngineManager(null).getEngineByName("nashorn");
|
this.engine = new ScriptEngineManager(null).getEngineByName("nashorn");
|
||||||
if (engine == null) {
|
if (this.engine == null) {
|
||||||
engine = new ScriptEngineManager(null).getEngineByName("JavaScript");
|
this.engine = new ScriptEngineManager(null).getEngineByName("JavaScript");
|
||||||
}
|
}
|
||||||
final ScriptContext context = new SimpleScriptContext();
|
ScriptContext context = new SimpleScriptContext();
|
||||||
scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
|
this.scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||||
|
|
||||||
// stuff
|
// stuff
|
||||||
scope.put("MainUtil", new MainUtil());
|
this.scope.put("MainUtil", new MainUtil());
|
||||||
scope.put("Settings", new Settings());
|
this.scope.put("Settings", new Settings());
|
||||||
scope.put("StringMan", new StringMan());
|
this.scope.put("StringMan", new StringMan());
|
||||||
scope.put("MathMan", new MathMan());
|
this.scope.put("MathMan", new MathMan());
|
||||||
scope.put("FlagManager", new FlagManager());
|
this.scope.put("FlagManager", new FlagManager());
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
scope.put("Location", Location.class);
|
this.scope.put("Location", Location.class);
|
||||||
scope.put("PlotBlock", PlotBlock.class);
|
this.scope.put("PlotBlock", PlotBlock.class);
|
||||||
scope.put("Plot", Plot.class);
|
this.scope.put("Plot", Plot.class);
|
||||||
scope.put("PlotId", PlotId.class);
|
this.scope.put("PlotId", PlotId.class);
|
||||||
scope.put("Runnable", Runnable.class);
|
this.scope.put("Runnable", Runnable.class);
|
||||||
scope.put("RunnableVal", RunnableVal.class);
|
this.scope.put("RunnableVal", RunnableVal.class);
|
||||||
|
|
||||||
// Instances
|
// Instances
|
||||||
scope.put("PS", PS.get());
|
this.scope.put("PS", PS.get());
|
||||||
scope.put("SetQueue", SetQueue.IMP);
|
this.scope.put("SetQueue", SetQueue.IMP);
|
||||||
scope.put("ExpireManager", ExpireManager.IMP);
|
this.scope.put("ExpireManager", ExpireManager.IMP);
|
||||||
if (PS.get().worldedit != null) {
|
if (PS.get().worldedit != null) {
|
||||||
scope.put("WEManager", new WEManager());
|
this.scope.put("WEManager", new WEManager());
|
||||||
}
|
}
|
||||||
scope.put("TaskManager", PS.get().TASK);
|
this.scope.put("TaskManager", PS.get().TASK);
|
||||||
scope.put("TitleManager", AbstractTitle.TITLE_CLASS);
|
this.scope.put("TitleManager", AbstractTitle.TITLE_CLASS);
|
||||||
scope.put("ConsolePlayer", ConsolePlayer.getConsole());
|
this.scope.put("ConsolePlayer", ConsolePlayer.getConsole());
|
||||||
scope.put("SchematicHandler", SchematicHandler.manager);
|
this.scope.put("SchematicHandler", SchematicHandler.manager);
|
||||||
scope.put("ChunkManager", ChunkManager.manager);
|
this.scope.put("ChunkManager", ChunkManager.manager);
|
||||||
scope.put("BlockManager", WorldUtil.IMP);
|
this.scope.put("BlockManager", WorldUtil.IMP);
|
||||||
scope.put("SetupUtils", SetupUtils.manager);
|
this.scope.put("SetupUtils", SetupUtils.manager);
|
||||||
scope.put("EventUtil", EventUtil.manager);
|
this.scope.put("EventUtil", EventUtil.manager);
|
||||||
scope.put("EconHandler", EconHandler.manager);
|
this.scope.put("EconHandler", EconHandler.manager);
|
||||||
scope.put("UUIDHandler", UUIDHandler.implementation);
|
this.scope.put("UUIDHandler", UUIDHandler.implementation);
|
||||||
scope.put("DBFunc", DBFunc.dbManager);
|
this.scope.put("DBFunc", DBFunc.dbManager);
|
||||||
scope.put("HybridUtils", HybridUtils.manager);
|
this.scope.put("HybridUtils", HybridUtils.manager);
|
||||||
scope.put("IMP", PS.get().IMP);
|
this.scope.put("IMP", PS.get().IMP);
|
||||||
scope.put("MainCommand", MainCommand.getInstance());
|
this.scope.put("MainCommand", MainCommand.getInstance());
|
||||||
|
|
||||||
// enums
|
// enums
|
||||||
for (final Enum<?> value : C.values()) {
|
for (Enum<?> value : C.values()) {
|
||||||
scope.put("C_" + value.name(), value);
|
this.scope.put("C_" + value.name(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer player, final String... args) {
|
public boolean onCommand(final PlotPlayer player, String... args) {
|
||||||
final java.util.List<String> allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen");
|
java.util.List<String> allowed_params =
|
||||||
|
Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen");
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
final String arg = args[0].toLowerCase();
|
String arg = args[0].toLowerCase();
|
||||||
String script;
|
String script;
|
||||||
boolean async = false;
|
boolean async = false;
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case "analyze": {
|
case "analyze": {
|
||||||
final Plot plot = player.getCurrentPlot();
|
Plot plot = player.getCurrentPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final PlotAnalysis analysis = plot.getComplexity();
|
PlotAnalysis analysis = plot.getComplexity();
|
||||||
if (analysis != null) {
|
if (analysis != null) {
|
||||||
final int complexity = analysis.getComplexity();
|
int complexity = analysis.getComplexity();
|
||||||
MainUtil.sendMessage(player, "Changes/column: " + analysis.changes / 1.0);
|
MainUtil.sendMessage(player, "Changes/column: " + analysis.changes / 1.0);
|
||||||
MainUtil.sendMessage(player, "Complexity: " + complexity);
|
MainUtil.sendMessage(player, "Complexity: " + complexity);
|
||||||
return true;
|
return true;
|
||||||
@ -191,13 +196,15 @@ public class DebugExec extends SubCommand {
|
|||||||
case "calibrate-analysis":
|
case "calibrate-analysis":
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
|
||||||
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
|
MainUtil.sendMessage(player,
|
||||||
|
"$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating "
|
||||||
|
+ "it)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
double threshold;
|
double threshold;
|
||||||
try {
|
try {
|
||||||
threshold = Integer.parseInt(args[1]) / 100d;
|
threshold = Integer.parseInt(args[1]) / 100d;
|
||||||
} catch (final NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
|
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
|
||||||
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
|
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
|
||||||
return false;
|
return false;
|
||||||
@ -219,8 +226,8 @@ public class DebugExec extends SubCommand {
|
|||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String flag = args[1];
|
String flag = args[1];
|
||||||
for (final Plot plot : PS.get().getBasePlots()) {
|
for (Plot plot : PS.get().getBasePlots()) {
|
||||||
if (FlagManager.getPlotFlagRaw(plot, flag) != null) {
|
if (FlagManager.getPlotFlagRaw(plot, flag) != null) {
|
||||||
FlagManager.removePlotFlag(plot, flag);
|
FlagManager.removePlotFlag(plot, flag);
|
||||||
}
|
}
|
||||||
@ -275,16 +282,16 @@ public class DebugExec extends SubCommand {
|
|||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
|
||||||
}
|
}
|
||||||
final UUID uuid = UUIDHandler.getUUID(args[1], null);
|
UUID uuid = UUIDHandler.getUUID(args[1], null);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return MainUtil.sendMessage(player, "Player not found: " + args[1]);
|
return MainUtil.sendMessage(player, "Player not found: " + args[1]);
|
||||||
}
|
}
|
||||||
final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
|
||||||
if (op == null || op.getLastPlayed() == 0) {
|
if (op == null || op.getLastPlayed() == 0) {
|
||||||
return MainUtil.sendMessage(player, "Player hasn't connected before: " + args[1]);
|
return MainUtil.sendMessage(player, "Player hasn't connected before: " + args[1]);
|
||||||
}
|
}
|
||||||
final Timestamp stamp = new Timestamp(op.getLastPlayed());
|
Timestamp stamp = new Timestamp(op.getLastPlayed());
|
||||||
final Date date = new Date(stamp.getTime());
|
Date date = new Date(stamp.getTime());
|
||||||
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
|
||||||
MainUtil.sendMessage(player, "UUID: " + uuid);
|
MainUtil.sendMessage(player, "UUID: " + uuid);
|
||||||
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
||||||
@ -300,17 +307,18 @@ public class DebugExec extends SubCommand {
|
|||||||
case "addcmd":
|
case "addcmd":
|
||||||
try {
|
try {
|
||||||
final String cmd = StringMan.join(Files
|
final String cmd = StringMan.join(Files
|
||||||
.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]),
|
||||||
|
StandardCharsets.UTF_8),
|
||||||
System.getProperty("line.separator"));
|
System.getProperty("line.separator"));
|
||||||
final Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
|
Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final PlotPlayer plr, final String[] args) {
|
public boolean onCommand(PlotPlayer plr, String[] args) {
|
||||||
try {
|
try {
|
||||||
scope.put("PlotPlayer", plr);
|
DebugExec.this.scope.put("PlotPlayer", plr);
|
||||||
scope.put("args", args);
|
DebugExec.this.scope.put("args", args);
|
||||||
engine.eval(cmd, scope);
|
DebugExec.this.engine.eval(cmd, DebugExec.this.scope);
|
||||||
return true;
|
return true;
|
||||||
} catch (final ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
|
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
|
||||||
return false;
|
return false;
|
||||||
@ -328,16 +336,18 @@ public class DebugExec extends SubCommand {
|
|||||||
async = true;
|
async = true;
|
||||||
case "run":
|
case "run":
|
||||||
try {
|
try {
|
||||||
script = StringMan.join(Files.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
|
script = StringMan.join(Files
|
||||||
System.getProperty("line.separator"));
|
.readLines(MainUtil.getFile(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]),
|
||||||
|
StandardCharsets.UTF_8),
|
||||||
|
System.getProperty("line.separator"));
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
final HashMap<String, String> replacements = new HashMap<>();
|
HashMap<String, String> replacements = new HashMap<>();
|
||||||
for (int i = 2; i < args.length; i++) {
|
for (int i = 2; i < args.length; i++) {
|
||||||
replacements.put("%s" + (i - 2), args[i]);
|
replacements.put("%s" + (i - 2), args[i]);
|
||||||
}
|
}
|
||||||
script = StringMan.replaceFromMap(script, replacements);
|
script = StringMan.replaceFromMap(script, replacements);
|
||||||
}
|
}
|
||||||
} catch (final IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -372,9 +382,11 @@ public class DebugExec extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
scope.put("_2", params);
|
this.scope.put("_2", params);
|
||||||
scope.put("_3", cmd);
|
this.scope.put("_3", cmd);
|
||||||
script = "_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if(" + args[1] + "){PlotPlayer.setMeta(\"location\",plot.getBottomAbs());PlotPlayer.setMeta(\"lastplot\",plot);_3.onCommand(PlotPlayer,_2)}}";
|
script = "_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if(" + args[1]
|
||||||
|
+ "){PlotPlayer.setMeta(\"location\",plot.getBottomAbs());PlotPlayer.setMeta(\"lastplot\",plot);_3.onCommand"
|
||||||
|
+ "(PlotPlayer,_2)}}";
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "all":
|
case "all":
|
||||||
@ -395,7 +407,7 @@ public class DebugExec extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
init();
|
init();
|
||||||
scope.put("PlotPlayer", player);
|
this.scope.put("PlotPlayer", player);
|
||||||
PS.debug("> " + script);
|
PS.debug("> " + script);
|
||||||
try {
|
try {
|
||||||
if (async) {
|
if (async) {
|
||||||
@ -403,23 +415,23 @@ public class DebugExec extends SubCommand {
|
|||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try {
|
try {
|
||||||
result = engine.eval(toExec, scope);
|
result = DebugExec.this.engine.eval(toExec, DebugExec.this.scope);
|
||||||
} catch (final ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
|
ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
final long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Object result = engine.eval(script, scope);
|
Object result = this.engine.eval(script, this.scope);
|
||||||
ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
|
ConsolePlayer.getConsole().sendMessage("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (final ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user