mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 14:16:44 +01:00
Merge branch 'breaking' into master
This commit is contained in:
commit
2596f37f66
@ -1,5 +1,5 @@
|
|||||||
repositories {
|
repositories {
|
||||||
maven {url "https://hub.spigotmc.org/nexus/content/groups/public/"}
|
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
|
||||||
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||||
maven { url "http://nexus.hc.to/content/repositories/pub_releases" }
|
maven { url "http://nexus.hc.to/content/repositories/pub_releases" }
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
@ -7,14 +7,16 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':Core')
|
compile project(':Core')
|
||||||
compile 'org.spigotmc:spigot-api:1.12.1-R0.1-SNAPSHOT'
|
compile 'org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT'
|
||||||
|
compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0-SNAPSHOT')
|
||||||
compile("net.milkbowl.vault:VaultAPI:1.6") {
|
compile("net.milkbowl.vault:VaultAPI:1.6") {
|
||||||
exclude module: 'bukkit'
|
exclude module: 'bukkit'
|
||||||
}
|
}
|
||||||
|
compileOnly 'org.projectlombok:lombok:1.16.18'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = 1.7
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.7
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
from('src/main/resources') {
|
from('src/main/resources') {
|
||||||
|
@ -1,100 +1,38 @@
|
|||||||
package com.plotsquared.bukkit;
|
package com.github.intellectualsites.plotsquared.bukkit;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
||||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||||
import com.intellectualcrafters.plot.IPlotMain;
|
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.listeners.*;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111;
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
import com.github.intellectualsites.plotsquared.bukkit.util.*;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.github.intellectualsites.plotsquared.bukkit.uuid.*;
|
||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
|
||||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.github.intellectualsites.plotsquared.plot.generator.HybridGen;
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
|
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.util.ChatManager;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
import com.intellectualcrafters.plot.util.ConsoleColors;
|
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
import com.intellectualcrafters.plot.util.EventUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.block.QueueProvider;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
|
||||||
import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
|
||||||
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
|
||||||
import com.plotsquared.bukkit.listeners.ChunkListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.EntityPortal_1_7_9;
|
|
||||||
import com.plotsquared.bukkit.listeners.EntitySpawnListener;
|
|
||||||
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_9;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener_1_12;
|
|
||||||
import com.plotsquared.bukkit.listeners.PlotPlusListener_Legacy;
|
|
||||||
import com.plotsquared.bukkit.listeners.SingleWorldListener;
|
|
||||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
|
||||||
import com.plotsquared.bukkit.titles.DefaultTitle_111;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitCommand;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitEventUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitSchematicHandler;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitSetupUtils;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitTaskManager;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
|
||||||
import com.plotsquared.bukkit.util.Metrics;
|
|
||||||
import com.plotsquared.bukkit.util.SendChunk;
|
|
||||||
import com.plotsquared.bukkit.util.SetGenCB;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_7;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_8_3;
|
|
||||||
import com.plotsquared.bukkit.util.block.BukkitLocalQueue_1_9;
|
|
||||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.FileUUIDHandler;
|
|
||||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import java.io.File;
|
import lombok.Getter;
|
||||||
import java.lang.reflect.Field;
|
import lombok.NonNull;
|
||||||
import java.lang.reflect.Method;
|
import org.bukkit.*;
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -107,9 +45,19 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||||
|
|
||||||
private static ConcurrentHashMap<String, Plugin> pluginMap;
|
@Getter private static WorldEdit worldEdit;
|
||||||
|
private static Map<String, Plugin> pluginMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Disable AWE as otherwise both fail to load
|
// Disable AWE as otherwise both fail to load
|
||||||
@ -128,14 +76,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
iter.remove();
|
iter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String, Plugin> lookupNames = (Map<String, Plugin>) lookupNamesField.get(manager);
|
Map<String, Plugin> lookupNames =
|
||||||
|
(Map<String, Plugin>) lookupNamesField.get(manager);
|
||||||
lookupNames.remove("PlotMe");
|
lookupNames.remove("PlotMe");
|
||||||
lookupNames.remove("PlotMe-DefaultGenerator");
|
lookupNames.remove("PlotMe-DefaultGenerator");
|
||||||
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
|
pluginsField.set(manager, new ArrayList<Plugin>(plugins) {
|
||||||
@Override
|
@Override public boolean add(Plugin plugin) {
|
||||||
public boolean add(Plugin plugin) {
|
|
||||||
if (plugin.getName().startsWith("PlotMe")) {
|
if (plugin.getName().startsWith("PlotMe")) {
|
||||||
System.out.print("Disabling `" + plugin.getName() + "` for PlotMe conversion (configure in PlotSquared settings.yml)");
|
System.out.print("Disabling `" + plugin.getName()
|
||||||
|
+ "` for PlotMe conversion (configure in PlotSquared settings.yml)");
|
||||||
} else {
|
} else {
|
||||||
return super.add(plugin);
|
return super.add(plugin);
|
||||||
}
|
}
|
||||||
@ -143,8 +92,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
pluginMap = new ConcurrentHashMap<String, Plugin>(lookupNames) {
|
pluginMap = new ConcurrentHashMap<String, Plugin>(lookupNames) {
|
||||||
@Override
|
@Override public Plugin put(String key, Plugin plugin) {
|
||||||
public Plugin put(String key, Plugin plugin) {
|
|
||||||
if (!plugin.getName().startsWith("PlotMe")) {
|
if (!plugin.getName().startsWith("PlotMe")) {
|
||||||
return super.put(key, plugin);
|
return super.put(key, plugin);
|
||||||
}
|
}
|
||||||
@ -153,17 +101,20 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
};
|
};
|
||||||
lookupNamesField.set(manager, pluginMap);
|
lookupNamesField.set(manager, pluginMap);
|
||||||
}
|
}
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WorldEdit worldEdit;
|
private final LegacyMappings legacyMappings = new BukkitLegacyMappings();
|
||||||
|
private final BlockRegistry<Material> blockRegistry =
|
||||||
|
new BukkitBlockRegistry(Material.values());
|
||||||
private int[] version;
|
private int[] version;
|
||||||
private String name;
|
@Getter private String pluginName;
|
||||||
private SingleWorldListener singleWorldListener;
|
@Getter private SingleWorldListener singleWorldListener;
|
||||||
|
private Method methodUnloadChunk0;
|
||||||
|
private boolean methodUnloadSetup = false;
|
||||||
|
|
||||||
@Override
|
@Override public int[] getServerVersion() {
|
||||||
public int[] getServerVersion() {
|
|
||||||
if (this.version == null) {
|
if (this.version == null) {
|
||||||
try {
|
try {
|
||||||
this.version = new int[3];
|
this.version = new int[3];
|
||||||
@ -175,32 +126,34 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug(StringMan.getString(Bukkit.getBukkitVersion()));
|
PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion()));
|
||||||
PS.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
|
PlotSquared.debug(
|
||||||
|
StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
|
||||||
return new int[] {1, 13, 0};
|
return new int[] {1, 13, 0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.version;
|
return this.version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onEnable() {
|
||||||
public void onEnable() {
|
|
||||||
if (pluginMap != null) {
|
if (pluginMap != null) {
|
||||||
pluginMap.put("PlotMe-DefaultGenerator", this);
|
pluginMap.put("PlotMe-DefaultGenerator", this);
|
||||||
}
|
}
|
||||||
this.name = getDescription().getName();
|
this.pluginName = getDescription().getName();
|
||||||
getServer().getName();
|
getServer().getName();
|
||||||
new PS(this, "Bukkit");
|
|
||||||
|
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
|
||||||
|
|
||||||
|
new PlotSquared(this, "Bukkit");
|
||||||
if (Settings.Enabled_Components.METRICS) {
|
if (Settings.Enabled_Components.METRICS) {
|
||||||
new Metrics(this).start();
|
new Metrics(this).start();
|
||||||
PS.log(C.PREFIX + "&6Metrics enabled.");
|
PlotSquared.log(C.PREFIX + "&6Metrics enabled.");
|
||||||
} else {
|
} else {
|
||||||
PS.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
|
PlotSquared.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
|
||||||
}
|
}
|
||||||
if (Settings.Enabled_Components.WORLDS) {
|
if (Settings.Enabled_Components.WORLDS) {
|
||||||
TaskManager.IMP.taskRepeat(new Runnable() {
|
TaskManager.IMP.taskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
}, 20);
|
}, 20);
|
||||||
@ -212,72 +165,73 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingleWorldListener getSingleWorldListener() {
|
|
||||||
return singleWorldListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Method methodUnloadChunk0;
|
|
||||||
private boolean methodUnloadSetup = false;
|
|
||||||
|
|
||||||
public void unload() {
|
public void unload() {
|
||||||
if (!methodUnloadSetup) {
|
if (!this.methodUnloadSetup) {
|
||||||
methodUnloadSetup = true;
|
this.methodUnloadSetup = true;
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
ReflectionUtils.RefClass classCraftWorld = getRefClass("{cb}.CraftWorld");
|
||||||
methodUnloadChunk0 = classCraftWorld.getRealClass().getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
this.methodUnloadChunk0 = classCraftWorld.getRealClass()
|
||||||
methodUnloadChunk0.setAccessible(true);
|
.getDeclaredMethod("unloadChunk0", int.class, int.class, boolean.class);
|
||||||
|
this.methodUnloadChunk0.setAccessible(true);
|
||||||
} catch (Throwable ignore) {
|
} catch (Throwable ignore) {
|
||||||
ignore.printStackTrace();
|
ignore.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlotAreaManager manager = PS.get().getPlotAreaManager();
|
final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||||
if (manager instanceof SinglePlotAreaManager) {
|
if (manager instanceof SinglePlotAreaManager) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (final World world : Bukkit.getWorlds()) {
|
||||||
String name = world.getName();
|
final String name = world.getName();
|
||||||
char char0 = name.charAt(0);
|
final char char0 = name.charAt(0);
|
||||||
if (!Character.isDigit(char0) && char0 != '-') continue;
|
if (!Character.isDigit(char0) && char0 != '-') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!world.getPlayers().isEmpty()) {
|
if (!world.getPlayers().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotId id = PlotId.fromString(name);
|
final PlotId id = PlotId.fromString(name);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
Plot plot = area.getOwnedPlot(id);
|
final Plot plot = area.getOwnedPlot(id);
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
if (PlotPlayer.wrap(plot.owner) == null) {
|
if (PlotPlayer.wrap(plot.owner) == null) {
|
||||||
if (world.getKeepSpawnInMemory()) {
|
if (world.getKeepSpawnInMemory()) {
|
||||||
world.setKeepSpawnInMemory(false);
|
world.setKeepSpawnInMemory(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Chunk[] chunks = world.getLoadedChunks();
|
final Chunk[] chunks = world.getLoadedChunks();
|
||||||
if (chunks.length == 0) {
|
if (chunks.length == 0) {
|
||||||
if (!Bukkit.unloadWorld(world, true)) {
|
if (!Bukkit.unloadWorld(world, true)) {
|
||||||
PS.debug("Failed to unload " + world.getName());
|
PlotSquared.debug("Failed to unload " + world.getName());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
do {
|
do {
|
||||||
Chunk chunkI = chunks[index++];
|
final Chunk chunkI = chunks[index++];
|
||||||
boolean result;
|
boolean result;
|
||||||
if (methodUnloadChunk0 != null) {
|
if (methodUnloadChunk0 != null) {
|
||||||
try {
|
try {
|
||||||
result = (boolean) methodUnloadChunk0.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
result = (boolean) methodUnloadChunk0
|
||||||
|
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
methodUnloadChunk0 = null;
|
methodUnloadChunk0 = null;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = world.unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
|
result = world
|
||||||
|
.unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
} while (index < chunks.length && System.currentTimeMillis() - start < 5);
|
} while (index < chunks.length
|
||||||
|
&& System.currentTimeMillis() - start < 5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,83 +241,68 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void onDisable() {
|
||||||
public void onDisable() {
|
PlotSquared.get().disable();
|
||||||
PS.get().disable();
|
|
||||||
Bukkit.getScheduler().cancelTasks(this);
|
Bukkit.getScheduler().cancelTasks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void log(@NonNull String message) {
|
||||||
public void log(String message) {
|
|
||||||
try {
|
try {
|
||||||
message = C.color(message);
|
message = C.color(message);
|
||||||
if (!Settings.Chat.CONSOLE_COLOR) {
|
if (!Settings.Chat.CONSOLE_COLOR) {
|
||||||
message = ChatColor.stripColor(message);
|
message = ChatColor.stripColor(message);
|
||||||
}
|
}
|
||||||
this.getServer().getConsoleSender().sendMessage(message);
|
this.getServer().getConsoleSender().sendMessage(message);
|
||||||
} catch (Throwable ignored) {
|
} catch (final Throwable ignored) {
|
||||||
System.out.println(ConsoleColors.fromString(message));
|
System.out.println(ConsoleColors.fromString(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void disable() {
|
||||||
public void disable() {
|
|
||||||
onDisable();
|
onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int[] getPluginVersion() {
|
||||||
public int[] getPluginVersion() {
|
|
||||||
String ver = getDescription().getVersion();
|
String ver = getDescription().getVersion();
|
||||||
if (ver.contains("-")) {
|
if (ver.contains("-")) {
|
||||||
ver = ver.split("-")[0];
|
ver = ver.split("-")[0];
|
||||||
}
|
}
|
||||||
String[] split = ver.split("\\.");
|
String[] split = ver.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 public String getPluginVersionString() {
|
@Override public String getPluginVersionString() {
|
||||||
return getDescription().getVersion();
|
return getDescription().getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerCommands() {
|
||||||
public String getPluginName() {
|
final BukkitCommand bukkitCommand = new BukkitCommand();
|
||||||
return name;
|
final PluginCommand plotCommand = getCommand("plots");
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerCommands() {
|
|
||||||
BukkitCommand bukkitCommand = new BukkitCommand();
|
|
||||||
PluginCommand plotCommand = getCommand("plots");
|
|
||||||
plotCommand.setExecutor(bukkitCommand);
|
plotCommand.setExecutor(bukkitCommand);
|
||||||
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot"));
|
||||||
plotCommand.setTabCompleter(bukkitCommand);
|
plotCommand.setTabCompleter(bukkitCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public File getDirectory() {
|
||||||
public File getDirectory() {
|
|
||||||
return getDataFolder();
|
return getDataFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public File getWorldContainer() {
|
||||||
public File getWorldContainer() {
|
|
||||||
return Bukkit.getWorldContainer();
|
return Bukkit.getWorldContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public TaskManager getTaskManager() {
|
||||||
public TaskManager getTaskManager() {
|
|
||||||
return new BukkitTaskManager(this);
|
return new BukkitTaskManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @SuppressWarnings("deprecation") public void runEntityTask() {
|
||||||
public void runEntityTask() {
|
PlotSquared.log(C.PREFIX + "KillAllEntities started.");
|
||||||
PS.log(C.PREFIX + "KillAllEntities started.");
|
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
PlotSquared.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||||
PS.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
@Override public void run(PlotArea plotArea) {
|
||||||
@Override
|
final World world = Bukkit.getWorld(plotArea.worldname);
|
||||||
public void run(PlotArea plotArea) {
|
|
||||||
World world = Bukkit.getWorld(plotArea.worldname);
|
|
||||||
try {
|
try {
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return;
|
return;
|
||||||
@ -416,10 +355,15 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
case MINECART_TNT:
|
case MINECART_TNT:
|
||||||
case BOAT:
|
case BOAT:
|
||||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||||
com.intellectualcrafters.plot.object.Location location = BukkitUtil.getLocation(entity.getLocation());
|
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||||
|
location =
|
||||||
|
BukkitUtil.getLocation(entity.getLocation());
|
||||||
Plot plot = location.getPlot();
|
Plot plot = location.getPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
if (location.isPlotArea()) {
|
if (location.isPlotArea()) {
|
||||||
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
@ -431,6 +375,9 @@ public final 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))) {
|
||||||
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
@ -503,10 +450,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
Location location = entity.getLocation();
|
Location location = entity.getLocation();
|
||||||
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity =
|
||||||
if (!livingEntity.isLeashed() || !entity.hasMetadata("keep")) {
|
(LivingEntity) entity;
|
||||||
|
if (!livingEntity.isLeashed() || !entity
|
||||||
|
.hasMetadata("keep")) {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
if (!(passenger instanceof Player) && entity
|
||||||
|
.getMetadata("keep").isEmpty()) {
|
||||||
|
if (entity
|
||||||
|
.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -514,7 +468,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (!(passenger instanceof Player) && entity.getMetadata("keep").isEmpty()) {
|
if (!(passenger instanceof Player) && entity
|
||||||
|
.getMetadata("keep").isEmpty()) {
|
||||||
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -529,18 +487,32 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
LivingEntity livingEntity = (LivingEntity) entity;
|
LivingEntity livingEntity = (LivingEntity) entity;
|
||||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||||
if (meta != null && !meta.isEmpty()) {
|
if (meta != null && !meta.isEmpty()) {
|
||||||
if (livingEntity.isLeashed()) continue;
|
if (livingEntity.isLeashed())
|
||||||
|
continue;
|
||||||
|
|
||||||
List<MetadataValue> keep = entity.getMetadata("keep");
|
List<MetadataValue> keep =
|
||||||
if (keep != null && !keep.isEmpty()) continue;
|
entity.getMetadata("keep");
|
||||||
|
if (keep != null && !keep.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
PlotId originalPlotId =
|
||||||
|
(PlotId) meta.get(0).value();
|
||||||
if (originalPlotId != null) {
|
if (originalPlotId != null) {
|
||||||
com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation());
|
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||||
|
pLoc = BukkitUtil
|
||||||
|
.getLocation(entity.getLocation());
|
||||||
PlotArea area = pLoc.getPlotArea();
|
PlotArea area = pLoc.getPlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
PlotId currentPlotId =
|
||||||
if (!originalPlotId.equals(currentPlotId) && (currentPlotId == null || !area.getPlot(originalPlotId).equals(area.getPlot(currentPlotId)))) {
|
PlotId.of(area.getPlotAbs(pLoc));
|
||||||
|
if (!originalPlotId.equals(currentPlotId)
|
||||||
|
&& (currentPlotId == null || !area
|
||||||
|
.getPlot(originalPlotId)
|
||||||
|
.equals(area.getPlot(currentPlotId)))) {
|
||||||
|
if (entity
|
||||||
|
.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
@ -548,17 +520,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||||
com.intellectualcrafters.plot.object.Location pLoc = BukkitUtil.getLocation(entity.getLocation());
|
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||||
|
pLoc =
|
||||||
|
BukkitUtil.getLocation(entity.getLocation());
|
||||||
PlotArea area = pLoc.getPlotArea();
|
PlotArea area = pLoc.getPlotArea();
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
PlotId currentPlotId =
|
||||||
|
PlotId.of(area.getPlotAbs(pLoc));
|
||||||
if (currentPlotId != null) {
|
if (currentPlotId != null) {
|
||||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, currentPlotId));
|
entity.setMetadata("plot",
|
||||||
|
new FixedMetadataValue(
|
||||||
|
(Plugin) PlotSquared.get().IMP,
|
||||||
|
currentPlotId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,87 +548,49 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @Nullable
|
||||||
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
|
public final ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
||||||
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
|
if (Settings.Enabled_Components.PLOTME_CONVERTER) {
|
||||||
initPlotMeConverter();
|
initPlotMeConverter();
|
||||||
Settings.Enabled_Components.PLOTME_CONVERTER = false;
|
Settings.Enabled_Components.PLOTME_CONVERTER = false;
|
||||||
}
|
}
|
||||||
IndependentPlotGenerator result;
|
final IndependentPlotGenerator result;
|
||||||
if (id != null && id.equalsIgnoreCase("single")) {
|
if (id != null && id.equalsIgnoreCase("single")) {
|
||||||
result = new SingleWorldGenerator();
|
result = new SingleWorldGenerator();
|
||||||
} else {
|
} else {
|
||||||
result = PS.get().IMP.getDefaultGenerator();
|
result = PlotSquared.get().IMP.getDefaultGenerator();
|
||||||
if (!PS.get().setupPlotWorld(world, id, result)) {
|
if (!PlotSquared.get().setupPlotWorld(world, id, result)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (ChunkGenerator) result.specify(world);
|
return (ChunkGenerator) result.specify(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerPlayerEvents() {
|
||||||
public void registerPlayerEvents() {
|
final PlayerEvents main = new PlayerEvents();
|
||||||
PlayerEvents main = new PlayerEvents();
|
|
||||||
getServer().getPluginManager().registerEvents(main, this);
|
getServer().getPluginManager().registerEvents(main, this);
|
||||||
try {
|
try {
|
||||||
getServer().getClass().getMethod("spigot");
|
getServer().getClass().getMethod("spigot");
|
||||||
Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
|
Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
|
||||||
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
||||||
} catch (NoSuchMethodException | ClassNotFoundException ignored) {
|
} catch (final NoSuchMethodException | ClassNotFoundException ignored) {
|
||||||
PS.debug("Not running Spigot. Skipping EntitySpawnListener event.");
|
PlotSquared.debug("Not running Spigot. Skipping EntitySpawnListener event.");
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), 1, 7, 9)) {
|
|
||||||
try {
|
|
||||||
getServer().getPluginManager().registerEvents(new EntityPortal_1_7_9(), this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
|
|
||||||
try {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
|
|
||||||
try {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
try {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerInventoryEvents() {
|
||||||
public void registerInventoryEvents() {
|
|
||||||
// Part of PlayerEvents - can be moved if necessary
|
// Part of PlayerEvents - can be moved if necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerPlotPlusEvents() {
|
||||||
public void registerPlotPlusEvents() {
|
|
||||||
PlotPlusListener.startRunnable(this);
|
PlotPlusListener.startRunnable(this);
|
||||||
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_12_0)) {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlotPlusListener_1_12(), this);
|
|
||||||
} else {
|
|
||||||
getServer().getPluginManager().registerEvents(new PlotPlusListener_Legacy(), this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerForceFieldEvents() {
|
||||||
public void registerForceFieldEvents() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean initWorldEdit() {
|
||||||
public boolean initWorldEdit() {
|
|
||||||
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
|
||||||
worldEdit = WorldEdit.getInstance();
|
worldEdit = WorldEdit.getInstance();
|
||||||
return true;
|
return true;
|
||||||
@ -659,50 +598,35 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public EconHandler getEconomyHandler() {
|
||||||
public EconHandler getEconomyHandler() {
|
|
||||||
try {
|
try {
|
||||||
BukkitEconHandler econ = new BukkitEconHandler();
|
BukkitEconHandler econ = new BukkitEconHandler();
|
||||||
if (econ.init()) {
|
if (econ.init()) {
|
||||||
return econ;
|
return econ;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
PS.debug("No economy detected!");
|
PlotSquared.debug("No economy detected!");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public QueueProvider initBlockQueue() {
|
||||||
public QueueProvider initBlockQueue() {
|
|
||||||
try {
|
try {
|
||||||
new SendChunk();
|
new SendChunk();
|
||||||
MainUtil.canSendChunk = true;
|
MainUtil.canSendChunk = true;
|
||||||
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
} catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
|
||||||
PS.debug(SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
|
PlotSquared.debug(
|
||||||
|
SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
|
||||||
MainUtil.canSendChunk = false;
|
MainUtil.canSendChunk = false;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_13_0)) {
|
|
||||||
return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class);
|
return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class);
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
return QueueProvider.of(BukkitLocalQueue_1_9.class, BukkitLocalQueue.class);
|
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
|
|
||||||
return QueueProvider.of(BukkitLocalQueue_1_8_3.class, BukkitLocalQueue.class);
|
|
||||||
}
|
|
||||||
if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
|
|
||||||
return QueueProvider.of(BukkitLocalQueue_1_8.class, BukkitLocalQueue.class);
|
|
||||||
}
|
|
||||||
return QueueProvider.of(BukkitLocalQueue_1_7.class, BukkitLocalQueue.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override public WorldUtil initWorldUtil() {
|
||||||
public WorldUtil initWorldUtil() {
|
|
||||||
return new BukkitUtil();
|
return new BukkitUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean initPlotMeConverter() {
|
||||||
public boolean initPlotMeConverter() {
|
|
||||||
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
|
if (new LikePlotMeConverter("PlotMe").run(new ClassicPlotMeConnector())) {
|
||||||
return true;
|
return true;
|
||||||
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
|
} else if (new LikePlotMeConverter("PlotMe").run(new PlotMeConnector_017())) {
|
||||||
@ -711,12 +635,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @Nullable public GeneratorWrapper<?> getGenerator(@NonNull final String world,
|
||||||
public GeneratorWrapper<?> getGenerator(String world, String name) {
|
@Nullable final String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
|
final Plugin genPlugin = Bukkit.getPluginManager().getPlugin(name);
|
||||||
if (genPlugin != null && genPlugin.isEnabled()) {
|
if (genPlugin != null && genPlugin.isEnabled()) {
|
||||||
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
|
ChunkGenerator gen = genPlugin.getDefaultWorldGenerator(world, "");
|
||||||
if (gen instanceof GeneratorWrapper<?>) {
|
if (gen instanceof GeneratorWrapper<?>) {
|
||||||
@ -724,28 +648,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
return new BukkitPlotGenerator(world, gen);
|
return new BukkitPlotGenerator(world, gen);
|
||||||
} else {
|
} else {
|
||||||
return new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator());
|
return new BukkitPlotGenerator(PlotSquared.get().IMP.getDefaultGenerator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HybridUtils initHybridUtils() {
|
||||||
public HybridUtils initHybridUtils() {
|
|
||||||
return new BukkitHybridUtils();
|
return new BukkitHybridUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public SetupUtils initSetupUtils() {
|
||||||
public SetupUtils initSetupUtils() {
|
|
||||||
return new BukkitSetupUtils();
|
return new BukkitSetupUtils();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
||||||
public UUIDHandlerImplementation initUUIDHandler() {
|
|
||||||
boolean checkVersion = false;
|
boolean checkVersion = false;
|
||||||
try {
|
try {
|
||||||
OfflinePlayer.class.getDeclaredMethod("getUniqueId");
|
OfflinePlayer.class.getDeclaredMethod("getUniqueId");
|
||||||
checkVersion = true;
|
checkVersion = true;
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
UUIDWrapper wrapper;
|
}
|
||||||
|
final UUIDWrapper wrapper;
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||||
wrapper = new LowerOfflineUUIDWrapper();
|
wrapper = new LowerOfflineUUIDWrapper();
|
||||||
@ -765,20 +687,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
Settings.UUID.OFFLINE = true;
|
Settings.UUID.OFFLINE = true;
|
||||||
}
|
}
|
||||||
if (!checkVersion) {
|
if (!checkVersion) {
|
||||||
PS.log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
PlotSquared.log(C.PREFIX
|
||||||
|
+ " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||||
Settings.TITLES = false;
|
Settings.TITLES = false;
|
||||||
} else {
|
} else {
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
|
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
|
||||||
if (wrapper instanceof DefaultUUIDWrapper || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
if (wrapper instanceof DefaultUUIDWrapper
|
||||||
|
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||||
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
PS.log(C.PREFIX
|
PlotSquared.log(C.PREFIX + " &6" + getPluginName()
|
||||||
+ " &6" + getPluginName() + " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||||
+ "Bukkit");
|
+ "Bukkit");
|
||||||
} else {
|
} else {
|
||||||
PS.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
PlotSquared.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
||||||
}
|
}
|
||||||
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
||||||
return new SQLUUIDHandler(wrapper);
|
return new SQLUUIDHandler(wrapper);
|
||||||
@ -787,53 +711,45 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChunkManager initChunkManager() {
|
||||||
public ChunkManager initChunkManager() {
|
|
||||||
return new BukkitChunkManager();
|
return new BukkitChunkManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public EventUtil initEventUtil() {
|
||||||
public EventUtil initEventUtil() {
|
|
||||||
return new BukkitEventUtil();
|
return new BukkitEventUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void unregister(@NonNull final PlotPlayer player) {
|
||||||
public void unregister(PlotPlayer player) {
|
|
||||||
BukkitUtil.removePlayer(player.getName());
|
BukkitUtil.removePlayer(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerChunkProcessor() {
|
||||||
public void registerChunkProcessor() {
|
|
||||||
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void registerWorldEvents() {
|
||||||
public void registerWorldEvents() {
|
|
||||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public IndependentPlotGenerator getDefaultGenerator() {
|
||||||
public IndependentPlotGenerator getDefaultGenerator() {
|
|
||||||
return new HybridGen();
|
return new HybridGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public InventoryUtil initInventoryUtil() {
|
||||||
public InventoryUtil initInventoryUtil() {
|
|
||||||
return new BukkitInventoryUtil();
|
return new BukkitInventoryUtil();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void startMetrics() {
|
||||||
public void startMetrics() {
|
|
||||||
new Metrics(this).start();
|
new Metrics(this).start();
|
||||||
PS.log(C.PREFIX + "&6Metrics enabled.");
|
PlotSquared.log(C.PREFIX + "&6Metrics enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setGenerator(@NonNull 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
|
||||||
ConfigurationSection worldConfig = PS.get().worlds.getConfigurationSection("worlds." + worldName);
|
ConfigurationSection worldConfig =
|
||||||
|
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
|
||||||
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
String manager = worldConfig.getString("generator.plugin", getPluginName());
|
||||||
SetupObject setup = new SetupObject();
|
SetupObject setup = new SetupObject();
|
||||||
setup.plotManager = manager;
|
setup.plotManager = manager;
|
||||||
@ -846,38 +762,35 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
world = Bukkit.getWorld(worldName);
|
world = Bukkit.getWorld(worldName);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (!PS.get().hasPlotArea(worldName)) {
|
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||||
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.log("Failed to reload world: " + world + " | " + ignored.getMessage());
|
PlotSquared.log("Failed to reload world: " + world + " | " + ignored.getMessage());
|
||||||
Bukkit.getServer().unloadWorld(world, false);
|
Bukkit.getServer().unloadWorld(world, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen instanceof BukkitPlotGenerator) {
|
if (gen instanceof BukkitPlotGenerator) {
|
||||||
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
||||||
} else if (gen != null) {
|
} else if (gen != null) {
|
||||||
PS.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
|
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
|
||||||
} else if (PS.get().worlds.contains("worlds." + worldName)) {
|
} else if (PlotSquared.get().worlds.contains("worlds." + worldName)) {
|
||||||
PS.get().loadWorld(worldName, null);
|
PlotSquared.get().loadWorld(worldName, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public SchematicHandler initSchematicHandler() {
|
||||||
public SchematicHandler initSchematicHandler() {
|
|
||||||
return new BukkitSchematicHandler();
|
return new BukkitSchematicHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public AbstractTitle initTitleManager() {
|
||||||
public AbstractTitle initTitleManager() {
|
|
||||||
// Already initialized in UUID handler
|
// Already initialized in UUID handler
|
||||||
return AbstractTitle.TITLE_CLASS;
|
return AbstractTitle.TITLE_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
|
||||||
public PlotPlayer wrapPlayer(Object player) {
|
|
||||||
if (player instanceof Player) {
|
if (player instanceof Player) {
|
||||||
return BukkitUtil.getPlayer((Player) player);
|
return BukkitUtil.getPlayer((Player) player);
|
||||||
}
|
}
|
||||||
@ -893,14 +806,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getNMSPackage() {
|
||||||
public String getNMSPackage() {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChatManager<?> initChatManager() {
|
||||||
public ChatManager<?> initChatManager() {
|
|
||||||
if (Settings.Chat.INTERACTIVE) {
|
if (Settings.Chat.INTERACTIVE) {
|
||||||
return new BukkitChatManager();
|
return new BukkitChatManager();
|
||||||
} else {
|
} else {
|
||||||
@ -908,17 +819,25 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||||
public GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator) {
|
@NonNull final IndependentPlotGenerator generator) {
|
||||||
return new BukkitPlotGenerator(generator);
|
return new BukkitPlotGenerator(generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<String> getPluginIds() {
|
||||||
public List<String> getPluginIds() {
|
final List<String> names = new ArrayList<>();
|
||||||
ArrayList<String> names = new ArrayList<>();
|
for (final Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin
|
||||||
names.add(plugin.getName() + ';' + plugin.getDescription().getVersion() + ':' + plugin.isEnabled());
|
.isEnabled());
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public BlockRegistry<Material> getBlockRegistry() {
|
||||||
|
return this.blockRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public LegacyMappings getLegacyMappings() {
|
||||||
|
return this.legacyMappings;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
||||||
@ -19,6 +19,8 @@ import java.util.Collection;
|
|||||||
*/
|
*/
|
||||||
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.
|
||||||
*
|
*
|
||||||
@ -28,7 +30,38 @@ public final class ArrayWrapper<E> {
|
|||||||
setArray(elements);
|
setArray(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
private E[] _array;
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @param list The iterable of objects which will be converted to an array.
|
||||||
|
* @param c The type of the elements of the array.
|
||||||
|
* @return An array of elements in the specified iterable.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked") public static <T> T[] toArray(Iterable<? extends T> list,
|
||||||
|
Class<T> c) {
|
||||||
|
int size = -1;
|
||||||
|
if (list instanceof Collection<?>) {
|
||||||
|
@SuppressWarnings("rawtypes") Collection coll = (Collection) list;
|
||||||
|
size = coll.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (size < 0) {
|
||||||
|
size = 0;
|
||||||
|
// Ugly hack: Count it ourselves
|
||||||
|
for (@SuppressWarnings("unused") T element : list) {
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
T[] result = (T[]) Array.newInstance(c, size);
|
||||||
|
int i = 0;
|
||||||
|
for (T element : list) { // Assumes iteration order is consistent
|
||||||
|
result[i++] = element; // Assign array element at index THEN increment counter
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a reference to the wrapped array instance.
|
* Retrieves a reference to the wrapped array instance.
|
||||||
@ -54,9 +87,7 @@ public final class ArrayWrapper<E> {
|
|||||||
*
|
*
|
||||||
* @see Arrays#equals(Object[], Object[])
|
* @see Arrays#equals(Object[], Object[])
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes") @Override public boolean equals(Object other) {
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (!(other instanceof ArrayWrapper)) {
|
if (!(other instanceof ArrayWrapper)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -69,43 +100,8 @@ public final class ArrayWrapper<E> {
|
|||||||
* @return This object's hash code.
|
* @return This object's hash code.
|
||||||
* @see Arrays#hashCode(Object[])
|
* @see Arrays#hashCode(Object[])
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public int hashCode() {
|
||||||
public int hashCode() {
|
|
||||||
return Arrays.hashCode(_array);
|
return Arrays.hashCode(_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @param list The iterable of objects which will be converted to an array.
|
|
||||||
* @param c The type of the elements of the array.
|
|
||||||
* @return An array of elements in the specified iterable.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T[] toArray(Iterable<? extends T> list, Class<T> c) {
|
|
||||||
int size = -1;
|
|
||||||
if (list instanceof Collection<?>) {
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
Collection coll = (Collection) list;
|
|
||||||
size = coll.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (size < 0) {
|
|
||||||
size = 0;
|
|
||||||
// Ugly hack: Count it ourselves
|
|
||||||
for (@SuppressWarnings("unused") T element : list) {
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
T[] result = (T[]) Array.newInstance(c, size);
|
|
||||||
int i = 0;
|
|
||||||
for (T element : list) { // Assumes iteration order is consistent
|
|
||||||
result[i++] = element; // Assign array element at index THEN increment counter
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,17 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import static com.plotsquared.bukkit.chat.TextualComponent.rawText;
|
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import org.bukkit.Achievement;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Statistic;
|
|
||||||
import org.bukkit.Statistic.Type;
|
import org.bukkit.Statistic.Type;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
@ -22,17 +16,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Field;
|
import java.util.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +30,14 @@ import java.util.logging.Level;
|
|||||||
* optionally initializing it with text. Further property-setting method calls will affect that editing component.
|
* optionally initializing it with text. Further property-setting method calls will affect that editing component.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<MessagePart>, ConfigurationSerializable {
|
public class FancyMessage
|
||||||
|
implements JsonRepresentedObject, Cloneable, Iterable<MessagePart>, ConfigurationSerializable {
|
||||||
|
|
||||||
|
private static Constructor<?> nmsPacketPlayOutChatConstructor;
|
||||||
|
// The ChatSerializer's instance of Gson
|
||||||
|
private static Object nmsChatSerializerGsonInstance;
|
||||||
|
private static Method fromJsonMethod;
|
||||||
|
private static JsonParser _stringParser = new JsonParser();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ConfigurationSerialization.registerClass(FancyMessage.class);
|
ConfigurationSerialization.registerClass(FancyMessage.class);
|
||||||
@ -55,27 +47,13 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
private String jsonString;
|
private String jsonString;
|
||||||
private boolean dirty;
|
private boolean dirty;
|
||||||
|
|
||||||
private static Constructor<?> nmsPacketPlayOutChatConstructor;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FancyMessage clone() throws CloneNotSupportedException {
|
|
||||||
FancyMessage instance = (FancyMessage) super.clone();
|
|
||||||
instance.messageParts = new ArrayList<>(messageParts.size());
|
|
||||||
for (int i = 0; i < messageParts.size(); i++) {
|
|
||||||
instance.messageParts.add(i, messageParts.get(i).clone());
|
|
||||||
}
|
|
||||||
instance.dirty = false;
|
|
||||||
instance.jsonString = null;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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(final String firstPartText) {
|
||||||
this(rawText(firstPartText));
|
this(TextualComponent.rawText(firstPartText));
|
||||||
}
|
}
|
||||||
|
|
||||||
private FancyMessage(final TextualComponent firstPartText) {
|
private FancyMessage(final TextualComponent firstPartText) {
|
||||||
@ -85,10 +63,12 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
dirty = false;
|
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 (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 (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);
|
||||||
}
|
}
|
||||||
@ -102,6 +82,113 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
this((TextualComponent) null);
|
this((TextualComponent) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a JSON-represented message from a mapping of key-value pairs.
|
||||||
|
* This is called by the Bukkit serialization API.
|
||||||
|
* It is not intended for direct public API consumption.
|
||||||
|
*
|
||||||
|
* @param serialized The key-value mapping which represents a fancy message.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked") public static FancyMessage deserialize(
|
||||||
|
Map<String, Object> serialized) {
|
||||||
|
FancyMessage msg = new FancyMessage();
|
||||||
|
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
||||||
|
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
||||||
|
msg.dirty = !serialized.containsKey("JSON");
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes a fancy message from its JSON representation. This JSON representation is of the format of
|
||||||
|
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
||||||
|
*
|
||||||
|
* @param json The JSON string which represents a fancy message.
|
||||||
|
* @return A {@code FancyMessage} representing the parameterized JSON message.
|
||||||
|
*/
|
||||||
|
public static FancyMessage deserialize(String json) {
|
||||||
|
JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
||||||
|
JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
||||||
|
FancyMessage returnVal = new FancyMessage();
|
||||||
|
returnVal.messageParts.clear();
|
||||||
|
for (JsonElement mPrt : extra) {
|
||||||
|
MessagePart component = new MessagePart();
|
||||||
|
JsonObject messagePart = mPrt.getAsJsonObject();
|
||||||
|
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
||||||
|
// Deserialize text
|
||||||
|
if (TextualComponent.isTextKey(entry.getKey())) {
|
||||||
|
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
||||||
|
Map<String, Object> serializedMapForm =
|
||||||
|
new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
||||||
|
serializedMapForm.put("key", entry.getKey());
|
||||||
|
if (entry.getValue().isJsonPrimitive()) {
|
||||||
|
// Assume string
|
||||||
|
serializedMapForm.put("value", entry.getValue().getAsString());
|
||||||
|
} else {
|
||||||
|
// Composite object, but we assume each element is a string
|
||||||
|
for (Map.Entry<String, JsonElement> compositeNestedElement : entry
|
||||||
|
.getValue().getAsJsonObject().entrySet()) {
|
||||||
|
serializedMapForm.put("value." + compositeNestedElement.getKey(),
|
||||||
|
compositeNestedElement.getValue().getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
component.text = TextualComponent.deserialize(serializedMapForm);
|
||||||
|
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
|
||||||
|
if (entry.getValue().getAsBoolean()) {
|
||||||
|
component.styles
|
||||||
|
.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));
|
||||||
|
}
|
||||||
|
} else if (entry.getKey().equals("color")) {
|
||||||
|
component.color =
|
||||||
|
ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
||||||
|
} else if (entry.getKey().equals("clickEvent")) {
|
||||||
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
|
component.clickActionName = object.get("action").getAsString();
|
||||||
|
component.clickActionData = object.get("value").getAsString();
|
||||||
|
} else if (entry.getKey().equals("hoverEvent")) {
|
||||||
|
JsonObject object = entry.getValue().getAsJsonObject();
|
||||||
|
component.hoverActionName = object.get("action").getAsString();
|
||||||
|
if (object.get("value").isJsonPrimitive()) {
|
||||||
|
// Assume string
|
||||||
|
component.hoverActionData =
|
||||||
|
new JsonString(object.get("value").getAsString());
|
||||||
|
} else {
|
||||||
|
// Assume composite type
|
||||||
|
// The only composite type we currently store is another FancyMessage
|
||||||
|
// Therefore, recursion time!
|
||||||
|
component.hoverActionData = deserialize(object.get("value")
|
||||||
|
.toString() /* This should properly serialize the JSON object as a JSON string */);
|
||||||
|
}
|
||||||
|
} else if (entry.getKey().equals("insertion")) {
|
||||||
|
component.insertionData = entry.getValue().getAsString();
|
||||||
|
} else if (entry.getKey().equals("with")) {
|
||||||
|
for (JsonElement object : entry.getValue().getAsJsonArray()) {
|
||||||
|
if (object.isJsonPrimitive()) {
|
||||||
|
component.translationReplacements
|
||||||
|
.add(new JsonString(object.getAsString()));
|
||||||
|
} else {
|
||||||
|
// Only composite type stored in this array is - again - FancyMessages
|
||||||
|
// Recurse within this function to parse this as a translation replacement
|
||||||
|
component.translationReplacements.add(deserialize(object.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
returnVal.messageParts.add(component);
|
||||||
|
}
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public FancyMessage clone() throws CloneNotSupportedException {
|
||||||
|
FancyMessage instance = (FancyMessage) super.clone();
|
||||||
|
instance.messageParts = new ArrayList<>(messageParts.size());
|
||||||
|
for (int i = 0; i < messageParts.size(); i++) {
|
||||||
|
instance.messageParts.add(i, messageParts.get(i).clone());
|
||||||
|
}
|
||||||
|
instance.dirty = false;
|
||||||
|
instance.jsonString = null;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the text of the current editing component to a value.
|
* Sets the text of the current editing component to a value.
|
||||||
*
|
*
|
||||||
@ -110,7 +197,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
*/
|
*/
|
||||||
public FancyMessage text(String text) {
|
public FancyMessage text(String text) {
|
||||||
MessagePart latest = latest();
|
MessagePart latest = latest();
|
||||||
latest.text = rawText(text);
|
latest.text = TextualComponent.rawText(text);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -242,8 +329,12 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
*/
|
*/
|
||||||
public FancyMessage achievementTooltip(final Achievement which) {
|
public FancyMessage achievementTooltip(final Achievement which) {
|
||||||
try {
|
try {
|
||||||
Object achievement = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class).invoke(null, which);
|
Object achievement = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name").get(achievement));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement",
|
||||||
|
Achievement.class).invoke(null, which);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name")
|
||||||
|
.get(achievement));
|
||||||
} catch (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;
|
||||||
@ -251,7 +342,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
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 (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,11 +359,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
public FancyMessage statisticTooltip(final Statistic which) {
|
public FancyMessage statisticTooltip(final Statistic which) {
|
||||||
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 {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class).invoke(null, which);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSStatistic",
|
||||||
|
Statistic.class).invoke(null, which);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (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;
|
||||||
@ -279,7 +376,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
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 (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,11 +397,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
if ((type == Type.BLOCK && item.isBlock()) || type == Type.ENTITY) {
|
if ((type == Type.BLOCK && item.isBlock()) || type == Type.ENTITY) {
|
||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException(
|
||||||
|
"Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic", Statistic.class, Material.class).invoke(null, which, item);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getMaterialStatistic",
|
||||||
|
Statistic.class, Material.class).invoke(null, which, item);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (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;
|
||||||
@ -311,7 +414,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
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 (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,11 +435,16 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
throw new IllegalArgumentException("That statistic needs no additional parameter!");
|
||||||
}
|
}
|
||||||
if (type != Type.ENTITY) {
|
if (type != Type.ENTITY) {
|
||||||
throw new IllegalArgumentException("Wrong parameter type for that statistic - needs " + type + "!");
|
throw new IllegalArgumentException(
|
||||||
|
"Wrong parameter type for that statistic - needs " + type + "!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object statistic = Reflection.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class).invoke(null, which, entity);
|
Object statistic = Reflection
|
||||||
return achievementTooltip((String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name").get(statistic));
|
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getEntityStatistic",
|
||||||
|
Statistic.class, EntityType.class).invoke(null, which, entity);
|
||||||
|
return achievementTooltip(
|
||||||
|
(String) Reflection.getField(Reflection.getNMSClass("Statistic"), "name")
|
||||||
|
.get(statistic));
|
||||||
} catch (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;
|
||||||
@ -343,7 +452,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
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 (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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,7 +466,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final String itemJSON) {
|
public FancyMessage itemTooltip(final 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,8 +480,13 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
*/
|
*/
|
||||||
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
public FancyMessage itemTooltip(final ItemStack itemStack) {
|
||||||
try {
|
try {
|
||||||
Object nmsItem = Reflection.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class).invoke(null, itemStack);
|
Object nmsItem = Reflection
|
||||||
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save", Reflection.getNMSClass("NBTTagCompound")).invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance()).toString());
|
.getMethod(Reflection.getOBCClass("inventory.CraftItemStack"), "asNMSCopy",
|
||||||
|
ItemStack.class).invoke(null, itemStack);
|
||||||
|
return itemTooltip(Reflection.getMethod(Reflection.getNMSClass("ItemStack"), "save",
|
||||||
|
Reflection.getNMSClass("NBTTagCompound"))
|
||||||
|
.invoke(nmsItem, Reflection.getNMSClass("NBTTagCompound").newInstance())
|
||||||
|
.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return this;
|
return this;
|
||||||
@ -397,9 +513,25 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage tooltip(final Iterable<String> lines) {
|
public FancyMessage tooltip(final Iterable<String> lines) {
|
||||||
tooltip(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, String.class));
|
tooltip(ArrayWrapper.toArray(lines, String.class));
|
||||||
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.
|
||||||
|
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
||||||
|
* @return This builder instance.
|
||||||
|
*/ /* ------------
|
||||||
|
public FancyMessage translationReplacements(final Iterable<? extends CharSequence> replacements){
|
||||||
|
for(CharSequence str : replacements){
|
||||||
|
latest().translationReplacements.add(new JsonString(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
@ -453,29 +585,34 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 (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(
|
||||||
} else if (component.hoverActionData != null && component.hoverActionName != null) {
|
"The tooltip text cannot have click data.");
|
||||||
throw new IllegalArgumentException("The tooltip text cannot have a tooltip.");
|
} else if (component.hoverActionData != null
|
||||||
|
&& component.hoverActionName != null) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"The tooltip text cannot have a tooltip.");
|
||||||
}
|
}
|
||||||
if (component.hasText()) {
|
if (component.hasText()) {
|
||||||
result.messageParts.add(component.clone());
|
result.messageParts.add(component.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i != lines.length - 1) {
|
if (i != lines.length - 1) {
|
||||||
result.messageParts.add(new MessagePart(rawText("\n")));
|
result.messageParts.add(new MessagePart(TextualComponent.rawText("\n")));
|
||||||
}
|
}
|
||||||
} catch (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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -486,7 +623,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
public FancyMessage formattedTooltip(final Iterable<FancyMessage> lines) {
|
||||||
return formattedTooltip(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(lines, FancyMessage.class));
|
return formattedTooltip(ArrayWrapper.toArray(lines, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -503,22 +640,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
|
|
||||||
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.
|
|
||||||
* @param replacements The replacements, in order, that will be used in the language-specific message.
|
|
||||||
* @return This builder instance.
|
|
||||||
*/ /* ------------
|
|
||||||
public FancyMessage translationReplacements(final Iterable<? extends CharSequence> replacements){
|
|
||||||
for(CharSequence str : replacements){
|
|
||||||
latest().translationReplacements.add(new JsonString(str));
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
||||||
@ -543,7 +664,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
public FancyMessage translationReplacements(final Iterable<FancyMessage> replacements) {
|
||||||
return translationReplacements(com.plotsquared.bukkit.chat.ArrayWrapper.toArray(replacements, FancyMessage.class));
|
return translationReplacements(ArrayWrapper.toArray(replacements, FancyMessage.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -554,7 +675,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
* @return This builder instance.
|
* @return This builder instance.
|
||||||
*/
|
*/
|
||||||
public FancyMessage then(final String text) {
|
public FancyMessage then(final String text) {
|
||||||
return then(rawText(text));
|
return then(TextualComponent.rawText(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -588,8 +709,7 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
if (messageParts.size() == 1) {
|
if (messageParts.size() == 1) {
|
||||||
latest().writeJson(writer);
|
latest().writeJson(writer);
|
||||||
} else {
|
} else {
|
||||||
@ -641,8 +761,11 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
try {
|
try {
|
||||||
Object handle = Reflection.getHandle(player);
|
Object handle = Reflection.getHandle(player);
|
||||||
Object connection = Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection =
|
||||||
Reflection.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet")).invoke(connection, createChatPacket(jsonString));
|
Reflection.getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
|
Reflection
|
||||||
|
.getMethod(connection.getClass(), "sendPacket", Reflection.getNMSClass("Packet"))
|
||||||
|
.invoke(connection, createChatPacket(jsonString));
|
||||||
} catch (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);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
@ -650,7 +773,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
} catch (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 (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 (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 (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
@ -658,11 +782,9 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ChatSerializer's instance of Gson
|
private Object createChatPacket(String json)
|
||||||
private static Object nmsChatSerializerGsonInstance;
|
throws IllegalArgumentException, IllegalAccessException, InstantiationException,
|
||||||
private static Method fromJsonMethod;
|
InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||||
|
|
||||||
private Object createChatPacket(String json) 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;
|
||||||
@ -673,7 +795,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
// Y = minor
|
// Y = minor
|
||||||
// Z = revision
|
// Z = revision
|
||||||
final String version = Reflection.getVersion();
|
final String version = Reflection.getVersion();
|
||||||
String[] split = version.substring(1, version.length() - 1).split("_"); // Remove trailing dot
|
String[] split =
|
||||||
|
version.substring(1, version.length() - 1).split("_"); // Remove trailing dot
|
||||||
//int majorVersion = Integer.parseInt(split[0]);
|
//int majorVersion = Integer.parseInt(split[0]);
|
||||||
int minorVersion = Integer.parseInt(split[1]);
|
int minorVersion = Integer.parseInt(split[1]);
|
||||||
int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R
|
int revisionVersion = Integer.parseInt(split[2].substring(1)); // Substring to ignore R
|
||||||
@ -689,11 +812,14 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (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);
|
||||||
fromJsonMethod = nmsChatSerializerGsonInstance.getClass().getMethod("fromJson", String.class, Class.class);
|
fromJsonMethod = nmsChatSerializerGsonInstance.getClass()
|
||||||
|
.getMethod("fromJson", String.class, Class.class);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -701,7 +827,8 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
|
|
||||||
// Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' than to reflectively call it
|
// Since the method is so simple, and all the obfuscated methods have the same name, it's easier to reimplement 'IChatBaseComponent a(String)' 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
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -786,22 +913,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes a JSON-represented message from a mapping of key-value pairs.
|
|
||||||
* This is called by the Bukkit serialization API.
|
|
||||||
* It is not intended for direct public API consumption.
|
|
||||||
*
|
|
||||||
* @param serialized The key-value mapping which represents a fancy message.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static FancyMessage deserialize(Map<String, Object> serialized) {
|
|
||||||
FancyMessage msg = new FancyMessage();
|
|
||||||
msg.messageParts = (List<MessagePart>) serialized.get("messageParts");
|
|
||||||
msg.jsonString = serialized.containsKey("JSON") ? serialized.get("JSON").toString() : null;
|
|
||||||
msg.dirty = !serialized.containsKey("JSON");
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>Internally called method. Not for API consumption.</b>
|
* <b>Internally called method. Not for API consumption.</b>
|
||||||
*/
|
*/
|
||||||
@ -809,78 +920,4 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
|
|||||||
return messageParts.iterator();
|
return messageParts.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonParser _stringParser = new JsonParser();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deserializes a fancy message from its JSON representation. This JSON representation is of the format of
|
|
||||||
* that returned by {@link #toJSONString()}, and is compatible with vanilla inputs.
|
|
||||||
*
|
|
||||||
* @param json The JSON string which represents a fancy message.
|
|
||||||
* @return A {@code FancyMessage} representing the parameterized JSON message.
|
|
||||||
*/
|
|
||||||
public static FancyMessage deserialize(String json) {
|
|
||||||
JsonObject serialized = _stringParser.parse(json).getAsJsonObject();
|
|
||||||
JsonArray extra = serialized.getAsJsonArray("extra"); // Get the extra component
|
|
||||||
FancyMessage returnVal = new FancyMessage();
|
|
||||||
returnVal.messageParts.clear();
|
|
||||||
for (JsonElement mPrt : extra) {
|
|
||||||
MessagePart component = new MessagePart();
|
|
||||||
JsonObject messagePart = mPrt.getAsJsonObject();
|
|
||||||
for (Map.Entry<String, JsonElement> entry : messagePart.entrySet()) {
|
|
||||||
// Deserialize text
|
|
||||||
if (TextualComponent.isTextKey(entry.getKey())) {
|
|
||||||
// The map mimics the YAML serialization, which has a "key" field and one or more "value" fields
|
|
||||||
Map<String, Object> serializedMapForm = new HashMap<>(); // Must be object due to Bukkit serializer API compliance
|
|
||||||
serializedMapForm.put("key", entry.getKey());
|
|
||||||
if (entry.getValue().isJsonPrimitive()) {
|
|
||||||
// Assume string
|
|
||||||
serializedMapForm.put("value", entry.getValue().getAsString());
|
|
||||||
} else {
|
|
||||||
// Composite object, but we assume each element is a string
|
|
||||||
for (Map.Entry<String, JsonElement> compositeNestedElement : entry.getValue().getAsJsonObject().entrySet()) {
|
|
||||||
serializedMapForm.put("value." + compositeNestedElement.getKey(), compositeNestedElement.getValue().getAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
component.text = TextualComponent.deserialize(serializedMapForm);
|
|
||||||
} else if (MessagePart.stylesToNames.inverse().containsKey(entry.getKey())) {
|
|
||||||
if (entry.getValue().getAsBoolean()) {
|
|
||||||
component.styles.add(MessagePart.stylesToNames.inverse().get(entry.getKey()));
|
|
||||||
}
|
|
||||||
} else if (entry.getKey().equals("color")) {
|
|
||||||
component.color = ChatColor.valueOf(entry.getValue().getAsString().toUpperCase());
|
|
||||||
} else if (entry.getKey().equals("clickEvent")) {
|
|
||||||
JsonObject object = entry.getValue().getAsJsonObject();
|
|
||||||
component.clickActionName = object.get("action").getAsString();
|
|
||||||
component.clickActionData = object.get("value").getAsString();
|
|
||||||
} else if (entry.getKey().equals("hoverEvent")) {
|
|
||||||
JsonObject object = entry.getValue().getAsJsonObject();
|
|
||||||
component.hoverActionName = object.get("action").getAsString();
|
|
||||||
if (object.get("value").isJsonPrimitive()) {
|
|
||||||
// Assume string
|
|
||||||
component.hoverActionData = new JsonString(object.get("value").getAsString());
|
|
||||||
} else {
|
|
||||||
// Assume composite type
|
|
||||||
// The only composite type we currently store is another FancyMessage
|
|
||||||
// Therefore, recursion time!
|
|
||||||
component.hoverActionData = deserialize(object.get("value").toString() /* This should properly serialize the JSON object as a JSON string */);
|
|
||||||
}
|
|
||||||
} else if (entry.getKey().equals("insertion")) {
|
|
||||||
component.insertionData = entry.getValue().getAsString();
|
|
||||||
} else if (entry.getKey().equals("with")) {
|
|
||||||
for (JsonElement object : entry.getValue().getAsJsonArray()) {
|
|
||||||
if (object.isJsonPrimitive()) {
|
|
||||||
component.translationReplacements.add(new JsonString(object.getAsString()));
|
|
||||||
} else {
|
|
||||||
// Only composite type stored in this array is - again - FancyMessages
|
|
||||||
// Recurse within this function to parse this as a translation replacement
|
|
||||||
component.translationReplacements.add(deserialize(object.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returnVal.messageParts.add(component);
|
|
||||||
}
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ 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.
|
||||||
*/
|
*/
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import com.google.gson.stream.JsonWriter;
|
import com.google.gson.stream.JsonWriter;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
@ -20,8 +20,11 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
|
|||||||
_value = value == null ? null : value.toString();
|
_value = value == null ? null : value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static JsonString deserialize(Map<String, Object> map) {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
return new JsonString(map.get("stringValue").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
writer.value(getValue());
|
writer.value(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,12 +38,7 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
|
|||||||
return theSingleValue;
|
return theSingleValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonString deserialize(Map<String, Object> map) {
|
@Override public String toString() {
|
||||||
return new JsonString(map.get("stringValue").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.ImmutableBiMap;
|
import com.google.common.collect.ImmutableBiMap;
|
||||||
@ -19,43 +19,6 @@ import java.util.logging.Level;
|
|||||||
*/
|
*/
|
||||||
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
|
final class MessagePart implements JsonRepresentedObject, ConfigurationSerializable, Cloneable {
|
||||||
|
|
||||||
ChatColor color = ChatColor.WHITE;
|
|
||||||
ArrayList<ChatColor> styles = new ArrayList<>();
|
|
||||||
String clickActionName = null;
|
|
||||||
String clickActionData = null;
|
|
||||||
String hoverActionName = null;
|
|
||||||
JsonRepresentedObject hoverActionData = null;
|
|
||||||
TextualComponent text = null;
|
|
||||||
String insertionData = null;
|
|
||||||
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
|
||||||
|
|
||||||
MessagePart(final TextualComponent text) {
|
|
||||||
this.text = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagePart() {
|
|
||||||
this.text = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasText() {
|
|
||||||
return text != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public MessagePart clone() throws CloneNotSupportedException {
|
|
||||||
MessagePart obj = (MessagePart) super.clone();
|
|
||||||
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
|
||||||
if (hoverActionData instanceof JsonString) {
|
|
||||||
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
|
||||||
} else if (hoverActionData instanceof FancyMessage) {
|
|
||||||
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
|
||||||
}
|
|
||||||
obj.translationReplacements = (ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
|
||||||
return obj;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static final BiMap<ChatColor, String> stylesToNames;
|
static final BiMap<ChatColor, String> stylesToNames;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -83,6 +46,62 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
stylesToNames = builder.build();
|
stylesToNames = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
ConfigurationSerialization.registerClass(MessagePart.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatColor color = ChatColor.WHITE;
|
||||||
|
ArrayList<ChatColor> styles = new ArrayList<>();
|
||||||
|
String clickActionName = null;
|
||||||
|
String clickActionData = null;
|
||||||
|
String hoverActionName = null;
|
||||||
|
JsonRepresentedObject hoverActionData = null;
|
||||||
|
TextualComponent text = null;
|
||||||
|
String insertionData = null;
|
||||||
|
ArrayList<JsonRepresentedObject> translationReplacements = new ArrayList<>();
|
||||||
|
|
||||||
|
MessagePart(final TextualComponent text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessagePart() {
|
||||||
|
this.text = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static MessagePart deserialize(Map<String, Object> serialized) {
|
||||||
|
MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
||||||
|
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
||||||
|
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
||||||
|
part.hoverActionName = (String) serialized.get("hoverActionName");
|
||||||
|
part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
|
||||||
|
part.clickActionName = (String) serialized.get("clickActionName");
|
||||||
|
part.clickActionData = (String) serialized.get("clickActionData");
|
||||||
|
part.insertionData = (String) serialized.get("insertion");
|
||||||
|
part.translationReplacements =
|
||||||
|
(ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasText() {
|
||||||
|
return text != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @SuppressWarnings("unchecked") public MessagePart clone()
|
||||||
|
throws CloneNotSupportedException {
|
||||||
|
MessagePart obj = (MessagePart) super.clone();
|
||||||
|
obj.styles = (ArrayList<ChatColor>) styles.clone();
|
||||||
|
if (hoverActionData instanceof JsonString) {
|
||||||
|
obj.hoverActionData = new JsonString(((JsonString) hoverActionData).getValue());
|
||||||
|
} else if (hoverActionData instanceof FancyMessage) {
|
||||||
|
obj.hoverActionData = ((FancyMessage) hoverActionData).clone();
|
||||||
|
}
|
||||||
|
obj.translationReplacements =
|
||||||
|
(ArrayList<JsonRepresentedObject>) translationReplacements.clone();
|
||||||
|
return obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void writeJson(JsonWriter json) {
|
public void writeJson(JsonWriter json) {
|
||||||
try {
|
try {
|
||||||
json.beginObject();
|
json.beginObject();
|
||||||
@ -92,16 +111,11 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
json.name(stylesToNames.get(style)).value(true);
|
json.name(stylesToNames.get(style)).value(true);
|
||||||
}
|
}
|
||||||
if (clickActionName != null && clickActionData != null) {
|
if (clickActionName != null && clickActionData != null) {
|
||||||
json.name("clickEvent")
|
json.name("clickEvent").beginObject().name("action").value(clickActionName)
|
||||||
.beginObject()
|
.name("value").value(clickActionData).endObject();
|
||||||
.name("action").value(clickActionName)
|
|
||||||
.name("value").value(clickActionData)
|
|
||||||
.endObject();
|
|
||||||
}
|
}
|
||||||
if (hoverActionName != null && hoverActionData != null) {
|
if (hoverActionName != null && hoverActionData != null) {
|
||||||
json.name("hoverEvent")
|
json.name("hoverEvent").beginObject().name("action").value(hoverActionName)
|
||||||
.beginObject()
|
|
||||||
.name("action").value(hoverActionName)
|
|
||||||
.name("value");
|
.name("value");
|
||||||
hoverActionData.writeJson(json);
|
hoverActionData.writeJson(json);
|
||||||
json.endObject();
|
json.endObject();
|
||||||
@ -109,7 +123,8 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
if (insertionData != null) {
|
if (insertionData != null) {
|
||||||
json.name("insertion").value(insertionData);
|
json.name("insertion").value(insertionData);
|
||||||
}
|
}
|
||||||
if (translationReplacements.size() > 0 && text != null && TextualComponent.isTranslatableText(text)) {
|
if (translationReplacements.size() > 0 && text != null && TextualComponent
|
||||||
|
.isTranslatableText(text)) {
|
||||||
json.name("with").beginArray();
|
json.name("with").beginArray();
|
||||||
for (JsonRepresentedObject obj : translationReplacements) {
|
for (JsonRepresentedObject obj : translationReplacements) {
|
||||||
obj.writeJson(json);
|
obj.writeJson(json);
|
||||||
@ -118,7 +133,8 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
}
|
}
|
||||||
json.endObject();
|
json.endObject();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "A problem occured during writing of JSON string", e);
|
Bukkit.getLogger()
|
||||||
|
.log(Level.WARNING, "A problem occured during writing of JSON string", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,22 +152,4 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static MessagePart deserialize(Map<String, Object> serialized) {
|
|
||||||
MessagePart part = new MessagePart((TextualComponent) serialized.get("text"));
|
|
||||||
part.styles = (ArrayList<ChatColor>) serialized.get("styles");
|
|
||||||
part.color = ChatColor.getByChar(serialized.get("color").toString());
|
|
||||||
part.hoverActionName = (String) serialized.get("hoverActionName");
|
|
||||||
part.hoverActionData = (JsonRepresentedObject) serialized.get("hoverActionData");
|
|
||||||
part.clickActionName = (String) serialized.get("clickActionName");
|
|
||||||
part.clickActionData = (String) serialized.get("clickActionData");
|
|
||||||
part.insertionData = (String) serialized.get("insertion");
|
|
||||||
part.translationReplacements = (ArrayList<JsonRepresentedObject>) serialized.get("translationReplacements");
|
|
||||||
return part;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
ConfigurationSerialization.registerClass(MessagePart.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@ -28,10 +28,12 @@ public final class Reflection {
|
|||||||
* Contains loaded methods in a cache.
|
* Contains loaded methods in a cache.
|
||||||
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
* The map maps [types to maps of [method names to maps of [parameter types to method instances]]].
|
||||||
*/
|
*/
|
||||||
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>> _loadedMethods = new HashMap<>();
|
private static final Map<Class<?>, Map<String, Map<ArrayWrapper<Class<?>>, Method>>>
|
||||||
|
_loadedMethods = new HashMap<>();
|
||||||
private static String _versionString;
|
private static String _versionString;
|
||||||
|
|
||||||
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.
|
||||||
@ -109,7 +111,8 @@ 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(Object obj) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
public synchronized static Object getHandle(Object obj)
|
||||||
|
throws InvocationTargetException, IllegalAccessException, IllegalArgumentException {
|
||||||
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
return getMethod(obj.getClass(), "getHandle").invoke(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +184,8 @@ public final class Reflection {
|
|||||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
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>());
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.chat;
|
package com.github.intellectualsites.plotsquared.bukkit.chat;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -27,7 +27,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
|
if (map.containsKey("key") && map.size() == 2 && map.containsKey("value")) {
|
||||||
// Arbitrary text component
|
// Arbitrary text component
|
||||||
return ArbitraryTextTypeComponent.deserialize(map);
|
return ArbitraryTextTypeComponent.deserialize(map);
|
||||||
} else if (map.size() >= 2 && map.containsKey("key") && !map.containsKey("value") /* It contains keys that START WITH value */) {
|
} else if (map.size() >= 2 && map.containsKey("key") && !map
|
||||||
|
.containsKey("value") /* It contains keys that START WITH value */) {
|
||||||
// Complex JSON object
|
// Complex JSON object
|
||||||
return ComplexTextTypeComponent.deserialize(map);
|
return ComplexTextTypeComponent.deserialize(map);
|
||||||
}
|
}
|
||||||
@ -36,11 +37,13 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static boolean isTextKey(String key) {
|
static boolean isTextKey(String key) {
|
||||||
return key.equals("translate") || key.equals("text") || key.equals("score") || key.equals("selector");
|
return key.equals("translate") || key.equals("text") || key.equals("score") || key
|
||||||
|
.equals("selector");
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isTranslatableText(TextualComponent component) {
|
static boolean isTranslatableText(TextualComponent component) {
|
||||||
return component instanceof ComplexTextTypeComponent && component.getKey().equals("translate");
|
return component instanceof ComplexTextTypeComponent && component.getKey()
|
||||||
|
.equals("translate");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +76,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void throwUnsupportedSnapshot() {
|
private static void throwUnsupportedSnapshot() {
|
||||||
throw new UnsupportedOperationException("This feature is only supported in snapshot releases.");
|
throw new UnsupportedOperationException(
|
||||||
|
"This feature is only supported in snapshot releases.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,10 +116,9 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
throwUnsupportedSnapshot(); // Remove this line when the feature is released to non-snapshot versions, in addition to updating ALL THE
|
||||||
// OVERLOADS documentation accordingly
|
// OVERLOADS documentation accordingly
|
||||||
|
|
||||||
return new ComplexTextTypeComponent("score", ImmutableMap.<String, String>builder()
|
return new ComplexTextTypeComponent("score",
|
||||||
.put("name", playerName)
|
ImmutableMap.<String, String>builder().put("name", playerName)
|
||||||
.put("objective", scoreboardObjective)
|
.put("objective", scoreboardObjective).build());
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,8 +139,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
return new ArbitraryTextTypeComponent("selector", selector);
|
return new ArbitraryTextTypeComponent("selector", selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
return getReadableString();
|
return getReadableString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +157,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
* Clones a textual component instance.
|
* Clones a textual component instance.
|
||||||
* The returned object should not reference this textual component instance, but should maintain the same key and value.
|
* The returned object should not reference this textual component instance, but should maintain the same key and value.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public abstract TextualComponent clone() throws CloneNotSupportedException;
|
||||||
public abstract TextualComponent clone() throws CloneNotSupportedException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the text data represented by this textual component to the specified JSON writer object.
|
* Writes the text data represented by this textual component to the specified JSON writer object.
|
||||||
@ -171,7 +172,8 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
* Internal class used to represent all types of text components.
|
* Internal class used to represent all types of text components.
|
||||||
* Exception validating done is on keys and values.
|
* Exception validating done is on keys and values.
|
||||||
*/
|
*/
|
||||||
private static final class ArbitraryTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ArbitraryTextTypeComponent extends TextualComponent
|
||||||
|
implements ConfigurationSerializable {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String value;
|
private String value;
|
||||||
@ -182,16 +184,17 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
|
public static ArbitraryTextTypeComponent deserialize(Map<String, Object> map) {
|
||||||
return new ArbitraryTextTypeComponent(map.get("key").toString(), map.get("value").toString());
|
return new ArbitraryTextTypeComponent(map.get("key").toString(),
|
||||||
|
map.get("value").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getKey() {
|
||||||
public String getKey() {
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String 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.");
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,20 +207,16 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
this.value = value;
|
this.value = 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
|
||||||
return new ArbitraryTextTypeComponent(getKey(), getValue());
|
return new ArbitraryTextTypeComponent(getKey(), getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
writer.name(getKey()).value(getValue());
|
writer.name(getKey()).value(getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @SuppressWarnings("serial") public Map<String, Object> serialize() {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
return new HashMap<String, Object>() {
|
return new HashMap<String, Object>() {
|
||||||
{
|
{
|
||||||
put("key", getKey());
|
put("key", getKey());
|
||||||
@ -226,19 +225,20 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getReadableString() {
|
||||||
public String getReadableString() {
|
|
||||||
return getValue();
|
return getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class used to represent a text component with a nested JSON
|
* Internal class used to represent a text component with a nested JSON
|
||||||
* value.
|
* value.
|
||||||
*
|
*
|
||||||
* <p>Exception validating done is on keys and values.
|
* <p>Exception validating done is on keys and values.
|
||||||
*/
|
*/
|
||||||
private static final class ComplexTextTypeComponent extends TextualComponent implements ConfigurationSerializable {
|
private static final class ComplexTextTypeComponent extends TextualComponent
|
||||||
|
implements ConfigurationSerializable {
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private Map<String, String> value;
|
private Map<String, String> value;
|
||||||
@ -255,19 +255,20 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
if (valEntry.getKey().equals("key")) {
|
if (valEntry.getKey().equals("key")) {
|
||||||
key = (String) valEntry.getValue();
|
key = (String) valEntry.getValue();
|
||||||
} else if (valEntry.getKey().startsWith("value.")) {
|
} else if (valEntry.getKey().startsWith("value.")) {
|
||||||
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */, valEntry.getValue().toString());
|
value.put(valEntry.getKey().substring(6) /* Strips out the value prefix */,
|
||||||
|
valEntry.getValue().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ComplexTextTypeComponent(key, value);
|
return new ComplexTextTypeComponent(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getKey() {
|
||||||
public String getKey() {
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKey(String 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.");
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,14 +281,12 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public TextualComponent clone() {
|
||||||
public TextualComponent clone() {
|
|
||||||
// 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
|
||||||
return new ComplexTextTypeComponent(getKey(), getValue());
|
return new ComplexTextTypeComponent(getKey(), getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void writeJson(JsonWriter writer) throws IOException {
|
||||||
public void writeJson(JsonWriter writer) throws IOException {
|
|
||||||
writer.name(getKey());
|
writer.name(getKey());
|
||||||
writer.beginObject();
|
writer.beginObject();
|
||||||
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
|
for (Map.Entry<String, String> jsonPair : value.entrySet()) {
|
||||||
@ -296,9 +295,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @SuppressWarnings("serial") public Map<String, Object> serialize() {
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public Map<String, Object> serialize() {
|
|
||||||
return new java.util.HashMap<String, Object>() {
|
return new java.util.HashMap<String, Object>() {
|
||||||
{
|
{
|
||||||
put("key", getKey());
|
put("key", getKey());
|
||||||
@ -309,8 +306,7 @@ public abstract class TextualComponent implements Cloneable {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getReadableString() {
|
||||||
public String getReadableString() {
|
|
||||||
return getKey();
|
return getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,54 +1,40 @@
|
|||||||
package com.plotsquared.bukkit.commands;
|
package com.github.intellectualsites.plotsquared.bukkit.commands;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.uuid.DatFileFilter;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.commands.Argument;
|
||||||
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.commands.RequiredType;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.commands.SubCommand;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
|
||||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
|
||||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.WorldUtil;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.DatFileFilter;
|
|
||||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
|
||||||
import com.plotsquared.general.commands.Argument;
|
|
||||||
import com.plotsquared.general.commands.CommandDeclaration;
|
|
||||||
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;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CommandDeclaration(
|
@CommandDeclaration(command = "uuidconvert", permission = "plots.admin", description = "Debug UUID conversion", usage = "/plot uuidconvert <lower|offline|online>", requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG)
|
||||||
command = "uuidconvert",
|
|
||||||
permission = "plots.admin",
|
|
||||||
description = "Debug UUID conversion",
|
|
||||||
usage = "/plot uuidconvert <lower|offline|online>",
|
|
||||||
requiredType = RequiredType.CONSOLE,
|
|
||||||
category = CommandCategory.DEBUG)
|
|
||||||
public class DebugUUID extends SubCommand {
|
public class DebugUUID extends SubCommand {
|
||||||
|
|
||||||
public DebugUUID() {
|
public DebugUUID() {
|
||||||
super(Argument.String);
|
super(Argument.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean onCommand(final PlotPlayer player, 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;
|
||||||
|
|
||||||
@ -67,7 +53,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
Class<?> clazz = Class.forName(args[0]);
|
Class<?> clazz = Class.forName(args[0]);
|
||||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||||
|
"/plot uuidconvert <lower|offline|online>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,23 +62,29 @@ public class DebugUUID extends SubCommand {
|
|||||||
if (args.length != 2 || !"-o".equals(args[1])) {
|
if (args.length != 2 || !"-o".equals(args[1])) {
|
||||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||||
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
|
MainUtil.sendMessage(player,
|
||||||
MainUtil.sendMessage(player, "&8 - &cIf the process is interrupted, all plots could be deleted");
|
"&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||||
|
MainUtil.sendMessage(player,
|
||||||
|
"&8 - &cIf the process is interrupted, all plots could be deleted");
|
||||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||||
MainUtil.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
MainUtil
|
||||||
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
|
.sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||||
|
MainUtil.sendMessage(player,
|
||||||
|
"&7Retype the command with the override parameter when ready :)");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
|
if (currentUUIDWrapper.getClass().getCanonicalName()
|
||||||
|
.equals(newWrapper.getClass().getCanonicalName())) {
|
||||||
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
MainUtil.sendMessage(player, "&cUUID mode already in use!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
|
||||||
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
MainUtil.sendMessage(player, "&7 - Disconnecting players");
|
||||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||||
entry.getValue().kick("UUID conversion has been initiated. You may reconnect when finished.");
|
entry.getValue()
|
||||||
|
.kick("UUID conversion has been initiated. You may reconnect when finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Initializing map");
|
MainUtil.sendMessage(player, "&7 - Initializing map");
|
||||||
@ -135,12 +128,14 @@ public class DebugUUID extends SubCommand {
|
|||||||
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 (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
MainUtil.sendMessage(player,
|
||||||
|
C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
@ -175,8 +170,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||||
String name = UUIDHandler.getName(entry.getKey());
|
String name = UUIDHandler.getName(entry.getKey());
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
@ -186,10 +180,11 @@ 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)");
|
||||||
|
|
||||||
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
File file = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
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();
|
||||||
@ -199,7 +194,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
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;
|
||||||
}
|
}
|
||||||
UUID old = currentUUIDWrapper.getUUID(name);
|
UUID old = currentUUIDWrapper.getUUID(name);
|
||||||
@ -224,7 +220,7 @@ public class DebugUUID extends SubCommand {
|
|||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||||
|
|
||||||
for (Plot plot : PS.get().getPlots()) {
|
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||||
UUID value = uCMap.get(plot.owner);
|
UUID value = uCMap.get(plot.owner);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
@ -243,15 +239,15 @@ public class DebugUUID extends SubCommand {
|
|||||||
DBFunc.createTables();
|
DBFunc.createTables();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||||
for (Plot plot : PS.get().getPlots()) {
|
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||||
UUID value = uCReverse.get(plot.owner);
|
UUID value = uCReverse.get(plot.owner);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
plot.owner = value;
|
plot.owner = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DBFunc.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override public void run() {
|
||||||
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -263,27 +259,26 @@ public class DebugUUID extends SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||||
PS.get().worlds.set("UUID.force-lowercase", false);
|
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||||
PS.get().worlds.set("UUID.offline", true);
|
PlotSquared.get().worlds.set("UUID.offline", true);
|
||||||
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||||
PS.get().worlds.set("UUID.force-lowercase", false);
|
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||||
PS.get().worlds.set("UUID.offline", false);
|
PlotSquared.get().worlds.set("UUID.offline", false);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
MainUtil.sendMessage(player, "Could not save configuration. It will need to be manual set!");
|
MainUtil.sendMessage(player,
|
||||||
|
"Could not save configuration. It will need to be manual set!");
|
||||||
}
|
}
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||||
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
|
||||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
MainUtil.sendMessage(player, "&aConversion complete!");
|
MainUtil.sendMessage(player, "&aConversion complete!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -291,7 +286,8 @@ public class DebugUUID extends SubCommand {
|
|||||||
});
|
});
|
||||||
|
|
||||||
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
MainUtil.sendMessage(player, "&aIt is now safe for players to join");
|
||||||
MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete");
|
MainUtil.sendMessage(player,
|
||||||
|
"&cConversion is still in progress, you will be notified when it is complete");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
@ -1,10 +1,10 @@
|
|||||||
package com.plotsquared.bukkit.database.plotme;
|
package com.github.intellectualsites.plotsquared.bukkit.database.plotme;
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
import com.github.intellectualsites.plotsquared.configuration.file.FileConfiguration;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -13,9 +13,11 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public abstract class APlotMeConnector {
|
public abstract class APlotMeConnector {
|
||||||
|
|
||||||
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder);
|
public abstract Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
|
String dataFolder);
|
||||||
|
|
||||||
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException;
|
public abstract HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
|
throws SQLException;
|
||||||
|
|
||||||
public abstract boolean accepts(String version);
|
public abstract boolean accepts(String version);
|
||||||
|
|
||||||
@ -25,21 +27,23 @@ public abstract class APlotMeConnector {
|
|||||||
|
|
||||||
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
public void copyConfig(FileConfiguration plotConfig, String world, String actualWorldName) {
|
||||||
int pathWidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
int pathWidth = plotConfig.getInt("worlds." + world + ".PathWidth"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.width", pathWidth);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".road.width", pathWidth);
|
||||||
int plotSize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
int plotSize = plotConfig.getInt("worlds." + world + ".PlotSize"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.size", plotSize);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".plot.size", plotSize);
|
||||||
String wallBlock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
String wallBlock = plotConfig.getString("worlds." + world + ".WallBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".wall.block", wallBlock);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".wall.block", wallBlock);
|
||||||
String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
String floor = plotConfig.getString("worlds." + world + ".PlotFloorBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
PlotSquared.get().worlds
|
||||||
|
.set("worlds." + actualWorldName + ".plot.floor", Collections.singletonList(floor));
|
||||||
String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
String filling = plotConfig.getString("worlds." + world + ".PlotFillingBlockId"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
PlotSquared.get().worlds
|
||||||
|
.set("worlds." + actualWorldName + ".plot.filling", Collections.singletonList(filling));
|
||||||
String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
String road = plotConfig.getString("worlds." + world + ".RoadMainBlockId");
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.block", road);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".road.block", road);
|
||||||
int height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
int height = plotConfig.getInt("worlds." + world + ".RoadHeight"); //
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getPlotTopLocAbs(int path, int plot, PlotId plotId) {
|
public Location getPlotTopLocAbs(int path, int plot, PlotId plotId) {
|
||||||
@ -58,7 +62,8 @@ public abstract class APlotMeConnector {
|
|||||||
return new Location(null, x, 1, z);
|
return new Location(null, x, 1, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world, PlotId id, int direction) {
|
public void setMerged(HashMap<String, HashMap<PlotId, boolean[]>> merges, String world,
|
||||||
|
PlotId id, int direction) {
|
||||||
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;
|
@ -1,25 +1,17 @@
|
|||||||
package com.plotsquared.bukkit.database.plotme;
|
package com.github.intellectualsites.plotsquared.bukkit.database.plotme;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.file.FileConfiguration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.SQLite;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
|
||||||
import com.intellectualcrafters.plot.database.SQLite;
|
|
||||||
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.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -29,8 +21,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
private String plugin = "PlotMe";
|
private String plugin = "PlotMe";
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
@Override
|
@Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
String dataFolder) {
|
||||||
this.plugin = plugin.toLowerCase();
|
this.plugin = plugin.toLowerCase();
|
||||||
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
|
this.prefix = plotConfig.getString("mySQLprefix", this.plugin.toLowerCase());
|
||||||
try {
|
try {
|
||||||
@ -40,7 +32,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
String con = plotConfig.getString("mySQLconn");
|
String con = plotConfig.getString("mySQLconn");
|
||||||
return DriverManager.getConnection(con, user, password);
|
return DriverManager.getConnection(con, user, password);
|
||||||
} else {
|
} else {
|
||||||
return new SQLite(new File(dataFolder + File.separator + "plots.db")).openConnection();
|
return new SQLite(new File(dataFolder + File.separator + "plots.db"))
|
||||||
|
.openConnection();
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -48,13 +41,14 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
throws SQLException {
|
||||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||||
HashMap<String, Integer> roadWidth = new HashMap<>();
|
HashMap<String, Integer> roadWidth = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
HashMap<String, HashMap<PlotId, Plot>> plots = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Plots`");
|
PreparedStatement statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.prefix + "Plots`");
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
String column = null;
|
String column = null;
|
||||||
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerid");
|
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerid");
|
||||||
@ -64,7 +58,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
} else if (checkUUID2) {
|
} else if (checkUUID2) {
|
||||||
column = "ownerId";
|
column = "ownerId";
|
||||||
}
|
}
|
||||||
boolean merge = !"plotme".equalsIgnoreCase(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
boolean merge =
|
||||||
|
!"plotme".equalsIgnoreCase(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
||||||
int missing = 0;
|
int missing = 0;
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
PlotId id = new PlotId(resultSet.getInt("idX"), resultSet.getInt("idZ"));
|
||||||
@ -73,8 +68,8 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
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) {
|
||||||
int plot = PS.get().worlds.getInt("worlds." + world + ".plot.size");
|
int plot = PlotSquared.get().worlds.getInt("worlds." + world + ".plot.size");
|
||||||
int path = PS.get().worlds.getInt("worlds." + world + ".road.width");
|
int path = PlotSquared.get().worlds.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[]>());
|
||||||
@ -105,7 +100,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
UUID owner = UUIDHandler.getUUID(name, null);
|
UUID owner = UUIDHandler.getUUID(name, null);
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
if ("*".equals(name)) {
|
if ("*".equals(name)) {
|
||||||
owner = DBFunc.everyone;
|
owner = DBFunc.EVERYONE;
|
||||||
} else {
|
} else {
|
||||||
if (checkUUID || checkUUID2) {
|
if (checkUUID || checkUUID2) {
|
||||||
byte[] bytes = resultSet.getBytes(column);
|
byte[] bytes = resultSet.getBytes(column);
|
||||||
@ -118,11 +113,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
PlotSquared.log(
|
||||||
|
"&cCould not identify owner for plot: " + id + " -> '" + name + "'");
|
||||||
missing++;
|
missing++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
owner = UUID.nameUUIDFromBytes(
|
||||||
|
("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UUIDHandler.add(new StringWrapper(name), owner);
|
UUIDHandler.add(new StringWrapper(name), owner);
|
||||||
@ -131,10 +128,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
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:");
|
PlotSquared.log("&cSome names could not be identified:");
|
||||||
PS.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
PlotSquared
|
||||||
PS.log("&7 - Names you have never seen before could be from people mistyping commands");
|
.log("&7 - Empty quotes mean PlotMe just stored an unowned plot in the database");
|
||||||
PS.log("&7 - Converting from a non-uuid version of PlotMe can't identify owners if the playerdata files are deleted (these plots will "
|
PlotSquared.log(
|
||||||
|
"&7 - Names you have never seen before could be from people mistyping commands");
|
||||||
|
PlotSquared.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)");
|
+ "remain unknown until the player connects)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
PS.log(" - " + this.prefix + "Denied");
|
PlotSquared.log(" - " + this.prefix + "Denied");
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Denied`");
|
statement = connection.prepareStatement("SELECT * FROM `" + this.prefix + "Denied`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
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 if (DBFunc.hasColumn(resultSet, "playerid")) {
|
} else if (DBFunc.hasColumn(resultSet, "playerid")) {
|
||||||
byte[] bytes = resultSet.getBytes("playerid");
|
byte[] bytes = resultSet.getBytes("playerid");
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
@ -177,7 +177,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (denied == null) {
|
if (denied == null) {
|
||||||
PS.log("&6Could not identify denied for plot: " + id);
|
PlotSquared.log("&6Could not identify denied for plot: " + id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
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 if (DBFunc.hasColumn(resultSet, "playerid")) {
|
} else if (DBFunc.hasColumn(resultSet, "playerid")) {
|
||||||
byte[] bytes = resultSet.getBytes("playerid");
|
byte[] bytes = resultSet.getBytes("playerid");
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
@ -212,7 +212,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (helper == null) {
|
if (helper == null) {
|
||||||
PS.log("&6Could not identify helper for plot: " + id);
|
PlotSquared.log("&6Could not identify helper for plot: " + id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,12 +228,13 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
|
|||||||
resultSet.close();
|
resultSet.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
||||||
} catch (SQLException ignored) {}
|
} catch (SQLException ignored) {
|
||||||
|
}
|
||||||
return plots;
|
return plots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean accepts(String version) {
|
||||||
public boolean accepts(String version) {
|
return version == null || PlotSquared.get().canUpdate(version, "0.17.0") || PlotSquared
|
||||||
return version == null || PS.get().canUpdate(version, "0.17.0") || PS.get().canUpdate("0.999.999", version);
|
.get().canUpdate("0.999.999", version);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,22 @@
|
|||||||
package com.plotsquared.bukkit.database.plotme;
|
package com.github.intellectualsites.plotsquared.bukkit.database.plotme;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.MemorySection;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.file.FileConfiguration;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldCreator;
|
||||||
|
import org.bukkit.command.CommandException;
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
|
||||||
import com.intellectualcrafters.configuration.MemorySection;
|
|
||||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
|
||||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
|
||||||
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;
|
||||||
@ -20,17 +25,9 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.command.CommandException;
|
|
||||||
|
|
||||||
public class LikePlotMeConverter {
|
public class LikePlotMeConverter {
|
||||||
|
|
||||||
@ -50,11 +47,13 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(String message) {
|
private void sendMessage(String message) {
|
||||||
PS.debug("&3PlotMe&8->&3" + PS.imp().getPluginName() + "&8: &7" + message);
|
PlotSquared
|
||||||
|
.debug("&3PlotMe&8->&3" + PlotSquared.imp().getPluginName() + "&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlotMePath() {
|
public String getPlotMePath() {
|
||||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator
|
||||||
|
+ plugin + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
public FileConfiguration getPlotMeConfig(String dataFolder) {
|
||||||
@ -71,8 +70,9 @@ public class LikePlotMeConverter {
|
|||||||
|
|
||||||
public void mergeWorldYml(FileConfiguration plotConfig) {
|
public void mergeWorldYml(FileConfiguration plotConfig) {
|
||||||
try {
|
try {
|
||||||
File genConfig =
|
File genConfig = new File(
|
||||||
new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
"plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator"
|
||||||
|
+ File.separator + "config.yml");
|
||||||
if (genConfig.exists()) {
|
if (genConfig.exists()) {
|
||||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
||||||
for (String key : yml.getKeys(true)) {
|
for (String key : yml.getKeys(true)) {
|
||||||
@ -97,40 +97,47 @@ public class LikePlotMeConverter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||||
String pluginName = PS.imp().getPluginName();
|
String pluginName = PlotSquared.imp().getPluginName();
|
||||||
content = content.replace("PlotMe-DefaultGenerator", pluginName);
|
content = content.replace("PlotMe-DefaultGenerator", pluginName);
|
||||||
content = content.replace("PlotMe", pluginName);
|
content = content.replace("PlotMe", pluginName);
|
||||||
content = content.replace("AthionPlots", pluginName);
|
content = content.replace("AthionPlots", pluginName);
|
||||||
content = content.replace("PlotZWorld", pluginName);
|
content = content.replace("PlotZWorld", pluginName);
|
||||||
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
|
Files.write(path, content.getBytes(StandardCharsets.UTF_8));
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyConfig(ConfigurationSection plotmeDgYml, String world) throws IOException {
|
private void copyConfig(ConfigurationSection plotmeDgYml, String world) throws IOException {
|
||||||
String actualWorldName = getWorld(world);
|
String actualWorldName = getWorld(world);
|
||||||
String plotMeWorldName = world.toLowerCase();
|
String plotMeWorldName = world.toLowerCase();
|
||||||
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
Integer pathWidth = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".road.width", pathWidth);
|
PlotSquared.get().worlds.set("worlds." + world + ".road.width", pathWidth);
|
||||||
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight", plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64)); //
|
int height = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".RoadHeight",
|
||||||
PS.get().worlds.set("worlds." + world + ".road.height", height);
|
plotmeDgYml.getInt("worlds." + plotMeWorldName + ".GroundHeight", 64)); //
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.height", height);
|
PlotSquared.get().worlds.set("worlds." + world + ".road.height", height);
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.height", height);
|
PlotSquared.get().worlds.set("worlds." + world + ".wall.height", height);
|
||||||
|
PlotSquared.get().worlds.set("worlds." + world + ".plot.height", height);
|
||||||
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
|
int plotSize = plotmeDgYml.getInt("worlds." + plotMeWorldName + ".PlotSize", 32); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.size", plotSize);
|
PlotSquared.get().worlds.set("worlds." + world + ".plot.size", plotSize);
|
||||||
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".UnclaimedBorder", plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44")); //
|
String wallblock = plotmeDgYml.getString("worlds." + plotMeWorldName + ".UnclaimedBorder",
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.block", wallblock);
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".WallBlock", "44")); //
|
||||||
String claimed = plotmeDgYml.getString("worlds." + plotMeWorldName + ".ProtectedWallBlock", "44:1"); //
|
PlotSquared.get().worlds.set("worlds." + world + ".wall.block", wallblock);
|
||||||
PS.get().worlds.set("worlds." + world + ".wall.block_claimed", claimed);
|
String claimed =
|
||||||
String floor = plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".ProtectedWallBlock", "44:1"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
PlotSquared.get().worlds.set("worlds." + world + ".wall.block_claimed", claimed);
|
||||||
|
String floor =
|
||||||
|
plotmeDgYml.getString("worlds." + plotMeWorldName + ".PlotFloorBlock", "2"); //
|
||||||
|
PlotSquared.get().worlds
|
||||||
|
.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
||||||
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
|
String filling = plotmeDgYml.getString("worlds." + plotMeWorldName + ".FillBlock", "3"); //
|
||||||
PS.get().worlds.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
PlotSquared.get().worlds
|
||||||
|
.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
||||||
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
|
String road = plotmeDgYml.getString("worlds." + plotMeWorldName + ".RoadMainBlock", "5");
|
||||||
PS.get().worlds.set("worlds." + world + ".road.block", road);
|
PlotSquared.get().worlds.set("worlds." + world + ".road.block", road);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".road.height", height);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".plot.height", height);
|
||||||
PS.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
|
PlotSquared.get().worlds.set("worlds." + actualWorldName + ".wall.height", height);
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean run(APlotMeConnector connector) {
|
public boolean run(APlotMeConnector connector) {
|
||||||
@ -149,7 +156,7 @@ public class LikePlotMeConverter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
|
PlotSquared.debug("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||||
|
|
||||||
Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||||
|
|
||||||
@ -158,7 +165,8 @@ public class LikePlotMeConverter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage("PlotMe conversion has started. To disable this, please set 'enabled-components -> plotme-converter' to false in the 'settings.yml'");
|
sendMessage(
|
||||||
|
"PlotMe conversion has started. To disable this, please set 'enabled-components -> plotme-converter' to false in the 'settings.yml'");
|
||||||
|
|
||||||
mergeWorldYml(plotConfig);
|
mergeWorldYml(plotConfig);
|
||||||
|
|
||||||
@ -181,7 +189,7 @@ public class LikePlotMeConverter {
|
|||||||
try {
|
try {
|
||||||
String actualWorldName = getWorld(world);
|
String actualWorldName = getWorld(world);
|
||||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sendMessage("&c-- &lFailed to save configuration for world '" + world
|
sendMessage("&c-- &lFailed to save configuration for world '" + world
|
||||||
@ -201,7 +209,9 @@ public class LikePlotMeConverter {
|
|||||||
sendMessage(" - " + dbPrefix + "Allowed");
|
sendMessage(" - " + dbPrefix + "Allowed");
|
||||||
|
|
||||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||||
File plotmeDgFile = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
File plotmeDgFile = new File(
|
||||||
|
dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator
|
||||||
|
+ "config.yml");
|
||||||
if (plotmeDgFile.exists()) {
|
if (plotmeDgFile.exists()) {
|
||||||
YamlConfiguration plotmeDgYml = YamlConfiguration.loadConfiguration(plotmeDgFile);
|
YamlConfiguration plotmeDgYml = YamlConfiguration.loadConfiguration(plotmeDgFile);
|
||||||
try {
|
try {
|
||||||
@ -216,7 +226,7 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||||
String world = entry.getKey();
|
String world = entry.getKey();
|
||||||
PlotArea area = PS.get().getPlotArea(world, null);
|
PlotArea area = PlotSquared.get().getPlotArea(world, null);
|
||||||
int duplicate = 0;
|
int duplicate = 0;
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
@ -227,12 +237,13 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world
|
PlotSquared.debug("&c[WARNING] Found " + duplicate
|
||||||
|
+ " duplicate plots already in DB for world: '" + world
|
||||||
+ "'. Have you run the converter already?");
|
+ "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (PS.get().plots_tmp != null) {
|
if (PlotSquared.get().plots_tmp != null) {
|
||||||
HashMap<PlotId, Plot> map = PS.get().plots_tmp.get(world);
|
HashMap<PlotId, Plot> map = PlotSquared.get().plots_tmp.get(world);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
if (map.containsKey(entry2.getKey())) {
|
if (map.containsKey(entry2.getKey())) {
|
||||||
@ -242,7 +253,8 @@ public class LikePlotMeConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world
|
PlotSquared.debug("&c[WARNING] Found " + duplicate
|
||||||
|
+ " duplicate plots already in DB for world: '" + world
|
||||||
+ "'. Have you run the converter already?");
|
+ "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -255,80 +267,96 @@ public class LikePlotMeConverter {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
final AtomicBoolean done = new AtomicBoolean(false);
|
final AtomicBoolean done = new AtomicBoolean(false);
|
||||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
if (done.get()) {
|
if (done.get()) {
|
||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PlotSquared.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PlotSquared.debug(
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
"&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
PS.debug("&c - Start the server");
|
PlotSquared.debug(
|
||||||
PS.get().setPlots(DBFunc.getPlots());
|
"&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
|
PlotSquared.debug("&c - Start the server");
|
||||||
|
PlotSquared.get().setPlots(DBFunc.getPlots());
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage(
|
||||||
|
"&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sendMessage("Saving configuration...");
|
sendMessage("Saving configuration...");
|
||||||
try {
|
try {
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
sendMessage(" - &cFailed to save configuration.");
|
sendMessage(" - &cFailed to save configuration.");
|
||||||
}
|
}
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
boolean mv = false;
|
boolean mv = false;
|
||||||
boolean mw = false;
|
boolean mw = false;
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null)
|
||||||
.isEnabled()) {
|
&& Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
mv = true;
|
mv = true;
|
||||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld")
|
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null)
|
||||||
.isEnabled()) {
|
&& Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
mw = true;
|
mw = true;
|
||||||
}
|
}
|
||||||
for (String worldName : worlds) {
|
for (String worldName : worlds) {
|
||||||
World world = Bukkit.getWorld(getWorld(worldName));
|
World world = Bukkit.getWorld(getWorld(worldName));
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldName);
|
sendMessage(
|
||||||
|
"&cInvalid world in PlotMe configuration: " + worldName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String actualWorldName = world.getName();
|
String actualWorldName = world.getName();
|
||||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
sendMessage(
|
||||||
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName().equals(worldName)) {
|
"Reloading generator for world: '" + actualWorldName + "'...");
|
||||||
sendMessage("&cYou need to stop the server to reload this world properly");
|
if (!Bukkit.getWorlds().isEmpty() && Bukkit.getWorlds().get(0).getName()
|
||||||
|
.equals(worldName)) {
|
||||||
|
sendMessage(
|
||||||
|
"&cYou need to stop the server to reload this world properly");
|
||||||
} else {
|
} else {
|
||||||
PS.get().removePlotAreas(actualWorldName);
|
PlotSquared.get().removePlotAreas(actualWorldName);
|
||||||
if (mv) {
|
if (mv) {
|
||||||
// unload world with MV
|
// unload world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MV
|
// load world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
Bukkit.getServer()
|
||||||
"mv import " + actualWorldName + " normal -g " + PS.imp().getPluginName());
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv import " + actualWorldName + " normal -g "
|
||||||
|
+ PlotSquared.imp().getPluginName());
|
||||||
} else if (mw) {
|
} else if (mw) {
|
||||||
// unload world with MW
|
// unload world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MW
|
// load world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
Bukkit.getServer()
|
||||||
"mw create " + actualWorldName + " plugin:" + PS.imp().getPluginName());
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw create " + actualWorldName + " plugin:"
|
||||||
|
+ PlotSquared.imp().getPluginName());
|
||||||
} else {
|
} else {
|
||||||
// Load using Bukkit API
|
// Load using Bukkit API
|
||||||
// - User must set generator manually
|
// - User must set generator manually
|
||||||
Bukkit.getServer().unloadWorld(world, true);
|
Bukkit.getServer().unloadWorld(world, true);
|
||||||
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator())).createWorld();
|
World myWorld = WorldCreator.name(actualWorldName).generator(
|
||||||
|
new BukkitPlotGenerator(
|
||||||
|
PlotSquared.get().IMP.getDefaultGenerator()))
|
||||||
|
.createWorld();
|
||||||
myWorld.save();
|
myWorld.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -339,24 +367,27 @@ public class LikePlotMeConverter {
|
|||||||
if (done.get()) {
|
if (done.get()) {
|
||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PlotSquared.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PlotSquared.debug(
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
"&c - Disable 'plotme-converter' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
PS.debug("&c - Start the server");
|
PlotSquared.debug(
|
||||||
|
"&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
|
PlotSquared.debug("&c - Start the server");
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage(
|
||||||
|
"&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InterruptedException | SQLException e) {
|
} catch (InterruptedException | SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("&/end/");
|
PlotSquared.debug("&/end/");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void done() {
|
public void done() {
|
||||||
PS.get().setPlots(DBFunc.getPlots());
|
PlotSquared.get().setPlots(DBFunc.getPlots());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,23 +1,15 @@
|
|||||||
package com.plotsquared.bukkit.database.plotme;
|
package com.github.intellectualsites.plotsquared.bukkit.database.plotme;
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
import com.github.intellectualsites.plotsquared.configuration.file.FileConfiguration;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.database.SQLite;
|
import com.github.intellectualsites.plotsquared.plot.database.SQLite;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -25,8 +17,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
|
|
||||||
private String plugin;
|
private String plugin;
|
||||||
|
|
||||||
@Override
|
@Override public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig,
|
||||||
public Connection getPlotMeConnection(String plugin, FileConfiguration plotConfig, String dataFolder) {
|
String dataFolder) {
|
||||||
this.plugin = plugin.toLowerCase();
|
this.plugin = plugin.toLowerCase();
|
||||||
try {
|
try {
|
||||||
if (plotConfig.getBoolean("usemySQL")) {
|
if (plotConfig.getBoolean("usemySQL")) {
|
||||||
@ -39,7 +31,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return new SQLite(file).openConnection();
|
return new SQLite(file).openConnection();
|
||||||
}
|
}
|
||||||
return new SQLite(new File(dataFolder + File.separator + "plots.db")).openConnection();
|
return new SQLite(new File(dataFolder + File.separator + "plots.db"))
|
||||||
|
.openConnection();
|
||||||
}
|
}
|
||||||
} catch (SQLException | ClassNotFoundException e) {
|
} catch (SQLException | ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -47,8 +40,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection)
|
||||||
public HashMap<String, HashMap<PlotId, Plot>> getPlotMePlots(Connection connection) throws SQLException {
|
throws SQLException {
|
||||||
ResultSet resultSet;
|
ResultSet resultSet;
|
||||||
PreparedStatement statement;
|
PreparedStatement statement;
|
||||||
HashMap<String, Integer> plotWidth = new HashMap<>();
|
HashMap<String, Integer> plotWidth = new HashMap<>();
|
||||||
@ -56,26 +49,30 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
HashMap<Integer, Plot> plots = new HashMap<>();
|
HashMap<Integer, Plot> plots = new HashMap<>();
|
||||||
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
HashMap<String, HashMap<PlotId, boolean[]>> merges = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_plots`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_plots`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
PS.debug("========= Table does not exist =========");
|
PlotSquared.debug("========= Table does not exist =========");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("=======================================");
|
PlotSquared.debug("=======================================");
|
||||||
PS.debug("&8 - &7The database does not match the version specified in the PlotMe config");
|
PlotSquared.debug(
|
||||||
PS.debug("&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3");
|
"&8 - &7The database does not match the version specified in the PlotMe config");
|
||||||
|
PlotSquared.debug(
|
||||||
|
"&8 - &7Please correct this, or if you are unsure, the most common is 0.16.3");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerID");
|
boolean checkUUID = DBFunc.hasColumn(resultSet, "ownerID");
|
||||||
boolean merge = !"plotme".equals(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
boolean merge =
|
||||||
|
!"plotme".equals(this.plugin) && Settings.Enabled_Components.PLOTME_CONVERTER;
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
int key = resultSet.getInt("plot_id");
|
int key = resultSet.getInt("plot_id");
|
||||||
PlotId id = new PlotId(resultSet.getInt("plotX"), resultSet.getInt("plotZ"));
|
PlotId id = new PlotId(resultSet.getInt("plotX"), resultSet.getInt("plotZ"));
|
||||||
String name = resultSet.getString("owner");
|
String name = resultSet.getString("owner");
|
||||||
String world = LikePlotMeConverter.getWorld(resultSet.getString("world"));
|
String world = LikePlotMeConverter.getWorld(resultSet.getString("world"));
|
||||||
if (!plots.containsKey(world) && merge) {
|
if (!plots.containsKey(world) && merge) {
|
||||||
int plot = PS.get().worlds.getInt("worlds." + world + ".plot.size");
|
int plot = PlotSquared.get().worlds.getInt("worlds." + world + ".plot.size");
|
||||||
int path = PS.get().worlds.getInt("worlds." + world + ".road.width");
|
int path = PlotSquared.get().worlds.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[]>());
|
||||||
@ -105,7 +102,7 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
UUID owner = UUIDHandler.getUUID(name, null);
|
UUID owner = UUIDHandler.getUUID(name, null);
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
if (name.equals("*")) {
|
if (name.equals("*")) {
|
||||||
owner = DBFunc.everyone;
|
owner = DBFunc.EVERYONE;
|
||||||
} else {
|
} else {
|
||||||
if (checkUUID) {
|
if (checkUUID) {
|
||||||
byte[] bytes = resultSet.getBytes("ownerid");
|
byte[] bytes = resultSet.getBytes("ownerid");
|
||||||
@ -115,7 +112,8 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + '\'');
|
PlotSquared.log(
|
||||||
|
"&cCould not identify owner for plot: " + id + " -> '" + name + '\'');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,35 +134,39 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
resultSet.close();
|
resultSet.close();
|
||||||
statement.close();
|
statement.close();
|
||||||
try {
|
try {
|
||||||
PS.log(" - " + this.plugin + "core_denied");
|
PlotSquared.log(" - " + this.plugin + "core_denied");
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_denied`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_denied`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
int key = resultSet.getInt("plot_id");
|
int key = resultSet.getInt("plot_id");
|
||||||
Plot plot = plots.get(key);
|
Plot plot = plots.get(key);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PS.log("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
PlotSquared
|
||||||
|
.log("&6Denied (" + key + ") references deleted plot; ignoring entry.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String player = resultSet.getString("player");
|
String player = resultSet.getString("player");
|
||||||
UUID denied = player.equals("*") ? DBFunc.everyone : UUID.fromString(player);
|
UUID denied = player.equals("*") ? DBFunc.EVERYONE : UUID.fromString(player);
|
||||||
plot.getDenied().add(denied);
|
plot.getDenied().add(denied);
|
||||||
}
|
}
|
||||||
|
|
||||||
PS.log(" - " + this.plugin + "core_allowed");
|
PlotSquared.log(" - " + this.plugin + "core_allowed");
|
||||||
statement = connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_allowed`");
|
statement =
|
||||||
|
connection.prepareStatement("SELECT * FROM `" + this.plugin + "core_allowed`");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next()) {
|
while (resultSet.next()) {
|
||||||
int key = resultSet.getInt("plot_id");
|
int key = resultSet.getInt("plot_id");
|
||||||
Plot plot = plots.get(key);
|
Plot plot = plots.get(key);
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
PS.log("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
PlotSquared
|
||||||
|
.log("&6Allowed (" + key + ") references deleted plot; ignoring entry.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String player = resultSet.getString("player");
|
String player = resultSet.getString("player");
|
||||||
UUID allowed = player.equals("*") ? DBFunc.everyone : UUID.fromString(player);
|
UUID allowed = player.equals("*") ? DBFunc.EVERYONE : UUID.fromString(player);
|
||||||
plot.getTrusted().add(allowed);
|
plot.getTrusted().add(allowed);
|
||||||
}
|
}
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
@ -186,11 +188,10 @@ public class PlotMeConnector_017 extends APlotMeConnector {
|
|||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean accepts(String version) {
|
||||||
public boolean accepts(String version) {
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !PS.get().canUpdate(version, "0.17");
|
return !PlotSquared.get().canUpdate(version, "0.17");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -49,18 +49,15 @@ public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -45,18 +45,15 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -34,8 +34,7 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -38,8 +38,7 @@ public class PlayerLeavePlotEvent extends PlayerEvent {
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -59,8 +59,7 @@ public class PlayerPlotDeniedEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -63,8 +63,7 @@ public class PlayerPlotHelperEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -63,8 +63,7 @@ public class PlayerPlotTrustedEvent extends PlotEvent {
|
|||||||
return this.initiator;
|
return this.initiator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -9,9 +9,6 @@ import org.bukkit.event.player.PlayerEvent;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
|
|
||||||
@ -37,8 +34,7 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
|||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +56,11 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
|
|||||||
return this.plot;
|
return this.plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean cancelled) {
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
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;
|
||||||
@ -24,7 +24,8 @@ public class PlotChangeOwnerEvent extends PlotEvent implements Cancellable {
|
|||||||
* @param oldOwner The old owner of the plot
|
* @param oldOwner The old owner of the plot
|
||||||
* @param plot The plot having its owner changed
|
* @param plot The plot having its owner changed
|
||||||
*/
|
*/
|
||||||
public PlotChangeOwnerEvent(Player initiator, Plot plot, UUID oldOwner, UUID newOwner, boolean hasOldOwner) {
|
public PlotChangeOwnerEvent(Player initiator, Plot plot, UUID oldOwner, UUID newOwner,
|
||||||
|
boolean hasOldOwner) {
|
||||||
super(plot);
|
super(plot);
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
this.newOwner = newOwner;
|
this.newOwner = newOwner;
|
||||||
@ -90,18 +91,15 @@ public class PlotChangeOwnerEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.hasOldOwner;
|
return this.hasOldOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public PlotClearEvent(Plot plot) {
|
public PlotClearEvent(Plot plot) {
|
||||||
super(plot);
|
super(plot);
|
||||||
}
|
}
|
||||||
@ -39,18 +39,15 @@ public class PlotClearEvent extends PlotEvent implements Cancellable {
|
|||||||
return getPlot().getWorldName();
|
return getPlot().getWorldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a plot component is set
|
* Called when a plot component is set
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PlotComponentSetEvent extends PlotEvent {
|
public class PlotComponentSetEvent extends PlotEvent {
|
||||||
|
|
||||||
@ -49,8 +48,7 @@ public class PlotComponentSetEvent extends PlotEvent {
|
|||||||
return this.component;
|
return this.component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
import org.bukkit.event.HandlerList;
|
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 {
|
||||||
|
|
||||||
@ -38,8 +37,7 @@ public class PlotDeleteEvent extends PlotEvent {
|
|||||||
return getPlot().getWorldName();
|
return getPlot().getWorldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
public abstract class PlotEvent extends Event {
|
public abstract class PlotEvent extends Event {
|
@ -1,13 +1,12 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
|
|
||||||
@ -39,18 +38,15 @@ public class PlotFlagAddEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setCancelled(boolean cancelled) {
|
||||||
public final void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,12 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
|
|
||||||
@ -39,18 +38,15 @@ public class PlotFlagRemoveEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setCancelled(boolean cancelled) {
|
||||||
public final void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.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.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
@ -45,18 +45,15 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.Rating;
|
import com.github.intellectualsites.plotsquared.plot.object.Rating;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@ -35,18 +35,15 @@ public class PlotRateEvent extends PlotEvent implements Cancellable {
|
|||||||
this.rating = rating;
|
this.rating = rating;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public HandlerList getHandlers() {
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isCancelled() {
|
||||||
public boolean isCancelled() {
|
|
||||||
return this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean cancelled) {
|
||||||
public void setCancelled(boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package com.plotsquared.bukkit.events;
|
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.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;
|
||||||
@ -50,18 +50,15 @@ public class PlotUnlinkEvent extends Event implements Cancellable {
|
|||||||
return this.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 this.cancelled;
|
return this.cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCancelled(boolean b) {
|
||||||
public void setCancelled(boolean b) {
|
|
||||||
this.cancelled = b;
|
this.cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.generator;
|
package com.github.intellectualsites.plotsquared.bukkit.generator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
import com.github.intellectualsites.plotsquared.plot.generator.AugmentedUtils;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
@ -24,8 +24,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
|||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void populate(World world, Random r, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,45 +1,36 @@
|
|||||||
package com.plotsquared.bukkit.generator;
|
package com.github.intellectualsites.plotsquared.bukkit.generator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.github.intellectualsites.plotsquared.bukkit.util.block.GenChunk;
|
||||||
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.object.ChunkWrapper;
|
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator;
|
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
|
||||||
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
|
||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import com.plotsquared.bukkit.util.block.GenChunk;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper<ChunkGenerator> {
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BukkitPlotGenerator extends ChunkGenerator
|
||||||
|
implements GeneratorWrapper<ChunkGenerator> {
|
||||||
|
|
||||||
private final GenChunk chunkSetter;
|
private final GenChunk chunkSetter;
|
||||||
private final PseudoRandom random = new PseudoRandom();
|
private final PseudoRandom random = new PseudoRandom();
|
||||||
private final IndependentPlotGenerator plotGenerator;
|
private final IndependentPlotGenerator plotGenerator;
|
||||||
private List<BlockPopulator> populators;
|
|
||||||
private final ChunkGenerator platformGenerator;
|
private final ChunkGenerator platformGenerator;
|
||||||
private final boolean full;
|
private final boolean full;
|
||||||
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
|
private final HashMap<ChunkLoc, byte[][]> dataMap = new HashMap<>();
|
||||||
|
private List<BlockPopulator> populators;
|
||||||
private boolean loaded = false;
|
private boolean loaded = false;
|
||||||
|
|
||||||
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
public BukkitPlotGenerator(IndependentPlotGenerator generator) {
|
||||||
@ -53,12 +44,12 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
private LocalBlockQueue queue;
|
private LocalBlockQueue queue;
|
||||||
|
|
||||||
@Override
|
@Override public void populate(World world, Random r, Chunk c) {
|
||||||
public void populate(World world, Random r, Chunk c) {
|
|
||||||
if (queue == null) {
|
if (queue == null) {
|
||||||
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
||||||
}
|
}
|
||||||
byte[][] resultData = dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
|
byte[][] resultData =
|
||||||
|
dataMap.isEmpty() ? null : dataMap.remove(new ChunkLoc(c.getX(), c.getZ()));
|
||||||
if (resultData == null) {
|
if (resultData == null) {
|
||||||
GenChunk result = BukkitPlotGenerator.this.chunkSetter;
|
GenChunk result = BukkitPlotGenerator.this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
@ -87,10 +78,11 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BukkitPlotGenerator.this.random.state = c.getX() << 16 | c.getZ() & 0xFFFF;
|
BukkitPlotGenerator.this.random.state = c.getX() << 16 | c.getZ() & 0xFFFF;
|
||||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||||
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
|
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
|
||||||
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
|
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
|
||||||
if (BukkitPlotGenerator.this.plotGenerator.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) {
|
if (BukkitPlotGenerator.this.plotGenerator
|
||||||
|
.populateChunk(chunk, area, BukkitPlotGenerator.this.random)) {
|
||||||
queue.flush();
|
queue.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,48 +94,47 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
|
||||||
if (cg instanceof BukkitPlotGenerator) {
|
if (cg instanceof BukkitPlotGenerator) {
|
||||||
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!");
|
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
|
||||||
|
+ " is already a BukkitPlotGenerator!");
|
||||||
}
|
}
|
||||||
this.full = false;
|
this.full = false;
|
||||||
PS.debug("BukkitPlotGenerator does not fully support: " + cg);
|
PlotSquared.debug("BukkitPlotGenerator does not fully support: " + cg);
|
||||||
this.platformGenerator = cg;
|
this.platformGenerator = cg;
|
||||||
this.plotGenerator = new IndependentPlotGenerator() {
|
this.plotGenerator = new IndependentPlotGenerator() {
|
||||||
@Override
|
@Override public void processSetup(SetupObject setup) {
|
||||||
public void processSetup(SetupObject setup) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(PlotArea area) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlotManager getNewPlotManager() {
|
|
||||||
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void initialize(PlotArea area) {
|
||||||
public String getName() {
|
}
|
||||||
|
|
||||||
|
@Override public PlotManager getNewPlotManager() {
|
||||||
|
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getName() {
|
||||||
return cg.getClass().getName();
|
return cg.getClass().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||||
return PS.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
|
return PlotSquared.get().IMP.getDefaultGenerator()
|
||||||
|
.getNewPlotArea(world, id, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) {
|
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings,
|
||||||
|
PseudoRandom random) {
|
||||||
World w = BukkitUtil.getWorld(world);
|
World w = BukkitUtil.getWorld(world);
|
||||||
Location min = result.getMin();
|
Location min = result.getMin();
|
||||||
int cx = min.getX() >> 4;
|
int cx = min.getX() >> 4;
|
||||||
int cz = min.getZ() >> 4;
|
int cz = min.getZ() >> 4;
|
||||||
Random r = new Random(MathMan.pair((short) cx, (short) cz));
|
Random r = new Random(MathMan.pair((short) cx, (short) cz));
|
||||||
BiomeGrid grid = new BiomeGrid() {
|
BiomeGrid grid = new BiomeGrid() {
|
||||||
@Override
|
@Override public void setBiome(int x, int z, Biome biome) {
|
||||||
public void setBiome(int x, int z, Biome biome) {
|
|
||||||
result.setBiome(x, z, biome.name());
|
result.setBiome(x, z, biome.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Biome getBiome(int arg0, int arg1) {
|
||||||
public Biome getBiome(int arg0, int arg1) {
|
|
||||||
return Biome.FOREST;
|
return Biome.FOREST;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -153,7 +144,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
if (data != null) {
|
if (data != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {}
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
// Populator spillage
|
// Populator spillage
|
||||||
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
|
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
@ -188,33 +180,28 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void augment(PlotArea area) {
|
||||||
public void augment(PlotArea area) {
|
|
||||||
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.worldname));
|
BukkitAugmentedGenerator.get(BukkitUtil.getWorld(area.worldname));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isFull() {
|
||||||
public boolean isFull() {
|
|
||||||
return this.full;
|
return this.full;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public IndependentPlotGenerator getPlotGenerator() {
|
||||||
public IndependentPlotGenerator getPlotGenerator() {
|
|
||||||
return this.plotGenerator;
|
return this.plotGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public ChunkGenerator getPlatformGenerator() {
|
||||||
public ChunkGenerator getPlatformGenerator() {
|
|
||||||
return this.platformGenerator;
|
return this.platformGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
|
||||||
try {
|
try {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
PS.get().loadWorld(name, this);
|
PlotSquared.get().loadWorld(name, this);
|
||||||
Set<PlotArea> areas = PS.get().getPlotAreas(name);
|
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(name);
|
||||||
if (!areas.isEmpty()) {
|
if (!areas.isEmpty()) {
|
||||||
PlotArea area = areas.iterator().next();
|
PlotArea area = areas.iterator().next();
|
||||||
if (!area.MOB_SPAWNING) {
|
if (!area.MOB_SPAWNING) {
|
||||||
@ -290,7 +277,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
// Load if improperly loaded
|
// Load if improperly loaded
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
PS.get().loadWorld(name, this);
|
PlotSquared.get().loadWorld(name, this);
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
// Set random seed
|
// Set random seed
|
||||||
@ -299,7 +286,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
if (ChunkManager.preProcessChunk(result)) {
|
if (ChunkManager.preProcessChunk(result)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlotArea area = PS.get().getPlotArea(world.getName(), null);
|
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||||
try {
|
try {
|
||||||
this.plotGenerator.generateChunk(this.chunkSetter, area, this.random);
|
this.plotGenerator.generateChunk(this.chunkSetter, area, this.random);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@ -309,8 +296,8 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
ChunkManager.postProcessChunk(result);
|
ChunkManager.postProcessChunk(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz,
|
||||||
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid grid) {
|
BiomeGrid grid) {
|
||||||
GenChunk result = this.chunkSetter;
|
GenChunk result = this.chunkSetter;
|
||||||
// Set the chunk location
|
// Set the chunk location
|
||||||
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
|
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
|
||||||
@ -342,18 +329,17 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow spawning everywhere.
|
* Allow spawning everywhere.
|
||||||
|
*
|
||||||
* @param world Ignored
|
* @param world Ignored
|
||||||
* @param x Ignored
|
* @param x Ignored
|
||||||
* @param z Ignored
|
* @param z Ignored
|
||||||
* @return always true
|
* @return always true
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public boolean canSpawn(World world, int x, int z) {
|
||||||
public boolean canSpawn(World world, int x, int z) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String toString() {
|
||||||
public String toString() {
|
|
||||||
if (this.platformGenerator == this) {
|
if (this.platformGenerator == this) {
|
||||||
return this.plotGenerator.getName();
|
return this.plotGenerator.getName();
|
||||||
}
|
}
|
||||||
@ -364,8 +350,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean equals(Object obj) {
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
@ -1,16 +1,14 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefClass;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -29,14 +27,17 @@ import org.bukkit.event.entity.ItemSpawnEvent;
|
|||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
public class ChunkListener implements Listener {
|
@SuppressWarnings("unused") public class ChunkListener implements Listener {
|
||||||
|
|
||||||
private RefMethod methodGetHandleChunk;
|
private RefMethod methodGetHandleChunk;
|
||||||
private RefField mustSave;
|
private RefField mustSave;
|
||||||
private Chunk lastChunk;
|
private Chunk lastChunk;
|
||||||
|
private boolean ignoreUnload = false;
|
||||||
|
|
||||||
public ChunkListener() {
|
public ChunkListener() {
|
||||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||||
@ -46,7 +47,8 @@ public class ChunkListener implements Listener {
|
|||||||
this.mustSave = classChunk.getField("mustSave");
|
this.mustSave = classChunk.getField("mustSave");
|
||||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
PS.debug(PS.imp().getPluginName() + "/Server not compatible for chunk processor trim/gc");
|
PlotSquared.debug(PlotSquared.imp().getPluginName()
|
||||||
|
+ "/Server not compatible for chunk processor trim/gc");
|
||||||
Settings.Chunk_Processor.AUTO_TRIM = false;
|
Settings.Chunk_Processor.AUTO_TRIM = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,21 +59,23 @@ public class ChunkListener implements Listener {
|
|||||||
world.setAutoSave(false);
|
world.setAutoSave(false);
|
||||||
}
|
}
|
||||||
TaskManager.runTaskRepeat(new Runnable() {
|
TaskManager.runTaskRepeat(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
HashSet<Chunk> toUnload = new HashSet<>();
|
HashSet<Chunk> toUnload = new HashSet<>();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
String worldName = world.getName();
|
String worldName = world.getName();
|
||||||
if (!PS.get().hasPlotArea(worldName)) {
|
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||||
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
Object chunkMap =
|
||||||
Method methodIsChunkInUse = chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||||
|
Method methodIsChunkInUse = chunkMap.getClass()
|
||||||
|
.getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||||
Chunk[] chunks = world.getLoadedChunks();
|
Chunk[] chunks = world.getLoadedChunks();
|
||||||
for (Chunk chunk : chunks) {
|
for (Chunk chunk : chunks) {
|
||||||
if ((boolean) methodIsChunkInUse.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
if ((boolean) methodIsChunkInUse
|
||||||
|
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int x = chunk.getX();
|
int x = chunk.getX();
|
||||||
@ -100,8 +104,6 @@ public class ChunkListener implements Listener {
|
|||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ignoreUnload = false;
|
|
||||||
|
|
||||||
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
|
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
|
||||||
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
|
if (safe && shouldSave(world, chunk.getX(), chunk.getZ())) {
|
||||||
return false;
|
return false;
|
||||||
@ -144,15 +146,14 @@ public class ChunkListener implements Listener {
|
|||||||
return plot != null && plot.hasOwner();
|
return plot != null && plot.hasOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onChunkUnload(ChunkUnloadEvent event) {
|
||||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
|
||||||
if (ignoreUnload) {
|
if (ignoreUnload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||||
Chunk chunk = event.getChunk();
|
Chunk chunk = event.getChunk();
|
||||||
String world = chunk.getWorld().getName();
|
String world = chunk.getWorld().getName();
|
||||||
if (PS.get().hasPlotArea(world)) {
|
if (PlotSquared.get().hasPlotArea(world)) {
|
||||||
if (unloadChunk(world, chunk, true)) {
|
if (unloadChunk(world, chunk, true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,13 +164,11 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onChunkLoad(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(ItemSpawnEvent event) {
|
||||||
public void onItemSpawn(ItemSpawnEvent event) {
|
|
||||||
Item entity = event.getEntity();
|
Item entity = event.getEntity();
|
||||||
Chunk chunk = entity.getLocation().getChunk();
|
Chunk chunk = entity.getLocation().getChunk();
|
||||||
if (chunk == this.lastChunk) {
|
if (chunk == this.lastChunk) {
|
||||||
@ -177,7 +176,7 @@ public class ChunkListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
@ -206,7 +205,7 @@ public class ChunkListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
@ -223,12 +222,12 @@ public class ChunkListener implements Listener {
|
|||||||
TaskManager.index.incrementAndGet();
|
TaskManager.index.incrementAndGet();
|
||||||
final Integer currentIndex = TaskManager.index.get();
|
final Integer currentIndex = TaskManager.index.get();
|
||||||
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()) {
|
||||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||||
TaskManager.tasks.remove(currentIndex);
|
TaskManager.tasks.remove(currentIndex);
|
||||||
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
PlotSquared
|
||||||
|
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -236,7 +235,8 @@ public class ChunkListener implements Listener {
|
|||||||
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);
|
||||||
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
PlotSquared
|
||||||
|
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -246,7 +246,8 @@ public class ChunkListener implements Listener {
|
|||||||
if (i >= tiles.length) {
|
if (i >= tiles.length) {
|
||||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||||
TaskManager.tasks.remove(currentIndex);
|
TaskManager.tasks.remove(currentIndex);
|
||||||
PS.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
PlotSquared
|
||||||
|
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||||
chunk.unload(true, true);
|
chunk.unload(true, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -259,7 +260,7 @@ public class ChunkListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean processChunk(Chunk chunk, boolean unload) {
|
public boolean processChunk(Chunk chunk, boolean unload) {
|
||||||
if (!PS.get().hasPlotArea(chunk.getWorld().getName())) {
|
if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Entity[] entities = chunk.getEntities();
|
Entity[] entities = chunk.getEntities();
|
||||||
@ -270,11 +271,15 @@ public class ChunkListener implements Listener {
|
|||||||
ent.remove();
|
ent.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PS.debug(C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
PlotSquared.debug(
|
||||||
|
C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4)
|
||||||
|
+ "," + (chunk.getX() << 4));
|
||||||
}
|
}
|
||||||
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
||||||
if (unload) {
|
if (unload) {
|
||||||
PS.debug(C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4));
|
PlotSquared.debug(
|
||||||
|
C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
|
||||||
|
chunk.getX() << 4));
|
||||||
cleanChunk(chunk);
|
cleanChunk(chunk);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
@ -0,0 +1,142 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Vehicle;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||||
|
import org.bukkit.event.vehicle.*;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.metadata.MetadataValue;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
|
||||||
|
|
||||||
|
private static boolean ignoreTP = false;
|
||||||
|
|
||||||
|
public static void test(Entity entity) {
|
||||||
|
List<MetadataValue> meta = entity.getMetadata("plotworld");
|
||||||
|
World world = entity.getLocation().getWorld();
|
||||||
|
if (meta == null || meta.isEmpty()) {
|
||||||
|
if (PlotSquared.get().hasPlotArea(world.getName())) {
|
||||||
|
entity.setMetadata("plotworld",
|
||||||
|
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
|
||||||
|
World originWorld = origin.getWorld();
|
||||||
|
if (!originWorld.equals(world)) {
|
||||||
|
if (!ignoreTP) {
|
||||||
|
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
|
||||||
|
try {
|
||||||
|
ignoreTP = true;
|
||||||
|
entity.teleport(origin);
|
||||||
|
} finally {
|
||||||
|
ignoreTP = false;
|
||||||
|
}
|
||||||
|
if (entity.getLocation().getWorld().equals(world)) {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
||||||
|
Entity entity = event.getEntity();
|
||||||
|
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||||
|
PlotArea area = location.getPlotArea();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Plot plot = area.getOwnedPlotAbs(location);
|
||||||
|
if (plot == null) {
|
||||||
|
if (!area.MOB_SPAWNING) {
|
||||||
|
EntityType type = entity.getType();
|
||||||
|
switch (type) {
|
||||||
|
case DROPPED_ITEM:
|
||||||
|
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PLAYER:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type.isAlive() || !area.MISC_SPAWN_UNOWNED) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
switch (entity.getType()) {
|
||||||
|
case ENDER_CRYSTAL:
|
||||||
|
if (PlayerEvents.checkEntity(entity, plot)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
case SHULKER:
|
||||||
|
if (!entity.hasMetadata("plot")) {
|
||||||
|
entity.setMetadata("plot",
|
||||||
|
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleUpdateEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleDestroyEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleEntityCollisionEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleCreateEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onTeleport(EntityTeleportEvent event) {
|
||||||
|
Entity ent = event.getEntity();
|
||||||
|
if (ent instanceof Vehicle || ent instanceof ArmorStand)
|
||||||
|
test(event.getEntity());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
|
||||||
|
test(event.getVehicle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler public void spawn(CreatureSpawnEvent event) {
|
||||||
|
switch (event.getEntityType()) {
|
||||||
|
case ARMOR_STAND:
|
||||||
|
test(event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,30 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class ForceFieldListener {
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused") public class ForceFieldListener {
|
||||||
|
|
||||||
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
private static Set<PlotPlayer> getNearbyPlayers(Player player, Plot plot) {
|
||||||
Set<PlotPlayer> players = new HashSet<>();
|
Set<PlotPlayer> players = new HashSet<>();
|
||||||
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
|
for (Player nearPlayer : Iterables
|
||||||
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
|
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||||
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!plot.isAdded(plotPlayer.getUUID())) {
|
if (!plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -32,9 +35,11 @@ public class ForceFieldListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
private static PlotPlayer hasNearbyPermitted(Player player, Plot plot) {
|
||||||
for (Player nearPlayer : Iterables.filter(player.getNearbyEntities(5d, 5d, 5d),Player.class)) {
|
for (Player nearPlayer : Iterables
|
||||||
|
.filter(player.getNearbyEntities(5d, 5d, 5d), Player.class)) {
|
||||||
PlotPlayer plotPlayer;
|
PlotPlayer plotPlayer;
|
||||||
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot.equals(plotPlayer.getCurrentPlot())) {
|
if ((plotPlayer = BukkitUtil.getPlayer(nearPlayer)) == null || !plot
|
||||||
|
.equals(plotPlayer.getCurrentPlot())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (plot.isAdded(plotPlayer.getUUID())) {
|
if (plot.isAdded(plotPlayer.getUUID())) {
|
||||||
@ -81,7 +86,8 @@ public class ForceFieldListener {
|
|||||||
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||||
for (PlotPlayer oPlayer : players) {
|
for (PlotPlayer oPlayer : players) {
|
||||||
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||||
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
((BukkitPlayer) oPlayer).player
|
||||||
|
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,18 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
|
||||||
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import com.plotsquared.listener.PlotListener;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -23,22 +20,28 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockDamageEvent;
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class PlotPlusListener extends PlotListener implements Listener {
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
|
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
|
||||||
private static final HashMap<String, Interval> healRunnable = new HashMap<>();
|
|
||||||
|
private static final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
|
||||||
|
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
|
||||||
|
|
||||||
public static void startRunnable(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 (Iterator<Entry<String, Interval>> iterator = healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||||
Entry<String, Interval> entry = iterator.next();
|
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||||
|
Entry<UUID, Interval> entry = iterator.next();
|
||||||
Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
@ -56,8 +59,9 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!feedRunnable.isEmpty()) {
|
if (!feedRunnable.isEmpty()) {
|
||||||
for (Iterator<Entry<String, Interval>> iterator = feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||||
Entry<String, Interval> entry = iterator.next();
|
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||||
|
Entry<UUID, Interval> entry = iterator.next();
|
||||||
Interval value = entry.getValue();
|
Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
@ -78,8 +82,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}, 0L, 20L);
|
}, 0L, 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH) public void onInteract(BlockDamageEvent event) {
|
||||||
public void onInteract(BlockDamageEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||||
return;
|
return;
|
||||||
@ -98,8 +101,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||||
public void onDamage(EntityDamageEvent event) {
|
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,8 +115,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
||||||
public void onItemDrop(PlayerDropItemEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
@ -129,41 +130,52 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||||
public void onPlotEnter(PlayerEnterPlotEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
||||||
if (feed.isPresent()) {
|
if (feed.isPresent()) {
|
||||||
Integer[] value = feed.get();
|
Integer[] value = feed.get();
|
||||||
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
|
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
|
||||||
if (heal.isPresent()) {
|
if (heal.isPresent()) {
|
||||||
Integer[] value = heal.get();
|
Integer[] value = heal.get();
|
||||||
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String name = player.getName();
|
feedRunnable.remove(player.getUniqueId());
|
||||||
feedRunnable.remove(name);
|
healRunnable.remove(player.getUniqueId());
|
||||||
healRunnable.remove(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
|
||||||
public void onPlotLeave(PlayerLeavePlotEvent event) {
|
|
||||||
Player leaver = event.getPlayer();
|
Player leaver = event.getPlayer();
|
||||||
Plot plot = event.getPlot();
|
Plot plot = event.getPlot();
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BukkitUtil.getPlayer(leaver);
|
BukkitUtil.getPlayer(leaver);
|
||||||
String name = leaver.getName();
|
feedRunnable.remove(leaver.getUniqueId());
|
||||||
feedRunnable.remove(name);
|
healRunnable.remove(leaver.getUniqueId());
|
||||||
healRunnable.remove(name);
|
}
|
||||||
|
|
||||||
|
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
||||||
|
LivingEntity ent = event.getEntity();
|
||||||
|
if (ent instanceof Player) {
|
||||||
|
Player player = (Player) ent;
|
||||||
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
|
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
|
if (plot == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UUID uuid = pp.getUUID();
|
||||||
|
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Interval {
|
private static class Interval {
|
@ -1,11 +1,9 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -16,10 +14,12 @@ import org.bukkit.event.world.ChunkEvent;
|
|||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
public class SingleWorldListener implements Listener {
|
@SuppressWarnings("unused") public class SingleWorldListener implements Listener {
|
||||||
|
|
||||||
private Method methodGetHandleChunk;
|
private Method methodGetHandleChunk;
|
||||||
private Field mustSave, done, lit, s;
|
private Field mustSave, done, lit, s;
|
||||||
@ -42,10 +42,14 @@ public class SingleWorldListener implements Listener {
|
|||||||
public void markChunkAsClean(Chunk chunk) {
|
public void markChunkAsClean(Chunk chunk) {
|
||||||
try {
|
try {
|
||||||
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
||||||
if (done != null) this.done.set(nmsChunk, true);
|
if (done != null)
|
||||||
if (mustSave != null) this.mustSave.set(nmsChunk, false);
|
this.done.set(nmsChunk, true);
|
||||||
if (lit != null) this.lit.set(nmsChunk, false);
|
if (mustSave != null)
|
||||||
if (s != null) this.s.set(nmsChunk, false);
|
this.mustSave.set(nmsChunk, false);
|
||||||
|
if (lit != null)
|
||||||
|
this.lit.set(nmsChunk, false);
|
||||||
|
if (s != null)
|
||||||
|
this.s.set(nmsChunk, false);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -54,9 +58,11 @@ public class SingleWorldListener implements Listener {
|
|||||||
private void handle(ChunkEvent event) {
|
private void handle(ChunkEvent event) {
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
PlotAreaManager man = PS.get().getPlotAreaManager();
|
PlotAreaManager man = PlotSquared.get().getPlotAreaManager();
|
||||||
if (!(man instanceof SinglePlotAreaManager)) return;
|
if (!(man instanceof SinglePlotAreaManager))
|
||||||
if (!isPlotId(name)) return;
|
return;
|
||||||
|
if (!isPlotId(name))
|
||||||
|
return;
|
||||||
|
|
||||||
markChunkAsClean(event.getChunk());
|
markChunkAsClean(event.getChunk());
|
||||||
}
|
}
|
||||||
@ -66,8 +72,7 @@ public class SingleWorldListener implements Listener {
|
|||||||
// handle(event);
|
// handle(event);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST) public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
|
||||||
handle(event);
|
handle(event);
|
||||||
}
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.worlds.PlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
|
||||||
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;
|
||||||
@ -12,13 +12,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;
|
||||||
|
|
||||||
public class WorldEvents implements Listener {
|
@SuppressWarnings("unused") public class WorldEvents implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onWorldInit(WorldInitEvent event) {
|
public void onWorldInit(WorldInitEvent event) {
|
||||||
World world = event.getWorld();
|
World world = event.getWorld();
|
||||||
String name = world.getName();
|
String name = world.getName();
|
||||||
PlotAreaManager manager = PS.get().getPlotAreaManager();
|
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||||
if (manager instanceof SinglePlotAreaManager) {
|
if (manager instanceof SinglePlotAreaManager) {
|
||||||
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
|
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
|
||||||
if (single.isWorld(name)) {
|
if (single.isWorld(name)) {
|
||||||
@ -28,9 +28,9 @@ public class WorldEvents implements Listener {
|
|||||||
}
|
}
|
||||||
ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen instanceof GeneratorWrapper) {
|
if (gen instanceof GeneratorWrapper) {
|
||||||
PS.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||||
} else {
|
} else {
|
||||||
PS.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.object;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.LazyBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
public class BukkitLazyBlock extends LazyBlock {
|
||||||
|
|
||||||
|
private StringPlotBlock pb;
|
||||||
|
|
||||||
|
public BukkitLazyBlock(Block block) {
|
||||||
|
this.pb = (StringPlotBlock) PlotBlock.get(block.getType().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BukkitLazyBlock(StringPlotBlock pb) {
|
||||||
|
this.pb = pb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringPlotBlock getPlotBlock() {
|
||||||
|
return this.pb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.object;
|
package com.github.intellectualsites.plotsquared.bukkit.object;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -19,23 +19,19 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
|||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID() {
|
||||||
public UUID getUUID() {
|
|
||||||
return this.player.getUniqueId();
|
return this.player.getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public long getLastPlayed() {
|
||||||
public long getLastPlayed() {
|
|
||||||
return this.player.getLastPlayed();
|
return this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOnline() {
|
||||||
public boolean isOnline() {
|
|
||||||
return this.player.isOnline();
|
return this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
return this.player.getName();
|
return this.player.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,26 +1,25 @@
|
|||||||
package com.plotsquared.bukkit.object;
|
package com.github.intellectualsites.plotsquared.bukkit.object;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.util.*;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.WeatherType;
|
import org.bukkit.WeatherType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventException;
|
import org.bukkit.event.EventException;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
|
||||||
|
|
||||||
public class BukkitPlayer extends PlotPlayer {
|
public class BukkitPlayer extends PlotPlayer {
|
||||||
|
|
||||||
public final Player player;
|
public final Player player;
|
||||||
@ -31,6 +30,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
/**
|
/**
|
||||||
* <p>Please do not use this method. Instead use
|
* <p>Please do not use this method. Instead use
|
||||||
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
* BukkitUtil.getPlayer(Player), as it caches player objects.</p>
|
||||||
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer(Player player) {
|
public BukkitPlayer(Player player) {
|
||||||
@ -44,14 +44,12 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
super.populatePersistentMetaMap();
|
super.populatePersistentMetaMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getLocation() {
|
||||||
public Location getLocation() {
|
|
||||||
Location location = super.getLocation();
|
Location location = super.getLocation();
|
||||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID() {
|
||||||
public UUID getUUID() {
|
|
||||||
if (this.uuid == null) {
|
if (this.uuid == null) {
|
||||||
this.uuid = UUIDHandler.getUUID(this);
|
this.uuid = UUIDHandler.getUUID(this);
|
||||||
}
|
}
|
||||||
@ -62,28 +60,23 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return this.player.getLastPlayed();
|
return this.player.getLastPlayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean canTeleport(Location loc) {
|
||||||
public boolean canTeleport(Location loc) {
|
|
||||||
org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
org.bukkit.Location to = BukkitUtil.getLocation(loc);
|
||||||
org.bukkit.Location from = player.getLocation();
|
org.bukkit.Location from = player.getLocation();
|
||||||
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
|
||||||
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
callEvent(event);
|
||||||
for (RegisteredListener listener : listeners) {
|
|
||||||
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
listener.callEvent(event);
|
|
||||||
} catch (EventException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (event.isCancelled() || !event.getTo().equals(to)) {
|
if (event.isCancelled() || !event.getTo().equals(to)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
event = new PlayerTeleportEvent(player, to, from);
|
event = new PlayerTeleportEvent(player, to, from);
|
||||||
|
callEvent(event);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void callEvent(final Event event) {
|
||||||
|
RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
|
||||||
for (RegisteredListener listener : listeners) {
|
for (RegisteredListener listener : listeners) {
|
||||||
if (listener.getPlugin().getName().equals(PS.imp().getPluginName())) {
|
if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -92,19 +85,16 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean hasPermission(String permission) {
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
if (this.offline && EconHandler.manager != null) {
|
if (this.offline && EconHandler.manager != null) {
|
||||||
return EconHandler.manager.hasPermission(getName(), permission);
|
return EconHandler.manager.hasPermission(getName(), permission);
|
||||||
}
|
}
|
||||||
return this.player.hasPermission(permission);
|
return this.player.hasPermission(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int hasPermissionRange(String stub, int range) {
|
||||||
public int hasPermissionRange(String stub, int range) {
|
|
||||||
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@ -131,8 +121,10 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
String end = perm.substring(stubPlus.length());
|
String end = perm.substring(stubPlus.length());
|
||||||
if (MathMan.isInteger(end)) {
|
if (MathMan.isInteger(end)) {
|
||||||
int val = Integer.parseInt(end);
|
int val = Integer.parseInt(end);
|
||||||
if (val > range) return val;
|
if (val > range)
|
||||||
if (val > max) max = val;
|
return val;
|
||||||
|
if (val > max)
|
||||||
|
max = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,57 +138,52 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isPermissionSet(String permission) {
|
||||||
public boolean isPermissionSet(String permission) {
|
|
||||||
return this.player.isPermissionSet(permission);
|
return this.player.isPermissionSet(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void sendMessage(String message) {
|
||||||
public void sendMessage(String message) {
|
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (
|
||||||
if (!StringMan.isEqual(this.<String>getMeta("lastMessage"), message) || (System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {
|
||||||
setMeta("lastMessage", message);
|
setMeta("lastMessage", message);
|
||||||
setMeta("lastMessageTime", System.currentTimeMillis());
|
setMeta("lastMessageTime", System.currentTimeMillis());
|
||||||
this.player.sendMessage(message);
|
this.player.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void teleport(Location location) {
|
||||||
public void teleport(Location location) {
|
|
||||||
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.player.teleport(
|
this.player.teleport(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, location.getY(), location.getZ() + 0.5,
|
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
|
||||||
location.getYaw(), location.getPitch()), TeleportCause.COMMAND);
|
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()),
|
||||||
|
TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getName() {
|
||||||
public String getName() {
|
|
||||||
if (this.name == null) {
|
if (this.name == null) {
|
||||||
this.name = this.player.getName();
|
this.name = this.player.getName();
|
||||||
}
|
}
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOnline() {
|
||||||
public boolean isOnline() {
|
|
||||||
return !this.offline && this.player.isOnline();
|
return !this.offline && this.player.isOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCompassTarget(Location location) {
|
||||||
public void setCompassTarget(Location location) {
|
|
||||||
this.player.setCompassTarget(
|
this.player.setCompassTarget(
|
||||||
new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ()));
|
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(this.player);
|
return BukkitUtil.getLocationFull(this.player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setWeather(PlotWeather weather) {
|
||||||
public void setWeather(PlotWeather weather) {
|
|
||||||
switch (weather) {
|
switch (weather) {
|
||||||
case CLEAR:
|
case CLEAR:
|
||||||
this.player.setPlayerWeather(WeatherType.CLEAR);
|
this.player.setPlayerWeather(WeatherType.CLEAR);
|
||||||
@ -213,8 +200,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotGameMode getGameMode() {
|
||||||
public PlotGameMode getGameMode() {
|
|
||||||
switch (this.player.getGameMode()) {
|
switch (this.player.getGameMode()) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
return PlotGameMode.ADVENTURE;
|
return PlotGameMode.ADVENTURE;
|
||||||
@ -229,8 +215,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setGameMode(PlotGameMode gameMode) {
|
||||||
public void setGameMode(PlotGameMode gameMode) {
|
|
||||||
switch (gameMode) {
|
switch (gameMode) {
|
||||||
case ADVENTURE:
|
case ADVENTURE:
|
||||||
this.player.setGameMode(GameMode.ADVENTURE);
|
this.player.setGameMode(GameMode.ADVENTURE);
|
||||||
@ -250,8 +235,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setTime(long time) {
|
||||||
public void setTime(long time) {
|
|
||||||
if (time != Long.MAX_VALUE) {
|
if (time != Long.MAX_VALUE) {
|
||||||
this.player.setPlayerTime(time, false);
|
this.player.setPlayerTime(time, false);
|
||||||
} else {
|
} else {
|
||||||
@ -259,24 +243,20 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean getFlight() {
|
||||||
public void setFlight(boolean fly) {
|
|
||||||
this.player.setAllowFlight(fly);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getFlight() {
|
|
||||||
return player.getAllowFlight();
|
return player.getAllowFlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setFlight(boolean fly) {
|
||||||
public void playMusic(Location location, int id) {
|
this.player.setAllowFlight(fly);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void playMusic(Location location, int id) {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void kick(String message) {
|
||||||
public void kick(String message) {
|
|
||||||
this.player.kickPlayer(message);
|
this.player.kickPlayer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,8 +266,7 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isBanned() {
|
||||||
public boolean isBanned() {
|
|
||||||
return this.player.isBanned();
|
return this.player.isBanned();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
class AgeableStats {
|
class AgeableStats {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
class ArmorStandStats {
|
class ArmorStandStats {
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
|
|
||||||
class EntityBaseStats {
|
class EntityBaseStats {
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
|
@Getter public abstract class EntityWrapper {
|
||||||
|
|
||||||
|
protected final float yaw;
|
||||||
|
protected final float pitch;
|
||||||
|
private final Entity entity;
|
||||||
|
private final EntityType type;
|
||||||
|
public double x;
|
||||||
|
public double y;
|
||||||
|
public double z;
|
||||||
|
|
||||||
|
EntityWrapper(@NonNull final Entity entity) {
|
||||||
|
this.entity = entity;
|
||||||
|
this.type = entity.getType();
|
||||||
|
|
||||||
|
final Location location = entity.getLocation();
|
||||||
|
this.x = location.getX();
|
||||||
|
this.y = location.getY();
|
||||||
|
this.z = location.getZ();
|
||||||
|
this.yaw = location.getYaw();
|
||||||
|
this.pitch = location.getPitch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") @Override public String toString() {
|
||||||
|
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Entity spawn(World world, int xOffset, int zOffset);
|
||||||
|
|
||||||
|
public abstract void saveEntity();
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
import org.bukkit.entity.Horse;
|
import org.bukkit.entity.Horse;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
@ -1,52 +1,21 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Art;
|
|
||||||
import org.bukkit.DyeColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Rotation;
|
|
||||||
import org.bukkit.TreeSpecies;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Bat;
|
|
||||||
import org.bukkit.entity.Boat;
|
|
||||||
import org.bukkit.entity.EnderDragon;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Guardian;
|
|
||||||
import org.bukkit.entity.Horse;
|
|
||||||
import org.bukkit.entity.IronGolem;
|
|
||||||
import org.bukkit.entity.Item;
|
|
||||||
import org.bukkit.entity.ItemFrame;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Painting;
|
|
||||||
import org.bukkit.entity.Rabbit;
|
|
||||||
import org.bukkit.entity.Rabbit.Type;
|
|
||||||
import org.bukkit.entity.Sheep;
|
|
||||||
import org.bukkit.entity.Skeleton;
|
|
||||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
|
||||||
import org.bukkit.entity.Slime;
|
|
||||||
import org.bukkit.entity.Tameable;
|
|
||||||
import org.bukkit.inventory.EntityEquipment;
|
import org.bukkit.inventory.EntityEquipment;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.EulerAngle;
|
import org.bukkit.util.EulerAngle;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class EntityWrapper {
|
public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||||
|
|
||||||
private final EntityType type;
|
|
||||||
private final float yaw;
|
|
||||||
private final float pitch;
|
|
||||||
private final short depth;
|
private final short depth;
|
||||||
private final int hash;
|
private final int hash;
|
||||||
private final EntityBaseStats base = new EntityBaseStats();
|
private final EntityBaseStats base = new EntityBaseStats();
|
||||||
public double x;
|
|
||||||
public double y;
|
|
||||||
public double z;
|
|
||||||
public ItemStack[] inventory;
|
public ItemStack[] inventory;
|
||||||
// Extended
|
// Extended
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
@ -60,22 +29,18 @@ public class EntityWrapper {
|
|||||||
private HorseStats horse;
|
private HorseStats horse;
|
||||||
private boolean noGravity;
|
private boolean noGravity;
|
||||||
|
|
||||||
public EntityWrapper(Entity entity, short depth) {
|
public ReplicatingEntityWrapper(Entity entity, short depth) {
|
||||||
|
super(entity);
|
||||||
|
|
||||||
this.hash = entity.getEntityId();
|
this.hash = entity.getEntityId();
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
Location location = entity.getLocation();
|
|
||||||
this.yaw = location.getYaw();
|
|
||||||
this.pitch = location.getPitch();
|
|
||||||
this.x = location.getX();
|
|
||||||
this.y = location.getY();
|
|
||||||
this.z = location.getZ();
|
|
||||||
this.type = entity.getType();
|
|
||||||
if (depth == 0) {
|
if (depth == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Entity passenger = entity.getPassenger();
|
Entity passenger = entity.getPassenger();
|
||||||
if (passenger != null) {
|
if (passenger != null) {
|
||||||
this.base.passenger = new EntityWrapper(passenger, depth);
|
this.base.passenger = new ReplicatingEntityWrapper(passenger, depth);
|
||||||
}
|
}
|
||||||
this.base.fall = entity.getFallDistance();
|
this.base.fall = entity.getFallDistance();
|
||||||
this.base.fire = (short) entity.getFireTicks();
|
this.base.fire = (short) entity.getFireTicks();
|
||||||
@ -87,18 +52,15 @@ public class EntityWrapper {
|
|||||||
if (depth == 1) {
|
if (depth == 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
|
|
||||||
if (!entity.hasGravity()) {
|
if (!entity.hasGravity()) {
|
||||||
this.noGravity = true;
|
this.noGravity = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case ARROW:
|
|
||||||
case BOAT:
|
case BOAT:
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
Boat boat = (Boat) entity;
|
Boat boat = (Boat) entity;
|
||||||
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
|
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
|
||||||
}
|
return;
|
||||||
|
case ARROW:
|
||||||
case COMPLEX_PART:
|
case COMPLEX_PART:
|
||||||
case EGG:
|
case EGG:
|
||||||
case ENDER_CRYSTAL:
|
case ENDER_CRYSTAL:
|
||||||
@ -134,9 +96,6 @@ public class EntityWrapper {
|
|||||||
case AREA_EFFECT_CLOUD:
|
case AREA_EFFECT_CLOUD:
|
||||||
// Do this stuff later
|
// Do this stuff later
|
||||||
return;
|
return;
|
||||||
default:
|
|
||||||
PS.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
|
||||||
return;
|
|
||||||
// MISC //
|
// MISC //
|
||||||
case DROPPED_ITEM:
|
case DROPPED_ITEM:
|
||||||
Item item = (Item) entity;
|
Item item = (Item) entity;
|
||||||
@ -210,7 +169,7 @@ public class EntityWrapper {
|
|||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
case RABBIT:
|
case RABBIT:
|
||||||
this.dataByte = getOrdinal(Type.values(), ((Rabbit) entity).getRabbitType());
|
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
|
||||||
storeAgeable((Ageable) entity);
|
storeAgeable((Ageable) entity);
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
@ -220,13 +179,16 @@ public class EntityWrapper {
|
|||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
case SKELETON:
|
case SKELETON:
|
||||||
this.dataByte = getOrdinal(SkeletonType.values(),((Skeleton)entity).getSkeletonType());
|
this.dataByte = getOrdinal(Skeleton.SkeletonType.values(),
|
||||||
|
((Skeleton) entity).getSkeletonType());
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return;
|
return;
|
||||||
case ARMOR_STAND:
|
case ARMOR_STAND:
|
||||||
ArmorStand stand = (ArmorStand) entity;
|
ArmorStand stand = (ArmorStand) entity;
|
||||||
this.inventory = new ItemStack[]{stand.getItemInHand().clone(), stand.getHelmet().clone(), stand.getChestplate().clone(),
|
this.inventory =
|
||||||
stand.getLeggings().clone(), stand.getBoots().clone()};
|
new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
|
||||||
|
stand.getChestplate().clone(), stand.getLeggings().clone(),
|
||||||
|
stand.getBoots().clone()};
|
||||||
storeLiving(stand);
|
storeLiving(stand);
|
||||||
this.stand = new ArmorStandStats();
|
this.stand = new ArmorStandStats();
|
||||||
|
|
||||||
@ -312,16 +274,16 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
// END LIVING //
|
// END LIVING //
|
||||||
|
default:
|
||||||
|
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean equals(Object obj) {
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return this.hash == obj.hashCode();
|
return this.hash == obj.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int hashCode() {
|
||||||
public int hashCode() {
|
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,12 +316,8 @@ public class EntityWrapper {
|
|||||||
|
|
||||||
void restoreEquipment(LivingEntity entity) {
|
void restoreEquipment(LivingEntity entity) {
|
||||||
EntityEquipment equipment = entity.getEquipment();
|
EntityEquipment equipment = entity.getEquipment();
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
equipment.setItemInMainHand(this.lived.mainHand);
|
equipment.setItemInMainHand(this.lived.mainHand);
|
||||||
equipment.setItemInOffHand(this.lived.offHand);
|
equipment.setItemInOffHand(this.lived.offHand);
|
||||||
} else {
|
|
||||||
equipment.setItemInHand(this.lived.mainHand);
|
|
||||||
}
|
|
||||||
equipment.setHelmet(this.lived.helmet);
|
equipment.setHelmet(this.lived.helmet);
|
||||||
equipment.setChestplate(this.lived.chestplate);
|
equipment.setChestplate(this.lived.chestplate);
|
||||||
equipment.setLeggings(this.lived.leggings);
|
equipment.setLeggings(this.lived.leggings);
|
||||||
@ -370,7 +328,7 @@ public class EntityWrapper {
|
|||||||
try {
|
try {
|
||||||
entity.getInventory().setContents(this.inventory);
|
entity.getInventory().setContents(this.inventory);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
PS.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
|
PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,13 +356,8 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void storeEquipment(EntityEquipment equipment) {
|
void storeEquipment(EntityEquipment equipment) {
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
this.lived.mainHand = equipment.getItemInMainHand().clone();
|
this.lived.mainHand = equipment.getItemInMainHand().clone();
|
||||||
this.lived.offHand = equipment.getItemInOffHand().clone();
|
this.lived.offHand = equipment.getItemInOffHand().clone();
|
||||||
} else {
|
|
||||||
this.lived.mainHand = equipment.getItemInHand().clone();
|
|
||||||
this.lived.offHand = null;
|
|
||||||
}
|
|
||||||
this.lived.boots = equipment.getBoots().clone();
|
this.lived.boots = equipment.getBoots().clone();
|
||||||
this.lived.leggings = equipment.getLeggings().clone();
|
this.lived.leggings = equipment.getLeggings().clone();
|
||||||
this.lived.chestplate = equipment.getChestplate().clone();
|
this.lived.chestplate = equipment.getChestplate().clone();
|
||||||
@ -443,15 +396,15 @@ public class EntityWrapper {
|
|||||||
this.tamed.tamed = tamed.isTamed();
|
this.tamed.tamed = tamed.isTamed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity spawn(World world, int xOffset, int zOffset) {
|
@Override public Entity spawn(World world, int xOffset, int zOffset) {
|
||||||
Location location = new Location(world, this.x + xOffset, this.y, this.z + zOffset);
|
Location location = new Location(world, this.x + xOffset, this.y, this.z + zOffset);
|
||||||
location.setYaw(this.yaw);
|
location.setYaw(this.yaw);
|
||||||
location.setPitch(this.pitch);
|
location.setPitch(this.pitch);
|
||||||
if (!this.type.isSpawnable()) {
|
if (!this.getType().isSpawnable()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Entity entity;
|
Entity entity;
|
||||||
switch (this.type) {
|
switch (this.getType()) {
|
||||||
case DROPPED_ITEM:
|
case DROPPED_ITEM:
|
||||||
return world.dropItem(location, this.stack);
|
return world.dropItem(location, this.stack);
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
@ -464,7 +417,7 @@ public class EntityWrapper {
|
|||||||
entity = world.spawn(location, Painting.class);
|
entity = world.spawn(location, Painting.class);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
entity = world.spawnEntity(location, this.type);
|
entity = world.spawnEntity(location, this.getType());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.depth == 0) {
|
if (this.depth == 0) {
|
||||||
@ -473,7 +426,8 @@ public class EntityWrapper {
|
|||||||
if (this.base.passenger != null) {
|
if (this.base.passenger != null) {
|
||||||
try {
|
try {
|
||||||
entity.setPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
entity.setPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this.base.fall != 0) {
|
if (this.base.fall != 0) {
|
||||||
entity.setFallDistance(this.base.fall);
|
entity.setFallDistance(this.base.fall);
|
||||||
@ -488,19 +442,18 @@ public class EntityWrapper {
|
|||||||
if (this.depth == 1) {
|
if (this.depth == 1) {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_10_0) || entity instanceof ArmorStand) {
|
|
||||||
if (this.noGravity) {
|
if (this.noGravity) {
|
||||||
entity.setGravity(false);
|
entity.setGravity(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
switch (entity.getType()) {
|
switch (entity.getType()) {
|
||||||
case ARROW:
|
|
||||||
case BOAT:
|
case BOAT:
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
|
|
||||||
Boat boat = (Boat) entity;
|
Boat boat = (Boat) entity;
|
||||||
boat.setWoodType(TreeSpecies.values()[dataByte]);
|
boat.setWoodType(TreeSpecies.values()[dataByte]);
|
||||||
}
|
return entity;
|
||||||
|
case SLIME:
|
||||||
|
((Slime) entity).setSize(this.dataByte);
|
||||||
|
return entity;
|
||||||
|
case ARROW:
|
||||||
case COMPLEX_PART:
|
case COMPLEX_PART:
|
||||||
case EGG:
|
case EGG:
|
||||||
case ENDER_CRYSTAL:
|
case ENDER_CRYSTAL:
|
||||||
@ -520,10 +473,6 @@ public class EntityWrapper {
|
|||||||
case MINECART_TNT:
|
case MINECART_TNT:
|
||||||
case PLAYER:
|
case PLAYER:
|
||||||
case PRIMED_TNT:
|
case PRIMED_TNT:
|
||||||
return entity;
|
|
||||||
case SLIME:
|
|
||||||
((Slime) entity).setSize(this.dataByte);
|
|
||||||
return entity;
|
|
||||||
case SMALL_FIREBALL:
|
case SMALL_FIREBALL:
|
||||||
case SNOWBALL:
|
case SNOWBALL:
|
||||||
case SPLASH_POTION:
|
case SPLASH_POTION:
|
||||||
@ -540,9 +489,6 @@ public class EntityWrapper {
|
|||||||
case UNKNOWN:
|
case UNKNOWN:
|
||||||
// Do this stuff later
|
// Do this stuff later
|
||||||
return entity;
|
return entity;
|
||||||
default:
|
|
||||||
PS.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
|
||||||
return entity;
|
|
||||||
// MISC //
|
// MISC //
|
||||||
case ITEM_FRAME:
|
case ITEM_FRAME:
|
||||||
ItemFrame itemframe = (ItemFrame) entity;
|
ItemFrame itemframe = (ItemFrame) entity;
|
||||||
@ -606,7 +552,7 @@ public class EntityWrapper {
|
|||||||
// END AGEABLE //
|
// END AGEABLE //
|
||||||
case RABBIT:
|
case RABBIT:
|
||||||
if (this.dataByte != 0) {
|
if (this.dataByte != 0) {
|
||||||
((Rabbit) entity).setRabbitType(Type.values()[this.dataByte]);
|
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
|
||||||
}
|
}
|
||||||
restoreAgeable((Ageable) entity);
|
restoreAgeable((Ageable) entity);
|
||||||
restoreLiving((LivingEntity) entity);
|
restoreLiving((LivingEntity) entity);
|
||||||
@ -619,7 +565,8 @@ public class EntityWrapper {
|
|||||||
return entity;
|
return entity;
|
||||||
case SKELETON:
|
case SKELETON:
|
||||||
if (this.dataByte != 0) {
|
if (this.dataByte != 0) {
|
||||||
((Skeleton) entity).setSkeletonType(SkeletonType.values()[this.dataByte]);
|
((Skeleton) entity)
|
||||||
|
.setSkeletonType(Skeleton.SkeletonType.values()[this.dataByte]);
|
||||||
}
|
}
|
||||||
storeLiving((LivingEntity) entity);
|
storeLiving((LivingEntity) entity);
|
||||||
return entity;
|
return entity;
|
||||||
@ -642,27 +589,37 @@ public class EntityWrapper {
|
|||||||
stand.setBoots(this.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) {
|
||||||
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) {
|
||||||
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
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftLeg[0], this.stand.leftLeg[1], this.stand.leftLeg[2]);
|
|| this.stand.leftLeg[2] != 0) {
|
||||||
|
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
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightLeg[0], this.stand.rightLeg[1], this.stand.rightLeg[2]);
|
|| this.stand.rightLeg[2] != 0) {
|
||||||
|
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
|
||||||
EulerAngle pose = new EulerAngle(this.stand.leftArm[0], this.stand.leftArm[1], this.stand.leftArm[2]);
|
|| this.stand.leftArm[2] != 0) {
|
||||||
|
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
|
||||||
EulerAngle pose = new EulerAngle(this.stand.rightArm[0], this.stand.rightArm[1], this.stand.rightArm[2]);
|
|| this.stand.rightArm[2] != 0) {
|
||||||
|
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) {
|
||||||
@ -716,10 +673,16 @@ public class EntityWrapper {
|
|||||||
}
|
}
|
||||||
restoreLiving((LivingEntity) entity);
|
restoreLiving((LivingEntity) entity);
|
||||||
return entity;
|
return entity;
|
||||||
|
default:
|
||||||
|
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||||
|
return entity;
|
||||||
// END LIVING
|
// END LIVING
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void saveEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
private byte getOrdinal(Object[] list, 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)) {
|
||||||
@ -729,9 +692,5 @@ public class EntityWrapper {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return String.format("[%s, x=%s, y=%s, z=%s]", type.getName(), x, y, z);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.object.entity;
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
import org.bukkit.entity.AnimalTamer;
|
import org.bukkit.entity.AnimalTamer;
|
||||||
|
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
|
||||||
|
public class TeleportEntityWrapper extends EntityWrapper {
|
||||||
|
|
||||||
|
private Location oldLocation;
|
||||||
|
private boolean gravityOld;
|
||||||
|
private boolean invulnerableOld;
|
||||||
|
private int fireTicksOld;
|
||||||
|
private int livingTicksOld;
|
||||||
|
|
||||||
|
public TeleportEntityWrapper(final Entity entity) {
|
||||||
|
super(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public Entity spawn(final World world, final int xOffset, final int zOffset) {
|
||||||
|
if (!getEntity().getLocation().getChunk().equals(oldLocation.getChunk())) {
|
||||||
|
final Location oldLocation = this.oldLocation.clone();
|
||||||
|
oldLocation.add(xOffset, 0, xOffset);
|
||||||
|
getEntity().teleport(oldLocation);
|
||||||
|
getEntity().setGravity(gravityOld);
|
||||||
|
getEntity().setInvulnerable(invulnerableOld);
|
||||||
|
getEntity().setFireTicks(fireTicksOld);
|
||||||
|
getEntity().setTicksLived(livingTicksOld);
|
||||||
|
getEntity().removeMetadata("ps-tmp-teleport", BukkitMain.getPlugin(BukkitMain.class));
|
||||||
|
}
|
||||||
|
return getEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void saveEntity() {
|
||||||
|
if (getEntity().hasMetadata("ps-tmp-teleport")) {
|
||||||
|
this.oldLocation = (Location) this.getEntity().getMetadata("ps-tmp-teleport").get(0);
|
||||||
|
} else {
|
||||||
|
this.oldLocation = this.getEntity().getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
// To account for offsets in the chunk manager
|
||||||
|
this.oldLocation = oldLocation.clone();
|
||||||
|
this.oldLocation.setX(this.x);
|
||||||
|
this.oldLocation.setY(this.y);
|
||||||
|
this.oldLocation.setZ(this.z);
|
||||||
|
|
||||||
|
this.gravityOld = this.getEntity().hasGravity();
|
||||||
|
this.getEntity().setGravity(false);
|
||||||
|
this.invulnerableOld = this.getEntity().isInvulnerable();
|
||||||
|
this.getEntity().setInvulnerable(true);
|
||||||
|
this.fireTicksOld = this.getEntity().getFireTicks();
|
||||||
|
this.livingTicksOld = this.getEntity().getTicksLived();
|
||||||
|
this.getEntity().setMetadata("ps-tmp-teleport",
|
||||||
|
new FixedMetadataValue(BukkitMain.getPlugin(BukkitMain.class), oldLocation));
|
||||||
|
final Chunk newChunk = getNewChunk();
|
||||||
|
this.getEntity().teleport(
|
||||||
|
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Chunk getNewChunk() {
|
||||||
|
final Chunk oldChunk = oldLocation.getChunk();
|
||||||
|
Chunk chunk = null;
|
||||||
|
|
||||||
|
for (Chunk lChunk : oldChunk.getWorld().getLoadedChunks()) {
|
||||||
|
if (!lChunk.equals(oldChunk) && lChunk.isLoaded()) {
|
||||||
|
chunk = lChunk;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (chunk == null) {
|
||||||
|
for (int dx = 1; dx < Integer.MAX_VALUE; dx++) {
|
||||||
|
for (int dz = 0; dz < Integer.MAX_VALUE; dz++) {
|
||||||
|
if ((chunk = getChunkRelative(oldChunk, dx, dz)).isLoaded()) {
|
||||||
|
break;
|
||||||
|
} else if ((chunk = getChunkRelative(oldChunk, -dx, dz)).isLoaded()) {
|
||||||
|
break;
|
||||||
|
} else if ((chunk = getChunkRelative(oldChunk, dx, -dz)).isLoaded()) {
|
||||||
|
break;
|
||||||
|
} else if ((chunk = getChunkRelative(oldChunk, -dx, -dz)).isLoaded()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Chunk getChunkRelative(final Chunk chunk, final int dx, final int dz) {
|
||||||
|
return chunk.getWorld().getChunkAt(chunk.getX() + dx, chunk.getZ() + dz);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,8 @@
|
|||||||
package com.plotsquared.bukkit.object.schematic;
|
package com.github.intellectualsites.plotsquared.bukkit.object.schematic;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.ByteTag;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import com.sk89q.jnbt.*;
|
||||||
import com.intellectualcrafters.jnbt.ListTag;
|
import org.bukkit.Material;
|
||||||
import com.intellectualcrafters.jnbt.ShortTag;
|
|
||||||
import com.intellectualcrafters.jnbt.Tag;
|
|
||||||
import com.intellectualcrafters.plot.object.schematic.ItemType;
|
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -43,21 +38,14 @@ public class StateWrapper {
|
|||||||
case "chest":
|
case "chest":
|
||||||
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
|
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
|
||||||
int length = itemsTag.size();
|
int length = itemsTag.size();
|
||||||
short[] ids = new short[length];
|
String[] ids = new String[length];
|
||||||
byte[] datas = new byte[length];
|
|
||||||
byte[] amounts = new byte[length];
|
byte[] amounts = new byte[length];
|
||||||
byte[] slots = new byte[length];
|
byte[] slots = new byte[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Tag itemTag = itemsTag.get(i);
|
Tag itemTag = itemsTag.get(i);
|
||||||
CompoundTag itemComp = (CompoundTag) itemTag;
|
CompoundTag itemComp = (CompoundTag) itemTag;
|
||||||
short id = itemComp.getShort("id");
|
String id = itemComp.getString("id");
|
||||||
String idStr = itemComp.getString("id");
|
|
||||||
if (idStr != null && !MathMan.isInteger(idStr)) {
|
|
||||||
idStr = idStr.split(":")[1].toLowerCase();
|
|
||||||
id = (short) ItemType.getId(idStr);
|
|
||||||
}
|
|
||||||
ids[i] = id;
|
ids[i] = id;
|
||||||
datas[i] = (byte) itemComp.getShort("Damage");
|
|
||||||
amounts[i] = itemComp.getByte("Count");
|
amounts[i] = itemComp.getByte("Count");
|
||||||
slots[i] = itemComp.getByte("Slot");
|
slots[i] = itemComp.getByte("Slot");
|
||||||
}
|
}
|
||||||
@ -71,7 +59,8 @@ public class StateWrapper {
|
|||||||
InventoryHolder holder = (InventoryHolder) state;
|
InventoryHolder holder = (InventoryHolder) state;
|
||||||
Inventory inv = holder.getInventory();
|
Inventory inv = holder.getInventory();
|
||||||
for (int i = 0; i < ids.length; i++) {
|
for (int i = 0; i < ids.length; i++) {
|
||||||
ItemStack item = new ItemStack(ids[i], amounts[i], datas[i]);
|
ItemStack item =
|
||||||
|
new ItemStack(Material.getMaterial(ids[i]), (int) amounts[i]);
|
||||||
inv.addItem(item);
|
inv.addItem(item);
|
||||||
}
|
}
|
||||||
state.update(true);
|
state.update(true);
|
||||||
@ -89,7 +78,7 @@ public class StateWrapper {
|
|||||||
InventoryHolder inv = (InventoryHolder) this.state;
|
InventoryHolder inv = (InventoryHolder) this.state;
|
||||||
ItemStack[] contents = inv.getInventory().getContents();
|
ItemStack[] contents = inv.getInventory().getContents();
|
||||||
Map<String, Tag> values = new HashMap<>();
|
Map<String, Tag> values = new HashMap<>();
|
||||||
values.put("Items", new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
|
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(contents)));
|
||||||
return new CompoundTag(values);
|
return new CompoundTag(values);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -104,41 +93,29 @@ public class StateWrapper {
|
|||||||
for (int i = 0; i < items.length; ++i) {
|
for (int i = 0; i < items.length; ++i) {
|
||||||
if (items[i] != null) {
|
if (items[i] != null) {
|
||||||
Map<String, Tag> tagData = serializeItem(items[i]);
|
Map<String, Tag> tagData = serializeItem(items[i]);
|
||||||
tagData.put("Slot", new ByteTag("Slot", (byte) i));
|
tagData.put("Slot", new ByteTag((byte) i));
|
||||||
tags.add(new CompoundTag(tagData));
|
tags.add(new CompoundTag(tagData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* TODO: Move this into the sponge module!
|
|
||||||
*
|
|
||||||
public Map<String, Tag> serializeItem(final org.spongepowered.api.item.inventory.ItemStack item) {
|
|
||||||
final Map<String, Tag> data = new HashMap<String, Tag>();
|
|
||||||
|
|
||||||
// FIXME serialize sponge item
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public Map<String, Tag> serializeItem(ItemStack item) {
|
public Map<String, Tag> serializeItem(ItemStack item) {
|
||||||
Map<String, Tag> data = new HashMap<>();
|
Map<String, Tag> data = new HashMap<>();
|
||||||
data.put("id", new ShortTag("id", (short) item.getTypeId()));
|
data.put("id", new StringTag(item.getType().name()));
|
||||||
data.put("Damage", new ShortTag("Damage", item.getDurability()));
|
data.put("Damage", new ShortTag(item.getDurability()));
|
||||||
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
|
data.put("Count", new ByteTag((byte) item.getAmount()));
|
||||||
if (!item.getEnchantments().isEmpty()) {
|
if (!item.getEnchantments().isEmpty()) {
|
||||||
List<CompoundTag> enchantmentList = new ArrayList<>();
|
List<CompoundTag> enchantmentList = new ArrayList<>();
|
||||||
for (Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
for (Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
||||||
Map<String, Tag> enchantment = new HashMap<>();
|
Map<String, Tag> enchantment = new HashMap<>();
|
||||||
enchantment.put("id", new ShortTag("id", (short) entry.getKey().getId()));
|
enchantment.put("id", new StringTag(entry.getKey().toString()));
|
||||||
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
|
enchantment.put("lvl", new ShortTag(entry.getValue().shortValue()));
|
||||||
enchantmentList.add(new CompoundTag(enchantment));
|
enchantmentList.add(new CompoundTag(enchantment));
|
||||||
}
|
}
|
||||||
Map<String, Tag> auxData = new HashMap<>();
|
Map<String, Tag> auxData = new HashMap<>();
|
||||||
auxData.put("ench", new ListTag("ench", CompoundTag.class, enchantmentList));
|
auxData.put("ench", new ListTag(CompoundTag.class, enchantmentList));
|
||||||
data.put("tag", new CompoundTag("tag", auxData));
|
data.put("tag", new CompoundTag(auxData));
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
import com.plotsquared.bukkit.chat.Reflection;
|
import com.github.intellectualsites.plotsquared.bukkit.chat.Reflection;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -18,7 +18,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
* @param stayTime Stay on screen time
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeOutTime Fade out time
|
* @param fadeOutTime Fade out time
|
||||||
*/
|
*/
|
||||||
DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
DefaultTitleManager(String title, String subtitle, int fadeInTime, int stayTime,
|
||||||
|
int fadeOutTime) {
|
||||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if (this.packetTitle != null) {
|
if (this.packetTitle != null) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
@ -41,38 +43,44 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
Object packet = this.packetTitle
|
||||||
|
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE,
|
||||||
|
Integer.TYPE, Integer.TYPE)
|
||||||
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
this.stayTime * (this.ticks ? 1 : 20), this.fadeOutTime * (this.ticks ? 1 : 20));
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
// Send if set
|
// Send if set
|
||||||
if (this.fadeInTime != -1 && this.fadeOutTime != -1 && this.stayTime != -1) {
|
if (this.fadeInTime != -1 && this.fadeOutTime != -1 && this.stayTime != -1) {
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||||
+ '}');
|
+ "\",color:" + this.titleColor.name().toLowerCase() + '}');
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[0], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
if (!this.getSubtitle().isEmpty()) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
|
||||||
.toLowerCase() + '}');
|
+ "\",color:" + this.subtitleColor.name().toLowerCase() + '}');
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void clearTitle(Player player)
|
||||||
public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[3], null);
|
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[3], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +92,15 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public void resetTitle(Player player)
|
||||||
public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[4], null);
|
Object packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
|
||||||
|
.newInstance(actions[4], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +117,8 @@ public class DefaultTitleManager extends TitleManager {
|
|||||||
|
|
||||||
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (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;
|
||||||
}
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") public class DefaultTitle_111 extends AbstractTitle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||||
|
try {
|
||||||
|
final Player playerObj = ((BukkitPlayer) player).player;
|
||||||
|
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
|
||||||
|
title.send(playerObj);
|
||||||
|
return;
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
|
||||||
|
|
||||||
|
public class HackTitle extends AbstractTitle {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
||||||
|
try {
|
||||||
|
HackTitleManager title = new HackTitleManager(head, sub, in, delay, out);
|
||||||
|
title.send(((BukkitPlayer) player).player);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
PlotSquared.debug("&cYour server version does not support titles!");
|
||||||
|
Settings.TITLES = false;
|
||||||
|
AbstractTitle.TITLE_CLASS = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
import com.plotsquared.bukkit.chat.Reflection;
|
import com.github.intellectualsites.plotsquared.bukkit.chat.Reflection;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -26,14 +26,14 @@ public class HackTitleManager extends TitleManager {
|
|||||||
/**
|
/**
|
||||||
* Load spigot and NMS classes.
|
* Load spigot and NMS classes.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override void loadClasses() {
|
||||||
void loadClasses() {
|
|
||||||
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
this.packetTitle = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
||||||
// First reset previous settings
|
// First reset previous settings
|
||||||
resetTitle(player);
|
resetTitle(player);
|
||||||
@ -42,8 +42,9 @@ public class HackTitleManager extends TitleManager {
|
|||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE).newInstance(actions[2],
|
Object packet = this.packetTitle
|
||||||
this.fadeInTime * (this.ticks ? 1 : 20),
|
.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.stayTime * (this.ticks ? 1 : 20),
|
||||||
this.fadeOutTime * (this.ticks ? 1 : 20));
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
// Send if set
|
// Send if set
|
||||||
@ -52,43 +53,49 @@ public class HackTitleManager extends TitleManager {
|
|||||||
}
|
}
|
||||||
// Send title
|
// Send title
|
||||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||||
+ "}");
|
+ "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
packet = this.packetTitle
|
||||||
|
.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||||
.newInstance(actions[0], serialized);
|
.newInstance(actions[0], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
if (!this.getSubtitle().isEmpty()) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
|
||||||
.toLowerCase() + "}");
|
+ "\",color:" + this.subtitleColor.name().toLowerCase() + "}");
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
packet = this.packetTitle.getConstructor(this.packetActions,
|
||||||
|
Reflection.getNMSClass("IChatBaseComponent"))
|
||||||
.newInstance(actions[1], serialized);
|
.newInstance(actions[1], serialized);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void clearTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
Object packet =
|
||||||
|
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
@Override public void resetTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||||
// Send timings first
|
// Send timings first
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object[] actions = this.packetActions.getEnumConstants();
|
Object[] actions = this.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
Object packet = this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
Object packet =
|
||||||
|
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +109,8 @@ public class HackTitleManager extends TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
private int getProtocolVersion(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
private int getProtocolVersion(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
Object networkManager = getValue("networkManager", connection);
|
Object networkManager = getValue("networkManager", connection);
|
||||||
@ -127,15 +135,18 @@ public class HackTitleManager extends TitleManager {
|
|||||||
private Class<?> getClass(String namespace) {
|
private Class<?> getClass(String namespace) {
|
||||||
try {
|
try {
|
||||||
return Class.forName(namespace);
|
return Class.forName(namespace);
|
||||||
} catch (ClassNotFoundException ignored) {}
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field getField(String name, Class<?> clazz) throws NoSuchFieldException, SecurityException {
|
private Field getField(String name, Class<?> clazz)
|
||||||
|
throws NoSuchFieldException, SecurityException {
|
||||||
return clazz.getDeclaredField(name);
|
return clazz.getDeclaredField(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getValue(String name, Object obj) throws ReflectiveOperationException, SecurityException, IllegalArgumentException {
|
private Object getValue(String name, Object obj)
|
||||||
|
throws ReflectiveOperationException, SecurityException, IllegalArgumentException {
|
||||||
Field f = getField(name, obj.getClass());
|
Field f = getField(name, obj.getClass());
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
return f.get(obj);
|
return f.get(obj);
|
||||||
@ -154,7 +165,8 @@ public class HackTitleManager extends TitleManager {
|
|||||||
|
|
||||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (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;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -12,17 +12,13 @@ import java.util.Map;
|
|||||||
public abstract class TitleManager {
|
public abstract class TitleManager {
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||||
/* Title packet */
|
/* Title packet */ Class<?> packetTitle;
|
||||||
Class<?> packetTitle;
|
/* Title packet actions ENUM */ Class<?> packetActions;
|
||||||
/* Title packet actions ENUM */
|
/* Chat serializer */ Class<?> nmsChatSerializer;
|
||||||
Class<?> packetActions;
|
|
||||||
/* Chat serializer */
|
|
||||||
Class<?> nmsChatSerializer;
|
|
||||||
Class<?> chatBaseComponent;
|
Class<?> chatBaseComponent;
|
||||||
ChatColor titleColor = ChatColor.WHITE;
|
ChatColor titleColor = ChatColor.WHITE;
|
||||||
ChatColor subtitleColor = ChatColor.WHITE;
|
ChatColor subtitleColor = ChatColor.WHITE;
|
||||||
/* Title timings */
|
/* Title timings */ int fadeInTime = -1;
|
||||||
int fadeInTime = -1;
|
|
||||||
int stayTime = -1;
|
int stayTime = -1;
|
||||||
int fadeOutTime = -1;
|
int fadeOutTime = -1;
|
||||||
boolean ticks = false;
|
boolean ticks = false;
|
||||||
@ -154,7 +150,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void send(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Broadcasts the title to all players.
|
* Broadcasts the title to all players.
|
||||||
@ -175,7 +172,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void clearTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the title settings.
|
* Resets the title settings.
|
||||||
@ -185,7 +183,8 @@ public abstract class TitleManager {
|
|||||||
* @throws ReflectiveOperationException
|
* @throws ReflectiveOperationException
|
||||||
* @throws SecurityException
|
* @throws SecurityException
|
||||||
*/
|
*/
|
||||||
public abstract void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
public abstract void resetTitle(Player player)
|
||||||
|
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||||
|
|
||||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||||
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
@ -1,14 +1,14 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minecraft 1.8 Title
|
* Minecraft 1.8 Title
|
||||||
* For 1.11
|
* For 1.11
|
||||||
@ -17,6 +17,8 @@ import org.bukkit.entity.Player;
|
|||||||
* @version 1.1.0
|
* @version 1.1.0
|
||||||
*/
|
*/
|
||||||
public class TitleManager_1_11 {
|
public class TitleManager_1_11 {
|
||||||
|
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES =
|
||||||
|
new HashMap<Class<?>, Class<?>>();
|
||||||
/* Title packet */
|
/* Title packet */
|
||||||
private static Class<?> packetTitle;
|
private static Class<?> packetTitle;
|
||||||
/* Title packet actions ENUM */
|
/* Title packet actions ENUM */
|
||||||
@ -43,8 +45,6 @@ public class TitleManager_1_11 {
|
|||||||
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<Class<?>, Class<?>>();
|
|
||||||
|
|
||||||
public TitleManager_1_11() {
|
public TitleManager_1_11() {
|
||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
@ -98,7 +98,8 @@ public class TitleManager_1_11 {
|
|||||||
* @param stayTime Stay on screen time
|
* @param stayTime Stay on screen time
|
||||||
* @param fadeOutTime Fade out time
|
* @param fadeOutTime Fade out time
|
||||||
*/
|
*/
|
||||||
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime,
|
||||||
|
int fadeOutTime) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.subtitle = subtitle;
|
this.subtitle = subtitle;
|
||||||
this.fadeInTime = fadeInTime;
|
this.fadeInTime = fadeInTime;
|
||||||
@ -107,6 +108,15 @@ public class TitleManager_1_11 {
|
|||||||
loadClasses();
|
loadClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
||||||
|
if (a.length != o.length)
|
||||||
|
return false;
|
||||||
|
for (int i = 0; i < a.length; i++)
|
||||||
|
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load spigot and NMS classes
|
* Load spigot and NMS classes
|
||||||
*/
|
*/
|
||||||
@ -118,23 +128,13 @@ public class TitleManager_1_11 {
|
|||||||
nmsChatSerializer = getNMSClass("ChatComponentText");
|
nmsChatSerializer = getNMSClass("ChatComponentText");
|
||||||
nmsPlayer = getNMSClass("EntityPlayer");
|
nmsPlayer = getNMSClass("EntityPlayer");
|
||||||
nmsPlayerConnection = getNMSClass("PlayerConnection");
|
nmsPlayerConnection = getNMSClass("PlayerConnection");
|
||||||
playerConnection = getField(nmsPlayer,
|
playerConnection = getField(nmsPlayer, "playerConnection");
|
||||||
"playerConnection");
|
|
||||||
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
|
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
|
||||||
obcPlayer = getOBCClass("entity.CraftPlayer");
|
obcPlayer = getOBCClass("entity.CraftPlayer");
|
||||||
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
|
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set title text
|
|
||||||
*
|
|
||||||
* @param title Title
|
|
||||||
*/
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get title text
|
* Get title text
|
||||||
*
|
*
|
||||||
@ -145,12 +145,12 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set subtitle text
|
* Set title text
|
||||||
*
|
*
|
||||||
* @param subtitle Subtitle text
|
* @param title Title
|
||||||
*/
|
*/
|
||||||
public void setSubtitle(String subtitle) {
|
public void setTitle(String title) {
|
||||||
this.subtitle = subtitle;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,48 +163,12 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the title color
|
* Set subtitle text
|
||||||
*
|
*
|
||||||
* @param color Chat color
|
* @param subtitle Subtitle text
|
||||||
*/
|
*/
|
||||||
public void setTitleColor(ChatColor color) {
|
public void setSubtitle(String subtitle) {
|
||||||
this.titleColor = color;
|
this.subtitle = subtitle;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,12 +199,10 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle
|
||||||
chatBaseComponent, Integer.TYPE, Integer.TYPE,
|
.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE,
|
||||||
Integer.TYPE).newInstance(actions[3], null,
|
Integer.TYPE).newInstance(actions[3], null, fadeInTime * (ticks ? 1 : 20),
|
||||||
fadeInTime * (ticks ? 1 : 20),
|
stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20));
|
||||||
stayTime * (ticks ? 1 : 20),
|
|
||||||
fadeOutTime * (ticks ? 1 : 20));
|
|
||||||
// Send if set
|
// Send if set
|
||||||
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
@ -248,22 +210,18 @@ public class TitleManager_1_11 {
|
|||||||
Object serialized;
|
Object serialized;
|
||||||
if (!subtitle.equals("")) {
|
if (!subtitle.equals("")) {
|
||||||
// Send subtitle if present
|
// Send subtitle if present
|
||||||
serialized = nmsChatSerializer.getConstructor(String.class)
|
serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
.newInstance(subtitleColor +
|
subtitleColor + ChatColor.translateAlternateColorCodes('&', subtitle));
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
subtitle));
|
.newInstance(actions[1], serialized);
|
||||||
packet = packetTitle.getConstructor(packetActions,
|
|
||||||
chatBaseComponent).newInstance(actions[1],
|
|
||||||
serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send title
|
// Send title
|
||||||
serialized = nmsChatSerializer.getConstructor(
|
serialized = nmsChatSerializer.getConstructor(String.class)
|
||||||
String.class).newInstance(titleColor +
|
.newInstance(titleColor + ChatColor.translateAlternateColorCodes('&', title));
|
||||||
ChatColor.translateAlternateColorCodes('&', title));
|
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
packet = packetTitle.getConstructor(packetActions,
|
.newInstance(actions[0], serialized);
|
||||||
chatBaseComponent).newInstance(actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -278,19 +236,12 @@ public class TitleManager_1_11 {
|
|||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
new Class[]{TitleManager_1_11.packetActions, chatBaseComponent,
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent, Integer.TYPE,
|
||||||
Integer.TYPE, Integer.TYPE, Integer.TYPE})
|
Integer.TYPE, Integer.TYPE})
|
||||||
.newInstance(
|
.newInstance(actions[3], null, this.fadeInTime * (this.ticks ? 1 : 20),
|
||||||
actions[3],
|
this.stayTime * (this.ticks ? 1 : 20),
|
||||||
null,
|
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||||
this.fadeInTime
|
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
||||||
* (this.ticks ? 1 : 20),
|
|
||||||
this.stayTime
|
|
||||||
* (this.ticks ? 1 : 20),
|
|
||||||
this.fadeOutTime
|
|
||||||
* (this.ticks ? 1 : 20));
|
|
||||||
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1)
|
|
||||||
&& (this.stayTime != -1)) {
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -303,21 +254,14 @@ public class TitleManager_1_11 {
|
|||||||
if (TitleManager_1_11.packetTitle != null) {
|
if (TitleManager_1_11.packetTitle != null) {
|
||||||
try {
|
try {
|
||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = getField(handle.getClass(),
|
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||||
"playerConnection").get(handle);
|
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Method sendPacket = getMethod(connection.getClass(),
|
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||||
"sendPacket");
|
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
Object serialized = nmsChatSerializer.getConstructor(
|
titleColor + ChatColor.translateAlternateColorCodes('&', this.title));
|
||||||
String.class)
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
.newInstance(titleColor +
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
.newInstance(actions[0], serialized);
|
||||||
this.title));
|
|
||||||
Object packet = TitleManager_1_11.packetTitle
|
|
||||||
.getConstructor(
|
|
||||||
new Class[]{TitleManager_1_11.packetActions,
|
|
||||||
chatBaseComponent}).newInstance(
|
|
||||||
actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -331,16 +275,11 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||||
Object serialized = nmsChatSerializer.getConstructor(
|
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||||
String.class)
|
subtitleColor + ChatColor.translateAlternateColorCodes('&', this.subtitle));
|
||||||
.newInstance(subtitleColor +
|
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||||
ChatColor.translateAlternateColorCodes('&',
|
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||||
this.subtitle));
|
.newInstance(actions[1], serialized);
|
||||||
Object packet = TitleManager_1_11.packetTitle
|
|
||||||
.getConstructor(
|
|
||||||
new Class[]{TitleManager_1_11.packetActions,
|
|
||||||
chatBaseComponent}).newInstance(
|
|
||||||
actions[1], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -368,8 +307,8 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
chatBaseComponent).newInstance(actions[4], null);
|
.newInstance(actions[4], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -387,8 +326,8 @@ public class TitleManager_1_11 {
|
|||||||
Object handle = getHandle(player);
|
Object handle = getHandle(player);
|
||||||
Object connection = playerConnection.get(handle);
|
Object connection = playerConnection.get(handle);
|
||||||
Object[] actions = packetActions.getEnumConstants();
|
Object[] actions = packetActions.getEnumConstants();
|
||||||
Object packet = packetTitle.getConstructor(packetActions,
|
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||||
chatBaseComponent).newInstance(actions[5], null);
|
.newInstance(actions[5], null);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -396,8 +335,7 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES
|
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||||
.get(clazz) : clazz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||||
@ -408,15 +346,6 @@ public class TitleManager_1_11 {
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean equalsTypeArray(Class<?>[] a, Class<?>[] o) {
|
|
||||||
if (a.length != o.length)
|
|
||||||
return false;
|
|
||||||
for (int i = 0; i < a.length; i++)
|
|
||||||
if (!a[i].equals(o[i]) && !a[i].isAssignableFrom(o[i]))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getHandle(Player player) {
|
private Object getHandle(Player player) {
|
||||||
try {
|
try {
|
||||||
return methodPlayerGetHandle.invoke(player);
|
return methodPlayerGetHandle.invoke(player);
|
||||||
@ -426,8 +355,7 @@ public class TitleManager_1_11 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getMethod(String name, Class<?> clazz,
|
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||||
Class<?>... paramTypes) {
|
|
||||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||||
for (Method m : clazz.getMethods()) {
|
for (Method m : clazz.getMethods()) {
|
||||||
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||||
@ -465,7 +393,6 @@ public class TitleManager_1_11 {
|
|||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Field getField(Class<?> clazz, String name) {
|
private Field getField(Class<?> clazz, String name) {
|
||||||
try {
|
try {
|
||||||
Field field = clazz.getDeclaredField(name);
|
Field field = clazz.getDeclaredField(name);
|
||||||
@ -479,8 +406,7 @@ public class TitleManager_1_11 {
|
|||||||
|
|
||||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||||
for (Method m : clazz.getMethods())
|
for (Method m : clazz.getMethods())
|
||||||
if (m.getName().equals(name)
|
if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args,
|
||||||
&& (args.length == 0 || ClassListEqual(args,
|
|
||||||
m.getParameterTypes()))) {
|
m.getParameterTypes()))) {
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return m;
|
return m;
|
||||||
@ -504,22 +430,67 @@ public class TitleManager_1_11 {
|
|||||||
return titleColor;
|
return titleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the title color
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setTitleColor(ChatColor color) {
|
||||||
|
this.titleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public ChatColor getSubtitleColor() {
|
public ChatColor getSubtitleColor() {
|
||||||
return subtitleColor;
|
return subtitleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subtitle color
|
||||||
|
*
|
||||||
|
* @param color Chat color
|
||||||
|
*/
|
||||||
|
public void setSubtitleColor(ChatColor color) {
|
||||||
|
this.subtitleColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
public int getFadeInTime() {
|
public int getFadeInTime() {
|
||||||
return fadeInTime;
|
return fadeInTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade in time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeInTime(int time) {
|
||||||
|
this.fadeInTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public int getFadeOutTime() {
|
public int getFadeOutTime() {
|
||||||
return fadeOutTime;
|
return fadeOutTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title fade out time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setFadeOutTime(int time) {
|
||||||
|
this.fadeOutTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStayTime() {
|
public int getStayTime() {
|
||||||
return stayTime;
|
return stayTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set title stay time
|
||||||
|
*
|
||||||
|
* @param time Time
|
||||||
|
*/
|
||||||
|
public void setStayTime(int time) {
|
||||||
|
this.stayTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTicks() {
|
public boolean isTicks() {
|
||||||
return ticks;
|
return ticks;
|
||||||
}
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class BukkitBlockRegistry extends BlockRegistry<Material> {
|
||||||
|
|
||||||
|
public BukkitBlockRegistry(final Material... preInitializedItems) {
|
||||||
|
super(Material.class, preInitializedItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public PlotBlock getPlotBlock(@NonNull final Material item) {
|
||||||
|
return PlotBlock.get(item.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.chat.FancyMessage;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.ChatManager;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||||
|
|
||||||
|
@Override public FancyMessage builder() {
|
||||||
|
return new FancyMessage("");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void color(PlotMessage message, String color) {
|
||||||
|
message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void tooltip(PlotMessage message, PlotMessage... tooltips) {
|
||||||
|
List<FancyMessage> lines = new ArrayList<>();
|
||||||
|
for (PlotMessage tooltip : tooltips) {
|
||||||
|
lines.add(tooltip.$(this));
|
||||||
|
}
|
||||||
|
message.$(this).formattedTooltip(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void command(PlotMessage message, String command) {
|
||||||
|
message.$(this).command(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void text(PlotMessage message, String text) {
|
||||||
|
message.$(this).then(ChatColor.stripColor(text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void send(PlotMessage plotMessage, PlotPlayer player) {
|
||||||
|
if (player instanceof ConsolePlayer || !Settings.Chat.INTERACTIVE) {
|
||||||
|
player.sendMessage(plotMessage.$(this).toOldMessageFormat());
|
||||||
|
} else {
|
||||||
|
plotMessage.$(this).send(((BukkitPlayer) player).player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void suggest(PlotMessage plotMessage, String command) {
|
||||||
|
plotMessage.$(this).suggest(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,62 +1,25 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.object.entity.EntityWrapper;
|
||||||
import com.intellectualcrafters.plot.generator.AugmentedUtils;
|
import com.github.intellectualsites.plotsquared.bukkit.object.entity.ReplicatingEntityWrapper;
|
||||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.github.intellectualsites.plotsquared.plot.generator.AugmentedUtils;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import org.bukkit.*;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import org.bukkit.block.*;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
|
||||||
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
|
||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
|
||||||
import com.plotsquared.bukkit.object.entity.EntityWrapper;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.DyeColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Note;
|
|
||||||
import org.bukkit.SkullType;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Banner;
|
|
||||||
import org.bukkit.block.Beacon;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.BrewingStand;
|
|
||||||
import org.bukkit.block.CommandBlock;
|
|
||||||
import org.bukkit.block.CreatureSpawner;
|
|
||||||
import org.bukkit.block.Dispenser;
|
|
||||||
import org.bukkit.block.Dropper;
|
|
||||||
import org.bukkit.block.Furnace;
|
|
||||||
import org.bukkit.block.Hopper;
|
|
||||||
import org.bukkit.block.Jukebox;
|
|
||||||
import org.bukkit.block.NoteBlock;
|
|
||||||
import org.bukkit.block.Sign;
|
|
||||||
import org.bukkit.block.Skull;
|
|
||||||
import org.bukkit.block.banner.Pattern;
|
import org.bukkit.block.banner.Pattern;
|
||||||
import org.bukkit.entity.Animals;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.entity.Creature;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class BukkitChunkManager extends ChunkManager {
|
public class BukkitChunkManager extends ChunkManager {
|
||||||
|
|
||||||
@ -73,7 +36,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2, RegionWrapper r1, RegionWrapper r2) {
|
public static ContentMap swapChunk(World world1, World world2, Chunk pos1, Chunk pos2,
|
||||||
|
RegionWrapper r1, RegionWrapper r2) {
|
||||||
ContentMap map = new ContentMap();
|
ContentMap map = new ContentMap();
|
||||||
int relX = r2.minX - r1.minX;
|
int relX = r2.minX - r1.minX;
|
||||||
int relZ = r2.minZ - r1.minZ;
|
int relZ = r2.minZ - r1.minZ;
|
||||||
@ -95,29 +59,35 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
map.saveBlocks(world1, 256, sx, sz, relX, relZ, false);
|
map.saveBlocks(world1, 256, sx, sz, relX, relZ, false);
|
||||||
for (int y = 0; y < 256; y++) {
|
for (int y = 0; y < 256; y++) {
|
||||||
Block block1 = world1.getBlockAt(x, y, z);
|
Block block1 = world1.getBlockAt(x, y, z);
|
||||||
int id1 = block1.getTypeId();
|
// int id1 = block1.getTypeId();
|
||||||
byte data1 = block1.getData();
|
Material id1 = block1.getType();
|
||||||
|
BlockData data1 = block1.getBlockData();
|
||||||
|
// byte data1 = block1.getData();
|
||||||
int xx = x + relX;
|
int xx = x + relX;
|
||||||
int zz = z + relZ;
|
int zz = z + relZ;
|
||||||
Block block2 = world2.getBlockAt(xx, y, zz);
|
Block block2 = world2.getBlockAt(xx, y, zz);
|
||||||
int id2 = block2.getTypeId();
|
// int id2 = block2.getTypeId();
|
||||||
byte data2 = block2.getData();
|
Material id2 = block2.getType();
|
||||||
if (id1 == 0) {
|
BlockData data2 = block2.getBlockData();
|
||||||
if (id2 != 0) {
|
// byte data2 = block2.getData();
|
||||||
queue1.setBlock(x, y, z, (short) id2, data2);
|
if (id1 == Material.AIR) {
|
||||||
|
if (id2 != Material.AIR) {
|
||||||
|
queue1.setBlock(x, y, z, id2.name());
|
||||||
queue2.setBlock(xx, y, zz, (short) 0, (byte) 0);
|
queue2.setBlock(xx, y, zz, (short) 0, (byte) 0);
|
||||||
}
|
}
|
||||||
} else if (id2 == 0) {
|
} else if (id2 == Material.AIR) {
|
||||||
queue1.setBlock(x, y, z, (short) 0, (byte) 0);
|
queue1.setBlock(x, y, z, (short) 0, (byte) 0);
|
||||||
queue2.setBlock(xx, y, zz, (short) id1, data1);
|
queue2.setBlock(xx, y, zz, id1.name());
|
||||||
} else if (id1 == id2) {
|
} else if (id1 == id2) {
|
||||||
if (data1 != data2) {
|
if (data1 != data2) {
|
||||||
block1.setData(data2);
|
block1.setBlockData(data2);
|
||||||
block2.setData(data1);
|
block2.setBlockData(data1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
queue1.setBlock(x, y, z, (short) id2, data2);
|
queue1.setBlock(x, y, z, id2.name());
|
||||||
queue2.setBlock(xx, y, zz, (short) id1, data1);
|
queue2.setBlock(xx, y, zz, id1.name());
|
||||||
|
// queue1.setBlock(x, y, z, (short) id2, data2);
|
||||||
|
// queue2.setBlock(xx, y, zz, (short) id1, data1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +97,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Set<ChunkLoc> getChunkChunks(String world) {
|
||||||
public Set<ChunkLoc> getChunkChunks(String world) {
|
|
||||||
Set<ChunkLoc> chunks = super.getChunkChunks(world);
|
Set<ChunkLoc> chunks = super.getChunkChunks(world);
|
||||||
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
||||||
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||||
@ -140,12 +109,18 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean copyRegion(Location pos1, Location pos2, Location newPos, final Runnable whenDone) {
|
public boolean copyRegion(com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||||
|
com.github.intellectualsites.plotsquared.plot.object.Location pos2,
|
||||||
|
com.github.intellectualsites.plotsquared.plot.object.Location newPos,
|
||||||
|
final Runnable whenDone) {
|
||||||
final int relX = newPos.getX() - pos1.getX();
|
final int relX = newPos.getX() - pos1.getX();
|
||||||
final int relZ = newPos.getZ() - pos1.getZ();
|
final int relZ = newPos.getZ() - pos1.getZ();
|
||||||
Location pos4 = new Location(newPos.getWorld(), newPos.getX() + relX, 256, newPos.getZ() + relZ);
|
com.github.intellectualsites.plotsquared.plot.object.Location pos4 =
|
||||||
|
new com.github.intellectualsites.plotsquared.plot.object.Location(newPos.getWorld(),
|
||||||
|
newPos.getX() + relX, 256, newPos.getZ() + relZ);
|
||||||
|
|
||||||
final RegionWrapper region = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
final RegionWrapper region =
|
||||||
|
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||||
final String newWorldName = newWorld.getName();
|
final String newWorldName = newWorld.getName();
|
||||||
@ -153,8 +128,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
final ContentMap map = new ContentMap();
|
final ContentMap map = new ContentMap();
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
||||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||||
@Override
|
@Override public void run(int[] value) {
|
||||||
public void run(int[] value) {
|
|
||||||
int bx = value[2];
|
int bx = value[2];
|
||||||
int bz = value[3];
|
int bz = value[3];
|
||||||
int tx = value[4];
|
int tx = value[4];
|
||||||
@ -171,8 +145,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
|
for (Entry<PlotLoc, PlotBlock[]> entry : map.allBlocks.entrySet()) {
|
||||||
PlotLoc loc = entry.getKey();
|
PlotLoc loc = entry.getKey();
|
||||||
PlotBlock[] blocks = entry.getValue();
|
PlotBlock[] blocks = entry.getValue();
|
||||||
@ -185,8 +158,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
queue.enqueue();
|
queue.enqueue();
|
||||||
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
map.restoreBlocks(newWorld, 0, 0);
|
map.restoreBlocks(newWorld, 0, 0);
|
||||||
map.restoreEntities(newWorld, relX, relZ);
|
map.restoreEntities(newWorld, relX, relZ);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -197,8 +169,10 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean regenerateRegion(
|
||||||
public boolean regenerateRegion(final Location pos1, final Location pos2, final boolean ignoreAugment, final Runnable whenDone) {
|
final com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||||
|
final com.github.intellectualsites.plotsquared.plot.object.Location pos2,
|
||||||
|
final boolean ignoreAugment, final Runnable whenDone) {
|
||||||
final String world = pos1.getWorld();
|
final String world = pos1.getWorld();
|
||||||
|
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
@ -219,8 +193,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
||||||
final ChunkLoc chunk = chunks.remove(0);
|
final ChunkLoc chunk = chunks.remove(0);
|
||||||
@ -235,11 +208,11 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||||
RegionWrapper currentPlotClear = new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
RegionWrapper currentPlotClear =
|
||||||
|
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||||
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
queue.regenChunkSafe(chunk.x, chunk.z);
|
queue.regenChunkSafe(chunk.x, chunk.z);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -306,12 +279,11 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||||
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
AugmentedUtils.bypass(ignoreAugment, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||||
@Override
|
@Override public void run(ScopedLocalBlockQueue value) {
|
||||||
public void run(ScopedLocalBlockQueue value) {
|
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||||
Location min = value.getMin();
|
min = value.getMin();
|
||||||
int bx = min.getX();
|
int bx = min.getX();
|
||||||
int bz = min.getZ();
|
int bz = min.getZ();
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
@ -319,7 +291,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
PlotLoc loc = new PlotLoc(bx + x, bz + z);
|
PlotLoc loc = new PlotLoc(bx + x, bz + z);
|
||||||
PlotBlock[] ids = map.allBlocks.get(loc);
|
PlotBlock[] ids = map.allBlocks.get(loc);
|
||||||
if (ids != null) {
|
if (ids != null) {
|
||||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
for (int y = 0;
|
||||||
|
y < Math.min(128, ids.length); y++) {
|
||||||
PlotBlock id = ids[y];
|
PlotBlock id = ids[y];
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
value.setBlock(x, y, z, id);
|
value.setBlock(x, y, z, id);
|
||||||
@ -327,7 +300,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
value.setBlock(x, y, z, 0, (byte) 0);
|
value.setBlock(x, y, z, 0, (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
for (int y = Math.min(128, ids.length);
|
||||||
|
y < ids.length; y++) {
|
||||||
PlotBlock id = ids[y];
|
PlotBlock id = ids[y];
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
value.setBlock(x, y, z, id);
|
value.setBlock(x, y, z, id);
|
||||||
@ -354,7 +328,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearAllEntities(Location pos1, Location pos2) {
|
public void clearAllEntities(com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||||
|
com.github.intellectualsites.plotsquared.plot.object.Location pos2) {
|
||||||
String world = pos1.getWorld();
|
String world = pos1.getWorld();
|
||||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||||
int bx = pos1.getX();
|
int bx = pos1.getX();
|
||||||
@ -364,26 +339,27 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
if (!(entity instanceof Player)) {
|
if (!(entity instanceof Player)) {
|
||||||
org.bukkit.Location location = entity.getLocation();
|
org.bukkit.Location location = entity.getLocation();
|
||||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz && location.getZ() <= tz) {
|
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz
|
||||||
|
&& location.getZ() <= tz) {
|
||||||
|
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
entity.remove();
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||||
public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
|
||||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override
|
||||||
@Override
|
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
|
||||||
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe) {
|
final boolean safe) {
|
||||||
if (!PS.get().isMainThread(Thread.currentThread())) {
|
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation") @Override public void run() {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -392,10 +368,15 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void swap(com.github.intellectualsites.plotsquared.plot.object.Location bot1,
|
||||||
public void swap(Location bot1, Location top1, Location bot2, Location top2, final Runnable whenDone) {
|
com.github.intellectualsites.plotsquared.plot.object.Location top1,
|
||||||
RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
com.github.intellectualsites.plotsquared.plot.object.Location bot2,
|
||||||
RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
com.github.intellectualsites.plotsquared.plot.object.Location top2,
|
||||||
|
final Runnable whenDone) {
|
||||||
|
RegionWrapper region1 =
|
||||||
|
new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
|
||||||
|
RegionWrapper region2 =
|
||||||
|
new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
|
||||||
final World world1 = Bukkit.getWorld(bot1.getWorld());
|
final World world1 = Bukkit.getWorld(bot1.getWorld());
|
||||||
World world2 = Bukkit.getWorld(bot2.getWorld());
|
World world2 = Bukkit.getWorld(bot2.getWorld());
|
||||||
|
|
||||||
@ -412,8 +393,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
GlobalBlockQueue.IMP.addTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
for (ContentMap map : maps) {
|
for (ContentMap map : maps) {
|
||||||
map.restoreBlocks(world1, 0, 0);
|
map.restoreBlocks(world1, 0, 0);
|
||||||
map.restoreEntities(world1, 0, 0);
|
map.restoreEntities(world1, 0, 0);
|
||||||
@ -423,17 +403,17 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int[] countEntities(Plot plot) {
|
||||||
public int[] countEntities(Plot plot) {
|
|
||||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
|
||||||
|
< 1000)) {
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
PlotArea area = plot.getArea();
|
PlotArea area = plot.getArea();
|
||||||
World world = BukkitUtil.getWorld(area.worldname);
|
World world = BukkitUtil.getWorld(area.worldname);
|
||||||
|
|
||||||
Location bot = plot.getBottomAbs();
|
com.github.intellectualsites.plotsquared.plot.object.Location bot = plot.getBottomAbs();
|
||||||
Location top = plot.getTopAbs();
|
com.github.intellectualsites.plotsquared.plot.object.Location top = plot.getTopAbs();
|
||||||
int bx = bot.getX() >> 4;
|
int bx = bot.getX() >> 4;
|
||||||
int bz = bot.getZ() >> 4;
|
int bz = bot.getZ() >> 4;
|
||||||
|
|
||||||
@ -691,7 +671,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
|
|
||||||
public void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
public void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
Location loc = BukkitUtil.getLocation(entity);
|
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||||
|
BukkitUtil.getLocation(entity);
|
||||||
int x = loc.getX();
|
int x = loc.getX();
|
||||||
int z = loc.getZ();
|
int z = loc.getZ();
|
||||||
if (isIn(region, x, z)) {
|
if (isIn(region, x, z)) {
|
||||||
@ -700,14 +681,17 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
if (entity.getVehicle() != null) {
|
if (entity.getVehicle() != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
EntityWrapper wrap = new EntityWrapper(entity, (short) 2);
|
EntityWrapper wrap = new ReplicatingEntityWrapper(entity, (short) 2);
|
||||||
|
wrap.saveEntity();
|
||||||
this.entities.add(wrap);
|
this.entities.add(wrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ, boolean delete) {
|
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ,
|
||||||
|
boolean delete) {
|
||||||
for (Entity entity : chunk.getEntities()) {
|
for (Entity entity : chunk.getEntities()) {
|
||||||
Location loc = BukkitUtil.getLocation(entity);
|
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||||
|
BukkitUtil.getLocation(entity);
|
||||||
int x = loc.getX();
|
int x = loc.getX();
|
||||||
int z = loc.getZ();
|
int z = loc.getZ();
|
||||||
if (!isIn(region, x, z)) {
|
if (!isIn(region, x, z)) {
|
||||||
@ -716,9 +700,10 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
if (entity.getVehicle() != null) {
|
if (entity.getVehicle() != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
EntityWrapper wrap = new EntityWrapper(entity, (short) 2);
|
EntityWrapper wrap = new ReplicatingEntityWrapper(entity, (short) 2);
|
||||||
wrap.x += offsetX;
|
wrap.x += offsetX;
|
||||||
wrap.z += offsetZ;
|
wrap.z += offsetZ;
|
||||||
|
wrap.saveEntity();
|
||||||
this.entities.add(wrap);
|
this.entities.add(wrap);
|
||||||
if (delete) {
|
if (delete) {
|
||||||
if (!(entity instanceof Player)) {
|
if (!(entity instanceof Player)) {
|
||||||
@ -733,7 +718,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
try {
|
try {
|
||||||
entity.spawn(world, xOffset, zOffset);
|
entity.spawn(world, xOffset, zOffset);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("Failed to restore entity (e): " + e.toString());
|
PlotSquared.debug("Failed to restore entity (e): " + e.toString());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -743,26 +728,30 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
public void restoreBlocks(World world, int xOffset, int zOffset) {
|
public void restoreBlocks(World world, int xOffset, int zOffset) {
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.chestContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof InventoryHolder) {
|
if (state instanceof InventoryHolder) {
|
||||||
InventoryHolder chest = (InventoryHolder) state;
|
InventoryHolder chest = (InventoryHolder) state;
|
||||||
chest.getInventory().setContents(blockLocEntry.getValue());
|
chest.getInventory().setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate chest: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate chest: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate chest (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, String[]> blockLocEntry : this.signContents.entrySet()) {
|
for (Entry<BlockLoc, String[]> blockLocEntry : this.signContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Sign) {
|
if (state instanceof Sign) {
|
||||||
Sign sign = (Sign) state;
|
Sign sign = (Sign) state;
|
||||||
@ -773,95 +762,105 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug(
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate sign: " + (
|
||||||
"&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
.getKey().y
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
+ ',' + (
|
|
||||||
blockLocEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException ignored) {
|
} catch (IndexOutOfBoundsException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate sign: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate sign: " + (
|
||||||
+ ',' + (
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
blockLocEntry.getKey().z + zOffset));
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dispenserContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dispenserContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Dispenser) {
|
if (state instanceof Dispenser) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dropperContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.dropperContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Dropper) {
|
if (state instanceof Dropper) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate dispenser: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate dispenser (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.beaconContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.beaconContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Beacon) {
|
if (state instanceof Beacon) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate beacon: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate beacon (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Material> blockLocMaterialEntry : this.jukeboxDisc.entrySet()) {
|
for (Entry<BlockLoc, Material> blockLocMaterialEntry : this.jukeboxDisc.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset,
|
||||||
world.getBlockAt(blockLocMaterialEntry.getKey().x + xOffset, blockLocMaterialEntry.getKey().y, blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().y,
|
||||||
.getKey().z + zOffset);
|
blockLocMaterialEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Jukebox) {
|
if (state instanceof Jukebox) {
|
||||||
((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue());
|
((Jukebox) state).setPlaying(blockLocMaterialEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore jukebox: " + (blockLocMaterialEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to restore jukebox: " + (
|
||||||
+ blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().x + xOffset) + ','
|
||||||
.getKey().y + ',' + (
|
+ blockLocMaterialEntry.getKey().y + ',' + (
|
||||||
blockLocMaterialEntry.getKey().z + zOffset));
|
blockLocMaterialEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (blockLocMaterialEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate jukebox (e): " + (
|
||||||
+ blockLocMaterialEntry
|
blockLocMaterialEntry.getKey().x + xOffset) + ',' + blockLocMaterialEntry
|
||||||
.getKey().y + ',' + (
|
.getKey().y + ',' + (blockLocMaterialEntry.getKey().z + zOffset));
|
||||||
blockLocMaterialEntry.getKey().z + zOffset));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Object[]> blockLocEntry : this.skullData.entrySet()) {
|
for (Entry<BlockLoc, Object[]> blockLocEntry : this.skullData.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Skull) {
|
if (state instanceof Skull) {
|
||||||
Object[] data = blockLocEntry.getValue();
|
Object[] data = blockLocEntry.getValue();
|
||||||
@ -872,193 +871,221 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
((Skull) state).setSkullType((SkullType) data[3]);
|
((Skull) state).setSkullType((SkullType) data[3]);
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore skull: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to restore skull: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate skull (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.hopperContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.hopperContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Hopper) {
|
if (state instanceof Hopper) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate hopper: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate hopper (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Note> blockLocNoteEntry : this.noteBlockContents.entrySet()) {
|
for (Entry<BlockLoc, Note> blockLocNoteEntry : this.noteBlockContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocNoteEntry.getKey().x + xOffset,
|
||||||
blockLocNoteEntry.getKey().x + xOffset, blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset);
|
blockLocNoteEntry.getKey().y, blockLocNoteEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof NoteBlock) {
|
if (state instanceof NoteBlock) {
|
||||||
((NoteBlock) state).setNote(blockLocNoteEntry.getValue());
|
((NoteBlock) state).setNote(blockLocNoteEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate note block: " + (blockLocNoteEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocNoteEntry
|
"&c[WARN] Plot clear failed to regenerate note block: " + (
|
||||||
.getKey().y + ',' + (
|
blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry
|
||||||
blockLocNoteEntry.getKey().z + zOffset));
|
.getKey().y + ',' + (blockLocNoteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate note block (e): " + (blockLocNoteEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocNoteEntry
|
"&c[WARN] Plot clear failed to regenerate note block (e): " + (
|
||||||
.getKey().y + ',' + (
|
blockLocNoteEntry.getKey().x + xOffset) + ',' + blockLocNoteEntry
|
||||||
blockLocNoteEntry.getKey().z + zOffset));
|
.getKey().y + ',' + (blockLocNoteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Short> blockLocShortEntry : this.brewTime.entrySet()) {
|
for (Entry<BlockLoc, Short> blockLocShortEntry : this.brewTime.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocShortEntry.getKey().x + xOffset,
|
||||||
blockLocShortEntry.getKey().x + xOffset, blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset);
|
blockLocShortEntry.getKey().y, blockLocShortEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof BrewingStand) {
|
if (state instanceof BrewingStand) {
|
||||||
((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue());
|
((BrewingStand) state).setBrewingTime(blockLocShortEntry.getValue());
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking: " + (blockLocShortEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocShortEntry
|
"&c[WARN] Plot clear failed to restore brewing stand cooking: " + (
|
||||||
.getKey().y + ',' + (
|
blockLocShortEntry.getKey().x + xOffset) + ',' + blockLocShortEntry
|
||||||
blockLocShortEntry.getKey().z + zOffset));
|
.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (blockLocShortEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocShortEntry.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
"&c[WARN] Plot clear failed to restore brewing stand cooking (e): " + (
|
||||||
|
blockLocShortEntry.getKey().x + xOffset) + ',' + blockLocShortEntry
|
||||||
|
.getKey().y + ',' + (blockLocShortEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, EntityType> blockLocEntityTypeEntry : this.spawnerData.entrySet()) {
|
for (Entry<BlockLoc, EntityType> blockLocEntityTypeEntry : this.spawnerData
|
||||||
|
.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset,
|
||||||
world.getBlockAt(blockLocEntityTypeEntry.getKey().x + xOffset, blockLocEntityTypeEntry.getKey().y, blockLocEntityTypeEntry
|
blockLocEntityTypeEntry.getKey().y,
|
||||||
.getKey().z + zOffset);
|
blockLocEntityTypeEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof CreatureSpawner) {
|
if (state instanceof CreatureSpawner) {
|
||||||
((CreatureSpawner) state).setSpawnedType(blockLocEntityTypeEntry.getValue());
|
((CreatureSpawner) state)
|
||||||
|
.setSpawnedType(blockLocEntityTypeEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore spawner type: " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to restore spawner type: " + (
|
||||||
+ blockLocEntityTypeEntry
|
blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
||||||
.getKey().y + ',' + (
|
+ blockLocEntityTypeEntry.getKey().y + ',' + (
|
||||||
blockLocEntityTypeEntry.getKey().z + zOffset));
|
blockLocEntityTypeEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to restore spawner type (e): " + (
|
||||||
+ blockLocEntityTypeEntry.getKey().y + ',' + (blockLocEntityTypeEntry.getKey().z + zOffset));
|
blockLocEntityTypeEntry.getKey().x + xOffset) + ','
|
||||||
|
+ blockLocEntityTypeEntry.getKey().y + ',' + (
|
||||||
|
blockLocEntityTypeEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, String> blockLocStringEntry : this.cmdData.entrySet()) {
|
for (Entry<BlockLoc, String> blockLocStringEntry : this.cmdData.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocStringEntry.getKey().x + xOffset,
|
||||||
blockLocStringEntry.getKey().x + xOffset, blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset);
|
blockLocStringEntry.getKey().y, blockLocStringEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof CommandBlock) {
|
if (state instanceof CommandBlock) {
|
||||||
((CommandBlock) state).setCommand(blockLocStringEntry.getValue());
|
((CommandBlock) state).setCommand(blockLocStringEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore command block: " + (blockLocStringEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocStringEntry
|
"&c[WARN] Plot clear failed to restore command block: " + (
|
||||||
.getKey().y + ',' + (
|
blockLocStringEntry.getKey().x + xOffset) + ','
|
||||||
|
+ blockLocStringEntry.getKey().y + ',' + (
|
||||||
blockLocStringEntry.getKey().z + zOffset));
|
blockLocStringEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to restore command block (e): " + (blockLocStringEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocStringEntry
|
"&c[WARN] Plot clear failed to restore command block (e): " + (
|
||||||
.getKey().y + ',' + (
|
blockLocStringEntry.getKey().x + xOffset) + ',' + blockLocStringEntry
|
||||||
blockLocStringEntry.getKey().z + zOffset));
|
.getKey().y + ',' + (blockLocStringEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.brewingStandContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.brewingStandContents
|
||||||
|
.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof BrewingStand) {
|
if (state instanceof BrewingStand) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand: " + (blockLocEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocEntry
|
"&c[WARN] Plot clear failed to regenerate brewing stand: " + (
|
||||||
.getKey().y + ',' + (
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
blockLocEntry.getKey().z
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
+ zOffset));
|
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (blockLocEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug(
|
||||||
+ blockLocEntry.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
"&c[WARN] Plot clear failed to regenerate brewing stand (e): " + (
|
||||||
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, Short[]> blockLocEntry : this.furnaceTime.entrySet()) {
|
for (Entry<BlockLoc, Short[]> blockLocEntry : this.furnaceTime.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Furnace) {
|
if (state instanceof Furnace) {
|
||||||
Short[] time = blockLocEntry.getValue();
|
Short[] time = blockLocEntry.getValue();
|
||||||
((Furnace) state).setBurnTime(time[0]);
|
((Furnace) state).setBurnTime(time[0]);
|
||||||
((Furnace) state).setCookTime(time[1]);
|
((Furnace) state).setCookTime(time[1]);
|
||||||
} else {
|
} else {
|
||||||
PS.debug(
|
PlotSquared.debug(
|
||||||
"&c[WARN] Plot clear failed to restore furnace cooking: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
"&c[WARN] Plot clear failed to restore furnace cooking: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug(
|
PlotSquared.debug(
|
||||||
"&c[WARN] Plot clear failed to restore furnace cooking (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
"&c[WARN] Plot clear failed to restore furnace cooking (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.furnaceContents.entrySet()) {
|
for (Entry<BlockLoc, ItemStack[]> blockLocEntry : this.furnaceContents.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block =
|
Block block = world
|
||||||
world.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y, blockLocEntry.getKey().z + zOffset);
|
.getBlockAt(blockLocEntry.getKey().x + xOffset, blockLocEntry.getKey().y,
|
||||||
|
blockLocEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Furnace) {
|
if (state instanceof Furnace) {
|
||||||
((InventoryHolder) state).getInventory().setContents(blockLocEntry.getValue());
|
((InventoryHolder) state).getInventory()
|
||||||
|
.setContents(blockLocEntry.getValue());
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate furnace: " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y
|
||||||
|
+ ',' + (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (IllegalArgumentException ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate furnace (e): " + (
|
||||||
.getKey().y + ',' + (blockLocEntry.getKey().z + zOffset));
|
blockLocEntry.getKey().x + xOffset) + ',' + blockLocEntry.getKey().y + ','
|
||||||
|
+ (blockLocEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<BlockLoc, DyeColor> blockLocByteEntry : this.bannerBase.entrySet()) {
|
for (Entry<BlockLoc, DyeColor> blockLocByteEntry : this.bannerBase.entrySet()) {
|
||||||
try {
|
try {
|
||||||
Block block = world.getBlockAt(
|
Block block = world.getBlockAt(blockLocByteEntry.getKey().x + xOffset,
|
||||||
blockLocByteEntry.getKey().x + xOffset, blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset);
|
blockLocByteEntry.getKey().y, blockLocByteEntry.getKey().z + zOffset);
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
if (state instanceof Banner) {
|
if (state instanceof Banner) {
|
||||||
Banner banner = (Banner) state;
|
Banner banner = (Banner) state;
|
||||||
DyeColor base = blockLocByteEntry.getValue();
|
DyeColor base = blockLocByteEntry.getValue();
|
||||||
List<Pattern> patterns = this.bannerPatterns.get(blockLocByteEntry.getKey());
|
List<Pattern> patterns =
|
||||||
|
this.bannerPatterns.get(blockLocByteEntry.getKey());
|
||||||
banner.setBaseColor(base);
|
banner.setBaseColor(base);
|
||||||
banner.setPatterns(patterns);
|
banner.setPatterns(patterns);
|
||||||
state.update(true);
|
state.update(true);
|
||||||
} else {
|
} else {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate banner: " + (blockLocByteEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate banner: " + (
|
||||||
+ blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
blockLocByteEntry.getKey().x + xOffset) + ',' + blockLocByteEntry
|
||||||
|
.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (blockLocByteEntry.getKey().x + xOffset) + ','
|
PlotSquared.debug("&c[WARN] Plot clear failed to regenerate banner (e): " + (
|
||||||
+ blockLocByteEntry.getKey().y + ',' + (blockLocByteEntry.getKey().z + zOffset));
|
blockLocByteEntry.getKey().x + xOffset) + ',' + blockLocByteEntry.getKey().y
|
||||||
|
+ ',' + (blockLocByteEntry.getKey().z + zOffset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ, boolean storeNormal) {
|
public void saveBlocks(World world, int maxY, int x, int z, int offsetX, int offsetZ,
|
||||||
|
boolean storeNormal) {
|
||||||
maxY = Math.min(255, maxY);
|
maxY = Math.min(255, maxY);
|
||||||
PlotBlock[] ids;
|
PlotBlock[] ids;
|
||||||
if (storeNormal) {
|
if (storeNormal) {
|
||||||
@ -1072,7 +1099,7 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
if (storeNormal) {
|
if (storeNormal) {
|
||||||
int typeId = id.getId();
|
int typeId = id.getId();
|
||||||
if (typeId == 0) {
|
if (typeId == 0) {
|
||||||
ids[y] = PlotBlock.EVERYTHING;
|
ids[y] = StringPlotBlock.EVERYTHING;
|
||||||
} else {
|
} else {
|
||||||
ids[y] = PlotBlock.get((short) typeId, block.getData());
|
ids[y] = PlotBlock.get((short) typeId, block.getData());
|
||||||
}
|
}
|
||||||
@ -1082,7 +1109,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ);
|
BlockLoc bl = new BlockLoc(x + offsetX, y, z + offsetZ);
|
||||||
if (block.getState() instanceof InventoryHolder) {
|
if (block.getState() instanceof InventoryHolder) {
|
||||||
InventoryHolder inventoryHolder = (InventoryHolder) block.getState();
|
InventoryHolder inventoryHolder = (InventoryHolder) block.getState();
|
||||||
ItemStack[] inventory = inventoryHolder.getInventory().getContents().clone();
|
ItemStack[] inventory =
|
||||||
|
inventoryHolder.getInventory().getContents().clone();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case CHEST:
|
case CHEST:
|
||||||
this.chestContents.put(bl, inventory);
|
this.chestContents.put(bl, inventory);
|
||||||
@ -1105,15 +1133,17 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
this.brewTime.put(bl, time);
|
this.brewTime.put(bl, time);
|
||||||
}
|
}
|
||||||
ItemStack[] invBre = brewingStand.getInventory().getContents().clone();
|
ItemStack[] invBre =
|
||||||
|
brewingStand.getInventory().getContents().clone();
|
||||||
this.brewingStandContents.put(bl, invBre);
|
this.brewingStandContents.put(bl, invBre);
|
||||||
break;
|
break;
|
||||||
case FURNACE:
|
case FURNACE:
|
||||||
case BURNING_FURNACE:
|
case LEGACY_BURNING_FURNACE:
|
||||||
Furnace furnace = (Furnace) inventoryHolder;
|
Furnace furnace = (Furnace) inventoryHolder;
|
||||||
short burn = furnace.getBurnTime();
|
short burn = furnace.getBurnTime();
|
||||||
short cook = furnace.getCookTime();
|
short cook = furnace.getCookTime();
|
||||||
ItemStack[] invFur = furnace.getInventory().getContents().clone();
|
ItemStack[] invFur =
|
||||||
|
furnace.getInventory().getContents().clone();
|
||||||
this.furnaceContents.put(bl, invFur);
|
this.furnaceContents.put(bl, invFur);
|
||||||
if (cook != 0) {
|
if (cook != 0) {
|
||||||
this.furnaceTime.put(bl, new Short[] {burn, cook});
|
this.furnaceTime.put(bl, new Short[] {burn, cook});
|
||||||
@ -1144,7 +1174,8 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
}
|
}
|
||||||
} else if (block.getState() instanceof Skull) {
|
} else if (block.getState() instanceof Skull) {
|
||||||
Skull skull = (Skull) block.getState();
|
Skull skull = (Skull) block.getState();
|
||||||
this.skullData.put(bl, new Object[]{skull.hasOwner(), skull.getOwner(), skull.getRotation(), skull.getSkullType()});
|
this.skullData.put(bl, new Object[] {skull.hasOwner(), skull.getOwner(),
|
||||||
|
skull.getRotation(), skull.getSkullType()});
|
||||||
} else if (block.getState() instanceof Banner) {
|
} else if (block.getState() instanceof Banner) {
|
||||||
Banner banner = (Banner) block.getState();
|
Banner banner = (Banner) block.getState();
|
||||||
DyeColor base = banner.getBaseColor();
|
DyeColor base = banner.getBaseColor();
|
||||||
@ -1153,9 +1184,9 @@ public class BukkitChunkManager extends ChunkManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PS.debug("------------ FAILED TO DO SOMETHING --------");
|
PlotSquared.debug("------------ FAILED TO DO SOMETHING --------");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("------------ but we caught it ^ --------");
|
PlotSquared.debug("------------ but we caught it ^ --------");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +1,10 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
import com.github.intellectualsites.plotsquared.bukkit.commands.DebugUUID;
|
||||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
|
||||||
import com.plotsquared.bukkit.commands.DebugUUID;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
|
||||||
import org.bukkit.command.ProxiedCommandSender;
|
|
||||||
import org.bukkit.command.RemoteConsoleCommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -25,11 +19,13 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) {
|
public boolean onCommand(CommandSender commandSender, Command command, String commandLabel,
|
||||||
|
String[] args) {
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args);
|
||||||
}
|
}
|
||||||
if (commandSender instanceof ConsoleCommandSender || commandSender instanceof ProxiedCommandSender
|
if (commandSender instanceof ConsoleCommandSender
|
||||||
|
|| commandSender instanceof ProxiedCommandSender
|
||||||
|| commandSender instanceof RemoteConsoleCommandSender) {
|
|| commandSender instanceof RemoteConsoleCommandSender) {
|
||||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), args);
|
||||||
}
|
}
|
||||||
@ -37,7 +33,8 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s,
|
||||||
|
String[] args) {
|
||||||
if (!(commandSender instanceof Player)) {
|
if (!(commandSender instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import com.intellectualcrafters.plot.util.EconHandler;
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -24,7 +24,8 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean setupPermissions() {
|
private boolean setupPermissions() {
|
||||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
RegisteredServiceProvider<Permission> permissionProvider =
|
||||||
|
Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
if (permissionProvider != null) {
|
if (permissionProvider != null) {
|
||||||
this.perms = permissionProvider.getProvider();
|
this.perms = permissionProvider.getProvider();
|
||||||
}
|
}
|
||||||
@ -35,15 +36,15 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
RegisteredServiceProvider<Economy> economyProvider =
|
||||||
|
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
if (economyProvider != null) {
|
if (economyProvider != null) {
|
||||||
this.econ = economyProvider.getProvider();
|
this.econ = economyProvider.getProvider();
|
||||||
}
|
}
|
||||||
return this.econ != null;
|
return this.econ != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public double getMoney(PlotPlayer player) {
|
||||||
public double getMoney(PlotPlayer player) {
|
|
||||||
double bal = super.getMoney(player);
|
double bal = super.getMoney(player);
|
||||||
if (Double.isNaN(bal)) {
|
if (Double.isNaN(bal)) {
|
||||||
return this.econ.getBalance(((BukkitPlayer) player).player);
|
return this.econ.getBalance(((BukkitPlayer) player).player);
|
||||||
@ -51,28 +52,23 @@ public class BukkitEconHandler extends EconHandler {
|
|||||||
return bal;
|
return bal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void withdrawMoney(PlotPlayer player, double amount) {
|
||||||
public void withdrawMoney(PlotPlayer player, double amount) {
|
|
||||||
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void depositMoney(PlotPlayer player, double amount) {
|
||||||
public void depositMoney(PlotPlayer player, double amount) {
|
|
||||||
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void depositMoney(OfflinePlotPlayer player, double amount) {
|
||||||
public void depositMoney(OfflinePlotPlayer player, double amount) {
|
|
||||||
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean hasPermission(String world, String player, String perm) {
|
||||||
public boolean hasPermission(String world, String player, String perm) {
|
|
||||||
return this.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 this.econ.getBalance(player.getName());
|
return this.econ.getBalance(player.getName());
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +1,10 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.github.intellectualsites.plotsquared.bukkit.events.*;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.Rating;
|
|
||||||
import com.intellectualcrafters.plot.util.EventUtil;
|
|
||||||
import com.plotsquared.bukkit.events.*;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
@ -34,89 +28,74 @@ public class BukkitEventUtil extends EventUtil {
|
|||||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callClaim(PlotPlayer player, Plot plot, 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(PlotPlayer player, Location from, 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 callComponentSet(Plot plot, String component) {
|
||||||
public boolean callComponentSet(Plot plot, String component) {
|
|
||||||
return callEvent(new PlotComponentSetEvent(plot, component));
|
return callEvent(new PlotComponentSetEvent(plot, component));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callClear(Plot plot) {
|
||||||
public boolean callClear(Plot plot) {
|
|
||||||
return callEvent(new PlotClearEvent(plot));
|
return callEvent(new PlotClearEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void callDelete(Plot plot) {
|
||||||
public void callDelete(Plot plot) {
|
|
||||||
callEvent(new PlotDeleteEvent(plot));
|
callEvent(new PlotDeleteEvent(plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callFlagAdd(Flag flag, 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(Flag<?> flag, Plot plot, Object value) {
|
||||||
public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
|
||||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
|
||||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callUnlink(PlotArea area, 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(PlotPlayer player, 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(PlotPlayer player, 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(PlotPlayer initiator, Plot plot, UUID player, 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(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||||
public void callTrusted(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 void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||||
public void callMember(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 boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID oldOwner, UUID newOwner, boolean hasOldOwner) {
|
public boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID oldOwner, UUID newOwner,
|
||||||
return callEvent(new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner));
|
boolean hasOldOwner) {
|
||||||
|
return callEvent(
|
||||||
|
new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
||||||
public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
|
||||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override @Nullable public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||||
@Nullable
|
|
||||||
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
|
||||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
@ -1,17 +1,17 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.MathMan;
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||||
import com.intellectualcrafters.plot.util.expiry.PlotAnalysis;
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -26,8 +26,8 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class BukkitHybridUtils extends HybridUtils {
|
public class BukkitHybridUtils extends HybridUtils {
|
||||||
|
|
||||||
@Override
|
@Override public void analyzeRegion(final String world, final RegionWrapper region,
|
||||||
public void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone) {
|
final RunnableVal<PlotAnalysis> whenDone) {
|
||||||
// int diff, int variety, int vertices, int rotation, int height_sd
|
// int diff, int variety, int vertices, int rotation, int height_sd
|
||||||
/*
|
/*
|
||||||
* diff: compare to base by looping through all blocks
|
* diff: compare to base by looping through all blocks
|
||||||
@ -41,8 +41,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
final ChunkGenerator gen = worldObj.getGenerator();
|
final ChunkGenerator gen = worldObj.getGenerator();
|
||||||
@ -50,12 +49,10 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
|
||||||
@Override
|
@Override public void setBiome(int a, int b, Biome c) {
|
||||||
public void setBiome(int a, int b, Biome c) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Biome getBiome(int a, int b) {
|
||||||
public Biome getBiome(int a, int b) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -82,15 +79,14 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
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 public void run() {
|
||||||
public void run() {
|
|
||||||
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
||||||
@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]
|
||||||
int X = value[0];
|
int X = value[0];
|
||||||
int Z = value[1];
|
int Z = value[1];
|
||||||
short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
short[][] result =
|
||||||
|
gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
|
||||||
int xb = (X << 4) - bx;
|
int xb = (X << 4) - bx;
|
||||||
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++) {
|
||||||
@ -125,11 +121,9 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
int size = width * length;
|
int size = width * length;
|
||||||
int[] changes = new int[size];
|
int[] changes = new int[size];
|
||||||
int[] faces = new int[size];
|
int[] faces = new int[size];
|
||||||
@ -151,7 +145,8 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
} else {
|
} else {
|
||||||
// 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]++;
|
||||||
}
|
}
|
||||||
@ -172,12 +167,15 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Material material = Material.getMaterial(now);
|
Material material =
|
||||||
|
Material.getMaterial(now);
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
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)) {
|
||||||
data[i]++;
|
data[i]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,11 +197,14 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
analysis.air = (int) (MathMan.getMean(air) * 100);
|
analysis.air = (int) (MathMan.getMean(air) * 100);
|
||||||
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
||||||
|
|
||||||
analysis.changes_sd = (int) MathMan.getSD(changes, analysis.changes);
|
analysis.changes_sd =
|
||||||
analysis.faces_sd = (int) MathMan.getSD(faces, analysis.faces);
|
(int) MathMan.getSD(changes, analysis.changes);
|
||||||
|
analysis.faces_sd =
|
||||||
|
(int) MathMan.getSD(faces, analysis.faces);
|
||||||
analysis.data_sd = (int) MathMan.getSD(data, analysis.data);
|
analysis.data_sd = (int) MathMan.getSD(data, analysis.data);
|
||||||
analysis.air_sd = (int) MathMan.getSD(air, analysis.air);
|
analysis.air_sd = (int) MathMan.getSD(air, analysis.air);
|
||||||
analysis.variety_sd = (int) MathMan.getSD(variety, analysis.variety);
|
analysis.variety_sd =
|
||||||
|
(int) MathMan.getSD(variety, analysis.variety);
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
whenDone.value = analysis;
|
whenDone.value = analysis;
|
||||||
@ -219,8 +220,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
MainUtil.initCache();
|
MainUtil.initCache();
|
||||||
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
|
||||||
|
|
||||||
@Override
|
@Override public void run(int[] value) {
|
||||||
public void run(int[] value) {
|
|
||||||
int X = value[0];
|
int X = value[0];
|
||||||
int Z = value[1];
|
int Z = value[1];
|
||||||
worldObj.loadChunk(X, Z);
|
worldObj.loadChunk(X, Z);
|
||||||
@ -269,8 +269,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
|||||||
worldObj.unloadChunkRequest(X, Z, true);
|
worldObj.unloadChunkRequest(X, Z, true);
|
||||||
}
|
}
|
||||||
}, new Runnable() {
|
}, new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
TaskManager.runTaskAsync(run);
|
TaskManager.runTaskAsync(run);
|
||||||
}
|
}
|
||||||
}, 5);
|
}, 5);
|
@ -1,12 +1,13 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotItemStack;
|
||||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
@ -23,7 +24,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ItemStack stack = new ItemStack(item.id, item.amount, item.data);
|
ItemStack stack = new ItemStack(BukkitUtil.getMaterial(item.getPlotBlock()), item.amount);
|
||||||
ItemMeta meta = null;
|
ItemMeta meta = null;
|
||||||
if (item.name != null) {
|
if (item.name != null) {
|
||||||
meta = stack.getItemMeta();
|
meta = stack.getItemMeta();
|
||||||
@ -45,8 +46,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void open(PlotInventory inv) {
|
||||||
public void open(PlotInventory inv) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||||
PlotItemStack[] items = inv.getItems();
|
PlotItemStack[] items = inv.getItems();
|
||||||
@ -60,8 +60,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
bp.player.openInventory(inventory);
|
bp.player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void close(PlotInventory inv) {
|
||||||
public void close(PlotInventory inv) {
|
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -70,8 +69,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
bp.player.closeInventory();
|
bp.player.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||||
public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
InventoryView opened = bp.player.getOpenInventory();
|
InventoryView opened = bp.player.getOpenInventory();
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
@ -85,7 +83,8 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
if (item == null) {
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int id = item.getTypeId();
|
// int id = item.getTypeId();
|
||||||
|
Material id = item.getType();
|
||||||
short data = item.getDurability();
|
short data = item.getDurability();
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
String name = null;
|
String name = null;
|
||||||
@ -100,11 +99,10 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
lore = itemLore.toArray(new String[itemLore.size()]);
|
lore = itemLore.toArray(new String[itemLore.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new PlotItemStack(id, data, amount, name, lore);
|
return new PlotItemStack(id.name(), amount, name, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
||||||
public PlotItemStack[] getItems(PlotPlayer player) {
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) player;
|
BukkitPlayer bp = (BukkitPlayer) player;
|
||||||
PlayerInventory inv = bp.player.getInventory();
|
PlayerInventory inv = bp.player.getInventory();
|
||||||
PlotItemStack[] items = new PlotItemStack[36];
|
PlotItemStack[] items = new PlotItemStack[36];
|
||||||
@ -114,13 +112,13 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean isOpen(PlotInventory inv) {
|
||||||
public boolean isOpen(PlotInventory inv) {
|
|
||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,814 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
||||||
|
import lombok.*;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Borrowed from https://github.com/Phoenix616/IDConverter/blob/master/mappings/src/main/java/de/themoep/idconverter/IdMappings.java
|
||||||
|
* Original License:
|
||||||
|
* <p>
|
||||||
|
* Minecraft ID mappings
|
||||||
|
* Copyright (C) 2017 Max Lee (https://github.com/Phoenix616)
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
public class BukkitLegacyMappings extends LegacyMappings {
|
||||||
|
|
||||||
|
private static final LegacyBlock[] BLOCKS =
|
||||||
|
new LegacyBlock[] {new LegacyBlock(0, "air"), new LegacyBlock(1, "stone"),
|
||||||
|
new LegacyBlock(1, 1, "stone", "granite"),
|
||||||
|
new LegacyBlock(1, 2, "stone", "polished_granite"),
|
||||||
|
new LegacyBlock(1, 3, "stone", "diorite"),
|
||||||
|
new LegacyBlock(1, 4, "stone", "polished_diorite"),
|
||||||
|
new LegacyBlock(1, 5, "stone", "andesite"),
|
||||||
|
new LegacyBlock(1, 6, "stone", "polished_andesite"),
|
||||||
|
new LegacyBlock(2, "grass", "grass_block"), new LegacyBlock(3, "dirt"),
|
||||||
|
new LegacyBlock(3, 1, "dirt", "coarse_dirt"), new LegacyBlock(3, 2, "dirt", "podzol"),
|
||||||
|
new LegacyBlock(4, "cobblestone"), new LegacyBlock(5, "wood", "oak_planks"),
|
||||||
|
new LegacyBlock(5, 1, "wood", "spruce_planks"),
|
||||||
|
new LegacyBlock(5, 2, "wood", "birch_planks"),
|
||||||
|
new LegacyBlock(5, 3, "wood", "jungle_planks"),
|
||||||
|
new LegacyBlock(5, 4, "wood", "acacia_planks"),
|
||||||
|
new LegacyBlock(5, 5, "wood", "dark_oak_planks"),
|
||||||
|
new LegacyBlock(6, "sapling", "oak_sapling"),
|
||||||
|
new LegacyBlock(6, 1, "sapling", "spruce_sapling"),
|
||||||
|
new LegacyBlock(6, 2, "sapling", "birch_sapling"),
|
||||||
|
new LegacyBlock(6, 3, "sapling", "jungle_sapling"),
|
||||||
|
new LegacyBlock(6, 4, "sapling", "acacia_sapling"),
|
||||||
|
new LegacyBlock(6, 5, "sapling", "dark_oak_sapling"), new LegacyBlock(7, "bedrock"),
|
||||||
|
new LegacyBlock(8, "water", "flowing_water"),
|
||||||
|
new LegacyBlock(9, "stationary_water", "water"),
|
||||||
|
new LegacyBlock(10, "lava", "flowing_lava"),
|
||||||
|
new LegacyBlock(11, "stationary_lava", "lava"), new LegacyBlock(12, "sand"),
|
||||||
|
new LegacyBlock(12, 1, "sand", "red_sand"), new LegacyBlock(13, "gravel"),
|
||||||
|
new LegacyBlock(14, "gold_ore"), new LegacyBlock(15, "iron_ore"),
|
||||||
|
new LegacyBlock(16, "coal_ore"), new LegacyBlock(17, "log", "oak_log"),
|
||||||
|
new LegacyBlock(17, 1, "log", "oak_log"), new LegacyBlock(17, 2, "log", "spruce_log"),
|
||||||
|
new LegacyBlock(17, 3, "log", "birch_log"), new LegacyBlock(17, 4, "log", "jungle_log"),
|
||||||
|
new LegacyBlock(17, 5, "log", "oak_bark"), new LegacyBlock(17, 6, "log", "spruce_bark"),
|
||||||
|
new LegacyBlock(17, 7, "log", "birch_bark"),
|
||||||
|
new LegacyBlock(17, 8, "log", "jungle_bark"),
|
||||||
|
new LegacyBlock(18, "leaves", "oak_leaves"),
|
||||||
|
new LegacyBlock(18, 1, "leaves", "spruce_leaves"),
|
||||||
|
new LegacyBlock(18, 2, "leaves", "birch_leaves"),
|
||||||
|
new LegacyBlock(18, 3, "leaves", "jungle_leaves"), new LegacyBlock(19, "sponge"),
|
||||||
|
new LegacyBlock(19, 1, "sponge", "wet_sponge"), new LegacyBlock(20, "glass"),
|
||||||
|
new LegacyBlock(21, "lapis_ore"), new LegacyBlock(22, "lapis_block"),
|
||||||
|
new LegacyBlock(23, "dispenser"), new LegacyBlock(24, "sandstone"),
|
||||||
|
new LegacyBlock(24, 1, "sandstone", "chisled_sandstone"),
|
||||||
|
new LegacyBlock(24, 2, "sandstone", "cut_sandstone"), new LegacyBlock(25, "note_block"),
|
||||||
|
new LegacyBlock(26, "bed_block"), new LegacyBlock(27, "powered_rail"),
|
||||||
|
new LegacyBlock(28, "detector_rail"),
|
||||||
|
new LegacyBlock(29, "piston_sticky_base", "sticky_piston"),
|
||||||
|
new LegacyBlock(30, "web", "cobweb"), new LegacyBlock(31, "long_grass", "dead_bush"),
|
||||||
|
new LegacyBlock(31, 1, "long_grass", "grass"),
|
||||||
|
new LegacyBlock(31, 2, "long_grass", "fern"), new LegacyBlock(32, "dead_bush"),
|
||||||
|
new LegacyBlock(33, "piston_base", "piston"),
|
||||||
|
new LegacyBlock(34, "piston_extension", "piston_head"),
|
||||||
|
new LegacyBlock(35, "wool", "white_wool"),
|
||||||
|
new LegacyBlock(35, 1, "wool", "orange_wool"),
|
||||||
|
new LegacyBlock(35, 2, "wool", "magenta_wool"),
|
||||||
|
new LegacyBlock(35, 3, "wool", "light_blue_wool"),
|
||||||
|
new LegacyBlock(35, 4, "wool", "yellow_wool"),
|
||||||
|
new LegacyBlock(35, 5, "wool", "lime_wool"),
|
||||||
|
new LegacyBlock(35, 6, "wool", "pink_wool"),
|
||||||
|
new LegacyBlock(35, 7, "wool", "gray_wool"),
|
||||||
|
new LegacyBlock(35, 8, "wool", "light_gray_wool"),
|
||||||
|
new LegacyBlock(35, 9, "wool", "cyan_wool"),
|
||||||
|
new LegacyBlock(35, 10, "wool", "purple_wool"),
|
||||||
|
new LegacyBlock(35, 11, "wool", "blue_wool"),
|
||||||
|
new LegacyBlock(35, 12, "wool", "brown_wool"),
|
||||||
|
new LegacyBlock(35, 13, "wool", "green_wool"),
|
||||||
|
new LegacyBlock(35, 14, "wool", "red_wool"),
|
||||||
|
new LegacyBlock(35, 15, "wool", "black_wool"),
|
||||||
|
new LegacyBlock(36, "piston_moving_piece", "moving_piston"),
|
||||||
|
new LegacyBlock(37, "yellow_flower", "dandelion"),
|
||||||
|
new LegacyBlock(38, "red_rose", "poppy"),
|
||||||
|
new LegacyBlock(38, 1, "red_rose", "blue_orchid"),
|
||||||
|
new LegacyBlock(38, 2, "red_rose", "allium"),
|
||||||
|
new LegacyBlock(38, 3, "red_rose", "azure_bluet"),
|
||||||
|
new LegacyBlock(38, 4, "red_rose", "red_tulip"),
|
||||||
|
new LegacyBlock(38, 5, "red_rose", "orange_tulip"),
|
||||||
|
new LegacyBlock(38, 6, "red_rose", "white_tulip"),
|
||||||
|
new LegacyBlock(38, 7, "red_rose", "pink_tulip"),
|
||||||
|
new LegacyBlock(38, 8, "red_rose", "oxeye_daisy"),
|
||||||
|
new LegacyBlock(39, "brown_mushroom"), new LegacyBlock(40, "red_mushroom"),
|
||||||
|
new LegacyBlock(41, "gold_block"), new LegacyBlock(42, "iron_block"),
|
||||||
|
new LegacyBlock(43, "double_step"),
|
||||||
|
new LegacyBlock(43, 6, "double_step", "smooth_quartz"),
|
||||||
|
new LegacyBlock(43, 8, "double_step", "smooth_stone"),
|
||||||
|
new LegacyBlock(43, 9, "double_step", "smooth_sandstone"),
|
||||||
|
new LegacyBlock(44, "step", "stone_slab"),
|
||||||
|
new LegacyBlock(44, 1, "step", "sandstone_slab"),
|
||||||
|
new LegacyBlock(44, 2, "step", "petrified_oak_slab"),
|
||||||
|
new LegacyBlock(44, 3, "step", "cobblestone_slab"),
|
||||||
|
new LegacyBlock(44, 4, "step", "brick_slab"),
|
||||||
|
new LegacyBlock(44, 5, "step", "stone_brick_slab"),
|
||||||
|
new LegacyBlock(44, 6, "step", "nether_brick_slab"),
|
||||||
|
new LegacyBlock(44, 7, "step", "quartz_slab"), new LegacyBlock(45, "brick", "bricks"),
|
||||||
|
new LegacyBlock(46, "tnt"), new LegacyBlock(47, "bookshelf"),
|
||||||
|
new LegacyBlock(48, "mossy_cobblestone"), new LegacyBlock(49, "obsidian"),
|
||||||
|
new LegacyBlock(50, "torch"), new LegacyBlock(50, 1, "torch", "wall_torch"),
|
||||||
|
new LegacyBlock(50, 2, "torch", "wall_torch"),
|
||||||
|
new LegacyBlock(50, 3, "torch", "wall_torch"),
|
||||||
|
new LegacyBlock(50, 4, "torch", "wall_torch"), new LegacyBlock(50, 5, "torch"),
|
||||||
|
new LegacyBlock(51, "fire"), new LegacyBlock(52, "mob_spawner"),
|
||||||
|
new LegacyBlock(53, "wood_stairs", "oak_stairs"), new LegacyBlock(54, "chest", "chest"),
|
||||||
|
new LegacyBlock(55, "redstone_wire"), new LegacyBlock(56, "diamond_ore"),
|
||||||
|
new LegacyBlock(57, "diamond_block"),
|
||||||
|
new LegacyBlock(58, "workbench", "crafting_table"),
|
||||||
|
new LegacyBlock(59, "crops", "wheat"), new LegacyBlock(60, "soil", "farmland"),
|
||||||
|
new LegacyBlock(61, "furnace"), new LegacyBlock(62, "burning_furnace"),
|
||||||
|
new LegacyBlock(63, "sign_post", "sign"),
|
||||||
|
new LegacyBlock(64, "wooden_door", "oak_door"), new LegacyBlock(65, "ladder"),
|
||||||
|
new LegacyBlock(66, "rails", "rail"), new LegacyBlock(67, "cobblestone_stairs"),
|
||||||
|
new LegacyBlock(68, "wall_sign"), new LegacyBlock(69, "lever"),
|
||||||
|
new LegacyBlock(70, "stone_plate", "stone_pressure_plate"),
|
||||||
|
new LegacyBlock(71, "iron_door_block", "iron_door"),
|
||||||
|
new LegacyBlock(72, "wood_plate", "oak_pressure_plate"),
|
||||||
|
new LegacyBlock(73, "redstone_ore"), new LegacyBlock(74, "glowing_redstone_ore"),
|
||||||
|
new LegacyBlock(75, "redstone_torch_off"),
|
||||||
|
new LegacyBlock(76, "redstone_torch_on", "redstone_torch"),
|
||||||
|
new LegacyBlock(76, 1, "redstone_torch_on", "redstone_wall_torch"),
|
||||||
|
new LegacyBlock(76, 2, "redstone_torch_on", "redstone_wall_torch"),
|
||||||
|
new LegacyBlock(76, 3, "redstone_torch_on", "redstone_wall_torch"),
|
||||||
|
new LegacyBlock(76, 4, "redstone_torch_on", "redstone_wall_torch"),
|
||||||
|
new LegacyBlock(76, 5, "redstone_torch_on", "redstone_torch"),
|
||||||
|
new LegacyBlock(77, "stone_button"), new LegacyBlock(78, "snow"),
|
||||||
|
new LegacyBlock(79, "ice"), new LegacyBlock(80, "snow_block"),
|
||||||
|
new LegacyBlock(81, "cactus"), new LegacyBlock(82, "clay"),
|
||||||
|
new LegacyBlock(83, "sugar_cane_block", "sugar_cane"), new LegacyBlock(84, "jukebox"),
|
||||||
|
new LegacyBlock(85, "fence", "oak_fence"),
|
||||||
|
new LegacyBlock(86, "pumpkin", "carved_pumpkin"), new LegacyBlock(87, "netherrack"),
|
||||||
|
new LegacyBlock(88, "soul_sand"), new LegacyBlock(89, "glowstone"),
|
||||||
|
new LegacyBlock(90, "portal"), new LegacyBlock(91, "jack_o_lantern"),
|
||||||
|
new LegacyBlock(92, "cake_block", "cake"), new LegacyBlock(93, "diode_block_off"),
|
||||||
|
new LegacyBlock(94, "diode_block_on", "repeater"),
|
||||||
|
new LegacyBlock(95, "stained_glass", "white_stained_glass"),
|
||||||
|
new LegacyBlock(95, 1, "stained_glass", "orange_stained_glass"),
|
||||||
|
new LegacyBlock(95, 2, "stained_glass", "magenta_stained_glass"),
|
||||||
|
new LegacyBlock(95, 3, "stained_glass", "light_blue_stained_glass"),
|
||||||
|
new LegacyBlock(95, 4, "stained_glass", "yellow_stained_glass"),
|
||||||
|
new LegacyBlock(95, 5, "stained_glass", "lime_stained_glass"),
|
||||||
|
new LegacyBlock(95, 6, "stained_glass", "pink_stained_glass"),
|
||||||
|
new LegacyBlock(95, 7, "stained_glass", "gray_stained_glass"),
|
||||||
|
new LegacyBlock(95, 8, "stained_glass", "light_gray_stained_glass"),
|
||||||
|
new LegacyBlock(95, 9, "stained_glass", "cyan_stained_glass"),
|
||||||
|
new LegacyBlock(95, 10, "stained_glass", "purple_stained_glass"),
|
||||||
|
new LegacyBlock(95, 11, "stained_glass", "blue_stained_glass"),
|
||||||
|
new LegacyBlock(95, 12, "stained_glass", "brown_stained_glass"),
|
||||||
|
new LegacyBlock(95, 13, "stained_glass", "green_stained_glass"),
|
||||||
|
new LegacyBlock(95, 14, "stained_glass", "red_stained_glass"),
|
||||||
|
new LegacyBlock(95, 15, "stained_glass", "black_stained_glass"),
|
||||||
|
new LegacyBlock(96, "trap_door", "oak_trapdoor"),
|
||||||
|
new LegacyBlock(97, "monster_eggs", "infested_stone"),
|
||||||
|
new LegacyBlock(97, 1, "monster_eggs", "infested_coblestone"),
|
||||||
|
new LegacyBlock(97, 2, "monster_eggs", "infested_stone_bricks"),
|
||||||
|
new LegacyBlock(97, 3, "monster_eggs", "infested_mossy_stone_bricks"),
|
||||||
|
new LegacyBlock(97, 4, "monster_eggs", "infested_crcked_stone_bricks"),
|
||||||
|
new LegacyBlock(97, 5, "monster_eggs", "infested_chiseled_stone_bricks"),
|
||||||
|
new LegacyBlock(98, "smooth_brick", "stone_bricks"),
|
||||||
|
new LegacyBlock(98, 1, "smooth_brick", "mossy_stone_bricks"),
|
||||||
|
new LegacyBlock(98, 2, "smooth_brick", "cracked_stone_bricks"),
|
||||||
|
new LegacyBlock(98, 3, "smooth_brick", "chiseled_bricks"),
|
||||||
|
new LegacyBlock(99, "huge_mushroom_1", "brown_mushroom_block"),
|
||||||
|
new LegacyBlock(99, 1, "huge_mushroom_1"), new LegacyBlock(99, 2, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(99, 3, "huge_mushroom_1"), new LegacyBlock(99, 4, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(99, 5, "huge_mushroom_1"), new LegacyBlock(99, 6, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(99, 7, "huge_mushroom_1"), new LegacyBlock(99, 8, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(99, 9, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(99, 10, "huge_mushroom_1", "mushroom_stem"),
|
||||||
|
new LegacyBlock(99, 14, "huge_mushroom_1"), new LegacyBlock(99, 15, "huge_mushroom_1"),
|
||||||
|
new LegacyBlock(100, "huge_mushroom_2", "red_mushroom_block"),
|
||||||
|
new LegacyBlock(100, 1, "huge_mushroom_2"), new LegacyBlock(100, 2, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 3, "huge_mushroom_2"), new LegacyBlock(100, 4, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 5, "huge_mushroom_2"), new LegacyBlock(100, 6, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 7, "huge_mushroom_2"), new LegacyBlock(100, 8, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 9, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 10, "huge_mushroom_2", "mushroom_stem"),
|
||||||
|
new LegacyBlock(100, 14, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(100, 15, "huge_mushroom_2"),
|
||||||
|
new LegacyBlock(101, "iron_fence", "ironbars"),
|
||||||
|
new LegacyBlock(102, "thin_glass", "glass_pane"), new LegacyBlock(103, "melon_block"),
|
||||||
|
new LegacyBlock(104, "pumpkin_stem"), new LegacyBlock(105, "melon_stem"),
|
||||||
|
new LegacyBlock(106, "vine"), new LegacyBlock(107, "fence_gate", "oak_fence_gate"),
|
||||||
|
new LegacyBlock(108, "brick_stairs"),
|
||||||
|
new LegacyBlock(109, "smooth_stairs", "stone_brick_stairs"),
|
||||||
|
new LegacyBlock(110, "mycel", "mycelium"),
|
||||||
|
new LegacyBlock(111, "water_lily", "lily_pad"),
|
||||||
|
new LegacyBlock(112, "nether_brick", "nether_bricks"),
|
||||||
|
new LegacyBlock(113, "nether_fence", "nether_brick_fence"),
|
||||||
|
new LegacyBlock(114, "nether_brick_stairs"),
|
||||||
|
new LegacyBlock(115, "nether_warts", "nether_wart"),
|
||||||
|
new LegacyBlock(116, "enchantment_table", "enchanting_table"),
|
||||||
|
new LegacyBlock(117, "brewing_stand"), new LegacyBlock(118, "cauldron"),
|
||||||
|
new LegacyBlock(119, "ender_portal", "end_portal"),
|
||||||
|
new LegacyBlock(120, "ender_portal_frame", "end_portal_frame"),
|
||||||
|
new LegacyBlock(121, "ender_stone", "end_stone"), new LegacyBlock(122, "dragon_egg"),
|
||||||
|
new LegacyBlock(123, "redstone_lamp_off"),
|
||||||
|
new LegacyBlock(124, "redstone_lamp_on", "redstone_lamp"),
|
||||||
|
new LegacyBlock(125, "wood_double_step"), new LegacyBlock(125, 1, "wood_double_step"),
|
||||||
|
new LegacyBlock(125, 2, "wood_double_step"),
|
||||||
|
new LegacyBlock(125, 3, "wood_double_step"),
|
||||||
|
new LegacyBlock(125, 4, "wood_double_step"),
|
||||||
|
new LegacyBlock(125, 5, "wood_double_step"),
|
||||||
|
new LegacyBlock(126, "wood_step", "oak_slab"),
|
||||||
|
new LegacyBlock(126, 1, "wood_step", "spruce_slab"),
|
||||||
|
new LegacyBlock(126, 2, "wood_step", "birch_slab"),
|
||||||
|
new LegacyBlock(126, 3, "wood_step", "jungle_slab"),
|
||||||
|
new LegacyBlock(126, 4, "wood_step", "acacia_slab"),
|
||||||
|
new LegacyBlock(126, 5, "wood_step", "dark_oak_slab"), new LegacyBlock(127, "cocoa"),
|
||||||
|
new LegacyBlock(128, "sandstone_stairs"), new LegacyBlock(129, "emerald_ore"),
|
||||||
|
new LegacyBlock(130, "ender_chest"), new LegacyBlock(131, "tripwire_hook"),
|
||||||
|
new LegacyBlock(132, "tripwire"), new LegacyBlock(133, "emerald_block"),
|
||||||
|
new LegacyBlock(134, "spruce_wood_stairs", "spruce_stairs"),
|
||||||
|
new LegacyBlock(135, "birch_wood_stairs", "birch_stairs"),
|
||||||
|
new LegacyBlock(136, "jungle_wood_stairs", "jungle_stairs"),
|
||||||
|
new LegacyBlock(137, "command", "command_block"), new LegacyBlock(138, "beacon"),
|
||||||
|
new LegacyBlock(139, "cobble_wall", "cobblestone_wall"),
|
||||||
|
new LegacyBlock(139, 1, "cobble_wall", "mossy_cobblestone_wall"),
|
||||||
|
new LegacyBlock(140, "flower_pot"), new LegacyBlock(141, "carrot", "carrots"),
|
||||||
|
new LegacyBlock(142, "potato", "potatoes"),
|
||||||
|
new LegacyBlock(143, "wood_button", "oak_button"),
|
||||||
|
new LegacyBlock(144, "skull", "skeleton_skull"),
|
||||||
|
new LegacyBlock(144, 1, "skull", "skeleton_wall_skull"),
|
||||||
|
new LegacyBlock(144, 2, "skull", "skeleton_wall_skull"),
|
||||||
|
new LegacyBlock(144, 3, "skull", "skeleton_wall_skull"),
|
||||||
|
new LegacyBlock(144, 4, "skull", "skeleton_wall_skull"),
|
||||||
|
new LegacyBlock(144, 5, "skull", "skeleton_wall_skull"), new LegacyBlock(145, "anvil"),
|
||||||
|
new LegacyBlock(145, 1, "anvil", "chipped_anvil"),
|
||||||
|
new LegacyBlock(145, 2, "anvil", "damaged_anvil"),
|
||||||
|
new LegacyBlock(146, "trapped_chest"),
|
||||||
|
new LegacyBlock(147, "gold_plate", "light_weighted_pressure_plate"),
|
||||||
|
new LegacyBlock(148, "iron_plate", "heavy_weighted_pressure_plate"),
|
||||||
|
new LegacyBlock(149, "redstone_comparator_off"),
|
||||||
|
new LegacyBlock(150, "redstone_comparator_on", "comparator"),
|
||||||
|
new LegacyBlock(151, "daylight_detector"), new LegacyBlock(152, "redstone_block"),
|
||||||
|
new LegacyBlock(153, "quartz_ore", "nether_quartz_ore"), new LegacyBlock(154, "hopper"),
|
||||||
|
new LegacyBlock(155, "quartz_block"), new LegacyBlock(156, "quartz_stairs"),
|
||||||
|
new LegacyBlock(157, "activator_rail"), new LegacyBlock(158, "dropper"),
|
||||||
|
new LegacyBlock(159, "stained_clay", "white_terracotta"),
|
||||||
|
new LegacyBlock(159, 1, "stained_clay", "orange_terracotta"),
|
||||||
|
new LegacyBlock(159, 2, "stained_clay", "magenta_terracotta"),
|
||||||
|
new LegacyBlock(159, 3, "stained_clay", "light_blue_terracotta"),
|
||||||
|
new LegacyBlock(159, 4, "stained_clay", "yellow_terracotta"),
|
||||||
|
new LegacyBlock(159, 5, "stained_clay", "lime_terracotta"),
|
||||||
|
new LegacyBlock(159, 6, "stained_clay", "pink_terracotta"),
|
||||||
|
new LegacyBlock(159, 7, "stained_clay", "gray_terracotta"),
|
||||||
|
new LegacyBlock(159, 8, "stained_clay", "light_gray_terracotta"),
|
||||||
|
new LegacyBlock(159, 9, "stained_clay", "cyan_terracotta"),
|
||||||
|
new LegacyBlock(159, 10, "stained_clay", "purple_terracotta"),
|
||||||
|
new LegacyBlock(159, 11, "stained_clay", "blue_terracotta"),
|
||||||
|
new LegacyBlock(159, 12, "stained_clay", "brown_terracotta"),
|
||||||
|
new LegacyBlock(159, 13, "stained_clay", "green_terracotta"),
|
||||||
|
new LegacyBlock(159, 14, "stained_clay", "red_terracotta"),
|
||||||
|
new LegacyBlock(159, 15, "stained_clay", "black_terracotta"),
|
||||||
|
new LegacyBlock(160, "stained_glass_pane", "white_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 1, "stained_glass_pane", "orange_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 2, "stained_glass_pane", "magenta_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 3, "stained_glass_pane", "light_blue_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 4, "stained_glass_pane", "yellow_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 5, "stained_glass_pane", "lime_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 6, "stained_glass_pane", "pink_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 7, "stained_glass_pane", "gray_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 8, "stained_glass_pane", "light_gray_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 9, "stained_glass_pane", "cyan_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 10, "stained_glass_pane", "purple_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 11, "stained_glass_pane", "blue_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 12, "stained_glass_pane", "brown_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 13, "stained_glass_pane", "green_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 14, "stained_glass_pane", "red_stained_glass_pane"),
|
||||||
|
new LegacyBlock(160, 15, "stained_glass_pane", "black_stained_glass_pane"),
|
||||||
|
new LegacyBlock(161, "leaves_2", "acacia_leaves"),
|
||||||
|
new LegacyBlock(161, 1, "leaves_2", "dark_oak_leaves"),
|
||||||
|
new LegacyBlock(162, "log_2", "acacia_log"),
|
||||||
|
new LegacyBlock(162, 1, "log_2", "spruce_log"),
|
||||||
|
new LegacyBlock(162, 2, "log_2", "birch_log"),
|
||||||
|
new LegacyBlock(162, 3, "log_2", "jungle_log"),
|
||||||
|
new LegacyBlock(163, "acacia_stairs", "acacia_stairs"),
|
||||||
|
new LegacyBlock(164, "dark_oak_stairs", "dark_oak_stairs"),
|
||||||
|
new LegacyBlock(165, "slime_block", "slime_block"),
|
||||||
|
new LegacyBlock(166, "barrier", "barrier"),
|
||||||
|
new LegacyBlock(167, "iron_trapdoor", "iron_trapdoor"),
|
||||||
|
new LegacyBlock(168, "prismarine"),
|
||||||
|
new LegacyBlock(168, 1, "prismarine", "prismarine_bricks"),
|
||||||
|
new LegacyBlock(168, 2, "prismarine", "dark_prismarine"),
|
||||||
|
new LegacyBlock(169, "sea_lantern"), new LegacyBlock(170, "hay_block"),
|
||||||
|
new LegacyBlock(171, "carpet", "white_carpet"),
|
||||||
|
new LegacyBlock(171, 1, "carpet", "orange_carpet"),
|
||||||
|
new LegacyBlock(171, 2, "carpet", "magenta_carpet"),
|
||||||
|
new LegacyBlock(171, 3, "carpet", "light_blue_carpet"),
|
||||||
|
new LegacyBlock(171, 4, "carpet", "yellow_carpet"),
|
||||||
|
new LegacyBlock(171, 5, "carpet", "lime_carpet"),
|
||||||
|
new LegacyBlock(171, 6, "carpet", "pink_carpet"),
|
||||||
|
new LegacyBlock(171, 7, "carpet", "gray_carpet"),
|
||||||
|
new LegacyBlock(171, 8, "carpet", "light_gray_carpet"),
|
||||||
|
new LegacyBlock(171, 9, "carpet", "cyan_carpet"),
|
||||||
|
new LegacyBlock(171, 10, "carpet", "purple_carpet"),
|
||||||
|
new LegacyBlock(171, 11, "carpet", "blue_carpet"),
|
||||||
|
new LegacyBlock(171, 12, "carpet", "brown_carpet"),
|
||||||
|
new LegacyBlock(171, 13, "carpet", "green_carpet"),
|
||||||
|
new LegacyBlock(171, 14, "carpet", "red_carpet"),
|
||||||
|
new LegacyBlock(171, 15, "carpet", "black_carpet"),
|
||||||
|
new LegacyBlock(172, "hard_clay", "terracotta"), new LegacyBlock(173, "coal_block"),
|
||||||
|
new LegacyBlock(174, "packed_ice"), new LegacyBlock(175, "double_plant", "sunflower"),
|
||||||
|
new LegacyBlock(175, 1, "double_plant", "lilac"),
|
||||||
|
new LegacyBlock(175, 2, "double_plant", "tall_grass"),
|
||||||
|
new LegacyBlock(175, 3, "double_plant", "large_fern"),
|
||||||
|
new LegacyBlock(175, 4, "double_plant", "rose_bush"),
|
||||||
|
new LegacyBlock(175, 5, "double_plant", "peony"),
|
||||||
|
new LegacyBlock(176, "standing_banner"), new LegacyBlock(177, "wall_banner"),
|
||||||
|
new LegacyBlock(178, "daylight_detector_inverted"),
|
||||||
|
new LegacyBlock(179, "red_sandstone", "red_sandstone"),
|
||||||
|
new LegacyBlock(179, 1, "red_sandstone", "chiseled_red_sandstone"),
|
||||||
|
new LegacyBlock(179, 2, "red_sandstone", "cut_red_sandstone"),
|
||||||
|
new LegacyBlock(180, "red_sandstone_stairs"),
|
||||||
|
new LegacyBlock(181, "double_stone_slab2"),
|
||||||
|
new LegacyBlock(181, 8, "double_stone_slab2", "smooth_red_sandstone"),
|
||||||
|
new LegacyBlock(182, "stone_slab2", "red_sandstone_slab"),
|
||||||
|
new LegacyBlock(183, "spruce_fence_gate"), new LegacyBlock(184, "birch_fence_gate"),
|
||||||
|
new LegacyBlock(185, "jungle_fence_gate"), new LegacyBlock(186, "dark_oak_fence_gate"),
|
||||||
|
new LegacyBlock(187, "acacia_fence_gate"), new LegacyBlock(188, "spruce_fence"),
|
||||||
|
new LegacyBlock(189, "birch_fence"), new LegacyBlock(190, "jungle_fence"),
|
||||||
|
new LegacyBlock(191, "dark_oak_fence"), new LegacyBlock(192, "acacia_fence"),
|
||||||
|
new LegacyBlock(193, "spruce_door"), new LegacyBlock(194, "birch_door"),
|
||||||
|
new LegacyBlock(195, "jungle_door"), new LegacyBlock(196, "acacia_door"),
|
||||||
|
new LegacyBlock(197, "dark_oak_door"), new LegacyBlock(198, "end_rod"),
|
||||||
|
new LegacyBlock(199, "chorus_plant"), new LegacyBlock(200, "chorus_flower"),
|
||||||
|
new LegacyBlock(201, "purpur_block"), new LegacyBlock(202, "purpur_pillar"),
|
||||||
|
new LegacyBlock(203, "purpur_stairs"), new LegacyBlock(204, "purpur_double_slab"),
|
||||||
|
new LegacyBlock(205, "purpur_slab"),
|
||||||
|
new LegacyBlock(206, "end_bricks", "end_stone_bricks"),
|
||||||
|
new LegacyBlock(207, "beetroot_block", "beetroots"), new LegacyBlock(208, "grass_path"),
|
||||||
|
new LegacyBlock(209, "end_gateway"),
|
||||||
|
new LegacyBlock(210, "command_repeating", "repeating_command_block"),
|
||||||
|
new LegacyBlock(211, "command_chain", "chain_command_block"),
|
||||||
|
new LegacyBlock(212, "frosted_ice"), new LegacyBlock(213, "magma", "magma_block"),
|
||||||
|
new LegacyBlock(214, "nether_wart_block"),
|
||||||
|
new LegacyBlock(215, "red_nether_brick", "red_nether_bricks"),
|
||||||
|
new LegacyBlock(216, "bone_block"), new LegacyBlock(217, "structure_void"),
|
||||||
|
new LegacyBlock(218, "observer"), new LegacyBlock(219, "white_shulker_box"),
|
||||||
|
new LegacyBlock(220, "orange_shulker_box"), new LegacyBlock(221, "magenta_shulker_box"),
|
||||||
|
new LegacyBlock(222, "light_blue_shulker_box"),
|
||||||
|
new LegacyBlock(223, "yellow_shulker_box"), new LegacyBlock(224, "lime_shulker_box"),
|
||||||
|
new LegacyBlock(225, "pink_shulker_box"), new LegacyBlock(226, "gray_shulker_box"),
|
||||||
|
new LegacyBlock(227, "silver_shulker_box", "light_gray_shulker_box"),
|
||||||
|
new LegacyBlock(228, "cyan_shulker_box"), new LegacyBlock(229, "purple_shulker_box"),
|
||||||
|
new LegacyBlock(230, "blue_shulker_box"), new LegacyBlock(231, "brown_shulker_box"),
|
||||||
|
new LegacyBlock(232, "green_shulker_box"), new LegacyBlock(233, "red_shulker_box"),
|
||||||
|
new LegacyBlock(234, "black_shulker_box"),
|
||||||
|
new LegacyBlock(235, "white_glazed_terracotta"),
|
||||||
|
new LegacyBlock(236, "orange_glazed_terracotta"),
|
||||||
|
new LegacyBlock(237, "magenta_glazed_terracotta"),
|
||||||
|
new LegacyBlock(238, "light_blue_glazed_terracotta"),
|
||||||
|
new LegacyBlock(239, "yellow_glazed_terracotta"),
|
||||||
|
new LegacyBlock(240, "lime_glazed_terracotta"),
|
||||||
|
new LegacyBlock(241, "pink_glazed_terracotta"),
|
||||||
|
new LegacyBlock(242, "gray_glazed_terracotta"),
|
||||||
|
new LegacyBlock(243, "silver_glazed_terracotta", "light_gray_glazed_terracotta"),
|
||||||
|
new LegacyBlock(244, "cyan_glazed_terracotta"),
|
||||||
|
new LegacyBlock(245, "purple_glazed_terracotta"),
|
||||||
|
new LegacyBlock(246, "blue_glazed_terracotta"),
|
||||||
|
new LegacyBlock(247, "brown_glazed_terracotta"),
|
||||||
|
new LegacyBlock(248, "green_glazed_terracotta"),
|
||||||
|
new LegacyBlock(249, "red_glazed_terracotta"),
|
||||||
|
new LegacyBlock(250, "black_glazed_terracotta"),
|
||||||
|
new LegacyBlock(251, "concrete", "white_concrete"),
|
||||||
|
new LegacyBlock(251, 1, "concrete", "orange_concrete"),
|
||||||
|
new LegacyBlock(251, 2, "concrete", "magenta_concrete"),
|
||||||
|
new LegacyBlock(251, 3, "concrete", "light_blue_concrete"),
|
||||||
|
new LegacyBlock(251, 4, "concrete", "yellow_concrete"),
|
||||||
|
new LegacyBlock(251, 5, "concrete", "lime_concrete"),
|
||||||
|
new LegacyBlock(251, 6, "concrete", "pink_concrete"),
|
||||||
|
new LegacyBlock(251, 7, "concrete", "gray_concrete"),
|
||||||
|
new LegacyBlock(251, 8, "concrete", "light_gray_concrete"),
|
||||||
|
new LegacyBlock(251, 9, "concrete", "cyan_concrete"),
|
||||||
|
new LegacyBlock(251, 10, "concrete", "purple_concrete"),
|
||||||
|
new LegacyBlock(251, 11, "concrete", "blue_concrete"),
|
||||||
|
new LegacyBlock(251, 12, "concrete", "brown_concrete"),
|
||||||
|
new LegacyBlock(251, 13, "concrete", "green_concrete"),
|
||||||
|
new LegacyBlock(251, 14, "concrete", "red_concrete"),
|
||||||
|
new LegacyBlock(251, 15, "concrete", "black_concrete"),
|
||||||
|
new LegacyBlock(252, "concrete_powder", "white_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 1, "concrete_powder", "orange_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 2, "concrete_powder", "magenta_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 3, "concrete_powder", "light_blue_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 4, "concrete_powder", "yellow_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 5, "concrete_powder", "lime_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 6, "concrete_powder", "pink_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 7, "concrete_powder", "gray_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 8, "concrete_powder", "light_gray_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 9, "concrete_powder", "cyan_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 10, "concrete_powder", "purple_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 11, "concrete_powder", "blue_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 12, "concrete_powder", "brown_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 13, "concrete_powder", "green_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 14, "concrete_powder", "red_concrete_powder"),
|
||||||
|
new LegacyBlock(252, 15, "concrete_powder", "black_concrete_powder"),
|
||||||
|
new LegacyBlock(255, "structure_block"),
|
||||||
|
new LegacyBlock(256, "iron_spade", "iron_shovel"), new LegacyBlock(257, "iron_pickaxe"),
|
||||||
|
new LegacyBlock(258, "iron_axe"), new LegacyBlock(259, "flint_and_steel"),
|
||||||
|
new LegacyBlock(260, "apple"), new LegacyBlock(261, "bow"),
|
||||||
|
new LegacyBlock(262, "arrow"), new LegacyBlock(263, "coal"),
|
||||||
|
new LegacyBlock(263, 1, "coal", "charcoal"), new LegacyBlock(264, "diamond"),
|
||||||
|
new LegacyBlock(265, "iron_ingot"), new LegacyBlock(266, "gold_ingot"),
|
||||||
|
new LegacyBlock(267, "iron_sword"), new LegacyBlock(268, "wood_sword", "wooden_sword"),
|
||||||
|
new LegacyBlock(269, "wood_spade", "wooden_shovel"),
|
||||||
|
new LegacyBlock(270, "wood_pickaxe", "wooden_pickaxe"),
|
||||||
|
new LegacyBlock(271, "wood_axe", "wooden_axe"), new LegacyBlock(272, "stone_sword"),
|
||||||
|
new LegacyBlock(273, "stone_spade", "stone_shovel"),
|
||||||
|
new LegacyBlock(274, "stone_pickaxe"), new LegacyBlock(275, "stone_axe"),
|
||||||
|
new LegacyBlock(276, "diamond_sword"),
|
||||||
|
new LegacyBlock(277, "diamond_spade", "diamond_shovel"),
|
||||||
|
new LegacyBlock(278, "diamond_pickaxe"), new LegacyBlock(279, "diamond_axe"),
|
||||||
|
new LegacyBlock(280, "stick"), new LegacyBlock(281, "bowl"),
|
||||||
|
new LegacyBlock(282, "mushroom_soup", "mushroom_stew"),
|
||||||
|
new LegacyBlock(283, "gold_sword", "golden_sword"),
|
||||||
|
new LegacyBlock(284, "gold_spade", "golden_shovel"),
|
||||||
|
new LegacyBlock(285, "gold_pickaxe", "golden_pickaxe"),
|
||||||
|
new LegacyBlock(286, "gold_axe", "golden_axe"), new LegacyBlock(287, "string"),
|
||||||
|
new LegacyBlock(288, "feather"), new LegacyBlock(289, "sulphur", "gunpowder"),
|
||||||
|
new LegacyBlock(290, "wood_hoe", "wooden_hoe"), new LegacyBlock(291, "stone_hoe"),
|
||||||
|
new LegacyBlock(292, "iron_hoe"), new LegacyBlock(293, "diamond_hoe"),
|
||||||
|
new LegacyBlock(294, "gold_hoe", "golden_hoe"),
|
||||||
|
new LegacyBlock(295, "seeds", "wheat_seeds"), new LegacyBlock(296, "wheat"),
|
||||||
|
new LegacyBlock(297, "bread"), new LegacyBlock(298, "leather_helmet"),
|
||||||
|
new LegacyBlock(299, "leather_chestplate"), new LegacyBlock(300, "leather_leggings"),
|
||||||
|
new LegacyBlock(301, "leather_boots"), new LegacyBlock(302, "chainmail_helmet"),
|
||||||
|
new LegacyBlock(303, "chainmail_chestplate"),
|
||||||
|
new LegacyBlock(304, "chainmail_leggings"), new LegacyBlock(305, "chainmail_boots"),
|
||||||
|
new LegacyBlock(306, "iron_helmet"), new LegacyBlock(307, "iron_chestplate"),
|
||||||
|
new LegacyBlock(308, "iron_leggings"), new LegacyBlock(309, "iron_boots"),
|
||||||
|
new LegacyBlock(310, "diamond_helmet"), new LegacyBlock(311, "diamond_chestplate"),
|
||||||
|
new LegacyBlock(312, "diamond_leggings"), new LegacyBlock(313, "diamond_boots"),
|
||||||
|
new LegacyBlock(314, "gold_helmet", "golden_helmet"),
|
||||||
|
new LegacyBlock(315, "gold_chestplate", "golden_chestplate"),
|
||||||
|
new LegacyBlock(316, "gold_leggings", "golden_leggings"),
|
||||||
|
new LegacyBlock(317, "gold_boots", "golden_boots"), new LegacyBlock(318, "flint"),
|
||||||
|
new LegacyBlock(319, "pork", "porkchop"),
|
||||||
|
new LegacyBlock(320, "grilled_pork", "cooked_porkchop"),
|
||||||
|
new LegacyBlock(321, "painting"), new LegacyBlock(322, "golden_apple", "golden_apple"),
|
||||||
|
new LegacyBlock(322, 1, "golden_apple", "enchanted_golden_apple"),
|
||||||
|
new LegacyBlock(323, "sign"), new LegacyBlock(324, "wood_door", "oak_door"),
|
||||||
|
new LegacyBlock(325, "bucket"), new LegacyBlock(326, "water_bucket"),
|
||||||
|
new LegacyBlock(327, "lava_bucket"), new LegacyBlock(328, "minecart"),
|
||||||
|
new LegacyBlock(329, "saddle"), new LegacyBlock(330, "iron_door"),
|
||||||
|
new LegacyBlock(331, "redstone"), new LegacyBlock(332, "snow_ball", "snowball"),
|
||||||
|
new LegacyBlock(333, "boat", "oak_boat"), new LegacyBlock(334, "leather"),
|
||||||
|
new LegacyBlock(335, "milk_bucket"), new LegacyBlock(336, "clay_brick", "brick"),
|
||||||
|
new LegacyBlock(337, "clay_ball"), new LegacyBlock(338, "sugar_cane"),
|
||||||
|
new LegacyBlock(339, "paper"), new LegacyBlock(340, "book"),
|
||||||
|
new LegacyBlock(341, "slime_ball"),
|
||||||
|
new LegacyBlock(342, "storage_minecart", "chest_minecart"),
|
||||||
|
new LegacyBlock(343, "powered_minecart", "furnace_minecart"),
|
||||||
|
new LegacyBlock(344, "egg"), new LegacyBlock(345, "compass"),
|
||||||
|
new LegacyBlock(346, "fishing_rod"), new LegacyBlock(347, "watch", "clock"),
|
||||||
|
new LegacyBlock(348, "glowstone_dust"), new LegacyBlock(349, "raw_fish", "cod"),
|
||||||
|
new LegacyBlock(349, 1, "raw_fish", "salmon"),
|
||||||
|
new LegacyBlock(349, 2, "raw_fish", "tropical_fish"),
|
||||||
|
new LegacyBlock(349, 3, "raw_fish", "pufferfish"),
|
||||||
|
new LegacyBlock(350, "cooked_fish", "cooked_cod"),
|
||||||
|
new LegacyBlock(350, 1, "cooked_fish", "cooked_salmon"),
|
||||||
|
new LegacyBlock(351, "ink_sack", "ink_sac"),
|
||||||
|
new LegacyBlock(351, 1, "ink_sack", "rose_red"),
|
||||||
|
new LegacyBlock(351, 2, "ink_sack", "cactus_green"),
|
||||||
|
new LegacyBlock(351, 3, "ink_sack", "cocoa_beans"),
|
||||||
|
new LegacyBlock(351, 4, "ink_sack", "lapis_lazuli"),
|
||||||
|
new LegacyBlock(351, 5, "ink_sack", "purple_dye"),
|
||||||
|
new LegacyBlock(351, 6, "ink_sack", "cyan_dye"),
|
||||||
|
new LegacyBlock(351, 7, "ink_sack", "light_gray_dye"),
|
||||||
|
new LegacyBlock(351, 8, "ink_sack", "gray_dye"),
|
||||||
|
new LegacyBlock(351, 9, "ink_sack", "pink_dye"),
|
||||||
|
new LegacyBlock(351, 10, "ink_sack", "lime_dye"),
|
||||||
|
new LegacyBlock(351, 11, "ink_sack", "dandelion_yellow"),
|
||||||
|
new LegacyBlock(351, 12, "ink_sack", "light_blue_dye"),
|
||||||
|
new LegacyBlock(351, 13, "ink_sack", "magenta_dye"),
|
||||||
|
new LegacyBlock(351, 14, "ink_sack", "orange_dye"),
|
||||||
|
new LegacyBlock(351, 15, "ink_sack", "bone_meal"), new LegacyBlock(352, "bone"),
|
||||||
|
new LegacyBlock(353, "sugar", "sugar"), new LegacyBlock(354, "cake", "cake"),
|
||||||
|
new LegacyBlock(355, "bed", "white_bed"), new LegacyBlock(355, 1, "bed", "orange_bed"),
|
||||||
|
new LegacyBlock(355, 2, "bed", "magenta_bed"),
|
||||||
|
new LegacyBlock(355, 3, "bed", "light_blue_bed"),
|
||||||
|
new LegacyBlock(355, 4, "bed", "yellow_bed"),
|
||||||
|
new LegacyBlock(355, 5, "bed", "lime_bed"), new LegacyBlock(355, 6, "bed", "pink_bed"),
|
||||||
|
new LegacyBlock(355, 7, "bed", "gray_bed"),
|
||||||
|
new LegacyBlock(355, 8, "bed", "light_gray_bed"),
|
||||||
|
new LegacyBlock(355, 9, "bed", "cyan_bed"),
|
||||||
|
new LegacyBlock(355, 10, "bed", "purple_bed"),
|
||||||
|
new LegacyBlock(355, 11, "bed", "blue_bed"),
|
||||||
|
new LegacyBlock(355, 12, "bed", "brown_bed"),
|
||||||
|
new LegacyBlock(355, 13, "bed", "green_bed"),
|
||||||
|
new LegacyBlock(355, 14, "bed", "red_bed"),
|
||||||
|
new LegacyBlock(355, 15, "bed", "black_bed"), new LegacyBlock(356, "diode", "repeater"),
|
||||||
|
new LegacyBlock(357, "cookie", "cookie"), new LegacyBlock(358, "map"),
|
||||||
|
new LegacyBlock(359, "shears"), new LegacyBlock(360, "melon", "melon"),
|
||||||
|
new LegacyBlock(361, "pumpkin_seeds", "pumpkin_seeds"),
|
||||||
|
new LegacyBlock(362, "melon_seeds", "melon_seeds"),
|
||||||
|
new LegacyBlock(363, "raw_beef", "beef"), new LegacyBlock(364, "cooked_beef"),
|
||||||
|
new LegacyBlock(365, "raw_chicken", "chicken"), new LegacyBlock(366, "cooked_chicken"),
|
||||||
|
new LegacyBlock(367, "rotten_flesh"), new LegacyBlock(368, "ender_pearl"),
|
||||||
|
new LegacyBlock(369, "blaze_rod"), new LegacyBlock(370, "ghast_tear"),
|
||||||
|
new LegacyBlock(371, "gold_nugget"),
|
||||||
|
new LegacyBlock(372, "nether_stalk", "nether_wart"),
|
||||||
|
new LegacyBlock(373, "potion", "potion"), new LegacyBlock(374, "glass_bottle"),
|
||||||
|
new LegacyBlock(375, "spider_eye"), new LegacyBlock(376, "fermented_spider_eye"),
|
||||||
|
new LegacyBlock(377, "blaze_powder"), new LegacyBlock(378, "magma_cream"),
|
||||||
|
new LegacyBlock(379, "brewing_stand_item", "brewing_stand"),
|
||||||
|
new LegacyBlock(380, "cauldron_item", "cauldron"),
|
||||||
|
new LegacyBlock(381, "eye_of_ender", "ender_eye"),
|
||||||
|
new LegacyBlock(382, "speckled_melon"), new LegacyBlock(383, "monster_egg"),
|
||||||
|
new LegacyBlock(383, 4, "monster_egg", "elder_guardian_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 5, "monster_egg", "wither_skeleton_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 6, "monster_egg", "stray_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 23, "monster_egg", "husk_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 27, "monster_egg", "zombe_villager_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 28, "monster_egg", "skeleton_horse_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 29, "monster_egg", "zombie_horse_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 31, "monster_egg", "donkey_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 32, "monster_egg", "mule_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 34, "monster_egg", "evocation_illager_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 35, "monster_egg", "vex_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 36, "monster_egg", "vindication_illager_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 50, "monster_egg", "creeper_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 51, "monster_egg", "skeleton_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 52, "monster_egg", "spider_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 54, "monster_egg", "zombie_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 55, "monster_egg", "slime_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 56, "monster_egg", "ghast_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 57, "monster_egg", "zombie_pigman_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 58, "monster_egg", "enderman_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 59, "monster_egg", "cave_spider_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 60, "monster_egg", "silverfish_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 61, "monster_egg", "blaze_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 62, "monster_egg", "magma_cube_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 65, "monster_egg", "bat_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 66, "monster_egg", "witch_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 67, "monster_egg", "endermite_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 68, "monster_egg", "guardian_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 69, "monster_egg", "shulker_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 90, "monster_egg", "pig_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 91, "monster_egg", "sheep_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 92, "monster_egg", "cow_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 93, "monster_egg", "chicken_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 94, "monster_egg", "squid_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 95, "monster_egg", "wolf_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 96, "monster_egg", "mooshroom_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 98, "monster_egg", "ocelot_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 100, "monster_egg", "horse_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 101, "monster_egg", "rabbit_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 102, "monster_egg", "polar_bear_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 103, "monster_egg", "llama_spawn_egg"),
|
||||||
|
new LegacyBlock(383, 120, "monster_egg", "villager_spawn_egg"),
|
||||||
|
new LegacyBlock(384, "exp_bottle", "experience_bottle"),
|
||||||
|
new LegacyBlock(385, "fireball", "fire_charge"),
|
||||||
|
new LegacyBlock(386, "book_and_quill", "writable_book"),
|
||||||
|
new LegacyBlock(387, "written_book"), new LegacyBlock(388, "emerald"),
|
||||||
|
new LegacyBlock(389, "item_frame"),
|
||||||
|
new LegacyBlock(390, "flower_pot_item", "flower_pot"),
|
||||||
|
new LegacyBlock(391, "carrot_item", "carrot"),
|
||||||
|
new LegacyBlock(392, "potato_item", "potato"), new LegacyBlock(393, "baked_potato"),
|
||||||
|
new LegacyBlock(394, "poisonous_potato"), new LegacyBlock(395, "empty_map", "map"),
|
||||||
|
new LegacyBlock(396, "golden_carrot"),
|
||||||
|
new LegacyBlock(397, "skull_item", "skeleton_skull"),
|
||||||
|
new LegacyBlock(397, 1, "skull_item", "wither_skeleton_skull"),
|
||||||
|
new LegacyBlock(397, 2, "skull_item", "zombie_head"),
|
||||||
|
new LegacyBlock(397, 3, "skull_item", "player_head"),
|
||||||
|
new LegacyBlock(397, 4, "skull_item", "creeper_head"),
|
||||||
|
new LegacyBlock(397, 5, "skull_item", "dragon_head"),
|
||||||
|
new LegacyBlock(398, "carrot_stick"), new LegacyBlock(399, "nether_star"),
|
||||||
|
new LegacyBlock(400, "pumpkin_pie"),
|
||||||
|
new LegacyBlock(401, "firework", "firework_rocket"),
|
||||||
|
new LegacyBlock(402, "firework_charge", "firework_star"),
|
||||||
|
new LegacyBlock(403, "enchanted_book"),
|
||||||
|
new LegacyBlock(404, "redstone_comparator", "comparator"),
|
||||||
|
new LegacyBlock(405, "nether_brick_item", "nether_brick"),
|
||||||
|
new LegacyBlock(406, "quartz"),
|
||||||
|
new LegacyBlock(407, "explosive_minecart", "tnt_minecart"),
|
||||||
|
new LegacyBlock(408, "hopper_minecart"), new LegacyBlock(409, "prismarine_shard"),
|
||||||
|
new LegacyBlock(410, "prismarine_crystals"), new LegacyBlock(411, "rabbit"),
|
||||||
|
new LegacyBlock(412, "cooked_rabbit"), new LegacyBlock(413, "rabbit_stew"),
|
||||||
|
new LegacyBlock(414, "rabbit_foot"), new LegacyBlock(415, "rabbit_hide"),
|
||||||
|
new LegacyBlock(416, "armor_stand"),
|
||||||
|
new LegacyBlock(417, "iron_barding", "iron_horse_armor"),
|
||||||
|
new LegacyBlock(418, "gold_barding", "gold_horse_armor"),
|
||||||
|
new LegacyBlock(419, "diamond_barding", "diamond_horse_armor"),
|
||||||
|
new LegacyBlock(420, "leash", "lead"), new LegacyBlock(421, "name_tag"),
|
||||||
|
new LegacyBlock(422, "command_minecart", "command_block_minecart"),
|
||||||
|
new LegacyBlock(423, "mutton"), new LegacyBlock(424, "cooked_mutton"),
|
||||||
|
new LegacyBlock(425, "banner", "white_banner"),
|
||||||
|
new LegacyBlock(425, 1, "banner", "orange_banner"),
|
||||||
|
new LegacyBlock(425, 2, "banner", "magenta_banner"),
|
||||||
|
new LegacyBlock(425, 3, "banner", "light_blue_banner"),
|
||||||
|
new LegacyBlock(425, 4, "banner", "yellow_banner"),
|
||||||
|
new LegacyBlock(425, 5, "banner", "lime_banner"),
|
||||||
|
new LegacyBlock(425, 6, "banner", "pink_banner"),
|
||||||
|
new LegacyBlock(425, 7, "banner", "gray_banner"),
|
||||||
|
new LegacyBlock(425, 8, "banner", "light_gray_banner"),
|
||||||
|
new LegacyBlock(425, 9, "banner", "cyan_banner"),
|
||||||
|
new LegacyBlock(425, 10, "banner", "purple_banner"),
|
||||||
|
new LegacyBlock(425, 11, "banner", "blue_banner"),
|
||||||
|
new LegacyBlock(425, 12, "banner", "brown_banner"),
|
||||||
|
new LegacyBlock(425, 13, "banner", "green_banner"),
|
||||||
|
new LegacyBlock(425, 14, "banner", "red_banner"),
|
||||||
|
new LegacyBlock(425, 15, "banner", "black_banner"), new LegacyBlock(426, "end_crystal"),
|
||||||
|
new LegacyBlock(427, "spruce_door_item", "spruce_door"),
|
||||||
|
new LegacyBlock(428, "birch_door_item", "birch_door"),
|
||||||
|
new LegacyBlock(429, "jungle_door_item", "jungle_door"),
|
||||||
|
new LegacyBlock(430, "acacia_door_item", "acacia_door"),
|
||||||
|
new LegacyBlock(431, "dark_oak_door_item", "dark_oak_door"),
|
||||||
|
new LegacyBlock(432, "chorus_fruit"), new LegacyBlock(433, "chorus_fruit_popped"),
|
||||||
|
new LegacyBlock(434, "beetroot"), new LegacyBlock(435, "beetroot_seeds"),
|
||||||
|
new LegacyBlock(436, "beetroot_soup"),
|
||||||
|
new LegacyBlock(437, "dragons_breath", "dragon_breath"),
|
||||||
|
new LegacyBlock(438, "splash_potion"), new LegacyBlock(439, "spectral_arrow"),
|
||||||
|
new LegacyBlock(440, "tipped_arrow"), new LegacyBlock(441, "lingering_potion"),
|
||||||
|
new LegacyBlock(442, "shield"), new LegacyBlock(443, "elytra"),
|
||||||
|
new LegacyBlock(444, "boat_spruce", "spruce_boat"),
|
||||||
|
new LegacyBlock(445, "boat_birch", "birch_boat"),
|
||||||
|
new LegacyBlock(446, "boat_jungle", "jungle_boat"),
|
||||||
|
new LegacyBlock(447, "boat_acacia", "acacia_boat"),
|
||||||
|
new LegacyBlock(448, "boat_dark_oak", "dark_oak_boat"),
|
||||||
|
new LegacyBlock(449, "totem", "totem_of_undying"),
|
||||||
|
new LegacyBlock(450, "shulker_shell"), new LegacyBlock(452, "iron_nugget"),
|
||||||
|
new LegacyBlock(453, "knowledge_book"),
|
||||||
|
new LegacyBlock(2256, "gold_record", "music_disc_13"),
|
||||||
|
new LegacyBlock(2257, "green_record", "music_disc_cat"),
|
||||||
|
new LegacyBlock(2258, "record_3", "music_disc_blocks"),
|
||||||
|
new LegacyBlock(2259, "record_4", "music_disc_chirp"),
|
||||||
|
new LegacyBlock(2260, "record_5", "music_disc_far"),
|
||||||
|
new LegacyBlock(2261, "record_6", "music_disc_mall"),
|
||||||
|
new LegacyBlock(2262, "record_7", "music_disc_mellohi"),
|
||||||
|
new LegacyBlock(2263, "record_8", "music_disc_stal"),
|
||||||
|
new LegacyBlock(2264, "record_9", "music_disc_strad"),
|
||||||
|
new LegacyBlock(2265, "record_10", "music_disc_ward"),
|
||||||
|
new LegacyBlock(2266, "record_11", "music_disc_11"),
|
||||||
|
new LegacyBlock(2267, "record_12", "music_disc_wait")};
|
||||||
|
|
||||||
|
private static final Map<Integer, PlotBlock> LEGACY_ID_TO_STRING_PLOT_BLOCK = new HashMap<>();
|
||||||
|
private static final Map<IdDataPair, PlotBlock> LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK =
|
||||||
|
new HashMap<>();
|
||||||
|
private static final Map<String, PlotBlock> NEW_STRING_TO_LEGACY_PLOT_BLOCK = new HashMap<>();
|
||||||
|
private static final Map<String, PlotBlock> OLD_STRING_TO_STRING_PLOT_BLOCK = new HashMap<>();
|
||||||
|
|
||||||
|
public BukkitLegacyMappings() {
|
||||||
|
for (final LegacyBlock legacyBlock : BLOCKS) {
|
||||||
|
LEGACY_ID_TO_STRING_PLOT_BLOCK
|
||||||
|
.put(legacyBlock.getNumericalId(), legacyBlock.toStringPlotBlock());
|
||||||
|
if (legacyBlock.getDataValue() != 0) {
|
||||||
|
LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK
|
||||||
|
.put(new IdDataPair(legacyBlock.getNumericalId(), legacyBlock.getDataValue()),
|
||||||
|
legacyBlock.toStringPlotBlock());
|
||||||
|
}
|
||||||
|
NEW_STRING_TO_LEGACY_PLOT_BLOCK
|
||||||
|
.put(legacyBlock.getLegacyName(), legacyBlock.toStringPlotBlock());
|
||||||
|
OLD_STRING_TO_STRING_PLOT_BLOCK
|
||||||
|
.put(legacyBlock.getNewName(), legacyBlock.toLegacyPlotBlock());
|
||||||
|
Material material;
|
||||||
|
try {
|
||||||
|
material = Material.valueOf(legacyBlock.getNewName());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
material = Material.getMaterial(legacyBlock.getLegacyName(), true);
|
||||||
|
}
|
||||||
|
legacyBlock.material = material;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<PlotBlock> getPlotBlocks() {
|
||||||
|
return Arrays.stream(BLOCKS).map(block -> PlotBlock.get(block.getNewName()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringComparison<PlotBlock>.ComparisonResult getClosestsMatch(
|
||||||
|
@NonNull final String string) {
|
||||||
|
final StringComparison<PlotBlock> comparison =
|
||||||
|
new StringComparison<>(string, getPlotBlocks());
|
||||||
|
return comparison.getBestMatchAdvanced();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to find a legacy plot block by any means possible.
|
||||||
|
* Strategy:
|
||||||
|
* - Check if the name contains a namespace, if so, strip it
|
||||||
|
* - Check if there's a (new) material matching the name
|
||||||
|
* - Check if there's a legacy material matching the name
|
||||||
|
* - Check if there's a numerical ID matching the name
|
||||||
|
* - Return null if everything else fails
|
||||||
|
*
|
||||||
|
* @param string String ID
|
||||||
|
* @return LegacyBlock if found, else null
|
||||||
|
*/
|
||||||
|
public PlotBlock fromAny(@NonNull final String string) {
|
||||||
|
String workingString = string;
|
||||||
|
String[] parts = null;
|
||||||
|
if (string.contains(":")) {
|
||||||
|
parts = string.split(":");
|
||||||
|
if (parts.length > 1) {
|
||||||
|
if (parts[0].equalsIgnoreCase("minecraft")) {
|
||||||
|
workingString = parts[1];
|
||||||
|
} else {
|
||||||
|
workingString = parts[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlotBlock plotBlock = fromStringToLegacy(workingString);
|
||||||
|
if (plotBlock != null) {
|
||||||
|
return plotBlock;
|
||||||
|
} else if ((plotBlock = fromLegacyToString(workingString)) != null) {
|
||||||
|
return plotBlock;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (parts != null && parts.length > 1) {
|
||||||
|
final int id = Integer.parseInt(parts[0]);
|
||||||
|
final int data = Integer.parseInt(parts[1]);
|
||||||
|
return fromLegacyToString(id, data);
|
||||||
|
} else {
|
||||||
|
return fromLegacyToString(Integer.parseInt(workingString));
|
||||||
|
}
|
||||||
|
} catch (final Throwable exception) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlotBlock fromLegacyToString(final int id) {
|
||||||
|
return LEGACY_ID_TO_STRING_PLOT_BLOCK.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlotBlock fromLegacyToString(final int id, final int data) {
|
||||||
|
if (data == 0) {
|
||||||
|
return fromLegacyToString(id);
|
||||||
|
}
|
||||||
|
return LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK.get(new IdDataPair(id, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlotBlock fromLegacyToString(final String id) {
|
||||||
|
return NEW_STRING_TO_LEGACY_PLOT_BLOCK.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlotBlock fromStringToLegacy(final String id) {
|
||||||
|
return OLD_STRING_TO_STRING_PLOT_BLOCK.get(id.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter @EqualsAndHashCode @ToString @RequiredArgsConstructor
|
||||||
|
private static final class IdDataPair {
|
||||||
|
private final int id;
|
||||||
|
private final int data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Getter @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public static final class LegacyBlock {
|
||||||
|
|
||||||
|
private final int numericalId;
|
||||||
|
private final int dataValue;
|
||||||
|
private final String legacyName;
|
||||||
|
private final String newName;
|
||||||
|
|
||||||
|
private Material material;
|
||||||
|
|
||||||
|
LegacyBlock(final int numericalId, final int dataValue, @NonNull final String legacyName) {
|
||||||
|
this(numericalId, dataValue, legacyName, legacyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyBlock(final int numericalId, @NonNull final String legacyName,
|
||||||
|
@NonNull final String newName) {
|
||||||
|
this(numericalId, 0, legacyName, newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
LegacyBlock(final int numericalId, @NonNull final String legacyName) {
|
||||||
|
this(numericalId, legacyName, legacyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlotBlock toStringPlotBlock() {
|
||||||
|
return StringPlotBlock.get(newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
PlotBlock toLegacyPlotBlock() {
|
||||||
|
return LegacyPlotBlock.get(numericalId, dataValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return this.newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,220 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||||
|
import com.sk89q.jnbt.*;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schematic Handler.
|
||||||
|
*/
|
||||||
|
public class BukkitSchematicHandler extends SchematicHandler {
|
||||||
|
|
||||||
|
@Override public void getCompoundTag(final String world, final Set<RegionWrapper> regions,
|
||||||
|
final RunnableVal<CompoundTag> whenDone) {
|
||||||
|
// async
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
// Main positions
|
||||||
|
Location[] corners = MainUtil.getCorners(world, regions);
|
||||||
|
final Location bot = corners[0];
|
||||||
|
Location top = corners[1];
|
||||||
|
|
||||||
|
CuboidRegion cuboidRegion =
|
||||||
|
new CuboidRegion(BukkitUtil.IMP.getWeWorld(world), bot.getBlockVector3(),
|
||||||
|
top.getBlockVector3());
|
||||||
|
|
||||||
|
final int width = top.getX() - bot.getX() + 1;
|
||||||
|
int height = top.getY() - bot.getY() + 1;
|
||||||
|
final int length = top.getZ() - bot.getZ() + 1;
|
||||||
|
Map<String, Tag> schematic = new HashMap<>();
|
||||||
|
schematic.put("Version", new IntTag(1));
|
||||||
|
|
||||||
|
Map<String, Tag> metadata = new HashMap<>();
|
||||||
|
metadata.put("WEOffsetX", new IntTag(0));
|
||||||
|
metadata.put("WEOffsetY", new IntTag(0));
|
||||||
|
metadata.put("WEOffsetZ", new IntTag(0));
|
||||||
|
|
||||||
|
schematic.put("Metadata", new CompoundTag(metadata));
|
||||||
|
|
||||||
|
schematic.put("Width", new ShortTag((short) width));
|
||||||
|
schematic.put("Height", new ShortTag((short) height));
|
||||||
|
schematic.put("Length", new ShortTag((short) length));
|
||||||
|
|
||||||
|
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
|
||||||
|
schematic.put("Offset", new IntArrayTag(new int[] {0, 0, 0,}));
|
||||||
|
|
||||||
|
final int[] paletteMax = {0};
|
||||||
|
Map<String, Integer> palette = new HashMap<>();
|
||||||
|
|
||||||
|
List<CompoundTag> tileEntities = new ArrayList<>();
|
||||||
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
|
||||||
|
// Queue
|
||||||
|
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
||||||
|
TaskManager.runTask(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
if (queue.isEmpty()) {
|
||||||
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
schematic.put("PaletteMax", new IntTag(paletteMax[0]));
|
||||||
|
|
||||||
|
Map<String, Tag> paletteTag = new HashMap<>();
|
||||||
|
palette.forEach(
|
||||||
|
(key, value) -> paletteTag.put(key, new IntTag(value)));
|
||||||
|
|
||||||
|
schematic.put("Palette", new CompoundTag(paletteTag));
|
||||||
|
schematic
|
||||||
|
.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
|
||||||
|
schematic.put("TileEntities",
|
||||||
|
new ListTag(CompoundTag.class, tileEntities));
|
||||||
|
whenDone.value = new CompoundTag(schematic);
|
||||||
|
TaskManager.runTask(whenDone);
|
||||||
|
System.gc();
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Runnable regionTask = this;
|
||||||
|
RegionWrapper region = queue.poll();
|
||||||
|
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
||||||
|
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
||||||
|
final int bx = bot.getX();
|
||||||
|
final int bz = bot.getZ();
|
||||||
|
final int p1x = pos1.getX();
|
||||||
|
final int p1z = pos1.getZ();
|
||||||
|
final int p2x = pos2.getX();
|
||||||
|
final int p2z = pos2.getZ();
|
||||||
|
final int bcx = p1x >> 4;
|
||||||
|
final int bcz = p1z >> 4;
|
||||||
|
final int tcx = p2x >> 4;
|
||||||
|
final int tcz = p2z >> 4;
|
||||||
|
final int sy = pos1.getY();
|
||||||
|
final int ey = pos2.getY();
|
||||||
|
// Generate list of chunks
|
||||||
|
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
|
||||||
|
for (int x = bcx; x <= tcx; x++) {
|
||||||
|
for (int z = bcz; z <= tcz; z++) {
|
||||||
|
chunks.add(new ChunkLoc(x, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
|
// Main thread
|
||||||
|
TaskManager.runTask(new Runnable() {
|
||||||
|
@Override public void run() {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
while (!chunks.isEmpty()
|
||||||
|
&& System.currentTimeMillis() - start < 20) {
|
||||||
|
// save schematics
|
||||||
|
ChunkLoc chunk = chunks.remove(0);
|
||||||
|
Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||||
|
if (!bc.load(false)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int X = chunk.x;
|
||||||
|
int Z = chunk.z;
|
||||||
|
int xxb = X << 4;
|
||||||
|
int zzb = Z << 4;
|
||||||
|
int xxt = xxb + 15;
|
||||||
|
int zzt = zzb + 15;
|
||||||
|
|
||||||
|
if (X == bcx) {
|
||||||
|
xxb = p1x;
|
||||||
|
}
|
||||||
|
if (X == tcx) {
|
||||||
|
xxt = p2x;
|
||||||
|
}
|
||||||
|
if (Z == bcz) {
|
||||||
|
zzb = p1z;
|
||||||
|
}
|
||||||
|
if (Z == tcz) {
|
||||||
|
zzt = p2z;
|
||||||
|
}
|
||||||
|
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||||
|
int ry = y - sy;
|
||||||
|
int i1 = ry * width * length;
|
||||||
|
for (int z = zzb; z <= zzt; z++) {
|
||||||
|
int rz = z - bz;
|
||||||
|
int i2 = i1 + rz * width;
|
||||||
|
for (int x = xxb; x <= xxt; x++) {
|
||||||
|
int rx = x - bx;
|
||||||
|
int index = i2 + rx;
|
||||||
|
BlockVector3 point = BlockVector3.at(x, y, z);
|
||||||
|
BaseBlock block =
|
||||||
|
cuboidRegion.getWorld().getFullBlock(point);
|
||||||
|
if (block.getNbtData() != null) {
|
||||||
|
Map<String, Tag> values = new HashMap<>();
|
||||||
|
for (Map.Entry<String, Tag> entry : block
|
||||||
|
.getNbtData().getValue().entrySet()) {
|
||||||
|
values
|
||||||
|
.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
values.remove(
|
||||||
|
"id"); // Remove 'id' if it exists. We want 'Id'
|
||||||
|
|
||||||
|
// Positions are kept in NBT, we don't want that.
|
||||||
|
values.remove("x");
|
||||||
|
values.remove("y");
|
||||||
|
values.remove("z");
|
||||||
|
|
||||||
|
values
|
||||||
|
.put("Id", new StringTag(block.getNbtId()));
|
||||||
|
values.put("Pos",
|
||||||
|
new IntArrayTag(new int[] {x, y, z}));
|
||||||
|
|
||||||
|
tileEntities.add(new CompoundTag(values));
|
||||||
|
}
|
||||||
|
String blockKey =
|
||||||
|
block.toImmutableState().getAsString();
|
||||||
|
int blockId;
|
||||||
|
if (palette.containsKey(blockKey)) {
|
||||||
|
blockId = palette.get(blockKey);
|
||||||
|
} else {
|
||||||
|
blockId = paletteMax[0];
|
||||||
|
palette.put(blockKey, blockId);
|
||||||
|
paletteMax[0]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((blockId & -128) != 0) {
|
||||||
|
buffer.write(blockId & 127 | 128);
|
||||||
|
blockId >>>= 7;
|
||||||
|
}
|
||||||
|
buffer.write(blockId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!chunks.isEmpty()) {
|
||||||
|
TaskManager.runTaskLater(this, 1);
|
||||||
|
} else {
|
||||||
|
regionTask.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean restoreTile(LocalBlockQueue queue, CompoundTag ct, int x, int y, int z) {
|
||||||
|
return new StateWrapper(ct).restoreTag(queue.getWorld(), x, y, z);
|
||||||
|
}
|
||||||
|
}
|
@ -1,33 +1,29 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||||
|
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
|
||||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
|
||||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.World.Environment;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.WorldType;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class BukkitSetupUtils extends SetupUtils {
|
public class BukkitSetupUtils extends SetupUtils {
|
||||||
|
|
||||||
@Override
|
@Override public void updateGenerators() {
|
||||||
public void updateGenerators() {
|
|
||||||
if (!SetupUtils.generators.isEmpty()) {
|
if (!SetupUtils.generators.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -37,7 +33,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
ChunkGenerator generator = plugin.getDefaultWorldGenerator(testWorld, "");
|
||||||
if (generator != null) {
|
if (generator != null) {
|
||||||
PS.get().removePlotAreas(testWorld);
|
PlotSquared.get().removePlotAreas(testWorld);
|
||||||
String name = plugin.getDescription().getName();
|
String name = plugin.getDescription().getName();
|
||||||
GeneratorWrapper<?> wrapped;
|
GeneratorWrapper<?> wrapped;
|
||||||
if (generator instanceof GeneratorWrapper<?>) {
|
if (generator instanceof GeneratorWrapper<?>) {
|
||||||
@ -54,8 +50,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void unload(String worldName, boolean save) {
|
||||||
public void unload(String worldName, boolean save) {
|
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return;
|
return;
|
||||||
@ -76,8 +71,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
Bukkit.unloadWorld(world, false);
|
Bukkit.unloadWorld(world, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String setupWorld(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;
|
||||||
String world = object.world;
|
String world = object.world;
|
||||||
@ -86,16 +80,18 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case 2: {
|
case 2: {
|
||||||
if (object.id != null) {
|
if (object.id != null) {
|
||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PlotSquared.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||||
String areaName = object.id + "-" + object.min + "-" + object.max;
|
String areaName = object.id + "-" + object.min + "-" + object.max;
|
||||||
String areaPath = "areas." + areaName;
|
String areaPath = "areas." + areaName;
|
||||||
if (!worldSection.contains(areaPath)) {
|
if (!worldSection.contains(areaPath)) {
|
||||||
worldSection.createSection(areaPath);
|
worldSection.createSection(areaPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection areaSection = worldSection.getConfigurationSection(areaPath);
|
ConfigurationSection areaSection =
|
||||||
|
worldSection.getConfigurationSection(areaPath);
|
||||||
HashMap<String, Object> options = new HashMap<>();
|
HashMap<String, Object> options = new HashMap<>();
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
options.put(step.getConstant(), step.getValue());
|
options.put(step.getConstant(), step.getValue());
|
||||||
@ -103,7 +99,8 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
options.put("generator.type", object.type);
|
options.put("generator.type", object.type);
|
||||||
options.put("generator.terrain", object.terrain);
|
options.put("generator.terrain", object.terrain);
|
||||||
options.put("generator.plugin", object.plotManager);
|
options.put("generator.plugin", object.plotManager);
|
||||||
if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) {
|
if (object.setupGenerator != null && !object.setupGenerator
|
||||||
|
.equals(object.plotManager)) {
|
||||||
options.put("generator.init", object.setupGenerator);
|
options.put("generator.init", object.setupGenerator);
|
||||||
}
|
}
|
||||||
for (Entry<String, Object> entry : options.entrySet()) {
|
for (Entry<String, Object> entry : options.entrySet()) {
|
||||||
@ -126,18 +123,23 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PlotSquared.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.type", object.type);
|
PlotSquared.get().worlds.set("worlds." + world + ".generator.type", object.type);
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.terrain", object.terrain);
|
PlotSquared.get().worlds
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.plugin", object.plotManager);
|
.set("worlds." + world + ".generator.terrain", object.terrain);
|
||||||
if (object.setupGenerator != null && !object.setupGenerator.equals(object.plotManager)) {
|
PlotSquared.get().worlds
|
||||||
PS.get().worlds.set("worlds." + world + ".generator.init", object.setupGenerator);
|
.set("worlds." + world + ".generator.plugin", object.plotManager);
|
||||||
|
if (object.setupGenerator != null && !object.setupGenerator
|
||||||
|
.equals(object.plotManager)) {
|
||||||
|
PlotSquared.get().worlds
|
||||||
|
.set("worlds." + world + ".generator.init", object.setupGenerator);
|
||||||
}
|
}
|
||||||
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
|
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
|
||||||
if (gen != null && gen.isFull()) {
|
if (gen != null && gen.isFull()) {
|
||||||
@ -147,10 +149,11 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
case 0: {
|
case 0: {
|
||||||
if (steps.length != 0) {
|
if (steps.length != 0) {
|
||||||
if (!PS.get().worlds.contains(worldPath)) {
|
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||||
PS.get().worlds.createSection(worldPath);
|
PlotSquared.get().worlds.createSection(worldPath);
|
||||||
}
|
}
|
||||||
ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath);
|
ConfigurationSection worldSection =
|
||||||
|
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||||
for (ConfigurationNode step : steps) {
|
for (ConfigurationNode step : steps) {
|
||||||
worldSection.set(step.getConstant(), step.getValue());
|
worldSection.set(step.getConstant(), step.getValue());
|
||||||
}
|
}
|
||||||
@ -159,22 +162,24 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
PS.get().worlds.save(PS.get().worldsFile);
|
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (object.setupGenerator != null) {
|
if (object.setupGenerator != null) {
|
||||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||||
.isEnabled()) {
|
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
Bukkit.getServer()
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
.dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal -g " + object.setupGenerator);
|
"mv create " + world + " normal -g " + object.setupGenerator);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world + " plugin:" + object.setupGenerator);
|
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mw create " + world + " plugin:" + object.setupGenerator);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
@ -187,20 +192,24 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
Bukkit.createWorld(wc);
|
Bukkit.createWorld(wc);
|
||||||
setGenerator(world, object.setupGenerator);
|
setGenerator(world, object.setupGenerator);
|
||||||
} else {
|
} else {
|
||||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit.getPluginManager().getPlugin("Multiverse-Core")
|
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||||
.isEnabled()) {
|
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv create " + world + " normal");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||||
|
"mv create " + world + " normal");
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
|
Bukkit.getServer()
|
||||||
|
.dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
||||||
if (Bukkit.getWorld(world) != null) {
|
if (Bukkit.getWorld(world) != null) {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
World bw = Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
|
World bw =
|
||||||
|
Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
|
||||||
}
|
}
|
||||||
return object.world;
|
return object.world;
|
||||||
}
|
}
|
||||||
@ -219,8 +228,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getGenerator(PlotArea plotArea) {
|
||||||
public String getGenerator(PlotArea plotArea) {
|
|
||||||
if (SetupUtils.generators.isEmpty()) {
|
if (SetupUtils.generators.isEmpty()) {
|
||||||
updateGenerators();
|
updateGenerators();
|
||||||
}
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class BukkitTaskManager extends TaskManager {
|
||||||
|
|
||||||
|
private final BukkitMain bukkitMain;
|
||||||
|
|
||||||
|
public BukkitTaskManager(BukkitMain bukkitMain) {
|
||||||
|
this.bukkitMain = bukkitMain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int taskRepeat(Runnable runnable, int interval) {
|
||||||
|
return this.bukkitMain.getServer().getScheduler()
|
||||||
|
.scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation") @Override
|
||||||
|
public int taskRepeatAsync(Runnable runnable, int interval) {
|
||||||
|
return this.bukkitMain.getServer().getScheduler()
|
||||||
|
.scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void taskAsync(Runnable runnable) {
|
||||||
|
this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable)
|
||||||
|
.getTaskId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void task(Runnable runnable) {
|
||||||
|
this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void taskLater(Runnable runnable, int delay) {
|
||||||
|
this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay)
|
||||||
|
.getTaskId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void taskLaterAsync(Runnable runnable, int delay) {
|
||||||
|
this.bukkitMain.getServer().getScheduler()
|
||||||
|
.runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void cancelTask(int task) {
|
||||||
|
if (task != -1) {
|
||||||
|
Bukkit.getScheduler().cancelTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,471 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.material.*;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil {
|
||||||
|
|
||||||
|
private static String lastString = null;
|
||||||
|
private static World lastWorld = null;
|
||||||
|
|
||||||
|
private static Player lastPlayer = null;
|
||||||
|
private static PlotPlayer lastPlotPlayer = null;
|
||||||
|
|
||||||
|
public static void removePlayer(String player) {
|
||||||
|
lastPlayer = null;
|
||||||
|
lastPlotPlayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotPlayer getPlayer(@NonNull final OfflinePlayer op) {
|
||||||
|
if (op.isOnline()) {
|
||||||
|
return getPlayer(op.getPlayer());
|
||||||
|
}
|
||||||
|
final Player player = OfflinePlayerUtil.loadPlayer(op);
|
||||||
|
player.loadData();
|
||||||
|
return new BukkitPlayer(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a plot based on the location.
|
||||||
|
*
|
||||||
|
* @param location the location to check
|
||||||
|
* @return plot if found, otherwise it creates a temporary plot
|
||||||
|
* @see Plot
|
||||||
|
*/
|
||||||
|
public static Plot getPlot(org.bukkit.Location location) {
|
||||||
|
if (location == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getLocation(location).getPlot();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a plot based on the player location.
|
||||||
|
*
|
||||||
|
* @param player the player to check
|
||||||
|
* @return plot if found, otherwise it creates a temporary plot
|
||||||
|
* @see #getPlot(org.bukkit.Location)
|
||||||
|
* @see Plot
|
||||||
|
*/
|
||||||
|
public static Plot getPlot(Player player) {
|
||||||
|
return getPlot(player.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get home location.
|
||||||
|
*
|
||||||
|
* @param plot Plot that you want to get the location for
|
||||||
|
* @return plot bottom location
|
||||||
|
* @see Plot
|
||||||
|
*/
|
||||||
|
public static org.bukkit.Location getHomeLocation(Plot plot) {
|
||||||
|
return BukkitUtil.getLocation(plot.getHome());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the PlotPlayer for an offline player.
|
||||||
|
*
|
||||||
|
* <p>Note that this will work if the player is offline, however not all
|
||||||
|
* functionality will work.
|
||||||
|
*
|
||||||
|
* @param player the player to wrap
|
||||||
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
|
*/
|
||||||
|
public static PlotPlayer wrapPlayer(OfflinePlayer player) {
|
||||||
|
return PlotPlayer.wrap(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
||||||
|
* will provide useful functions relating to players.
|
||||||
|
*
|
||||||
|
* @param player the player to wrap
|
||||||
|
* @return a {@code PlotPlayer}
|
||||||
|
* @see PlotPlayer#wrap(Object)
|
||||||
|
*/
|
||||||
|
public static PlotPlayer wrapPlayer(Player player) {
|
||||||
|
return PlotPlayer.wrap(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the number of plots, which the player is able to build in.
|
||||||
|
*
|
||||||
|
* @param player player, for whom we're getting the plots
|
||||||
|
* @return the number of allowed plots
|
||||||
|
*/
|
||||||
|
public static int getAllowedPlots(Player player) {
|
||||||
|
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
||||||
|
return plotPlayer.getAllowedPlots();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether or not a player is in a plot.
|
||||||
|
*
|
||||||
|
* @param player who we're checking for
|
||||||
|
* @return true if the player is in a plot, false if not-
|
||||||
|
*/
|
||||||
|
public static boolean isInPlot(Player player) {
|
||||||
|
return getPlot(player) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a collection containing the players plots.
|
||||||
|
*
|
||||||
|
* @param world Specify the world we want to select the plots from
|
||||||
|
* @param player Player, for whom we're getting the plots
|
||||||
|
* @return a set containing the players plots
|
||||||
|
* @see Plot
|
||||||
|
*/
|
||||||
|
public static Set<Plot> getPlayerPlots(String world, Player player) {
|
||||||
|
if (world == null) {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
return PlotPlayer.wrap(player).getPlots(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to a player. The message supports color codes.
|
||||||
|
*
|
||||||
|
* @param player the recipient of the message
|
||||||
|
* @param string the message
|
||||||
|
* @see MainUtil#sendMessage(PlotPlayer, String)
|
||||||
|
*/
|
||||||
|
public static void sendMessage(Player player, String string) {
|
||||||
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player plot count.
|
||||||
|
*
|
||||||
|
* @param world Specify the world we want to select the plots from
|
||||||
|
* @param player Player, for whom we're getting the plot count
|
||||||
|
* @return the number of plots the player has
|
||||||
|
*/
|
||||||
|
public static int getPlayerPlotCount(String world, Player player) {
|
||||||
|
if (world == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return BukkitUtil.getPlayer(player).getPlotCount(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to a player.
|
||||||
|
*
|
||||||
|
* @param player the recipient of the message
|
||||||
|
* @param caption the message
|
||||||
|
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||||
|
*/
|
||||||
|
public static void sendMessage(Player player, C caption) {
|
||||||
|
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotPlayer getPlayer(@NonNull final Player player) {
|
||||||
|
if (player == lastPlayer) {
|
||||||
|
return lastPlotPlayer;
|
||||||
|
}
|
||||||
|
final String name = player.getName();
|
||||||
|
final PlotPlayer plotPlayer = UUIDHandler.getPlayer(name);
|
||||||
|
if (plotPlayer != null) {
|
||||||
|
return plotPlayer;
|
||||||
|
}
|
||||||
|
lastPlotPlayer = new BukkitPlayer(player);
|
||||||
|
UUIDHandler.getPlayers().put(name, lastPlotPlayer);
|
||||||
|
lastPlayer = player;
|
||||||
|
return lastPlotPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location getLocation(@NonNull final org.bukkit.Location location) {
|
||||||
|
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||||
|
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.bukkit.Location getLocation(@NonNull final Location location) {
|
||||||
|
return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(),
|
||||||
|
location.getY(), location.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static World getWorld(@NonNull final String string) {
|
||||||
|
return Bukkit.getWorld(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getWorld(@NonNull final Entity entity) {
|
||||||
|
return entity.getWorld().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Entity> getEntities(@NonNull final String worldName) {
|
||||||
|
World world = getWorld(worldName);
|
||||||
|
return world != null ? world.getEntities() : new ArrayList<Entity>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location getLocation(@NonNull final Entity entity) {
|
||||||
|
final org.bukkit.Location location = entity.getLocation();
|
||||||
|
String world = location.getWorld().getName();
|
||||||
|
return new Location(world, location.getBlockX(), location.getBlockY(),
|
||||||
|
location.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Location getLocationFull(@NonNull final Entity entity) {
|
||||||
|
final org.bukkit.Location location = entity.getLocation();
|
||||||
|
return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()),
|
||||||
|
MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), location.getYaw(),
|
||||||
|
location.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitLegacyMappings getBukkitLegacyMappings() {
|
||||||
|
return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Material getMaterial(@NonNull final PlotBlock plotBlock) {
|
||||||
|
if (plotBlock instanceof StringPlotBlock) {
|
||||||
|
return Material
|
||||||
|
.getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH));
|
||||||
|
} else {
|
||||||
|
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||||
|
return getBukkitLegacyMappings()
|
||||||
|
.fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData())
|
||||||
|
.to(Material.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean isBlockSame(PlotBlock block1, PlotBlock block2) {
|
||||||
|
if (block1.equals(block2)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Material mat1 = getMaterial(block1), mat2 = getMaterial(block2);
|
||||||
|
return mat1 == mat2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean isWorld(@NonNull final String worldName) {
|
||||||
|
return getWorld(worldName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getBiome(String world, int x, int z) {
|
||||||
|
return getWorld(world).getBiome(x, z).name();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @SuppressWarnings("deprecation")
|
||||||
|
public void setSign(@NonNull final String worldName, final int x, final int y, final int z,
|
||||||
|
@NonNull final String[] lines) {
|
||||||
|
final World world = getWorld(worldName);
|
||||||
|
final Block block = world.getBlockAt(x, y, z);
|
||||||
|
// block.setType(Material.AIR);
|
||||||
|
final Material type = block.getType();
|
||||||
|
if (type != Material.SIGN && type != Material.WALL_SIGN) {
|
||||||
|
int data = 2;
|
||||||
|
if (world.getBlockAt(x, y, z + 1).getType().isSolid())
|
||||||
|
data = 2;
|
||||||
|
else if (world.getBlockAt(x + 1, y, z).getType().isSolid())
|
||||||
|
data = 4;
|
||||||
|
else if (world.getBlockAt(x, y, z - 1).getType().isSolid())
|
||||||
|
data = 3;
|
||||||
|
else if (world.getBlockAt(x - 1, y, z).getType().isSolid())
|
||||||
|
data = 5;
|
||||||
|
block.setType(Material.WALL_SIGN, false);
|
||||||
|
final Sign sign = (Sign) block.getBlockData();
|
||||||
|
sign.setRawData((byte) data);
|
||||||
|
}
|
||||||
|
final BlockState blockstate = block.getState();
|
||||||
|
if (blockstate instanceof Sign) {
|
||||||
|
final Sign sign = (Sign) blockstate;
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
sign.setLine(i, lines[i]);
|
||||||
|
}
|
||||||
|
sign.update(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @Nullable public String[] getSign(@NonNull final Location location) {
|
||||||
|
Block block = getWorld(location.getWorld())
|
||||||
|
.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
|
if (block != null) {
|
||||||
|
if (block.getState() instanceof Sign) {
|
||||||
|
Sign sign = (Sign) block.getState();
|
||||||
|
return sign.getLines();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public Location getSpawn(@NonNull final PlotPlayer player) {
|
||||||
|
return getLocation(((BukkitPlayer) player).player.getBedSpawnLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public Location getSpawn(@NonNull final String world) {
|
||||||
|
final org.bukkit.Location temp = getWorld(world).getSpawnLocation();
|
||||||
|
return new Location(world, temp.getBlockX(), temp.getBlockY(), temp.getBlockZ(),
|
||||||
|
temp.getYaw(), temp.getPitch());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void setSpawn(@NonNull final Location location) {
|
||||||
|
final World world = getWorld(location.getWorld());
|
||||||
|
if (world != null) {
|
||||||
|
world.setSpawnLocation(location.getX(), location.getY(), location.getZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void saveWorld(@NonNull final String worldName) {
|
||||||
|
final World world = getWorld(worldName);
|
||||||
|
if (world != null) {
|
||||||
|
world.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int getHighestBlock(@NonNull final String world, final int x, final int z) {
|
||||||
|
final World bukkitWorld = getWorld(world);
|
||||||
|
// Skip top and bottom block
|
||||||
|
int air = 1;
|
||||||
|
for (int y = bukkitWorld.getMaxHeight() - 1; y >= 0; y--) {
|
||||||
|
Block block = bukkitWorld.getBlockAt(x, y, z);
|
||||||
|
if (block != null) {
|
||||||
|
Material type = block.getType();
|
||||||
|
if (type.isSolid()) {
|
||||||
|
if (air > 1)
|
||||||
|
return y;
|
||||||
|
air = 0;
|
||||||
|
} else {
|
||||||
|
switch (type) {
|
||||||
|
case WATER:
|
||||||
|
case LAVA:
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
air++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bukkitWorld.getMaxHeight() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int getBiomeFromString(@NonNull final String biomeString) {
|
||||||
|
try {
|
||||||
|
final Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
||||||
|
return Arrays.asList(Biome.values()).indexOf(biome);
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String[] getBiomeList() {
|
||||||
|
final Biome[] biomes = Biome.values();
|
||||||
|
final String[] list = new String[biomes.length];
|
||||||
|
for (int i = 0; i < biomes.length; i++) {
|
||||||
|
list[i] = biomes[i].name();
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) {
|
||||||
|
final World world = getWorld(worldName);
|
||||||
|
final Block block = world.getBlockAt(items.x, items.y, items.z);
|
||||||
|
if (block == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final BlockState state = block.getState();
|
||||||
|
if (state instanceof InventoryHolder) {
|
||||||
|
InventoryHolder holder = (InventoryHolder) state;
|
||||||
|
Inventory inv = holder.getInventory();
|
||||||
|
for (int i = 0; i < items.types.length; i++) {
|
||||||
|
// ItemStack item = new ItemStack(LegacyMappings.fromLegacyId(items.id[i]).getMaterial(), items.amount[i], items.data[i]);
|
||||||
|
ItemStack item = new ItemStack(items.types[i].to(Material.class), items.amount[i]);
|
||||||
|
inv.addItem(item);
|
||||||
|
}
|
||||||
|
state.update(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean isBlockSolid(@NonNull final PlotBlock block) {
|
||||||
|
try {
|
||||||
|
final Material material = getMaterial(block);
|
||||||
|
if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
|
||||||
|
Class<? extends MaterialData> data = material.getData();
|
||||||
|
if (data.equals(MaterialData.class) && !material.isTransparent() && material
|
||||||
|
.isOccluding() || data.equals(Tree.class) || data.equals(Sandstone.class)
|
||||||
|
|| data.equals(Wool.class) || data.equals(Step.class) || data
|
||||||
|
.equals(WoodenStep.class)) {
|
||||||
|
switch (material) {
|
||||||
|
case NOTE_BLOCK:
|
||||||
|
case SPAWNER:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getClosestMatchingName(@NonNull final PlotBlock block) {
|
||||||
|
try {
|
||||||
|
return getMaterial(block).name();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override @Nullable
|
||||||
|
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
|
||||||
|
final PlotBlock plotBlock = BukkitUtil.getBukkitLegacyMappings().fromAny(name);
|
||||||
|
if (plotBlock != null) {
|
||||||
|
return new StringComparison<PlotBlock>().new ComparisonResult(1, plotBlock);
|
||||||
|
}
|
||||||
|
return BukkitUtil.getBukkitLegacyMappings().getClosestsMatch(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBiomes(@NonNull final String worldName, @NonNull final RegionWrapper region,
|
||||||
|
@NonNull final String biomeString) {
|
||||||
|
final World world = getWorld(worldName);
|
||||||
|
final Biome biome = Biome.valueOf(biomeString.toUpperCase());
|
||||||
|
for (int x = region.minX; x <= region.maxX; x++) {
|
||||||
|
for (int z = region.minZ; z <= region.maxZ; z++) {
|
||||||
|
world.setBiome(x, z, biome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public com.sk89q.worldedit.world.World getWeWorld(String world) {
|
||||||
|
return new BukkitWorld(Bukkit.getWorld(world));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public PlotBlock getBlock(@NonNull final Location location) {
|
||||||
|
final World world = getWorld(location.getWorld());
|
||||||
|
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||||
|
if (block == null) {
|
||||||
|
return StringPlotBlock.EVERYTHING;
|
||||||
|
}
|
||||||
|
return PlotBlock.get(block.getType().name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getMainWorld() {
|
||||||
|
return Bukkit.getWorlds().get(0).getName();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
|
public class BukkitVersion {
|
||||||
|
public static int[] v1_13_2 = {1, 13, 2};
|
||||||
|
public static int[] v1_13_1 = {1, 13, 1};
|
||||||
|
public static int[] v1_13_0 = {1, 13, 0};
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -6,12 +6,7 @@ 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.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
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.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
@ -22,19 +17,33 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
|
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
|
|
||||||
/** The current revision number. */
|
/**
|
||||||
|
* The current revision number.
|
||||||
|
*/
|
||||||
private static final int REVISION = 7;
|
private static final int REVISION = 7;
|
||||||
/** The base url of the metrics domain.*/
|
/**
|
||||||
|
* The base url of the metrics domain.
|
||||||
|
*/
|
||||||
private static final String BASE_URL = "http://report.mcstats.org";
|
private static final String BASE_URL = "http://report.mcstats.org";
|
||||||
/** The url used to report a server's status. */
|
/**
|
||||||
|
* The url used to report a server's status.
|
||||||
|
*/
|
||||||
private static final String REPORT_URL = "/plugin/%s";
|
private static final String REPORT_URL = "/plugin/%s";
|
||||||
/** Interval of time to ping (in minutes). */
|
/**
|
||||||
|
* Interval of time to ping (in minutes).
|
||||||
|
*/
|
||||||
private static final int PING_INTERVAL = 15;
|
private static final int PING_INTERVAL = 15;
|
||||||
/** The plugin this metrics submits for. */
|
/**
|
||||||
|
* The plugin this metrics submits for.
|
||||||
|
*/
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
/** Unique server id. */
|
/**
|
||||||
|
* Unique server id.
|
||||||
|
*/
|
||||||
private final String guid;
|
private final String guid;
|
||||||
/** The scheduled task. */
|
/**
|
||||||
|
* The scheduled task.
|
||||||
|
*/
|
||||||
private volatile BukkitTask task = null;
|
private volatile BukkitTask task = null;
|
||||||
|
|
||||||
public Metrics(Plugin plugin) {
|
public Metrics(Plugin plugin) {
|
||||||
@ -46,7 +55,6 @@ public class Metrics {
|
|||||||
* GZip compress a string of bytes.
|
* GZip compress a string of bytes.
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input
|
||||||
*
|
|
||||||
* @return byte[] the file as a byte array
|
* @return byte[] the file as a byte array
|
||||||
*/
|
*/
|
||||||
public static byte[] gzip(String input) {
|
public static byte[] gzip(String input) {
|
||||||
@ -61,7 +69,8 @@ public class Metrics {
|
|||||||
if (gzos != null) {
|
if (gzos != null) {
|
||||||
try {
|
try {
|
||||||
gzos.close();
|
gzos.close();
|
||||||
} catch (IOException ignore) {}
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
@ -73,7 +82,6 @@ public class Metrics {
|
|||||||
* @param json
|
* @param json
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private static void appendJSONPair(StringBuilder json, String key, String value) {
|
private static void appendJSONPair(StringBuilder json, String key, String value) {
|
||||||
boolean isValueNumeric = false;
|
boolean isValueNumeric = false;
|
||||||
@ -101,7 +109,6 @@ public class Metrics {
|
|||||||
* Escape a string to create a valid JSON string
|
* Escape a string to create a valid JSON string
|
||||||
*
|
*
|
||||||
* @param text
|
* @param text
|
||||||
*
|
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private static String escapeJSON(String text) {
|
private static String escapeJSON(String text) {
|
||||||
@ -145,7 +152,6 @@ public class Metrics {
|
|||||||
* Encode text as UTF-8
|
* Encode text as UTF-8
|
||||||
*
|
*
|
||||||
* @param text the text to encode
|
* @param text the text to encode
|
||||||
*
|
|
||||||
* @return the encoded text, as UTF-8
|
* @return the encoded text, as UTF-8
|
||||||
*/
|
*/
|
||||||
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
private static String urlEncode(String text) throws UnsupportedEncodingException {
|
||||||
@ -165,11 +171,11 @@ public class Metrics {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Begin hitting the server with glorious data
|
// Begin hitting the server with glorious data
|
||||||
this.task = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.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(!this.firstPost);
|
postPlugin(!this.firstPost);
|
||||||
// After the first post we set firstPost to
|
// After the first post we set firstPost to
|
||||||
@ -196,10 +202,15 @@ public class Metrics {
|
|||||||
String serverVersion = Bukkit.getVersion();
|
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()
|
||||||
playersOnline = ((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).size();
|
== Collection.class) {
|
||||||
|
playersOnline =
|
||||||
|
((Collection<?>) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0])
|
||||||
|
.invoke(null)).size();
|
||||||
} else {
|
} else {
|
||||||
playersOnline = ((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0]).invoke(null)).length;
|
playersOnline =
|
||||||
|
((Player[]) Bukkit.class.getMethod("getOnlinePlayers", new Class<?>[0])
|
||||||
|
.invoke(null)).length;
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
|
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -256,7 +267,8 @@ public class Metrics {
|
|||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
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 (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
if (response == null || response.startsWith("ERR") || response.startsWith("7")) {
|
||||||
@ -267,6 +279,7 @@ public class Metrics {
|
|||||||
}
|
}
|
||||||
throw new IOException(response);
|
throw new IOException(response);
|
||||||
}
|
}
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
@ -8,36 +8,18 @@ import com.google.common.collect.MapMaker;
|
|||||||
import com.google.common.io.ByteSink;
|
import com.google.common.io.ByteSink;
|
||||||
import com.google.common.io.Closeables;
|
import com.google.common.io.Closeables;
|
||||||
import com.google.common.primitives.Primitives;
|
import com.google.common.primitives.Primitives;
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.AbstractList;
|
|
||||||
import java.util.AbstractMap;
|
|
||||||
import java.util.AbstractSet;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
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.lang.reflect.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class NbtFactory {
|
public class NbtFactory {
|
||||||
|
|
||||||
// Convert between NBT type and the equivalent class in java
|
// Convert between NBT type and the equivalent class in java
|
||||||
@ -77,10 +59,12 @@ public class NbtFactory {
|
|||||||
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
Class<?> offlinePlayer = loader.loadClass(packageName + ".CraftOfflinePlayer");
|
||||||
|
|
||||||
// Prepare NBT
|
// Prepare NBT
|
||||||
this.COMPOUND_CLASS = getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
this.COMPOUND_CLASS =
|
||||||
|
getMethod(0, Modifier.STATIC, offlinePlayer, "getData").getReturnType();
|
||||||
this.BASE_CLASS = loader.loadClass(craftpackageName + ".NBTBase");
|
this.BASE_CLASS = loader.loadClass(craftpackageName + ".NBTBase");
|
||||||
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
this.NBT_GET_TYPE = getMethod(0, Modifier.STATIC, this.BASE_CLASS, "getTypeId");
|
||||||
this.NBT_CREATE_TAG = getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
this.NBT_CREATE_TAG =
|
||||||
|
getMethod(Modifier.STATIC, 0, this.BASE_CLASS, "createTag", byte.class);
|
||||||
|
|
||||||
// Prepare CraftItemStack
|
// Prepare CraftItemStack
|
||||||
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
this.CRAFT_STACK = loader.loadClass(packageName + ".inventory.CraftItemStack");
|
||||||
@ -92,11 +76,14 @@ public class NbtFactory {
|
|||||||
initializeNMS(loader, nmsPackage);
|
initializeNMS(loader, nmsPackage);
|
||||||
|
|
||||||
if (this.READ_LIMITER_CLASS != null) {
|
if (this.READ_LIMITER_CLASS != null) {
|
||||||
this.LOAD_COMPOUND = new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
this.LOAD_COMPOUND =
|
||||||
|
new LoadMethodSkinUpdate(this.STREAM_TOOLS, this.READ_LIMITER_CLASS);
|
||||||
} else {
|
} else {
|
||||||
this.LOAD_COMPOUND = new LoadMethodWorldUpdate(this.STREAM_TOOLS);
|
this.LOAD_COMPOUND = new LoadMethodWorldUpdate(this.STREAM_TOOLS);
|
||||||
}
|
}
|
||||||
this.SAVE_COMPOUND = getMethod(Modifier.STATIC, 0, this.STREAM_TOOLS, null, this.BASE_CLASS, DataOutput.class);
|
this.SAVE_COMPOUND =
|
||||||
|
getMethod(Modifier.STATIC, 0, this.STREAM_TOOLS, null, this.BASE_CLASS,
|
||||||
|
DataOutput.class);
|
||||||
|
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new IllegalStateException("Unable to find offline player.", e);
|
throw new IllegalStateException("Unable to find offline player.", e);
|
||||||
@ -106,6 +93,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve or construct a shared NBT factory.
|
* Retrieve or construct a shared NBT factory.
|
||||||
|
*
|
||||||
* @return The factory.
|
* @return The factory.
|
||||||
*/
|
*/
|
||||||
private static NbtFactory get() {
|
private static NbtFactory get() {
|
||||||
@ -117,6 +105,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(Object... content) {
|
public static NbtList createList(Object... content) {
|
||||||
@ -125,6 +114,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(Iterable<? extends Object> iterable) {
|
public static NbtList createList(Iterable<? extends Object> iterable) {
|
||||||
@ -148,6 +138,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT wrapper from a list.
|
* Construct a new NBT wrapper from a list.
|
||||||
|
*
|
||||||
* @param nmsList - the NBT list.
|
* @param nmsList - the NBT list.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
@ -163,7 +154,8 @@ public class NbtFactory {
|
|||||||
* @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(InputStream input, StreamOptions option) throws IOException {
|
public static NbtCompound fromStream(InputStream input, StreamOptions option)
|
||||||
|
throws IOException {
|
||||||
DataInputStream data = null;
|
DataInputStream data = null;
|
||||||
boolean suppress = true;
|
boolean suppress = true;
|
||||||
|
|
||||||
@ -195,14 +187,16 @@ 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 static void saveStream(NbtCompound source, ByteSink stream, 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;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
output = stream.openStream();
|
output = stream.openStream();
|
||||||
data = new DataOutputStream(option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
|
data = new DataOutputStream(
|
||||||
|
option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
|
||||||
|
|
||||||
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
|
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
|
||||||
suppress = false;
|
suppress = false;
|
||||||
@ -218,6 +212,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NBT wrapper from a compound.
|
* Construct a new NBT wrapper from a compound.
|
||||||
|
*
|
||||||
* @param nmsCompound - the NBT compound.
|
* @param nmsCompound - the NBT compound.
|
||||||
* @return The wrapper.
|
* @return The wrapper.
|
||||||
*/
|
*/
|
||||||
@ -228,6 +223,7 @@ public class NbtFactory {
|
|||||||
/**
|
/**
|
||||||
* Set the NBT compound tag of a given item stack.
|
* Set the NBT compound tag of a given item stack.
|
||||||
* <p>
|
* <p>
|
||||||
|
*
|
||||||
* @param stack - the item stack, cannot be air.
|
* @param stack - the item stack, cannot be air.
|
||||||
* @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.
|
||||||
@ -246,6 +242,7 @@ public class NbtFactory {
|
|||||||
* material, damage value or count.
|
* material, damage value or count.
|
||||||
* <p>
|
* <p>
|
||||||
* The item stack must be a wrapper for a CraftItemStack.
|
* The item stack must be a wrapper for a CraftItemStack.
|
||||||
|
*
|
||||||
* @param stack - the item stack.
|
* @param stack - the item stack.
|
||||||
* @return A wrapper for its NBT tag.
|
* @return A wrapper for its NBT tag.
|
||||||
*/
|
*/
|
||||||
@ -265,6 +262,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a CraftItemStack version of the stack.
|
* Retrieve a CraftItemStack version of the stack.
|
||||||
|
*
|
||||||
* @param stack - the stack to convert.
|
* @param stack - the stack to convert.
|
||||||
* @return The CraftItemStack version.
|
* @return The CraftItemStack version.
|
||||||
*/
|
*/
|
||||||
@ -279,12 +277,14 @@ public class NbtFactory {
|
|||||||
caller.setAccessible(true);
|
caller.setAccessible(true);
|
||||||
return (ItemStack) caller.newInstance(stack);
|
return (ItemStack) caller.newInstance(stack);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
throw new IllegalStateException("Unable to convert " + stack + " + to a CraftItemStack.");
|
throw new IllegalStateException(
|
||||||
|
"Unable to convert " + stack + " + to a CraftItemStack.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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(ItemStack stack) {
|
private static void checkItemStack(ItemStack stack) {
|
||||||
@ -295,12 +295,14 @@ public class NbtFactory {
|
|||||||
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
|
throw new IllegalArgumentException("Stack must be a CraftItemStack.");
|
||||||
}
|
}
|
||||||
if (stack.getType() == Material.AIR) {
|
if (stack.getType() == Material.AIR) {
|
||||||
throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information.");
|
throw new IllegalArgumentException(
|
||||||
|
"ItemStacks representing air cannot store NMS information.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke a method on the given target instance using the provided parameters.
|
* Invoke a method on the given target instance using the provided parameters.
|
||||||
|
*
|
||||||
* @param method - the method to invoke.
|
* @param method - the method to invoke.
|
||||||
* @param target - the target.
|
* @param target - the target.
|
||||||
* @param params - the parameters to supply.
|
* @param params - the parameters to supply.
|
||||||
@ -332,6 +334,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for the first publicly and privately defined method of the given name and parameter count.
|
* Search for the first publicly and privately defined method of the given name and parameter count.
|
||||||
|
*
|
||||||
* @param requireMod - modifiers that are required.
|
* @param requireMod - modifiers that are required.
|
||||||
* @param bannedMod - modifiers that are banned.
|
* @param bannedMod - modifiers that are banned.
|
||||||
* @param clazz - a class to start with.
|
* @param clazz - a class to start with.
|
||||||
@ -340,14 +343,14 @@ 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(int requireMod, int bannedMod, Class<?> clazz, String methodName,
|
private static Method getMethod(int requireMod, int bannedMod, Class<?> clazz,
|
||||||
Class<?>... params) {
|
String methodName, Class<?>... params) {
|
||||||
for (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) && ((methodName == null) || method
|
||||||
&& ((methodName == null) || method.getName().equals(methodName))
|
.getName().equals(methodName)) && Arrays
|
||||||
&& Arrays.equals(method.getParameterTypes(), params)) {
|
.equals(method.getParameterTypes(), params)) {
|
||||||
|
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return method;
|
return method;
|
||||||
@ -357,11 +360,13 @@ public class NbtFactory {
|
|||||||
if (clazz.getSuperclass() != null) {
|
if (clazz.getSuperclass() != null) {
|
||||||
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
|
return getMethod(requireMod, bannedMod, clazz.getSuperclass(), methodName, params);
|
||||||
}
|
}
|
||||||
throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
|
throw new IllegalStateException(
|
||||||
|
String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for the first publicly and privately defined field of the given name.
|
* Search for the first publicly and privately defined field of the given name.
|
||||||
|
*
|
||||||
* @param instance - an instance of the class with the field.
|
* @param instance - an instance of the class with the field.
|
||||||
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
|
* @param clazz - an optional class to start with, or NULL to deduce it from instance.
|
||||||
* @param fieldName - the field name.
|
* @param fieldName - the field name.
|
||||||
@ -390,7 +395,8 @@ public class NbtFactory {
|
|||||||
try {
|
try {
|
||||||
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
this.STREAM_TOOLS = loader.loadClass(nmsPackage + ".NBTCompressedStreamTools");
|
||||||
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
this.READ_LIMITER_CLASS = loader.loadClass(nmsPackage + ".NBTReadLimiter");
|
||||||
} catch (ClassNotFoundException ignored) {}
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPackageName() {
|
private String getPackageName() {
|
||||||
@ -406,22 +412,23 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getCraftPackageName() {
|
private String getCraftPackageName() {
|
||||||
String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
String version =
|
||||||
|
Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||||
return "net.minecraft.server." + version;
|
return "net.minecraft.server." + version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") private Map<String, Object> getDataMap(Object handle) {
|
||||||
private Map<String, Object> getDataMap(Object handle) {
|
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle),
|
||||||
return (Map<String, Object>) getFieldValue(getDataField(NbtType.TAG_COMPOUND, handle), handle);
|
handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") private List<Object> getDataList(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert wrapped List and Map objects into their respective NBT counterparts.
|
* Convert wrapped List and Map objects into their respective NBT counterparts.
|
||||||
|
*
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@ -444,6 +451,7 @@ public class NbtFactory {
|
|||||||
/**
|
/**
|
||||||
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
|
* Convert a given NBT element to a primitive wrapper or List/Map equivalent.
|
||||||
* <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
|
* <p> All changes to any mutable objects will be reflected in the underlying NBT element(s).
|
||||||
|
*
|
||||||
* @param nms - the NBT element.
|
* @param nms - the NBT element.
|
||||||
* @return The wrapper equivalent.
|
* @return The wrapper equivalent.
|
||||||
*/
|
*/
|
||||||
@ -470,6 +478,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new NMS NBT tag initialized with the given value.
|
* Construct a new NMS NBT tag initialized with the given value.
|
||||||
|
*
|
||||||
* @param type - the NBT type.
|
* @param type - the NBT type.
|
||||||
* @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.
|
||||||
@ -485,6 +494,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the field where the NBT class stores its value.
|
* Retrieve the field where the NBT class stores its value.
|
||||||
|
*
|
||||||
* @param type - the NBT type.
|
* @param type - the NBT type.
|
||||||
* @param nms - the NBT class instance.
|
* @param nms - the NBT class instance.
|
||||||
* @return The corresponding field.
|
* @return The corresponding field.
|
||||||
@ -498,6 +508,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the NBT type from a given NMS NBT tag.
|
* Retrieve the NBT type from a given NMS NBT tag.
|
||||||
|
*
|
||||||
* @param nms - the native NBT tag.
|
* @param nms - the native NBT tag.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
@ -508,40 +519,38 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the nearest NBT type for a given primitive type.
|
* Retrieve the nearest NBT type for a given primitive type.
|
||||||
|
*
|
||||||
* @param primitive - the primitive type.
|
* @param primitive - the primitive type.
|
||||||
* @return The corresponding type.
|
* @return The corresponding type.
|
||||||
*/
|
*/
|
||||||
private NbtType getPrimitiveType(Object primitive) {
|
private NbtType getPrimitiveType(Object primitive) {
|
||||||
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) {
|
||||||
throw new IllegalArgumentException(String.format("Illegal type: %s (%s)", primitive.getClass(), primitive));
|
throw new IllegalArgumentException(
|
||||||
|
String.format("Illegal type: %s (%s)", primitive.getClass(), primitive));
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not to enable stream compression.
|
* Whether or not to enable stream compression.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public enum StreamOptions {
|
public enum StreamOptions {
|
||||||
NO_COMPRESSION, GZIP_COMPRESSION,
|
NO_COMPRESSION, GZIP_COMPRESSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private enum NbtType {
|
private enum NbtType {
|
||||||
TAG_END(0, Void.class),
|
TAG_END(0, Void.class), TAG_BYTE(1, byte.class), TAG_SHORT(2, short.class), TAG_INT(3,
|
||||||
TAG_BYTE(1, byte.class),
|
int.class), TAG_LONG(4, long.class), TAG_FLOAT(5, float.class), TAG_DOUBLE(6,
|
||||||
TAG_SHORT(2, short.class),
|
double.class), TAG_BYTE_ARRAY(7, byte[].class), TAG_INT_ARRAY(11,
|
||||||
TAG_INT(3, int.class),
|
int[].class), TAG_STRING(8, String.class), TAG_LIST(9, List.class), TAG_COMPOUND(10,
|
||||||
TAG_LONG(4, long.class),
|
Map.class);
|
||||||
TAG_FLOAT(5, float.class),
|
|
||||||
TAG_DOUBLE(6, double.class),
|
|
||||||
TAG_BYTE_ARRAY(7, byte[].class),
|
|
||||||
TAG_INT_ARRAY(11, int[].class),
|
|
||||||
TAG_STRING(8, String.class),
|
|
||||||
TAG_LIST(9, List.class),
|
|
||||||
TAG_COMPOUND(10, Map.class);
|
|
||||||
|
|
||||||
// Unique NBT type
|
// Unique NBT type
|
||||||
public final int id;
|
public final int id;
|
||||||
@ -563,21 +572,26 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an object that provides a view of a native NMS class.
|
* Represents an object that provides a view of a native NMS class.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public interface Wrapper {
|
public interface Wrapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the underlying native NBT tag.
|
* Retrieve the underlying native NBT tag.
|
||||||
|
*
|
||||||
* @return The underlying NBT.
|
* @return The underlying NBT.
|
||||||
*/
|
*/
|
||||||
Object getHandle();
|
Object getHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a method for loading an NBT compound.
|
* Represents a method for loading an NBT compound.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private static abstract class LoadCompoundMethod {
|
private static abstract class LoadCompoundMethod {
|
||||||
@ -591,12 +605,14 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from a given stream.
|
* Load an NBT compound from a given stream.
|
||||||
|
*
|
||||||
* @param input - the input stream.
|
* @param input - the input stream.
|
||||||
* @return The loaded NBT compound.
|
* @return The loaded NBT compound.
|
||||||
*/
|
*/
|
||||||
public abstract Object loadNbt(DataInput input);
|
public abstract Object loadNbt(DataInput input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.2 - 1.7.5
|
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.2 - 1.7.5
|
||||||
*/
|
*/
|
||||||
@ -606,12 +622,12 @@ public class NbtFactory {
|
|||||||
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
setMethod(getMethod(Modifier.STATIC, 0, streamClass, null, DataInput.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object loadNbt(DataInput input) {
|
||||||
public Object loadNbt(DataInput input) {
|
|
||||||
return invokeMethod(this.staticMethod, null, input);
|
return invokeMethod(this.staticMethod, null, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.8
|
* Load an NBT compound from the NBTCompressedStreamTools static method in 1.7.8
|
||||||
*/
|
*/
|
||||||
@ -620,7 +636,8 @@ public class NbtFactory {
|
|||||||
private Object readLimiter;
|
private Object readLimiter;
|
||||||
|
|
||||||
LoadMethodSkinUpdate(Class<?> streamClass, Class<?> readLimiterClass) {
|
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 (Field field : readLimiterClass.getDeclaredFields()) {
|
for (Field field : readLimiterClass.getDeclaredFields()) {
|
||||||
@ -634,12 +651,12 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object loadNbt(DataInput input) {
|
||||||
public Object loadNbt(DataInput input) {
|
|
||||||
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
return invokeMethod(this.staticMethod, null, input, this.readLimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a root NBT compound.
|
* Represents a root NBT compound.
|
||||||
* <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
|
* <p> All changes to this map will be reflected in the underlying NBT compound. Values may only be one of the following:
|
||||||
@ -655,6 +672,7 @@ public class NbtFactory {
|
|||||||
* <li>{@link NbtFactory#createCompound()}</li>
|
* <li>{@link NbtFactory#createCompound()}</li>
|
||||||
* <li>{@link NbtFactory#fromCompound(Object)}</li>
|
* <li>{@link NbtFactory#fromCompound(Object)}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public final class NbtCompound extends ConvertedMap {
|
public final class NbtCompound extends ConvertedMap {
|
||||||
@ -702,6 +720,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list by the given name.
|
* Retrieve the list by the given name.
|
||||||
|
*
|
||||||
* @param key - the name of the list.
|
* @param key - the name of the list.
|
||||||
* @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.
|
||||||
@ -717,6 +736,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the map by the given name.
|
* Retrieve the map by the given name.
|
||||||
|
*
|
||||||
* @param key - the name of the map.
|
* @param key - the name of the map.
|
||||||
* @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.
|
||||||
@ -732,6 +752,7 @@ public class NbtFactory {
|
|||||||
* <p>
|
* <p>
|
||||||
* Every element of the path (except the end) are assumed to be compounds, and will
|
* Every element of the path (except the end) are assumed to be compounds, and will
|
||||||
* be created if they are missing.
|
* be created if they are missing.
|
||||||
|
*
|
||||||
* @param path - the path to the entry.
|
* @param path - the path to the entry.
|
||||||
* @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.
|
||||||
@ -749,11 +770,11 @@ public class NbtFactory {
|
|||||||
* <p>
|
* <p>
|
||||||
* Every element of the path (except the end) are assumed to be compounds. The
|
* Every element of the path (except the end) are assumed to be compounds. The
|
||||||
* retrieval operation will be cancelled if any of them are missing.
|
* retrieval operation will be cancelled if any of them are missing.
|
||||||
|
*
|
||||||
* @param path - path to the entry.
|
* @param path - path to the entry.
|
||||||
* @return The value, or NULL if not found.
|
* @return The value, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked") public <T> T getPath(String path) {
|
||||||
public <T> T getPath(String path) {
|
|
||||||
List<String> entries = getPathElements(path);
|
List<String> entries = getPathElements(path);
|
||||||
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
NbtCompound map = getMap(entries.subList(0, entries.size() - 1), false);
|
||||||
|
|
||||||
@ -765,6 +786,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the content of a NBT compound to a stream.
|
* Save the content of a NBT compound to a stream.
|
||||||
|
*
|
||||||
* @param stream - the output stream.
|
* @param stream - the output 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.
|
||||||
@ -775,6 +797,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a map from a given path.
|
* Retrieve a map from a given path.
|
||||||
|
*
|
||||||
* @param path - path of compounds to look up.
|
* @param path - path of compounds to look up.
|
||||||
* @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.
|
||||||
@ -798,6 +821,7 @@ public class NbtFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Split the path into separate elements.
|
* Split the path into separate elements.
|
||||||
|
*
|
||||||
* @param path - the path to split.
|
* @param path - the path to split.
|
||||||
* @return The elements.
|
* @return The elements.
|
||||||
*/
|
*/
|
||||||
@ -806,6 +830,7 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a root NBT list.
|
* Represents a root NBT list.
|
||||||
* See also:
|
* See also:
|
||||||
@ -813,6 +838,7 @@ public class NbtFactory {
|
|||||||
* <li>{@link NbtFactory#createList(Iterable)}}</li>
|
* <li>{@link NbtFactory#createList(Iterable)}}</li>
|
||||||
* <li>{@link NbtFactory#fromList(Object)}</li>
|
* <li>{@link NbtFactory#fromList(Object)}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
public final class NbtList extends ConvertedList {
|
public final class NbtList extends ConvertedList {
|
||||||
@ -822,8 +848,10 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a class for caching wrappers.
|
* Represents a class for caching wrappers.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private final class CachedNativeWrapper {
|
private final class CachedNativeWrapper {
|
||||||
@ -846,9 +874,11 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a map that wraps another map and automatically
|
* Represents a map that wraps another map and automatically
|
||||||
* converts entries of its type and another exposed type.
|
* converts entries of its type and another exposed type.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private class ConvertedMap extends AbstractMap<String, Object> implements Wrapper {
|
private class ConvertedMap extends AbstractMap<String, Object> implements Wrapper {
|
||||||
@ -873,32 +903,26 @@ public class NbtFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modification
|
// Modification
|
||||||
@Override
|
@Override public Object put(String key, Object value) {
|
||||||
public Object put(String key, Object value) {
|
|
||||||
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
return wrapOutgoing(this.original.put(key, unwrapIncoming(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Performance
|
// Performance
|
||||||
@Override
|
@Override public Object get(Object key) {
|
||||||
public Object get(Object key) {
|
|
||||||
return wrapOutgoing(this.original.get(key));
|
return wrapOutgoing(this.original.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object remove(Object key) {
|
||||||
public Object remove(Object key) {
|
|
||||||
return wrapOutgoing(this.original.remove(key));
|
return wrapOutgoing(this.original.remove(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean containsKey(Object key) {
|
||||||
public boolean containsKey(Object key) {
|
|
||||||
return this.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(Entry<String, Object> e) {
|
||||||
public boolean add(Entry<String, Object> e) {
|
|
||||||
String key = e.getKey();
|
String key = e.getKey();
|
||||||
Object value = e.getValue();
|
Object value = e.getValue();
|
||||||
|
|
||||||
@ -906,13 +930,11 @@ public class NbtFactory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int size() {
|
||||||
public int size() {
|
|
||||||
return ConvertedMap.this.original.size();
|
return ConvertedMap.this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Iterator<Entry<String, Object>> iterator() {
|
||||||
public Iterator<Entry<String, Object>> iterator() {
|
|
||||||
return ConvertedMap.this.iterator();
|
return ConvertedMap.this.iterator();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -922,34 +944,33 @@ public class NbtFactory {
|
|||||||
final Iterator<Entry<String, Object>> proxy = this.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 public boolean hasNext() {
|
||||||
public boolean hasNext() {
|
|
||||||
return proxy.hasNext();
|
return proxy.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Entry<String, Object> next() {
|
||||||
public Entry<String, Object> next() {
|
|
||||||
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void remove() {
|
||||||
public void remove() {
|
|
||||||
proxy.remove();
|
proxy.remove();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object getHandle() {
|
||||||
public Object getHandle() {
|
|
||||||
return this.handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a list that wraps another list and converts elements
|
* Represents a list that wraps another list and converts elements
|
||||||
* of its type and another exposed type.
|
* of its type and another exposed type.
|
||||||
|
*
|
||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
private class ConvertedList extends AbstractList<Object> implements Wrapper {
|
private class ConvertedList extends AbstractList<Object> implements Wrapper {
|
||||||
@ -975,44 +996,38 @@ public class NbtFactory {
|
|||||||
return unwrapValue(wrapped);
|
return unwrapValue(wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object get(int index) {
|
||||||
public Object get(int index) {
|
|
||||||
return wrapOutgoing(this.original.get(index));
|
return wrapOutgoing(this.original.get(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public int size() {
|
||||||
public int size() {
|
|
||||||
return this.original.size();
|
return this.original.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object set(int index, Object element) {
|
||||||
public Object set(int index, Object element) {
|
|
||||||
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
return wrapOutgoing(this.original.set(index, unwrapIncoming(element)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void add(int index, Object element) {
|
||||||
public void add(int index, Object element) {
|
|
||||||
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(NbtFactory.this.NBT_LIST_TYPE, this.handle, (byte) getNbtType(nbt).id);
|
setFieldValue(NbtFactory.this.NBT_LIST_TYPE, this.handle,
|
||||||
|
(byte) getNbtType(nbt).id);
|
||||||
}
|
}
|
||||||
this.original.add(index, nbt);
|
this.original.add(index, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object remove(int index) {
|
||||||
public Object remove(int index) {
|
|
||||||
return wrapOutgoing(this.original.remove(index));
|
return wrapOutgoing(this.original.remove(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean remove(Object o) {
|
||||||
public boolean remove(Object o) {
|
|
||||||
return this.original.remove(unwrapIncoming(o));
|
return this.original.remove(unwrapIncoming(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Object getHandle() {
|
||||||
public Object getHandle() {
|
|
||||||
return this.handle;
|
return this.handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,4 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callConstructor;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.callMethod;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getCbClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getNmsClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getUtilClass;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeConstructor;
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.makeMethod;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -17,6 +9,8 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.*;
|
||||||
|
|
||||||
public class OfflinePlayerUtil {
|
public class OfflinePlayerUtil {
|
||||||
|
|
||||||
public static Player loadPlayer(String name) {
|
public static Player loadPlayer(String name) {
|
||||||
@ -43,10 +37,12 @@ public class OfflinePlayerUtil {
|
|||||||
Object worldServer = getWorldServer();
|
Object worldServer = getWorldServer();
|
||||||
Object profile = newGameProfile(id, name);
|
Object profile = newGameProfile(id, name);
|
||||||
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
Class<?> entityPlayerClass = getNmsClass("EntityPlayer");
|
||||||
Constructor entityPlayerConstructor = makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
Constructor entityPlayerConstructor =
|
||||||
getUtilClass("com.mojang.authlib.GameProfile"),
|
makeConstructor(entityPlayerClass, getNmsClass("MinecraftServer"),
|
||||||
|
getNmsClass("WorldServer"), getUtilClass("com.mojang.authlib.GameProfile"),
|
||||||
getNmsClass("PlayerInteractManager"));
|
getNmsClass("PlayerInteractManager"));
|
||||||
Object entityPlayer = callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
Object entityPlayer =
|
||||||
|
callConstructor(entityPlayerConstructor, server, worldServer, profile, interactManager);
|
||||||
return (Player) getBukkitEntity(entityPlayer);
|
return (Player) getBukkitEntity(entityPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +51,8 @@ public class OfflinePlayerUtil {
|
|||||||
if (gameProfileClass == null) { //Before uuids
|
if (gameProfileClass == null) { //Before uuids
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
Constructor gameProfileConstructor = makeConstructor(gameProfileClass, UUID.class, String.class);
|
Constructor gameProfileConstructor =
|
||||||
|
makeConstructor(gameProfileClass, UUID.class, String.class);
|
||||||
if (gameProfileConstructor == null) { //Version has string constructor
|
if (gameProfileConstructor == null) { //Version has string constructor
|
||||||
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
gameProfileConstructor = makeConstructor(gameProfileClass, String.class, String.class);
|
||||||
return callConstructor(gameProfileConstructor, id.toString(), name);
|
return callConstructor(gameProfileConstructor, id.toString(), name);
|
@ -1,19 +1,17 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefClass;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefConstructor;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -25,6 +23,8 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility that can be used to send chunks, rather than using bukkit code
|
* An utility that can be used to send chunks, rather than using bukkit code
|
||||||
* to do so (uses heavy NMS).
|
* to do so (uses heavy NMS).
|
||||||
@ -50,16 +50,7 @@ public class SendChunk {
|
|||||||
RefClass classChunk = getRefClass("{nms}.Chunk");
|
RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
this.methodInitLighting = classChunk.getMethod("initLighting");
|
this.methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
|
|
||||||
//this works for 1.9.4 and 1.10
|
|
||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
|
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
|
||||||
} catch (NoSuchMethodException ignored) {
|
|
||||||
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(),boolean.class, int.class, int.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.mapChunk = tempMapChunk;
|
this.mapChunk = tempMapChunk;
|
||||||
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||||
this.connection = classEntityPlayer.getField("playerConnection");
|
this.connection = classEntityPlayer.getField("playerConnection");
|
||||||
@ -116,38 +107,29 @@ public class SendChunk {
|
|||||||
chunks.remove(chunk);
|
chunks.remove(chunk);
|
||||||
Object con = this.connection.of(entity).get();
|
Object con = this.connection.of(entity).get();
|
||||||
Object packet = null;
|
Object packet = null;
|
||||||
if (PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
|
|
||||||
try {
|
try {
|
||||||
packet = this.mapChunk.create(c, 65535);
|
packet = this.mapChunk.create(c, 65535);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
packet = this.mapChunk.create(c, true, 65535);
|
|
||||||
} catch (ReflectiveOperationException | IllegalArgumentException e) {
|
|
||||||
try {
|
|
||||||
packet = this.mapChunk.create(c, true, 65535, 5);
|
|
||||||
} catch (ReflectiveOperationException | IllegalArgumentException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (packet == null) {
|
if (packet == null) {
|
||||||
PS.debug("Error with PacketPlayOutMapChunk reflection.");
|
PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");
|
||||||
}
|
}
|
||||||
this.send.of(con).call(packet);
|
this.send.of(con).call(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final Chunk chunk : chunks) {
|
for (final Chunk chunk : chunks) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
String worldName = chunk.getWorld().getName();
|
String worldName = chunk.getWorld().getName();
|
||||||
PS.debug("$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + chunk.getZ());
|
PlotSquared.debug(
|
||||||
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
"$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";"
|
||||||
PS.debug("$3 - $4" + worldName + "/level.dat or " + worldName
|
+ chunk.getZ());
|
||||||
|
PlotSquared
|
||||||
|
.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
|
PlotSquared.debug("$3 - $4" + worldName + "/level.dat or " + worldName
|
||||||
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitAugmentedGenerator;
|
||||||
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
import com.plotsquared.bukkit.generator.BukkitAugmentedGenerator;
|
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
@ -16,7 +16,7 @@ public class SetGenCB {
|
|||||||
|
|
||||||
public static void setGenerator(World world) throws Exception {
|
public static void setGenerator(World world) throws Exception {
|
||||||
SetupUtils.manager.updateGenerators();
|
SetupUtils.manager.updateGenerators();
|
||||||
PS.get().removePlotAreas(world.getName());
|
PlotSquared.get().removePlotAreas(world.getName());
|
||||||
ChunkGenerator gen = world.getGenerator();
|
ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen == null) {
|
if (gen == null) {
|
||||||
return;
|
return;
|
||||||
@ -52,6 +52,7 @@ public class SetGenCB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PS.get().loadWorld(world.getName(), PS.get().IMP.getGenerator(world.getName(), null));
|
PlotSquared.get()
|
||||||
|
.loadWorld(world.getName(), PlotSquared.get().IMP.getGenerator(world.getName(), null));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,68 +1,72 @@
|
|||||||
package com.plotsquared.bukkit.util.block;
|
package com.github.intellectualsites.plotsquared.bukkit.util.block;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.block.BasicLocalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||||
import java.lang.reflect.Field;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import java.lang.reflect.Method;
|
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue;
|
||||||
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||||
|
|
||||||
|
private Field fieldNeighbors;
|
||||||
|
private Method chunkGetHandle;
|
||||||
|
|
||||||
public BukkitLocalQueue(String world) {
|
public BukkitLocalQueue(String world) {
|
||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public LocalChunk<T> getLocalChunk(int x, int z) {
|
||||||
public LocalChunk<T> getLocalChunk(int x, int z) {
|
|
||||||
return (LocalChunk<T>) new BasicLocalChunk(this, x, z) {
|
return (LocalChunk<T>) new BasicLocalChunk(this, x, z) {
|
||||||
// Custom stuff?
|
// Custom stuff?
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void optimize() {
|
||||||
public void optimize() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||||
public PlotBlock getBlock(int x, int y, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
Block block = worldObj.getBlockAt(x, y, z);
|
Block block = worldObj.getBlockAt(x, y, z);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
return PlotBlock.get(0, 0);
|
return PlotBlock.get(0, 0);
|
||||||
}
|
}
|
||||||
int id = block.getTypeId();
|
// int id = block.getTypeId();
|
||||||
if (id == 0) {
|
// if (id == 0) {
|
||||||
return PlotBlock.get(0, 0);
|
// return PlotBlock.get(0, 0);
|
||||||
}
|
// }
|
||||||
return PlotBlock.get(id, block.getData());
|
// return PlotBlock.get(id, block.getData());
|
||||||
|
return PlotBlock.get(block.getType().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void refreshChunk(int x, int z) {
|
||||||
public void refreshChunk(int x, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
worldObj.refreshChunk(x, z);
|
worldObj.refreshChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fixChunkLighting(int x, int z) {
|
||||||
public void fixChunkLighting(int x, int z) {
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void regenChunk(int x, int z) {
|
||||||
public final void regenChunk(int x, int z) {
|
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
worldObj.regenerateChunk(x, z);
|
worldObj.regenerateChunk(x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public final void setComponents(LocalChunk<T> lc) {
|
||||||
public final void setComponents(LocalChunk<T> lc) {
|
|
||||||
setBlocks(lc);
|
setBlocks(lc);
|
||||||
setBiomes(lc);
|
setBiomes(lc);
|
||||||
}
|
}
|
||||||
@ -89,22 +93,53 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
int y = MainUtil.y_loc[layer][j];
|
int y = MainUtil.y_loc[layer][j];
|
||||||
int z = MainUtil.z_loc[layer][j];
|
int z = MainUtil.z_loc[layer][j];
|
||||||
Block existing = chunk.getBlock(x, y, z);
|
Block existing = chunk.getBlock(x, y, z);
|
||||||
int existingId = existing.getTypeId();
|
// int existingId = existing.getTypeId();
|
||||||
if (existingId == block.id) {
|
// if (existingId == block.id) {
|
||||||
if (existingId == 0) {
|
// if (existingId == 0) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (existing.getData() == block.data) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
if (equals(block, existing)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (existing.getData() == block.data) {
|
setMaterial(block, existing);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
existing.setTypeIdAndData(block.id, block.data, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setMaterial(@NonNull final PlotBlock plotBlock, @NonNull final Block block) {
|
||||||
|
if (plotBlock instanceof StringPlotBlock) {
|
||||||
|
final Material material = Material
|
||||||
|
.getMaterial(((StringPlotBlock) plotBlock).getItemId().toLowerCase(Locale.ENGLISH));
|
||||||
|
if (material == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
String.format("Could not find material that matches %s", block.toString()));
|
||||||
|
}
|
||||||
|
block.setType(material, false);
|
||||||
|
} else {
|
||||||
|
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||||
|
block.setType(Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings()
|
||||||
|
.fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData())
|
||||||
|
.toString()));
|
||||||
|
// block.setTypeIdAndData(legacyPlotBlock.getId(), legacyPlotBlock.getData(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(@NonNull final PlotBlock plotBlock, @NonNull final Block block) {
|
||||||
|
if (plotBlock instanceof StringPlotBlock) {
|
||||||
|
return ((StringPlotBlock) plotBlock).idEquals(block.getType().name());
|
||||||
|
}
|
||||||
|
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||||
|
return Material.getMaterial(PlotSquared.get().IMP.getLegacyMappings()
|
||||||
|
.fromLegacyToString(((LegacyPlotBlock) plotBlock).id).toString()) == block.getType()
|
||||||
|
&& (legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
|
||||||
|
}
|
||||||
|
|
||||||
public void setBiomes(LocalChunk<T> lc) {
|
public void setBiomes(LocalChunk<T> lc) {
|
||||||
if (lc.biomes != null) {
|
if (lc.biomes != null) {
|
||||||
World worldObj = Bukkit.getWorld(getWorld());
|
World worldObj = Bukkit.getWorld(getWorld());
|
||||||
@ -129,13 +164,11 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Field fieldNeighbors;
|
|
||||||
private Method chunkGetHandle;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
|
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
|
||||||
* - Could have been achieved without reflection by force unloading specific chunks
|
* - Could have been achieved without reflection by force unloading specific chunks
|
||||||
* - Much faster just setting the variable manually though
|
* - Much faster just setting the variable manually though
|
||||||
|
*
|
||||||
* @param chunk
|
* @param chunk
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -153,7 +186,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
Object value = fieldNeighbors.get(nmsChunk);
|
Object value = fieldNeighbors.get(nmsChunk);
|
||||||
fieldNeighbors.set(nmsChunk, 0);
|
fieldNeighbors.set(nmsChunk, 0);
|
||||||
return new Object[] {nmsChunk, value};
|
return new Object[] {nmsChunk, value};
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +215,8 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
|||||||
if (disableResult != null) {
|
if (disableResult != null) {
|
||||||
try {
|
try {
|
||||||
fieldNeighbors.set(disableResult[0], 0x739C0);
|
fieldNeighbors.set(disableResult[0], 0x739C0);
|
||||||
} catch (Throwable ignore) {}
|
} catch (Throwable ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package com.plotsquared.bukkit.util.block;
|
package com.github.intellectualsites.plotsquared.bukkit.util.block;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkWrapper;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper;
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||||
import java.util.Arrays;
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -15,6 +14,8 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
|||||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class GenChunk extends ScopedLocalBlockQueue {
|
public class GenChunk extends ScopedLocalBlockQueue {
|
||||||
|
|
||||||
public final Biome[] biomes;
|
public final Biome[] biomes;
|
||||||
@ -37,13 +38,6 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChunk(ChunkWrapper wrap) {
|
|
||||||
chunk = null;
|
|
||||||
world = wrap.world;
|
|
||||||
cx = wrap.x;
|
|
||||||
cz = wrap.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Chunk getChunk() {
|
public Chunk getChunk() {
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
World worldObj = BukkitUtil.getWorld(world);
|
World worldObj = BukkitUtil.getWorld(world);
|
||||||
@ -54,6 +48,13 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChunk(ChunkWrapper wrap) {
|
||||||
|
chunk = null;
|
||||||
|
world = wrap.world;
|
||||||
|
cx = wrap.x;
|
||||||
|
cz = wrap.z;
|
||||||
|
}
|
||||||
|
|
||||||
public ChunkWrapper getChunkWrapper() {
|
public ChunkWrapper getChunkWrapper() {
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
return new ChunkWrapper(world, cx, cz);
|
return new ChunkWrapper(world, cx, cz);
|
||||||
@ -61,8 +62,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
return new ChunkWrapper(chunk.getWorld().getName(), chunk.getX(), chunk.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fillBiome(String biomeName) {
|
||||||
public void fillBiome(String biomeName) {
|
|
||||||
if (grid == null) {
|
if (grid == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -74,9 +74,9 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
|
||||||
public void setCuboid(Location pos1, Location pos2, PlotBlock block) {
|
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0
|
||||||
if (block.data == 0 && result != null && pos1.getX() == 0 && pos1.getZ() == 0 && pos2.getX() == 15 && pos2.getZ() == 15) {
|
&& pos2.getX() == 15 && pos2.getZ() == 15) {
|
||||||
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
for (int y = pos1.getY(); y <= pos2.getY(); y++) {
|
||||||
int layer = y >> 4;
|
int layer = y >> 4;
|
||||||
short[] data = result[layer];
|
short[] data = result[layer];
|
||||||
@ -92,8 +92,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean setBiome(int x, int z, String biome) {
|
||||||
public boolean setBiome(int x, int z, String biome) {
|
|
||||||
return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));
|
return setBiome(x, z, Biome.valueOf(biome.toUpperCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +112,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean setBlock(int x, int y, int z, int id, int data) {
|
||||||
public boolean setBlock(int x, int y, int z, int id, int data) {
|
|
||||||
if (this.result == null) {
|
if (this.result == null) {
|
||||||
this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data));
|
this.cd.setBlock(x, y, z, new MaterialData(Material.getMaterial(id), (byte) data));
|
||||||
return true;
|
return true;
|
||||||
@ -136,8 +134,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||||
public PlotBlock getBlock(int x, int y, int z) {
|
|
||||||
int i = MainUtil.CACHE_I[y][x][z];
|
int i = MainUtil.CACHE_I[y][x][z];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
MaterialData md = cd.getTypeAndData(x, y, z);
|
MaterialData md = cd.getTypeAndData(x, y, z);
|
||||||
@ -167,23 +164,21 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
|||||||
return chunk == null ? cz : chunk.getZ();
|
return chunk == null ? cz : chunk.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public String getWorld() {
|
||||||
public String getWorld() {
|
|
||||||
return chunk == null ? world : chunk.getWorld().getName();
|
return chunk == null ? world : chunk.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getMax() {
|
||||||
public Location getMax() {
|
|
||||||
return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
return new Location(getWorld(), 15 + (getX() << 4), 255, 15 + (getZ() << 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public Location getMin() {
|
||||||
public Location getMin() {
|
|
||||||
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
|
return new Location(getWorld(), getX() << 4, 0, getZ() << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenChunk clone() {
|
public GenChunk clone() {
|
||||||
GenChunk toReturn = new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
|
GenChunk toReturn =
|
||||||
|
new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
|
||||||
if (this.result != null) {
|
if (this.result != null) {
|
||||||
for (int i = 0; i < this.result.length; i++) {
|
for (int i = 0; i < this.result.length; i++) {
|
||||||
short[] matrix = this.result[i];
|
short[] matrix = this.result[i];
|
@ -1,12 +1,11 @@
|
|||||||
package com.plotsquared.nukkit.uuid;
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
|
||||||
public class DatFileFilter implements FilenameFilter {
|
public class DatFileFilter implements FilenameFilter {
|
||||||
|
|
||||||
@Override
|
@Override public boolean accept(File dir, String name) {
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith(".dat");
|
return name.endsWith(".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||||
|
|
||||||
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
|
return ((BukkitPlayer) player).player.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
|
return player.getUUID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
||||||
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UUID getUUID(String name) {
|
||||||
|
return Bukkit.getOfflinePlayer(name).getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public OfflinePlotPlayer[] getOfflinePlayers() {
|
||||||
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
|
BukkitOfflinePlayer[] toReturn = new BukkitOfflinePlayer[ops.length];
|
||||||
|
for (int i = 0; i < ops.length; i++) {
|
||||||
|
toReturn[i] = new BukkitOfflinePlayer(ops[i]);
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||||
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,23 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.util.NbtFactory;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import org.bukkit.Bukkit;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import org.bukkit.World;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
|
||||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.StringMan;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
|
||||||
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.util.NbtFactory;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -24,9 +27,6 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
public class FileUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
@ -34,8 +34,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
super(wrapper);
|
super(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean startCaching(Runnable whenDone) {
|
||||||
public boolean startCaching(Runnable whenDone) {
|
|
||||||
return super.startCaching(whenDone) && cache(whenDone);
|
return super.startCaching(whenDone) && cache(whenDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +48,13 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
world = worlds.get(0).getName();
|
world = worlds.get(0).getName();
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
PlotSquared.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
||||||
PS.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
File uuidFile = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||||
File uuidFile = new File(PS.get().IMP.getDirectory(), "uuids.txt");
|
|
||||||
if (uuidFile.exists()) {
|
if (uuidFile.exists()) {
|
||||||
try {
|
try {
|
||||||
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,7 +64,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||||
String[] split = line.split("\\|");
|
String[] split = line.split("\\|");
|
||||||
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;
|
||||||
}
|
}
|
||||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
@ -81,11 +81,13 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd =
|
||||||
|
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
||||||
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||||
PS.debug("&aFast mode UUID caching enabled!");
|
PlotSquared.debug("&aFast mode UUID caching enabled!");
|
||||||
File playerDataFolder = new File(container, world + File.separator + "playerdata");
|
File playerDataFolder =
|
||||||
|
new File(container, world + File.separator + "playerdata");
|
||||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||||
boolean check = all.isEmpty();
|
boolean check = all.isEmpty();
|
||||||
if (dat != null) {
|
if (dat != null) {
|
||||||
@ -95,11 +97,15 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
if (check || all.remove(uuid)) {
|
if (check || all.remove(uuid)) {
|
||||||
File file = new File(playerDataFolder, current);
|
File file = new File(playerDataFolder, current);
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory
|
||||||
|
.fromStream(new FileInputStream(file),
|
||||||
|
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
if (!compound.containsKey("bukkit")) {
|
if (!compound.containsKey("bukkit")) {
|
||||||
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
|
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||||
|
+ ".dat) does not contain the the key \"bukkit\"");
|
||||||
} else {
|
} else {
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit =
|
||||||
|
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
long first = (long) bukkit.get("firstPlayed");
|
long first = (long) bukkit.get("firstPlayed");
|
||||||
@ -112,7 +118,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug(C.PREFIX + "Invalid playerdata: " + current);
|
PlotSquared.debug(C.PREFIX + "Invalid playerdata: " + current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +129,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
PS.debug("Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
PlotSquared.debug("Failed to cache: " + all.size()
|
||||||
|
+ " uuids - slowly processing all files");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashSet<String> worlds = Sets.newHashSet(world, "world");
|
HashSet<String> worlds = Sets.newHashSet(world, "world");
|
||||||
@ -132,7 +139,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
File playerDataFolder = null;
|
File playerDataFolder = null;
|
||||||
for (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 DatFileFilter());
|
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||||
if ((dat != null) && (dat.length != 0)) {
|
if ((dat != null) && (dat.length != 0)) {
|
||||||
for (String current : dat) {
|
for (String current : dat) {
|
||||||
@ -141,7 +149,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
UUID uuid = UUID.fromString(s);
|
UUID uuid = UUID.fromString(s);
|
||||||
uuids.add(uuid);
|
uuids.add(uuid);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug(C.PREFIX + "Invalid PlayerData: " + current);
|
PlotSquared.debug(C.PREFIX + "Invalid PlayerData: " + current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -158,22 +166,28 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
for (UUID uuid : uuids) {
|
for (UUID uuid : uuids) {
|
||||||
try {
|
try {
|
||||||
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;
|
||||||
}
|
}
|
||||||
NbtFactory.NbtCompound compound = NbtFactory.fromStream(new FileInputStream(file), NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
NbtFactory.NbtCompound compound = NbtFactory
|
||||||
|
.fromStream(new FileInputStream(file),
|
||||||
|
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||||
if (!compound.containsKey("bukkit")) {
|
if (!compound.containsKey("bukkit")) {
|
||||||
PS.debug("ERROR: Player data (" + uuid.toString() + ".dat) does not contain the the key \"bukkit\"");
|
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||||
|
+ ".dat) does not contain the the key \"bukkit\"");
|
||||||
} else {
|
} else {
|
||||||
NbtFactory.NbtCompound bukkit = (NbtFactory.NbtCompound) compound.get("bukkit");
|
NbtFactory.NbtCompound bukkit =
|
||||||
|
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||||
String name = (String) bukkit.get("lastKnownName");
|
String name = (String) bukkit.get("lastKnownName");
|
||||||
StringWrapper wrap = new StringWrapper(name);
|
StringWrapper wrap = new StringWrapper(name);
|
||||||
if (!toAdd.containsKey(wrap)) {
|
if (!toAdd.containsKey(wrap)) {
|
||||||
long last = (long) bukkit.get("lastPlayed");
|
long last = (long) bukkit.get("lastPlayed");
|
||||||
long first = (long) bukkit.get("firstPlayed");
|
long first = (long) bukkit.get("firstPlayed");
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase().equals(name)) {
|
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
|
||||||
|
.equals(name)) {
|
||||||
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
} else {
|
} else {
|
||||||
long most = (long) compound.get("UUIDMost");
|
long most = (long) compound.get("UUIDMost");
|
||||||
@ -189,7 +203,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
PS.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
|
PlotSquared
|
||||||
|
.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
@ -199,7 +214,8 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getUUIDMap().isEmpty()) {
|
if (getUUIDMap().isEmpty()) {
|
||||||
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper.getOfflinePlayers()) {
|
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper
|
||||||
|
.getOfflinePlayers()) {
|
||||||
long last = op.getLastPlayed();
|
long last = op.getLastPlayed();
|
||||||
if (last != 0) {
|
if (last != 0) {
|
||||||
String name = op.getName();
|
String name = op.getName();
|
||||||
@ -223,11 +239,9 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||||
TaskManager.runTask(ifFetch);
|
TaskManager.runTask(ifFetch);
|
||||||
}
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class LowerOfflineUUIDWrapper extends OfflineUUIDWrapper {
|
||||||
|
|
||||||
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
|
return UUID.nameUUIDFromBytes(
|
||||||
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
|
return UUID.nameUUIDFromBytes(
|
||||||
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UUID getUUID(OfflinePlayer player) {
|
||||||
|
return UUID.nameUUIDFromBytes(
|
||||||
|
("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public UUID getUUID(String name) {
|
||||||
|
return UUID
|
||||||
|
.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
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.object.OfflinePlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitOfflinePlayer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -32,22 +32,22 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(PlotPlayer player) {
|
||||||
public UUID getUUID(PlotPlayer player) {
|
return UUID
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||||
public UUID getUUID(OfflinePlotPlayer player) {
|
return UUID
|
||||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUUID(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(UUID uuid) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
|
|
||||||
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
BiMap<UUID, StringWrapper> map = UUIDHandler.getUuidMap().inverse();
|
||||||
String name = null;
|
String name = null;
|
||||||
if (map.containsKey(uuid)) {
|
if (map.containsKey(uuid)) {
|
||||||
@ -77,24 +77,23 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
if (players instanceof Player[]) {
|
if (players instanceof Player[]) {
|
||||||
return (Player[]) players;
|
return (Player[]) players;
|
||||||
} else {
|
} else {
|
||||||
@SuppressWarnings("unchecked") Collection<? extends Player> p = (Collection<? extends Player>) players;
|
@SuppressWarnings("unchecked") Collection<? extends Player> p =
|
||||||
|
(Collection<? extends Player>) players;
|
||||||
return p.toArray(new Player[p.size()]);
|
return p.toArray(new Player[p.size()]);
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
||||||
PS.debug("Failed to resolve online players");
|
PlotSquared.debug("Failed to resolve online players");
|
||||||
this.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(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() {
|
|
||||||
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
|
||||||
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++) {
|
||||||
@ -103,8 +102,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||||
public OfflinePlotPlayer getOfflinePlayer(String name) {
|
|
||||||
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1,22 @@
|
|||||||
package com.plotsquared.bukkit.uuid;
|
package com.github.intellectualsites.plotsquared.bukkit.uuid;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.database.SQLite;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import org.json.simple.JSONArray;
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import org.json.simple.JSONObject;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import org.json.simple.parser.JSONParser;
|
||||||
import com.intellectualcrafters.plot.database.SQLite;
|
import org.json.simple.parser.ParseException;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
||||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@ -26,22 +31,20 @@ import java.util.ArrayDeque;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||||
|
|
||||||
final int MAX_REQUESTS = 500;
|
final int MAX_REQUESTS = 500;
|
||||||
private final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
private final String PROFILE_URL =
|
||||||
|
"https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||||
private final int INTERVAL = 12000;
|
private final int INTERVAL = 12000;
|
||||||
private final JSONParser jsonParser = new JSONParser();
|
private final JSONParser jsonParser = new JSONParser();
|
||||||
private final SQLite sqlite;
|
private final SQLite sqlite;
|
||||||
|
|
||||||
public SQLUUIDHandler(UUIDWrapper wrapper) {
|
public SQLUUIDHandler(UUIDWrapper wrapper) {
|
||||||
super(wrapper);
|
super(wrapper);
|
||||||
this.sqlite = new SQLite(MainUtil.getFile(PS.get().IMP.getDirectory(), "usercache.db"));
|
this.sqlite =
|
||||||
|
new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db"));
|
||||||
try {
|
try {
|
||||||
this.sqlite.openConnection();
|
this.sqlite.openConnection();
|
||||||
} catch (ClassNotFoundException | SQLException e) {
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
@ -64,20 +67,21 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean startCaching(final Runnable whenDone) {
|
||||||
public boolean startCaching(final Runnable whenDone) {
|
|
||||||
if (!super.startCaching(whenDone)) {
|
if (!super.startCaching(whenDone)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
HashBiMap<StringWrapper, UUID> toAdd =
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||||
|
try (PreparedStatement statement = getConnection()
|
||||||
|
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||||
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"));
|
||||||
toAdd.put(new StringWrapper(username.value), uuid);
|
toAdd.put(new StringWrapper(username.value), uuid);
|
||||||
}
|
}
|
||||||
@ -96,10 +100,10 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
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() {
|
|
||||||
// If the file based UUID handler didn't cache it, then we can't cache offline mode
|
// If the file based UUID handler didn't cache it, then we can't cache offline mode
|
||||||
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
|
// Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
|
||||||
if (Settings.UUID.OFFLINE) {
|
if (Settings.UUID.OFFLINE) {
|
||||||
@ -110,18 +114,24 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
while (!toFetch.isEmpty()) {
|
while (!toFetch.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
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 connection =
|
||||||
(HttpURLConnection) new URL(SQLUUIDHandler.this.PROFILE_URL + uuid.toString().replace("-", ""))
|
(HttpURLConnection) new URL(
|
||||||
|
SQLUUIDHandler.this.PROFILE_URL + uuid
|
||||||
|
.toString().replace("-", ""))
|
||||||
.openConnection();
|
.openConnection();
|
||||||
try (InputStream con = connection.getInputStream()) {
|
try (InputStream con = connection
|
||||||
InputStreamReader reader = new InputStreamReader(con);
|
.getInputStream()) {
|
||||||
JSONObject response = (JSONObject) SQLUUIDHandler.this.jsonParser.parse(reader);
|
InputStreamReader reader =
|
||||||
|
new InputStreamReader(con);
|
||||||
|
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);
|
||||||
@ -130,7 +140,8 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
PS.debug("Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
PlotSquared.debug(
|
||||||
|
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(INTERVAL * 50);
|
Thread.sleep(INTERVAL * 50);
|
||||||
@ -155,15 +166,14 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||||
public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
PlotSquared.debug(C.PREFIX + "UUID for '" + name
|
||||||
PS.debug(C.PREFIX + "UUID for '" + name + "' was null. We'll cache this from the Mojang servers!");
|
+ "' was null. We'll cache this from the Mojang servers!");
|
||||||
if (ifFetch == null) {
|
if (ifFetch == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
@ -177,13 +187,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) SQLUUIDHandler.this.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(
|
ifFetch.value = UUID.fromString(
|
||||||
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16) + '-' + id.substring(16, 20) + '-' + id
|
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
|
||||||
.substring(20, 32));
|
+ '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -192,8 +203,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public void handleShutdown() {
|
||||||
public void handleShutdown() {
|
|
||||||
super.handleShutdown();
|
super.handleShutdown();
|
||||||
try {
|
try {
|
||||||
getConnection().close();
|
getConnection().close();
|
||||||
@ -202,18 +212,18 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override public boolean add(final StringWrapper name, final UUID uuid) {
|
||||||
public boolean add(final StringWrapper name, final UUID uuid) {
|
|
||||||
// Ignoring duplicates
|
// Ignoring duplicates
|
||||||
if (super.add(name, uuid)) {
|
if (super.add(name, uuid)) {
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
try (PreparedStatement statement = getConnection().prepareStatement(
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
"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'");
|
PlotSquared
|
||||||
|
.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -227,17 +237,17 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
|||||||
/**
|
/**
|
||||||
* This is useful for name changes
|
* This is useful for name changes
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override public void rename(final UUID uuid, final StringWrapper name) {
|
||||||
public void rename(final UUID uuid, final StringWrapper name) {
|
|
||||||
super.rename(uuid, name);
|
super.rename(uuid, name);
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override public void run() {
|
||||||
public void run() {
|
try (PreparedStatement statement = getConnection()
|
||||||
try (PreparedStatement statement = getConnection().prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
.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 + '\'');
|
PlotSquared.debug(
|
||||||
|
C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
@ -1,733 +0,0 @@
|
|||||||
package com.intellectualcrafters.plot.api;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
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.util.ChunkManager;
|
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
|
||||||
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
|
|
||||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PlotSquared API.
|
|
||||||
*
|
|
||||||
* <p>Useful classes:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@link BukkitUtil}</li>
|
|
||||||
* <li>{@link PlotPlayer}</li>
|
|
||||||
* <li>{@link Plot}</li>
|
|
||||||
* <li>{@link com.intellectualcrafters.plot.object.Location}</li>
|
|
||||||
* <li>{@link PlotArea}</li>
|
|
||||||
* <li>{@link PS}</li>
|
|
||||||
* </ul>
|
|
||||||
* @version 3.3.3
|
|
||||||
*/
|
|
||||||
public class PlotAPI {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated, does nothing.
|
|
||||||
* @param plugin not needed
|
|
||||||
* @deprecated Not needed
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PlotAPI(JavaPlugin plugin) {}
|
|
||||||
|
|
||||||
public PlotAPI(){}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots.
|
|
||||||
*
|
|
||||||
* @return all plots
|
|
||||||
*
|
|
||||||
* @see PS#getPlots()
|
|
||||||
*/
|
|
||||||
public Set<Plot> getAllPlots() {
|
|
||||||
return PS.get().getPlots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return all plots for a player.
|
|
||||||
*
|
|
||||||
* @param player Player, whose plots to search for
|
|
||||||
*
|
|
||||||
* @return all plots that a player owns
|
|
||||||
*/
|
|
||||||
public Set<Plot> getPlayerPlots(Player player) {
|
|
||||||
return PS.get().getPlots(BukkitUtil.getPlayer(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a plot world.
|
|
||||||
*
|
|
||||||
* @param plotArea Plot World Object
|
|
||||||
* @see PS#addPlotArea(PlotArea)
|
|
||||||
*/
|
|
||||||
public void addPlotArea(PlotArea plotArea) {
|
|
||||||
PS.get().addPlotArea(plotArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the PlotSquared configurations file.
|
|
||||||
* @return main configuration
|
|
||||||
*
|
|
||||||
* @see PS#config
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getConfig() {
|
|
||||||
return PS.get().config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the PlotSquared storage file.
|
|
||||||
* @return storage configuration
|
|
||||||
*
|
|
||||||
* @see PS#storage
|
|
||||||
*/
|
|
||||||
public YamlConfiguration getStorage() {
|
|
||||||
return PS.get().storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the main class for this plugin. Only use this if you really need it.
|
|
||||||
*
|
|
||||||
* @return PlotSquared PlotSquared Main Class
|
|
||||||
*
|
|
||||||
* @see PS
|
|
||||||
*/
|
|
||||||
public PS getMain() {
|
|
||||||
return PS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ChunkManager class contains several useful methods.
|
|
||||||
* <ul>
|
|
||||||
* <li>Chunk deletion</li>
|
|
||||||
* <li>Moving or copying regions</li>
|
|
||||||
* <li>Plot swapping</li>
|
|
||||||
* <li>Entity Tracking</li>
|
|
||||||
* <li>Region Regeneration</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @return ChunkManager
|
|
||||||
*
|
|
||||||
* @see ChunkManager
|
|
||||||
*/
|
|
||||||
public ChunkManager getChunkManager() {
|
|
||||||
return ChunkManager.manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the block/biome set queue
|
|
||||||
* @return GlobalBlockQueue.IMP
|
|
||||||
*/
|
|
||||||
public GlobalBlockQueue getBlockQueue() {
|
|
||||||
return GlobalBlockQueue.IMP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* UUIDWrapper class has basic methods for getting UUIDS. It's recommended
|
|
||||||
* to use the UUIDHandler class instead.
|
|
||||||
*
|
|
||||||
* @return UUIDWrapper
|
|
||||||
*
|
|
||||||
* @see UUIDWrapper
|
|
||||||
*/
|
|
||||||
public UUIDWrapper getUUIDWrapper() {
|
|
||||||
return UUIDHandler.getUUIDWrapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not use this. Instead use FlagManager.[method] in your code.
|
|
||||||
* - Flag related stuff
|
|
||||||
*
|
|
||||||
* @return FlagManager
|
|
||||||
*
|
|
||||||
* @deprecated Use {@link FlagManager} directly
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public FlagManager getFlagManager() {
|
|
||||||
return new FlagManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not use this. Instead use MainUtil.[method] in your code.
|
|
||||||
*
|
|
||||||
* @return MainUtil
|
|
||||||
* @deprecated Use {@link MainUtil} directly
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public MainUtil getMainUtil() {
|
|
||||||
return new MainUtil();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not use this. Instead use C.PERMISSION_[method] in your code.
|
|
||||||
*
|
|
||||||
* @return Array of strings
|
|
||||||
*
|
|
||||||
* @see Permissions
|
|
||||||
* @deprecated Use {@link C} to list all the permissions
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public String[] getPermissions() {
|
|
||||||
ArrayList<String> perms = new ArrayList<>();
|
|
||||||
for (C caption : C.values()) {
|
|
||||||
if ("static.permissions".equals(caption.getCategory())) {
|
|
||||||
perms.add(caption.s());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return perms.toArray(new String[perms.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SchematicHandler class contains methods related to pasting, reading
|
|
||||||
* and writing schematics.
|
|
||||||
*
|
|
||||||
* @return SchematicHandler
|
|
||||||
*
|
|
||||||
* @see SchematicHandler
|
|
||||||
*/
|
|
||||||
public SchematicHandler getSchematicHandler() {
|
|
||||||
return SchematicHandler.manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use C.[caption] instead
|
|
||||||
*
|
|
||||||
* @return C
|
|
||||||
* @deprecated Use {@link C}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public C[] getCaptions() {
|
|
||||||
return C.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plot manager for a world. Most of these methods can be accessed
|
|
||||||
* through the MainUtil.
|
|
||||||
*
|
|
||||||
* @param world the world to retrieve the manager from
|
|
||||||
*
|
|
||||||
* @return PlotManager
|
|
||||||
*
|
|
||||||
* @see PlotManager
|
|
||||||
* @see PS#getPlotManager(Plot)
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public PlotManager getPlotManager(World world) {
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return getPlotManager(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of PlotAreas in the world.
|
|
||||||
* @param world The world to check for plot areas
|
|
||||||
* @return A set of PlotAreas
|
|
||||||
*/
|
|
||||||
public Set<PlotArea> getPlotAreas(World world) {
|
|
||||||
if (world == null) {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
return PS.get().getPlotAreas(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the plot manager for a world. Contains useful low level methods for
|
|
||||||
* plot merging, clearing, and tessellation.
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
*
|
|
||||||
* @return PlotManager
|
|
||||||
*
|
|
||||||
* @see PS#getPlotManager(Plot)
|
|
||||||
* @see PlotManager
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PlotManager getPlotManager(String world) {
|
|
||||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
|
||||||
switch (areas.size()) {
|
|
||||||
case 0:
|
|
||||||
return null;
|
|
||||||
case 1:
|
|
||||||
return areas.iterator().next().manager;
|
|
||||||
default:
|
|
||||||
PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the settings for a world (settings bundled in PlotArea class). You
|
|
||||||
* will need to downcast for the specific settings a Generator has. e.g.
|
|
||||||
* DefaultPlotWorld class implements PlotArea
|
|
||||||
*
|
|
||||||
* @param world The World
|
|
||||||
*
|
|
||||||
* @return The {@link PlotArea} for the world or null if not in plotworld
|
|
||||||
*
|
|
||||||
* @see #getPlotAreas(World)
|
|
||||||
* @see PlotArea
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public PlotArea getWorldSettings(World world) {
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return getWorldSettings(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the settings for a world.
|
|
||||||
*
|
|
||||||
* @param world the world to retrieve settings from
|
|
||||||
*
|
|
||||||
* @return The {@link PlotArea} for the world or null if not in plotworld
|
|
||||||
*
|
|
||||||
* @see PS#getPlotArea(String, String)
|
|
||||||
* @see PlotArea
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public PlotArea getWorldSettings(String world) {
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Set<PlotArea> areas = PS.get().getPlotAreas(world);
|
|
||||||
switch (areas.size()) {
|
|
||||||
case 0:
|
|
||||||
return null;
|
|
||||||
case 1:
|
|
||||||
return areas.iterator().next();
|
|
||||||
default:
|
|
||||||
PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to a player.
|
|
||||||
*
|
|
||||||
* @param player the recipient of the message
|
|
||||||
* @param caption the message
|
|
||||||
*
|
|
||||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
|
||||||
*/
|
|
||||||
public void sendMessage(Player player, C caption) {
|
|
||||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to a player. The message supports color codes.
|
|
||||||
*
|
|
||||||
* @param player the recipient of the message
|
|
||||||
* @param string the message
|
|
||||||
*
|
|
||||||
* @see MainUtil#sendMessage(PlotPlayer, String)
|
|
||||||
*/
|
|
||||||
public void sendMessage(Player player, String string) {
|
|
||||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to the console. The message supports color codes.
|
|
||||||
*
|
|
||||||
* @param message the message
|
|
||||||
*
|
|
||||||
* @see MainUtil#sendConsoleMessage(C, String...)
|
|
||||||
*/
|
|
||||||
public void sendConsoleMessage(String message) {
|
|
||||||
PS.log(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a message to the console.
|
|
||||||
*
|
|
||||||
* @param caption the message
|
|
||||||
*
|
|
||||||
* @see #sendConsoleMessage(String)
|
|
||||||
* @see C
|
|
||||||
*/
|
|
||||||
public void sendConsoleMessage(C caption) {
|
|
||||||
sendConsoleMessage(caption.s());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a flag for use in plots.
|
|
||||||
*
|
|
||||||
* @param flag the flag to register
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void addFlag(Flag<?> flag) {
|
|
||||||
Flags.registerFlag(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a plot based on the ID.
|
|
||||||
*
|
|
||||||
* @param world the world the plot is located in
|
|
||||||
* @param x The PlotID x coordinate
|
|
||||||
* @param z The PlotID y coordinate
|
|
||||||
*
|
|
||||||
* @return plot, null if ID is wrong
|
|
||||||
*
|
|
||||||
* @see PlotArea#getPlot(PlotId)
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public Plot getPlot(World world, int x, int z) {
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
PlotArea area = getWorldSettings(world);
|
|
||||||
if (area == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return area.getPlot(new PlotId(x, z));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a plot based on the location.
|
|
||||||
*
|
|
||||||
* @param location the location to check
|
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
public Plot getPlot(Location location) {
|
|
||||||
if (location == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return BukkitUtil.getLocation(location).getPlot();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a plot based on the player location.
|
|
||||||
*
|
|
||||||
* @param player the player to check
|
|
||||||
*
|
|
||||||
* @return plot if found, otherwise it creates a temporary plot
|
|
||||||
*
|
|
||||||
* @see #getPlot(Location)
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
public Plot getPlot(Player player) {
|
|
||||||
return this.getPlot(player.getLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether or not a player has a plot.
|
|
||||||
*
|
|
||||||
* @param player Player that you want to check for
|
|
||||||
* @param world The world to check
|
|
||||||
* @return true if player has a plot, false if not.
|
|
||||||
*
|
|
||||||
* @see #getPlots(World, Player, boolean)
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public boolean hasPlot(World world, Player player) {
|
|
||||||
return getPlots(world, player, true).length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots for the player.
|
|
||||||
*
|
|
||||||
* @param world The world to retrieve plots from
|
|
||||||
* @param player The player to search for
|
|
||||||
* @param justOwner should we just search for owner? Or with rights?
|
|
||||||
* @return An array of plots for the player
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Plot[] getPlots(World world, Player player, boolean justOwner) {
|
|
||||||
ArrayList<Plot> pPlots = new ArrayList<>();
|
|
||||||
UUID uuid = BukkitUtil.getPlayer(player).getUUID();
|
|
||||||
for (Plot plot : PS.get().getPlots(world.getName())) {
|
|
||||||
if (justOwner) {
|
|
||||||
if (plot.hasOwner() && plot.isOwner(uuid)) {
|
|
||||||
pPlots.add(plot);
|
|
||||||
}
|
|
||||||
} else if (plot.isAdded(uuid)) {
|
|
||||||
pPlots.add(plot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pPlots.toArray(new Plot[pPlots.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plots for the world.
|
|
||||||
*
|
|
||||||
* @param world to get plots of
|
|
||||||
*
|
|
||||||
* @return Plot[] - array of plot objects in world
|
|
||||||
*
|
|
||||||
* @see PS#getPlots(String)
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Plot[] getPlots(World world) {
|
|
||||||
if (world == null) {
|
|
||||||
return new Plot[0];
|
|
||||||
}
|
|
||||||
Collection<Plot> plots = PS.get().getPlots(world.getName());
|
|
||||||
return plots.toArray(new Plot[plots.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all plot worlds.
|
|
||||||
*
|
|
||||||
* @return World[] - array of plot worlds
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public String[] getPlotWorlds() {
|
|
||||||
Set<String> plotWorldStrings = PS.get().getPlotWorldStrings();
|
|
||||||
return plotWorldStrings.toArray(new String[plotWorldStrings.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get if plotworld.
|
|
||||||
*
|
|
||||||
* @param world The world to check
|
|
||||||
*
|
|
||||||
* @return boolean (if plot world or not)
|
|
||||||
*
|
|
||||||
* @see PS#hasPlotArea(String)
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public boolean isPlotWorld(World world) {
|
|
||||||
return PS.get().hasPlotArea(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get plot locations.
|
|
||||||
*
|
|
||||||
* @param plot Plot to get the locations for
|
|
||||||
*
|
|
||||||
* @return [0] = bottomLc, [1] = topLoc, [2] = home
|
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public Location[] getLocations(Plot plot) {
|
|
||||||
Location bukkitBottom = BukkitUtil.getLocation(plot.getCorners()[0]);
|
|
||||||
Location bukkitTop = BukkitUtil.getLocation(plot.getCorners()[1]);
|
|
||||||
Location bukkitHome = BukkitUtil.getLocation(plot.getHome());
|
|
||||||
return new Location[]{bukkitBottom, bukkitTop, bukkitHome};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get home location.
|
|
||||||
*
|
|
||||||
* @param plot Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot bottom location
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
public Location getHomeLocation(Plot plot) {
|
|
||||||
return BukkitUtil.getLocation(plot.getHome());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Bottom Location (min, min, min).
|
|
||||||
*
|
|
||||||
* @param plot Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot bottom location
|
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public Location getBottomLocation(Plot plot) {
|
|
||||||
return BukkitUtil.getLocation(plot.getCorners()[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Top Location (max, max, max).
|
|
||||||
*
|
|
||||||
* @param plot Plot that you want to get the location for
|
|
||||||
*
|
|
||||||
* @return plot top location
|
|
||||||
*
|
|
||||||
* @deprecated As merged plots may not have a rectangular shape
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Deprecated
|
|
||||||
public Location getTopLocation(Plot plot) {
|
|
||||||
return BukkitUtil.getLocation(plot.getCorners()[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether or not a player is in a plot.
|
|
||||||
*
|
|
||||||
* @param player who we're checking for
|
|
||||||
*
|
|
||||||
* @return true if the player is in a plot, false if not-
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public boolean isInPlot(Player player) {
|
|
||||||
return getPlot(player) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a subcommand.
|
|
||||||
* @deprecated Command registration is done on object creation
|
|
||||||
* @param c SubCommand, that we want to register
|
|
||||||
* @see SubCommand
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void registerCommand(SubCommand c) {
|
|
||||||
PS.debug("SubCommands are now registered on creation");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the PlotSquared class.
|
|
||||||
*
|
|
||||||
* @return PlotSquared Class
|
|
||||||
*
|
|
||||||
* @see PS
|
|
||||||
*/
|
|
||||||
public PS getPlotSquared() {
|
|
||||||
return PS.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the player plot count.
|
|
||||||
*
|
|
||||||
* @param world Specify the world we want to select the plots from
|
|
||||||
* @param player Player, for whom we're getting the plot count
|
|
||||||
*
|
|
||||||
* @return the number of plots the player has
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public int getPlayerPlotCount(World world, Player player) {
|
|
||||||
if (world == null) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return BukkitUtil.getPlayer(player).getPlotCount(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a collection containing the players plots.
|
|
||||||
*
|
|
||||||
* @param world Specify the world we want to select the plots from
|
|
||||||
* @param player Player, for whom we're getting the plots
|
|
||||||
*
|
|
||||||
* @return a set containing the players plots
|
|
||||||
*
|
|
||||||
* @see PS#getPlots(String, PlotPlayer)
|
|
||||||
*
|
|
||||||
* @see Plot
|
|
||||||
*/
|
|
||||||
public Set<Plot> getPlayerPlots(World world, Player player) {
|
|
||||||
if (world == null) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
return PlotPlayer.wrap(player).getPlots(world.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of plots, which the player is able to build in.
|
|
||||||
*
|
|
||||||
* @param player player, for whom we're getting the plots
|
|
||||||
*
|
|
||||||
* @return the number of allowed plots
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public int getAllowedPlots(Player player) {
|
|
||||||
PlotPlayer plotPlayer = PlotPlayer.wrap(player);
|
|
||||||
return plotPlayer.getAllowedPlots();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the PlotPlayer for a player. The PlotPlayer is usually cached and
|
|
||||||
* will provide useful functions relating to players.
|
|
||||||
*
|
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
|
||||||
* @return a {@code PlotPlayer}
|
|
||||||
*/
|
|
||||||
public PlotPlayer wrapPlayer(Player player) {
|
|
||||||
return PlotPlayer.wrap(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the PlotPlayer for a UUID.
|
|
||||||
*
|
|
||||||
* <p><i>Please note that PlotSquared can be configured to provide
|
|
||||||
* different UUIDs than bukkit</i>
|
|
||||||
*
|
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param uuid the uuid of the player to wrap
|
|
||||||
* @return a {@code PlotPlayer}
|
|
||||||
*/
|
|
||||||
public PlotPlayer wrapPlayer(UUID uuid) {
|
|
||||||
return PlotPlayer.wrap(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the PlotPlayer for a username.
|
|
||||||
*
|
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
|
||||||
* @return a {@code PlotPlayer}
|
|
||||||
*/
|
|
||||||
public PlotPlayer wrapPlayer(String player) {
|
|
||||||
return PlotPlayer.wrap(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the PlotPlayer for an offline player.
|
|
||||||
*
|
|
||||||
* <p>Note that this will work if the player is offline, however not all
|
|
||||||
* functionality will work.
|
|
||||||
*
|
|
||||||
* @see PlotPlayer#wrap(Object)
|
|
||||||
*
|
|
||||||
* @param player the player to wrap
|
|
||||||
* @return a {@code PlotPlayer}
|
|
||||||
*/
|
|
||||||
public PlotPlayer wrapPlayer(OfflinePlayer player) {
|
|
||||||
return PlotPlayer.wrap(player);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,99 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import java.util.List;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Vehicle;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
|
||||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
|
||||||
import org.bukkit.event.vehicle.*;
|
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
|
||||||
import org.bukkit.metadata.MetadataValue;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class EntityPortal_1_7_9 implements Listener {
|
|
||||||
public EntityPortal_1_7_9() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleUpdateEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleDestroyEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleEntityCollisionEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleCreateEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onVehicle(VehicleBlockCollisionEvent event) {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onTeleport(EntityTeleportEvent event) {
|
|
||||||
Entity ent = event.getEntity();
|
|
||||||
if (ent instanceof Vehicle || ent instanceof ArmorStand) test(event.getEntity());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
|
|
||||||
test(event.getVehicle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void spawn(CreatureSpawnEvent event) {
|
|
||||||
switch (event.getEntityType()) {
|
|
||||||
case ARMOR_STAND:
|
|
||||||
test(event.getEntity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean ignoreTP = false;
|
|
||||||
|
|
||||||
public static void test(Entity entity) {
|
|
||||||
List<MetadataValue> meta = entity.getMetadata("plotworld");
|
|
||||||
World world = entity.getLocation().getWorld();
|
|
||||||
if (meta == null || meta.isEmpty()) {
|
|
||||||
if (PS.get().isPlotWorld(world.getName())) {
|
|
||||||
entity.setMetadata("plotworld", new FixedMetadataValue((Plugin) PS.get().IMP, entity.getLocation()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Location origin = (Location) meta.get(0).value();
|
|
||||||
World originWorld = origin.getWorld();
|
|
||||||
if (!originWorld.equals(world)) {
|
|
||||||
if (!ignoreTP) {
|
|
||||||
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
|
|
||||||
try {
|
|
||||||
ignoreTP = true;
|
|
||||||
entity.teleport(origin);
|
|
||||||
} finally {
|
|
||||||
ignoreTP = false;
|
|
||||||
}
|
|
||||||
if (entity.getLocation().getWorld().equals(world)) {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entity.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
public class EntitySpawnListener implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void creatureSpawnEvent(EntitySpawnEvent event) {
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
|
||||||
PlotArea area = location.getPlotArea();
|
|
||||||
if (area == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Plot plot = area.getOwnedPlotAbs(location);
|
|
||||||
if (plot == null) {
|
|
||||||
if (!area.MOB_SPAWNING) {
|
|
||||||
EntityType type = entity.getType();
|
|
||||||
switch (type) {
|
|
||||||
case DROPPED_ITEM:
|
|
||||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PLAYER:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type.isAlive() || !area.MISC_SPAWN_UNOWNED) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
switch (entity.getType()) {
|
|
||||||
case ENDER_CRYSTAL:
|
|
||||||
if (PlayerEvents.checkEntity(entity, plot)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
case SHULKER:
|
|
||||||
if(!entity.hasMetadata("plot")) {
|
|
||||||
entity.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.BlockExplodeEvent;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class PlayerEvents183 implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onBigBoom(BlockExplodeEvent event) {
|
|
||||||
Block block = event.getBlock();
|
|
||||||
Location location = BukkitUtil.getLocation(block.getLocation());
|
|
||||||
String world = location.getWorld();
|
|
||||||
if (!PS.get().hasPlotArea(world)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlotArea area = location.getPlotArea();
|
|
||||||
if (area == null) {
|
|
||||||
Iterator<Block> iterator = event.blockList().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
location = BukkitUtil.getLocation(iterator.next().getLocation());
|
|
||||||
if (location.getPlotArea() != null) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Plot plot = area.getOwnedPlot(location);
|
|
||||||
if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
Iterator<Block> iterator = event.blockList().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Block b = iterator.next();
|
|
||||||
if (!plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation())))) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,175 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
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 java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.HumanEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
public class PlayerEvents_1_8 extends PlotListener implements Listener {
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
|
||||||
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event.isShiftClick()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HumanEntity entity = event.getWhoClicked();
|
|
||||||
if (!(entity instanceof Player) || !PS.get().hasPlotArea(entity.getWorld().getName())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Player player = (Player) entity;
|
|
||||||
PlayerInventory inv = player.getInventory();
|
|
||||||
int slot = inv.getHeldItemSlot();
|
|
||||||
if ((slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemStack current = inv.getItemInHand();
|
|
||||||
ItemStack newItem = event.getCursor();
|
|
||||||
ItemMeta newMeta = newItem.getItemMeta();
|
|
||||||
ItemMeta oldMeta = newItem.getItemMeta();
|
|
||||||
String newLore = "";
|
|
||||||
if (newMeta != null) {
|
|
||||||
List<String> lore = newMeta.getLore();
|
|
||||||
if (lore != null) {
|
|
||||||
newLore = lore.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String oldLore = "";
|
|
||||||
if (oldMeta != null) {
|
|
||||||
List<String> lore = oldMeta.getLore();
|
|
||||||
if (lore != null) {
|
|
||||||
oldLore = lore.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
|
|
||||||
switch (newItem.getType()) {
|
|
||||||
case BANNER:
|
|
||||||
case SKULL_ITEM:
|
|
||||||
if (newMeta != null) break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<Material> blocks = null;
|
|
||||||
Block block = player.getTargetBlock(blocks, 7);
|
|
||||||
BlockState state = block.getState();
|
|
||||||
if (state == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Material stateType = state.getType();
|
|
||||||
Material itemType = newItem.getType();
|
|
||||||
if (stateType != itemType) {
|
|
||||||
switch (stateType) {
|
|
||||||
case STANDING_BANNER:
|
|
||||||
case WALL_BANNER:
|
|
||||||
if (itemType == Material.BANNER) break;
|
|
||||||
case SKULL:
|
|
||||||
if (itemType == Material.SKULL_ITEM) break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Location l = BukkitUtil.getLocation(state.getLocation());
|
|
||||||
PlotArea area = l.getPlotArea();
|
|
||||||
if (area == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Plot plot = area.getPlotAbs(l);
|
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
|
||||||
boolean cancelled = false;
|
|
||||||
if (plot == null) {
|
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
|
||||||
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 {
|
|
||||||
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 ((current.getType() == newItem.getType()) && (current.getDurability() == newItem.getDurability())) {
|
|
||||||
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.setCursor(new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onInteract(PlayerInteractAtEntityEvent e) {
|
|
||||||
Entity entity = e.getRightClicked();
|
|
||||||
if (!(entity instanceof ArmorStand)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
|
|
||||||
PlotArea area = l.getPlotArea();
|
|
||||||
if (area == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityPortal_1_7_9.test(entity);
|
|
||||||
|
|
||||||
Plot plot = area.getPlotAbs(l);
|
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
|
|
||||||
if (plot == null) {
|
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
|
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
|
|
||||||
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 {
|
|
||||||
UUID uuid = pp.getUUID();
|
|
||||||
if (!plot.isAdded(uuid)) {
|
|
||||||
if (Flags.MISC_INTERACT.isTrue(plot)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
|
|
||||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
|
|
||||||
e.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import org.bukkit.entity.LingeringPotion;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.LingeringPotionSplashEvent;
|
|
||||||
|
|
||||||
public class PlayerEvents_1_9 implements Listener {
|
|
||||||
|
|
||||||
private final PlayerEvents parent;
|
|
||||||
|
|
||||||
public PlayerEvents_1_9(PlayerEvents parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onPotionSplash(LingeringPotionSplashEvent event) {
|
|
||||||
LingeringPotion entity = event.getEntity();
|
|
||||||
Location l = BukkitUtil.getLocation(entity);
|
|
||||||
if (!PS.get().hasPlotArea(l.getWorld())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!parent.onProjectileHit(event)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
|
||||||
|
|
||||||
public class PlotPlusListener_1_12 implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onItemPickup(EntityPickupItemEvent event) {
|
|
||||||
LivingEntity ent = event.getEntity();
|
|
||||||
if (ent instanceof Player) {
|
|
||||||
Player player = (Player) ent;
|
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
|
||||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
|
||||||
if (plot == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UUID uuid = pp.getUUID();
|
|
||||||
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.listeners;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flags;
|
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
|
||||||
|
|
||||||
public class PlotPlusListener_Legacy implements Listener {
|
|
||||||
@EventHandler
|
|
||||||
public void onItemPickup(PlayerPickupItemEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
|
||||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
|
||||||
if (plot == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UUID uuid = pp.getUUID();
|
|
||||||
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,138 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.object;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.LazyBlock;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
|
||||||
public class BukkitLazyBlock extends LazyBlock {
|
|
||||||
|
|
||||||
private int id;
|
|
||||||
private Block block;
|
|
||||||
private PlotBlock pb;
|
|
||||||
|
|
||||||
public BukkitLazyBlock(int id, Block block) {
|
|
||||||
this.id = id;
|
|
||||||
this.block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitLazyBlock(PlotBlock pb) {
|
|
||||||
this.id = pb.id;
|
|
||||||
this.pb = pb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitLazyBlock(Block block) {
|
|
||||||
this.block = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PlotBlock getPlotBlock() {
|
|
||||||
if (this.pb != null) {
|
|
||||||
return this.pb;
|
|
||||||
}
|
|
||||||
if (this.id == 0) {
|
|
||||||
this.id = this.block.getTypeId();
|
|
||||||
}
|
|
||||||
byte data;
|
|
||||||
switch (this.id) {
|
|
||||||
case 0:
|
|
||||||
case 2:
|
|
||||||
case 4:
|
|
||||||
case 13:
|
|
||||||
case 14:
|
|
||||||
case 15:
|
|
||||||
case 20:
|
|
||||||
case 21:
|
|
||||||
case 22:
|
|
||||||
case 24:
|
|
||||||
case 25:
|
|
||||||
case 30:
|
|
||||||
case 32:
|
|
||||||
case 37:
|
|
||||||
case 39:
|
|
||||||
case 40:
|
|
||||||
case 41:
|
|
||||||
case 42:
|
|
||||||
case 45:
|
|
||||||
case 46:
|
|
||||||
case 47:
|
|
||||||
case 48:
|
|
||||||
case 49:
|
|
||||||
case 51:
|
|
||||||
case 52:
|
|
||||||
case 54:
|
|
||||||
case 55:
|
|
||||||
case 56:
|
|
||||||
case 57:
|
|
||||||
case 58:
|
|
||||||
case 60:
|
|
||||||
case 61:
|
|
||||||
case 62:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
case 10:
|
|
||||||
case 11:
|
|
||||||
case 73:
|
|
||||||
case 74:
|
|
||||||
case 78:
|
|
||||||
case 79:
|
|
||||||
case 80:
|
|
||||||
case 81:
|
|
||||||
case 82:
|
|
||||||
case 83:
|
|
||||||
case 84:
|
|
||||||
case 85:
|
|
||||||
case 87:
|
|
||||||
case 88:
|
|
||||||
case 101:
|
|
||||||
case 102:
|
|
||||||
case 103:
|
|
||||||
case 110:
|
|
||||||
case 112:
|
|
||||||
case 113:
|
|
||||||
case 117:
|
|
||||||
case 121:
|
|
||||||
case 122:
|
|
||||||
case 123:
|
|
||||||
case 124:
|
|
||||||
case 129:
|
|
||||||
case 133:
|
|
||||||
case 138:
|
|
||||||
case 137:
|
|
||||||
case 140:
|
|
||||||
case 165:
|
|
||||||
case 166:
|
|
||||||
case 169:
|
|
||||||
case 170:
|
|
||||||
case 172:
|
|
||||||
case 173:
|
|
||||||
case 174:
|
|
||||||
case 176:
|
|
||||||
case 177:
|
|
||||||
case 181:
|
|
||||||
case 182:
|
|
||||||
case 188:
|
|
||||||
case 189:
|
|
||||||
case 190:
|
|
||||||
case 191:
|
|
||||||
case 192:
|
|
||||||
data = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
data = this.block.getData();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.pb = PlotBlock.get((short) this.id, data);
|
|
||||||
return this.pb;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getId() {
|
|
||||||
if (this.id == 0) {
|
|
||||||
this.id = this.block.getTypeId();
|
|
||||||
}
|
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
|
||||||
|
|
||||||
import com.plotsquared.bukkit.chat.Reflection;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
public class DefaultTitleManager_183 extends DefaultTitleManager {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new 1.8 title.
|
|
||||||
*
|
|
||||||
* @param title Title text
|
|
||||||
* @param subtitle Subtitle text
|
|
||||||
* @param fadeInTime Fade in time
|
|
||||||
* @param stayTime Stay on screen time
|
|
||||||
* @param fadeOutTime Fade out time
|
|
||||||
*/
|
|
||||||
DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
|
||||||
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load spigot and NMS classes.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
void loadClasses() {
|
|
||||||
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
|
|
||||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
|
||||||
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
|
||||||
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
|
||||||
if (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, this.chatBaseComponent, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
|
||||||
.newInstance(actions[2], null,
|
|
||||||
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.getTitle()) + "\",color:" + this.titleColor.name().toLowerCase()
|
|
||||||
+ "}");
|
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[0], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
if (!this.getSubtitle().isEmpty()) {
|
|
||||||
// Send subtitle if present
|
|
||||||
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
|
||||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle()) + "\",color:" + this.subtitleColor.name()
|
|
||||||
.toLowerCase() + "}");
|
|
||||||
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent).newInstance(actions[1], serialized);
|
|
||||||
sendPacket.invoke(connection, packet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitVersion;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class DefaultTitle_111 extends AbstractTitle {
|
|
||||||
|
|
||||||
private final boolean valid;
|
|
||||||
|
|
||||||
public DefaultTitle_111() {
|
|
||||||
this.valid = PS.get().checkVersion(PS.get().IMP.getServerVersion(), BukkitVersion.v1_11_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
|
||||||
if (valid) {
|
|
||||||
try {
|
|
||||||
final Player playerObj = ((BukkitPlayer) player).player;
|
|
||||||
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
|
|
||||||
title.send(playerObj);
|
|
||||||
return;
|
|
||||||
} catch (Throwable ignored) {}
|
|
||||||
}
|
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_180();
|
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
|
|
||||||
public class DefaultTitle_180 extends AbstractTitle {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
|
||||||
try {
|
|
||||||
DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
|
|
||||||
title.send(((BukkitPlayer) player).player);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
|
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.plotsquared.bukkit.titles;
|
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
||||||
import com.intellectualcrafters.plot.util.AbstractTitle;
|
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
|
||||||
|
|
||||||
public class DefaultTitle_183 extends AbstractTitle {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
|
|
||||||
try {
|
|
||||||
DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out);
|
|
||||||
title.send(((BukkitPlayer) player).player);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
AbstractTitle.TITLE_CLASS = new HackTitle();
|
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user