mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Merge branch 'breaking' into paperstuff
# Conflicts: # Bukkit/build.gradle # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java # Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SubCommand.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
repositories {
|
||||
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 = "https://repo.codemc.org/repository/maven-public" }
|
||||
maven {
|
||||
@ -11,16 +11,16 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':Core')
|
||||
compile project(':Core')
|
||||
testCompile project(':Core')
|
||||
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
||||
compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0-SNAPSHOT')
|
||||
compile(group: 'org.bstats', name: 'bstats-bukkit', version: '1.4')
|
||||
compile 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT'
|
||||
//implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT'
|
||||
implementation 'org.spigotmc:spigot-api:1.14.3-R0.1-SNAPSHOT'
|
||||
compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0')
|
||||
compile "io.papermc:paperlib:1.0.1"
|
||||
compile("net.milkbowl.vault:VaultAPI:1.7") {
|
||||
exclude module: 'bukkit'
|
||||
}
|
||||
compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
@ -41,7 +41,12 @@ jar.enabled = false
|
||||
shadowJar {
|
||||
dependencies {
|
||||
include(dependency(':Core'))
|
||||
include(dependency('org.bstats:bstats-bukkit:1.4'))
|
||||
// update notification stuff
|
||||
include(dependency('com.github.Sauilitired:Jenkins4J:2.0-SNAPSHOT'))
|
||||
include(dependency('com.squareup.retrofit2:retrofit:2.4.0'))
|
||||
include(dependency('com.squareup.okhttp3:okhttp:3.14.0'))
|
||||
include(dependency('com.squareup.okio:okio:2.2.2'))
|
||||
include(dependency('org.jetbrains.kotlin:kotlin-stdlib:1.3.30'))
|
||||
include(dependency("io.papermc:paperlib:1.0.1"))
|
||||
}
|
||||
relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib'
|
||||
|
@ -9,7 +9,7 @@ import com.github.intellectualsites.plotsquared.bukkit.uuid.*;
|
||||
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
@ -42,8 +42,19 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
@ -57,25 +68,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
|
||||
static {
|
||||
// Disable AWE as otherwise both fail to load
|
||||
PluginManager manager = Bukkit.getPluginManager();
|
||||
try {
|
||||
Settings.load(new File("plugins/PlotSquared/config/settings.yml"));
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
// Force WorldEdit to load
|
||||
try {
|
||||
System.out.println("[P2] Force loading WorldEdit");
|
||||
if (!manager.isPluginEnabled("WorldEdit")) {
|
||||
manager.enablePlugin(WorldEditPlugin.getPlugin(WorldEditPlugin.class));
|
||||
}
|
||||
System.out.println("[P2] Testing platform capabilities");
|
||||
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS);
|
||||
} catch (final Throwable throwable) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to force load WorldEdit." + " Road schematics will fail to generate",
|
||||
throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private final LegacyMappings legacyMappings = new BukkitLegacyMappings();
|
||||
@ -115,17 +111,54 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
|
||||
@Override public void onEnable() {
|
||||
this.pluginName = getDescription().getName();
|
||||
getServer().getName();
|
||||
|
||||
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
|
||||
PaperLib.suggestPaper(this);
|
||||
|
||||
new PlotSquared(this, "Bukkit");
|
||||
if (Settings.Enabled_Components.METRICS) {
|
||||
this.startMetrics();
|
||||
} else {
|
||||
PlotSquared.log(C.CONSOLE_PLEASE_ENABLE_METRICS.f(getPluginName()));
|
||||
|
||||
if (PlotSquared.get().IMP.getServerVersion()[1] < 13) {
|
||||
System.out.println(
|
||||
"You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
|
||||
System.out
|
||||
.println("Please check the download page for the link to the legacy versions.");
|
||||
System.out.println("The server will now be shutdown to prevent any corruption.");
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
if (PlotSquared.get().getUpdateUtility() != null) {
|
||||
final UpdateUtility updateUtility = PlotSquared.get().getUpdateUtility();
|
||||
updateUtility
|
||||
.checkForUpdate(this.getPluginVersionString(), ((updateDescription, throwable) -> {
|
||||
Bukkit.getScheduler().runTask(BukkitMain.this, () -> {
|
||||
getLogger().info("-------- PlotSquared Update Check --------");
|
||||
if (throwable != null) {
|
||||
getLogger().severe(String
|
||||
.format("Could not check for update. Reason: %s",
|
||||
throwable.getMessage()));
|
||||
} else {
|
||||
if (updateDescription == null) {
|
||||
getLogger().info(
|
||||
"You appear to be running the latest version of PlotSquared. Congratulations!");
|
||||
} else {
|
||||
getLogger()
|
||||
.info("There appears to be a PlotSquared update available!");
|
||||
getLogger().info(String.format("You are running version %s,"
|
||||
+ " the newest available version is %s",
|
||||
getPluginVersionString(), updateDescription.getVersion()));
|
||||
getLogger().info(
|
||||
String.format("Update URL: %s", updateDescription.getUrl()));
|
||||
}
|
||||
}
|
||||
getLogger().info("-------- PlotSquared Update Check --------");
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
getLogger().warning("Update checking disabled. Skipping.");
|
||||
}
|
||||
|
||||
this.startMetrics();
|
||||
if (Settings.Enabled_Components.WORLDS) {
|
||||
TaskManager.IMP.taskRepeat(this::unload, 20);
|
||||
try {
|
||||
@ -165,46 +198,49 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
continue;
|
||||
}
|
||||
|
||||
final PlotId id = PlotId.fromString(name);
|
||||
if (id != null) {
|
||||
final Plot plot = area.getOwnedPlot(id);
|
||||
if (plot != null) {
|
||||
if (PlotPlayer.wrap(plot.owner) == null) {
|
||||
if (world.getKeepSpawnInMemory()) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
PlotId id;
|
||||
try {
|
||||
id = PlotId.fromString(name);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
continue;
|
||||
}
|
||||
final Plot plot = area.getOwnedPlot(id);
|
||||
if (plot != null) {
|
||||
if (!MainUtil.isServerOwned(plot) || PlotPlayer.wrap(plot.getOwner()) == null) {
|
||||
if (world.getKeepSpawnInMemory()) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
}
|
||||
final Chunk[] chunks = world.getLoadedChunks();
|
||||
if (chunks.length == 0) {
|
||||
if (!Bukkit.unloadWorld(world, true)) {
|
||||
PlotSquared.debug("Failed to unload " + world.getName());
|
||||
}
|
||||
final Chunk[] chunks = world.getLoadedChunks();
|
||||
if (chunks.length == 0) {
|
||||
if (!Bukkit.unloadWorld(world, true)) {
|
||||
PlotSquared.debug("Failed to unload " + world.getName());
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
int index = 0;
|
||||
do {
|
||||
final Chunk chunkI = chunks[index++];
|
||||
boolean result;
|
||||
if (methodUnloadChunk0 != null) {
|
||||
try {
|
||||
result = (boolean) methodUnloadChunk0
|
||||
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||
} catch (Throwable e) {
|
||||
methodUnloadChunk0 = null;
|
||||
e.printStackTrace();
|
||||
continue outer;
|
||||
}
|
||||
} else {
|
||||
result = world
|
||||
.unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
|
||||
}
|
||||
if (!result) {
|
||||
return;
|
||||
} else {
|
||||
int index = 0;
|
||||
do {
|
||||
final Chunk chunkI = chunks[index++];
|
||||
boolean result;
|
||||
if (methodUnloadChunk0 != null) {
|
||||
try {
|
||||
result = (boolean) methodUnloadChunk0
|
||||
.invoke(world, chunkI.getX(), chunkI.getZ(), true);
|
||||
} catch (Throwable e) {
|
||||
methodUnloadChunk0 = null;
|
||||
e.printStackTrace();
|
||||
continue outer;
|
||||
}
|
||||
} while (index < chunks.length
|
||||
&& System.currentTimeMillis() - start < 5);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
result = world.unloadChunk(chunkI.getX(), chunkI.getZ(), true);
|
||||
}
|
||||
if (!result) {
|
||||
continue outer;
|
||||
}
|
||||
if (System.currentTimeMillis() - start > 5) {
|
||||
return;
|
||||
}
|
||||
} while (index < chunks.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -219,7 +255,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
|
||||
@Override public void log(@NonNull String message) {
|
||||
try {
|
||||
message = C.color(message);
|
||||
message = Captions.color(message);
|
||||
if (!Settings.Chat.CONSOLE_COLOR) {
|
||||
message = ChatColor.stripColor(message);
|
||||
}
|
||||
@ -233,10 +269,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
@Override public void disable() {
|
||||
onDisable();
|
||||
}
|
||||
|
||||
@Override public int[] getPluginVersion() {
|
||||
String ver = getDescription().getVersion();
|
||||
if (ver.contains("-")) {
|
||||
@ -272,276 +304,266 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
|
||||
@Override @SuppressWarnings("deprecation") public void runEntityTask() {
|
||||
PlotSquared.log(C.PREFIX + "KillAllEntities started.");
|
||||
TaskManager
|
||||
.runTaskRepeat(() -> PlotSquared.get().foreachPlotArea(new RunnableVal<PlotArea>() {
|
||||
@Override public void run(PlotArea plotArea) {
|
||||
final World world = Bukkit.getWorld(plotArea.worldname);
|
||||
try {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
List<Entity> entities = world.getEntities();
|
||||
Iterator<Entity> iterator = entities.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entity entity = iterator.next();
|
||||
switch (entity.getType()) {
|
||||
case EGG:
|
||||
case COMPLEX_PART:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case LINGERING_POTION:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case WEATHER:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case PLAYER:
|
||||
// non moving / unmovable
|
||||
PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
|
||||
TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> {
|
||||
final World world = Bukkit.getWorld(plotArea.worldname);
|
||||
try {
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
List<Entity> entities = world.getEntities();
|
||||
Iterator<Entity> iterator = entities.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entity entity = iterator.next();
|
||||
switch (entity.getType()) {
|
||||
case EGG:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case PLAYER:
|
||||
// non moving / unmovable
|
||||
continue;
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPLASH_POTION:
|
||||
case SNOWBALL:
|
||||
case SHULKER_BULLET:
|
||||
case SPECTRAL_ARROW:
|
||||
case ENDER_PEARL:
|
||||
case ARROW:
|
||||
case LLAMA_SPIT:
|
||||
case TRIDENT:
|
||||
// managed elsewhere | projectile
|
||||
continue;
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
// Not vehicles
|
||||
continue;
|
||||
case ARMOR_STAND:
|
||||
// Temporarily classify as vehicle
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case ENDER_CRYSTAL:
|
||||
case MINECART_TNT:
|
||||
case BOAT:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||
location = BukkitUtil.getLocation(entity.getLocation());
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
if (location.isPlotArea()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
}
|
||||
continue;
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case SPLASH_POTION:
|
||||
case SNOWBALL:
|
||||
case SHULKER_BULLET:
|
||||
case SPECTRAL_ARROW:
|
||||
case TIPPED_ARROW:
|
||||
case ENDER_PEARL:
|
||||
case ARROW:
|
||||
case LLAMA_SPIT:
|
||||
case TRIDENT:
|
||||
// managed elsewhere | projectile
|
||||
}
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
continue;
|
||||
case ITEM_FRAME:
|
||||
case PAINTING:
|
||||
// Not vehicles
|
||||
continue;
|
||||
case ARMOR_STAND:
|
||||
// Temporarily classify as vehicle
|
||||
case MINECART:
|
||||
case MINECART_CHEST:
|
||||
case MINECART_COMMAND:
|
||||
case MINECART_FURNACE:
|
||||
case MINECART_HOPPER:
|
||||
case MINECART_MOB_SPAWNER:
|
||||
case ENDER_CRYSTAL:
|
||||
case MINECART_TNT:
|
||||
case BOAT:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (!plot.equals(origin.getBasePlot(false))) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
case DRAGON_FIREBALL:
|
||||
case DROPPED_ITEM:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS && plotArea
|
||||
.getOwnedPlotAbs(BukkitUtil.getLocation(entity.getLocation()))
|
||||
== null) {
|
||||
entity.remove();
|
||||
}
|
||||
// dropped item
|
||||
continue;
|
||||
case PRIMED_TNT:
|
||||
case FALLING_BLOCK:
|
||||
// managed elsewhere
|
||||
continue;
|
||||
case SHULKER:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
List<MetadataValue> meta = entity.getMetadata("shulkerPlot");
|
||||
if (!meta.isEmpty()) {
|
||||
if (livingEntity.isLeashed()) {
|
||||
continue;
|
||||
}
|
||||
List<MetadataValue> keep = entity.getMetadata("keep");
|
||||
if (!keep.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
||||
if (originalPlotId != null) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||
location = BukkitUtil.getLocation(entity.getLocation());
|
||||
Plot plot = location.getPlot();
|
||||
if (plot == null) {
|
||||
if (location.isPlotArea()) {
|
||||
pLoc = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId 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();
|
||||
entity.remove();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||
pLoc = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId = PlotId.of(area.getPlotAbs(pLoc));
|
||||
if (currentPlotId != null) {
|
||||
entity.setMetadata("shulkerPlot", new FixedMetadataValue(
|
||||
(Plugin) PlotSquared.get().IMP, currentPlotId));
|
||||
}
|
||||
Plot origin = (Plot) meta.get(0).value();
|
||||
if (!plot.equals(origin.getBasePlot(false))) {
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
case LLAMA:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case HUSK:
|
||||
case ELDER_GUARDIAN:
|
||||
case WITHER_SKELETON:
|
||||
case STRAY:
|
||||
case ZOMBIE_VILLAGER:
|
||||
case EVOKER:
|
||||
case EVOKER_FANGS:
|
||||
case VEX:
|
||||
case VINDICATOR:
|
||||
case POLAR_BEAR:
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case CREEPER:
|
||||
case ENDERMAN:
|
||||
case ENDERMITE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case GUARDIAN:
|
||||
case HORSE:
|
||||
case IRON_GOLEM:
|
||||
case MAGMA_CUBE:
|
||||
case MUSHROOM_COW:
|
||||
case OCELOT:
|
||||
case PIG:
|
||||
case PIG_ZOMBIE:
|
||||
case RABBIT:
|
||||
case SHEEP:
|
||||
case SILVERFISH:
|
||||
case SKELETON:
|
||||
case SLIME:
|
||||
case SNOWMAN:
|
||||
case SPIDER:
|
||||
case SQUID:
|
||||
case VILLAGER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case WOLF:
|
||||
case ZOMBIE:
|
||||
case PARROT:
|
||||
case SALMON:
|
||||
case DOLPHIN:
|
||||
case TROPICAL_FISH:
|
||||
case DROWNED:
|
||||
case COD:
|
||||
case TURTLE:
|
||||
case PUFFERFISH:
|
||||
case PHANTOM:
|
||||
case ILLUSIONER:
|
||||
default: {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
Location location = entity.getLocation();
|
||||
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
if (!livingEntity.isLeashed() || !entity
|
||||
.hasMetadata("keep")) {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
case DRAGON_FIREBALL:
|
||||
case DROPPED_ITEM:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||
entity.remove();
|
||||
}
|
||||
// dropped item
|
||||
continue;
|
||||
case PRIMED_TNT:
|
||||
case FALLING_BLOCK:
|
||||
// managed elsewhere
|
||||
continue;
|
||||
case LLAMA:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
case ZOMBIE_HORSE:
|
||||
case SKELETON_HORSE:
|
||||
case HUSK:
|
||||
case ELDER_GUARDIAN:
|
||||
case WITHER_SKELETON:
|
||||
case STRAY:
|
||||
case ZOMBIE_VILLAGER:
|
||||
case EVOKER:
|
||||
case EVOKER_FANGS:
|
||||
case VEX:
|
||||
case VINDICATOR:
|
||||
case POLAR_BEAR:
|
||||
case BAT:
|
||||
case BLAZE:
|
||||
case CAVE_SPIDER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case CREEPER:
|
||||
case ENDERMAN:
|
||||
case ENDERMITE:
|
||||
case ENDER_DRAGON:
|
||||
case GHAST:
|
||||
case GIANT:
|
||||
case GUARDIAN:
|
||||
case HORSE:
|
||||
case IRON_GOLEM:
|
||||
case MAGMA_CUBE:
|
||||
case MUSHROOM_COW:
|
||||
case OCELOT:
|
||||
case PIG:
|
||||
case PIG_ZOMBIE:
|
||||
case RABBIT:
|
||||
case SHEEP:
|
||||
case SILVERFISH:
|
||||
case SKELETON:
|
||||
case SLIME:
|
||||
case SNOWMAN:
|
||||
case SPIDER:
|
||||
case SQUID:
|
||||
case VILLAGER:
|
||||
case WITCH:
|
||||
case WITHER:
|
||||
case WOLF:
|
||||
case ZOMBIE:
|
||||
default: {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
Location location = entity.getLocation();
|
||||
if (BukkitUtil.getLocation(location).isPlotRoad()) {
|
||||
if (entity instanceof LivingEntity) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
if (!livingEntity.isLeashed() || !entity
|
||||
.hasMetadata("keep")) {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (!(passenger instanceof Player) && entity
|
||||
.getMetadata("keep").isEmpty()) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
iterator.remove();
|
||||
entity.remove();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
case SHULKER: {
|
||||
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
List<MetadataValue> meta = entity.getMetadata("plot");
|
||||
if (meta != null && !meta.isEmpty()) {
|
||||
if (livingEntity.isLeashed())
|
||||
continue;
|
||||
|
||||
List<MetadataValue> keep = entity.getMetadata("keep");
|
||||
if (keep != null && !keep.isEmpty())
|
||||
continue;
|
||||
|
||||
PlotId originalPlotId = (PlotId) meta.get(0).value();
|
||||
if (originalPlotId != null) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||
pLoc =
|
||||
BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId 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();
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//This is to apply the metadata to already spawned shulkers (see EntitySpawnListener.java)
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location
|
||||
pLoc = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = pLoc.getPlotArea();
|
||||
if (area != null) {
|
||||
PlotId currentPlotId =
|
||||
PlotId.of(area.getPlotAbs(pLoc));
|
||||
if (currentPlotId != null) {
|
||||
entity.setMetadata("plot",
|
||||
new FixedMetadataValue(
|
||||
(Plugin) PlotSquared.get().IMP,
|
||||
currentPlotId));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}), 20);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}), 20);
|
||||
}
|
||||
|
||||
@Override @Nullable
|
||||
public final ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
|
||||
public final ChunkGenerator getDefaultWorldGenerator(@NotNull final String worldName,
|
||||
final String id) {
|
||||
final IndependentPlotGenerator result;
|
||||
if (id != null && id.equalsIgnoreCase("single")) {
|
||||
result = new SingleWorldGenerator();
|
||||
} else {
|
||||
result = PlotSquared.get().IMP.getDefaultGenerator();
|
||||
if (!PlotSquared.get().setupPlotWorld(world, id, result)) {
|
||||
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return (ChunkGenerator) result.specify(world);
|
||||
return (ChunkGenerator) result.specify(worldName);
|
||||
}
|
||||
|
||||
@Override public void registerPlayerEvents() {
|
||||
final PlayerEvents main = new PlayerEvents();
|
||||
getServer().getPluginManager().registerEvents(main, this);
|
||||
try {
|
||||
getServer().getClass().getMethod("spigot");
|
||||
Class.forName("org.bukkit.event.entity.EntitySpawnEvent");
|
||||
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
||||
} catch (final NoSuchMethodException | ClassNotFoundException ignored) {
|
||||
PlotSquared.debug("Not running Spigot. Skipping EntitySpawnListener event.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void registerInventoryEvents() {
|
||||
// Part of PlayerEvents - can be moved if necessary
|
||||
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
|
||||
}
|
||||
|
||||
@Override public void registerPlotPlusEvents() {
|
||||
@ -613,55 +635,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitSetupUtils();
|
||||
}
|
||||
|
||||
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
||||
boolean checkVersion = false;
|
||||
try {
|
||||
OfflinePlayer.class.getDeclaredMethod("getUniqueId");
|
||||
checkVersion = true;
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
final UUIDWrapper wrapper;
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
wrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.UUID.OFFLINE = true;
|
||||
} else if (checkVersion) {
|
||||
wrapper = new DefaultUUIDWrapper();
|
||||
Settings.UUID.OFFLINE = false;
|
||||
} else {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
wrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.UUID.OFFLINE = true;
|
||||
}
|
||||
if (!checkVersion) {
|
||||
PlotSquared.log(C.PREFIX
|
||||
+ " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
|
||||
Settings.TITLES = false;
|
||||
} else {
|
||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_111();
|
||||
if (wrapper instanceof DefaultUUIDWrapper
|
||||
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
||||
}
|
||||
}
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
PlotSquared.log(C.PREFIX + " &6" + getPluginName()
|
||||
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||
+ "Bukkit");
|
||||
} else {
|
||||
PlotSquared.log(C.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
||||
}
|
||||
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
||||
return new SQLUUIDHandler(wrapper);
|
||||
} else {
|
||||
return new FileUUIDHandler(wrapper);
|
||||
@Override public void startMetrics() {
|
||||
if (this.metricsStarted) {
|
||||
return;
|
||||
}
|
||||
this.metricsStarted = true;
|
||||
Metrics metrics = new Metrics(this);// bstats
|
||||
PlotSquared.log(Captions.PREFIX + "&6Metrics enabled.");
|
||||
}
|
||||
|
||||
@Override public ChunkManager initChunkManager() {
|
||||
@ -684,7 +664,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
|
||||
}
|
||||
|
||||
@Override public IndependentPlotGenerator getDefaultGenerator() {
|
||||
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
|
||||
return new HybridGen();
|
||||
}
|
||||
|
||||
@ -692,15 +672,37 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitInventoryUtil();
|
||||
}
|
||||
|
||||
@Override public void startMetrics() {
|
||||
if (this.metricsStarted) {
|
||||
return;
|
||||
@Override public UUIDHandlerImplementation initUUIDHandler() {
|
||||
final UUIDWrapper wrapper;
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE) {
|
||||
wrapper = new LowerOfflineUUIDWrapper();
|
||||
} else {
|
||||
wrapper = new OfflineUUIDWrapper();
|
||||
}
|
||||
Settings.UUID.OFFLINE = true;
|
||||
} else {
|
||||
wrapper = new DefaultUUIDWrapper();
|
||||
Settings.UUID.OFFLINE = false;
|
||||
}
|
||||
if (!Bukkit.getVersion().contains("git-Spigot")) {
|
||||
if (wrapper instanceof DefaultUUIDWrapper
|
||||
|| wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
|
||||
Settings.UUID.NATIVE_UUID_PROVIDER = true;
|
||||
}
|
||||
}
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
PlotSquared.log(Captions.PREFIX + " &6" + getPluginName()
|
||||
+ " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
|
||||
+ "Bukkit");
|
||||
} else {
|
||||
PlotSquared.log(Captions.PREFIX + " &6" + getPluginName() + " is using online UUIDs");
|
||||
}
|
||||
if (Settings.UUID.USE_SQLUUIDHANDLER) {
|
||||
return new SQLUUIDHandler(wrapper);
|
||||
} else {
|
||||
return new FileUUIDHandler(wrapper);
|
||||
}
|
||||
System.setProperty("bstats.relocatecheck",
|
||||
"false"); // We do not want to relocate the package...
|
||||
new org.bstats.bukkit.Metrics(this); // bstats
|
||||
PlotSquared.log(C.PREFIX + "&6Metrics enabled.");
|
||||
this.metricsStarted = true;
|
||||
}
|
||||
|
||||
@Override public void setGenerator(@NonNull final String worldName) {
|
||||
@ -730,6 +732,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert world != null;
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof BukkitPlotGenerator) {
|
||||
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
|
||||
@ -744,11 +747,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return new BukkitSchematicHandler();
|
||||
}
|
||||
|
||||
@Override public AbstractTitle initTitleManager() {
|
||||
// Already initialized in UUID handler
|
||||
return AbstractTitle.TITLE_CLASS;
|
||||
}
|
||||
|
||||
@Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
|
||||
if (player instanceof Player) {
|
||||
return BukkitUtil.getPlayer((Player) player);
|
||||
|
@ -5,7 +5,10 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
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.command.CommandSender;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
@ -320,34 +323,6 @@ public class FancyMessage
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about an achievement when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
*
|
||||
* @param which The achievement to display.
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage achievementTooltip(final Achievement which) {
|
||||
try {
|
||||
Object achievement = Reflection
|
||||
.getMethod(Reflection.getOBCClass("CraftStatistic"), "getNMSAchievement",
|
||||
Achievement.class).invoke(null, which);
|
||||
return achievementTooltip(
|
||||
(String) Reflection.getField(Reflection.getNMSClass("Achievement"), "name")
|
||||
.get(achievement));
|
||||
} catch (IllegalAccessException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Could not access method.", e);
|
||||
return this;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Argument could not be passed.", e);
|
||||
return this;
|
||||
} catch (InvocationTargetException e) {
|
||||
Bukkit.getLogger()
|
||||
.log(Level.WARNING, "A error has occurred during invoking of method.", e);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behavior of the current editing component to display information about a parameterless statistic when the client hovers over the text.
|
||||
* <p>Tooltips do not inherit display characteristics, such as color and styles, from the message component on which they are applied.</p>
|
||||
@ -648,9 +623,7 @@ public class FancyMessage
|
||||
* @return This builder instance.
|
||||
*/
|
||||
public FancyMessage translationReplacements(final FancyMessage... replacements) {
|
||||
for (FancyMessage str : replacements) {
|
||||
latest().translationReplacements.add(str);
|
||||
}
|
||||
Collections.addAll(latest().translationReplacements, replacements);
|
||||
|
||||
dirty = true;
|
||||
|
||||
@ -869,7 +842,6 @@ public class FancyMessage
|
||||
* <li>The core text of the message part.</li>
|
||||
* </ol>
|
||||
* The primary omissions are tooltips and clickable actions. Consequently, this method should be used only as a last resort.
|
||||
* </p>
|
||||
* <p>
|
||||
* Color and formatting can be removed from the returned string by using {@link ChatColor#stripColor(String)}.</p>
|
||||
*
|
||||
|
@ -134,7 +134,7 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
|
||||
json.endObject();
|
||||
} catch (IOException e) {
|
||||
Bukkit.getLogger()
|
||||
.log(Level.WARNING, "A problem occured during writing of JSON string", e);
|
||||
.log(Level.WARNING, "A problem occurred during writing of JSON string", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,6 @@ public final class Reflection {
|
||||
*/
|
||||
public synchronized static String getVersion() {
|
||||
if (_versionString == null) {
|
||||
if (Bukkit.getServer() == null) {
|
||||
// The server hasn't started, static initializer call?
|
||||
return null;
|
||||
}
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
_versionString = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
@ -180,15 +176,11 @@ public final class Reflection {
|
||||
* @return A method object with the specified name declared by the specified class.
|
||||
*/
|
||||
public synchronized static Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
if (!_loadedMethods.containsKey(clazz)) {
|
||||
_loadedMethods.put(clazz, new HashMap<String, Map<ArrayWrapper<Class<?>>, Method>>());
|
||||
}
|
||||
_loadedMethods.computeIfAbsent(clazz, k -> new HashMap<>());
|
||||
|
||||
Map<String, Map<ArrayWrapper<Class<?>>, Method>> loadedMethodNames =
|
||||
_loadedMethods.get(clazz);
|
||||
if (!loadedMethodNames.containsKey(name)) {
|
||||
loadedMethodNames.put(name, new HashMap<ArrayWrapper<Class<?>>, Method>());
|
||||
}
|
||||
loadedMethodNames.computeIfAbsent(name, k -> new HashMap<>());
|
||||
|
||||
Map<ArrayWrapper<Class<?>>, Method> loadedSignatures = loadedMethodNames.get(name);
|
||||
ArrayWrapper<Class<?>> wrappedArg = new ArrayWrapper<>(args);
|
||||
|
@ -10,7 +10,7 @@ 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.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
@ -55,14 +55,15 @@ import java.util.Map.Entry;
|
||||
Class<?> clazz = Class.forName(args[0]);
|
||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX,
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
|
||||
"/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length != 2 || !"-o".equals(args[1])) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
|
||||
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
|
||||
"/plot uuidconvert " + args[0] + " - o");
|
||||
MainUtil.sendMessage(player, "&cBe aware of the following!");
|
||||
MainUtil.sendMessage(player,
|
||||
"&8 - &cUse the database command or another method to backup your plots beforehand");
|
||||
@ -109,7 +110,8 @@ import java.util.Map.Entry;
|
||||
UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
MainUtil.sendMessage(player, C.PREFIX + "Invalid playerdata: " + current);
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.PREFIX + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,7 +139,7 @@ import java.util.Map.Entry;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
Captions.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
@ -171,126 +173,114 @@ import java.util.Map.Entry;
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing cache");
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
String name = UUIDHandler.getName(entry.getKey());
|
||||
if (name != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
String name = UUIDHandler.getName(entry.getKey());
|
||||
if (name != null) {
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
||||
|
||||
File file = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
List<String> lines =
|
||||
Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || name.length() > 16 || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID old = currentUUIDWrapper.getUUID(name);
|
||||
if (old == null) {
|
||||
continue;
|
||||
}
|
||||
UUID now = newWrapper.getUUID(name);
|
||||
UUIDHandler.add(new StringWrapper(name), now);
|
||||
uCMap.put(old, now);
|
||||
uCReverse.put(now, old);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing wrapper");
|
||||
UUIDHandler.setUUIDWrapper(newWrapper);
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCMap.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
plot.getTrusted().clear();
|
||||
plot.getMembers().clear();
|
||||
plot.getDenied().clear();
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Deleting database");
|
||||
boolean result = DBFunc.deleteTables();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Creating tables");
|
||||
MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
|
||||
|
||||
File file = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
DBFunc.createTables();
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCReverse.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || name.length() > 16 || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID old = currentUUIDWrapper.getUUID(name);
|
||||
if (old == null) {
|
||||
continue;
|
||||
}
|
||||
UUID now = newWrapper.getUUID(name);
|
||||
UUIDHandler.add(new StringWrapper(name), now);
|
||||
uCMap.put(old, now);
|
||||
uCReverse.put(now, old);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),
|
||||
new Runnable() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&6Recovery was successful!");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Replacing wrapper");
|
||||
UUIDHandler.setUUIDWrapper(newWrapper);
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Updating plot objects");
|
||||
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCMap.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
plot.getTrusted().clear();
|
||||
plot.getMembers().clear();
|
||||
plot.getDenied().clear();
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Deleting database");
|
||||
boolean result = DBFunc.deleteTables();
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Creating tables");
|
||||
|
||||
try {
|
||||
DBFunc.createTables();
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PlotSquared.get().getPlots()) {
|
||||
UUID value = uCReverse.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
}
|
||||
DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),
|
||||
() -> MainUtil.sendMessage(player, "&6Recovery was successful!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", true);
|
||||
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
} catch (IOException ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
"Could not save configuration. It will need to be manual set!");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override public void run() {
|
||||
MainUtil.sendMessage(player, "&aConversion complete!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
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");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", true);
|
||||
} else if (newWrapper instanceof DefaultUUIDWrapper) {
|
||||
PlotSquared.get().worlds.set("UUID.force-lowercase", false);
|
||||
PlotSquared.get().worlds.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
|
||||
} catch (IOException ignored) {
|
||||
MainUtil.sendMessage(player,
|
||||
"Could not save configuration. It will need to be manual set!");
|
||||
}
|
||||
|
||||
MainUtil.sendMessage(player, "&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
|
||||
DBFunc.createPlotsAndData(plots,
|
||||
() -> MainUtil.sendMessage(player, "&aConversion complete!"));
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.events;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotCluster;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Called when a flag is removed from a plot.
|
||||
*/
|
||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final PlotCluster cluster;
|
||||
private final Flag flag;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot.
|
||||
*
|
||||
* @param flag Flag that was removed
|
||||
* @param cluster PlotCluster from which the flag was removed
|
||||
*/
|
||||
public ClusterFlagRemoveEvent(Flag flag, PlotCluster cluster) {
|
||||
this.cluster = cluster;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster involved.
|
||||
*
|
||||
* @return PlotCluster
|
||||
*/
|
||||
public PlotCluster getCluster() {
|
||||
return this.cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag involved.
|
||||
*
|
||||
* @return Flag
|
||||
*/
|
||||
public Flag getFlag() {
|
||||
return this.flag;
|
||||
}
|
||||
|
||||
@Override public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override public void setCancelled(boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
}
|
@ -6,8 +6,7 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*
|
||||
*/
|
||||
public class PlayerLeavePlotEvent extends PlayerEvent {
|
||||
|
||||
|
@ -7,8 +7,7 @@ import org.bukkit.event.HandlerList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*
|
||||
*/
|
||||
public class PlayerPlotHelperEvent extends PlotEvent {
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.plot.generator.AugmentedUtils;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -24,7 +25,8 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override public void populate(World world, Random r, Chunk chunk) {
|
||||
AugmentedUtils.generate(world.getName(), chunk.getX(), chunk.getZ(), null);
|
||||
@Override
|
||||
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) {
|
||||
AugmentedUtils.generate(world.getName(), source.getX(), source.getZ(), null);
|
||||
}
|
||||
}
|
||||
|
@ -4,21 +4,19 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.block.GenChunk;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -28,7 +26,8 @@ import java.util.Set;
|
||||
public class BukkitPlotGenerator extends ChunkGenerator
|
||||
implements GeneratorWrapper<ChunkGenerator> {
|
||||
|
||||
private final GenChunk chunkSetter;
|
||||
@SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true;
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private final ChunkGenerator platformGenerator;
|
||||
private final boolean full;
|
||||
@ -41,24 +40,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
}
|
||||
this.plotGenerator = generator;
|
||||
this.platformGenerator = this;
|
||||
populators = new ArrayList<>();
|
||||
this.populators.add(new BlockPopulator() {
|
||||
|
||||
private LocalBlockQueue queue;
|
||||
|
||||
@Override public void populate(World world, Random r, Chunk c) {
|
||||
if (queue == null) {
|
||||
queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
||||
}
|
||||
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||
ChunkWrapper wrap = new ChunkWrapper(area.worldname, c.getX(), c.getZ());
|
||||
ScopedLocalBlockQueue chunk = queue.getForChunk(wrap.x, wrap.z);
|
||||
if (BukkitPlotGenerator.this.plotGenerator.populateChunk(chunk, area)) {
|
||||
queue.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.chunkSetter = new GenChunk(null, null);
|
||||
this.populators = new ArrayList<>();
|
||||
this.populators.add(new PlotBlockPopulator(this.plotGenerator));
|
||||
this.full = true;
|
||||
MainUtil.initCache();
|
||||
}
|
||||
@ -69,110 +52,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
+ " is already a BukkitPlotGenerator!");
|
||||
}
|
||||
this.full = false;
|
||||
PlotSquared.debug("BukkitPlotGenerator does not fully support: " + cg);
|
||||
this.platformGenerator = cg;
|
||||
this.plotGenerator = new IndependentPlotGenerator() {
|
||||
@Override public void processSetup(SetupObject setup) {
|
||||
}
|
||||
|
||||
@Override public void initialize(PlotArea area) {
|
||||
}
|
||||
|
||||
@Override public PlotManager getNewPlotManager() {
|
||||
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager();
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return cg.getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||
return PlotSquared.get().IMP.getDefaultGenerator()
|
||||
.getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) {
|
||||
BlockBucket[][] blockBuckets = new BlockBucket[16][];
|
||||
HybridPlotWorld hpw = (HybridPlotWorld) settings;
|
||||
// Bedrock
|
||||
if (hpw.PLOT_BEDROCK) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
blockBuckets[0][(z << 4) | x] =
|
||||
BlockBucket.withSingle(PlotBlock.get("bedrock"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
|
||||
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK;
|
||||
}
|
||||
blockBuckets[hpw.PLOT_HEIGHT >> 4][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4)
|
||||
| x] = hpw.MAIN_BLOCK;
|
||||
}
|
||||
}
|
||||
return blockBuckets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
|
||||
World w = BukkitUtil.getWorld(world);
|
||||
Location min = result.getMin();
|
||||
int cx = min.getX() >> 4;
|
||||
int cz = min.getZ() >> 4;
|
||||
Random r = new Random(MathMan.pair((short) cx, (short) cz));
|
||||
BiomeGrid grid = new BiomeGrid() {
|
||||
@Override public void setBiome(int x, int z, Biome biome) {
|
||||
result.setBiome(x, z, biome.name());
|
||||
}
|
||||
|
||||
@Override public Biome getBiome(int arg0, int arg1) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
};
|
||||
try {
|
||||
// ChunkData will spill a bit
|
||||
ChunkData data = cg.generateChunkData(w, r, cx, cz, grid);
|
||||
if (data != null) {
|
||||
return;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
/* TODO: Redo this
|
||||
// Populator spillage
|
||||
short[][] tmp = cg.generateExtBlockSections(w, r, cx, cz, grid);
|
||||
if (tmp != null) {
|
||||
for (int i = 0; i < tmp.length; i++) {
|
||||
short[] section = tmp[i];
|
||||
if (section == null) {
|
||||
if (i < 7) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int y = i << 4; y < (i << 4) + 16; y++) {
|
||||
result.setBlock(x, y, z, PlotBlock.get("air"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < section.length; j++) {
|
||||
int x = MainUtil.x_loc[i][j];
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
int z = MainUtil.z_loc[i][j];
|
||||
result.setBlock(x, y, z, section[j], (byte) 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
for (BlockPopulator populator : cg.getDefaultPopulators(w)) {
|
||||
populator.populate(w, r, w.getChunkAt(cx, cz));
|
||||
}
|
||||
}
|
||||
};
|
||||
this.chunkSetter = new GenChunk(null, new ChunkWrapper(world, 0, 0));
|
||||
this.plotGenerator = new DelegatePlotGenerator(cg, world);
|
||||
MainUtil.initCache();
|
||||
}
|
||||
|
||||
@ -192,7 +73,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
return this.platformGenerator;
|
||||
}
|
||||
|
||||
@Override public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||
@Override @NotNull public List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
try {
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
@ -226,50 +107,54 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
if (populators == null && platformGenerator != null) {
|
||||
populators = new ArrayList<>(platformGenerator.getDefaultPopulators(world));
|
||||
}
|
||||
for (BlockPopulator populator : this.populators) {
|
||||
if (!existing.contains(populator)) {
|
||||
toAdd.add(populator);
|
||||
if (populators != null) {
|
||||
for (BlockPopulator populator : this.populators) {
|
||||
if (!existing.contains(populator)) {
|
||||
toAdd.add(populator);
|
||||
}
|
||||
}
|
||||
}
|
||||
return toAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int cx, int cz, BiomeGrid grid) {
|
||||
GenChunk result = this.chunkSetter;
|
||||
@Override @NotNull
|
||||
public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z,
|
||||
@NotNull BiomeGrid biome) {
|
||||
|
||||
GenChunk result = new GenChunk();
|
||||
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
|
||||
if (result.getCd() != null) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
grid.setBiome(x, z, Biome.PLAINS);
|
||||
if (result.getChunkData() != null) {
|
||||
for (int chunkX = 0; chunkX < 16; chunkX++) {
|
||||
for (int chunkZ = 0; chunkZ < 16; chunkZ++) {
|
||||
biome.setBiome(chunkX, chunkZ, Biome.PLAINS);
|
||||
}
|
||||
}
|
||||
return result.getCd();
|
||||
return result.getChunkData();
|
||||
}
|
||||
}
|
||||
// Set the chunk location
|
||||
result.setChunk(new ChunkWrapper(world.getName(), cx, cz));
|
||||
result.setChunk(new ChunkWrapper(world.getName(), x, z));
|
||||
// Set the result data
|
||||
result.setCd(createChunkData(world));
|
||||
result.grid = grid;
|
||||
result.setChunkData(createChunkData(world));
|
||||
result.biomeGrid = biome;
|
||||
result.result = null;
|
||||
|
||||
// Catch any exceptions (as exceptions usually thrown)
|
||||
try {
|
||||
// Fill the result data if necessary
|
||||
if (this.platformGenerator != this) {
|
||||
return this.platformGenerator.generateChunkData(world, random, cx, cz, grid);
|
||||
return this.platformGenerator.generateChunkData(world, random, x, z, biome);
|
||||
} else {
|
||||
generate(world, result);
|
||||
generate(new ChunkLoc(x, z), world, result);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Return the result data
|
||||
return result.getCd();
|
||||
return result.getChunkData();
|
||||
}
|
||||
|
||||
private void generate(World world, ScopedLocalBlockQueue result) {
|
||||
private void generate(ChunkLoc loc, World world, ScopedLocalBlockQueue result) {
|
||||
// Load if improperly loaded
|
||||
if (!this.loaded) {
|
||||
String name = world.getName();
|
||||
@ -277,17 +162,17 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
this.loaded = true;
|
||||
}
|
||||
// Process the chunk
|
||||
if (ChunkManager.preProcessChunk(result)) {
|
||||
if (ChunkManager.preProcessChunk(loc, result)) {
|
||||
return;
|
||||
}
|
||||
PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||
try {
|
||||
this.plotGenerator.generateChunk(this.chunkSetter, area);
|
||||
this.plotGenerator.generateChunk(result, area);
|
||||
} catch (Throwable e) {
|
||||
// Recover from generator error
|
||||
e.printStackTrace();
|
||||
}
|
||||
ChunkManager.postProcessChunk(result);
|
||||
ChunkManager.postProcessChunk(loc, result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,7 +183,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
* @param z Ignored
|
||||
* @return always true
|
||||
*/
|
||||
@Override public boolean canSpawn(World world, int x, int z) {
|
||||
@Override public boolean canSpawn(@NotNull final World world, final int x, final int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -313,10 +198,11 @@ public class BukkitPlotGenerator extends ChunkGenerator
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean equals(Object obj) {
|
||||
@Override public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
return toString().equals(obj.toString()) || toString().equals(obj.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.generator;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@RequiredArgsConstructor final class DelegatePlotGenerator extends IndependentPlotGenerator {
|
||||
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final String world;
|
||||
|
||||
@Override public void initialize(PlotArea area) {
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return this.chunkGenerator.getClass().getName();
|
||||
}
|
||||
|
||||
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
|
||||
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
|
||||
}
|
||||
|
||||
@Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) {
|
||||
BlockBucket[][] blockBuckets = new BlockBucket[16][];
|
||||
HybridPlotWorld hpw = (HybridPlotWorld) settings;
|
||||
// Bedrock
|
||||
if (hpw.PLOT_BEDROCK) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
blockBuckets[0][(z << 4) | x] =
|
||||
BlockBucket.withSingle(PlotBlock.get("bedrock"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
|
||||
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK;
|
||||
}
|
||||
blockBuckets[hpw.PLOT_HEIGHT >> 4][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] =
|
||||
hpw.MAIN_BLOCK;
|
||||
}
|
||||
}
|
||||
return blockBuckets;
|
||||
}
|
||||
|
||||
@Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
|
||||
World world = BukkitUtil.getWorld(this.world);
|
||||
Location min = result.getMin();
|
||||
int chunkX = min.getX() >> 4;
|
||||
int chunkZ = min.getZ() >> 4;
|
||||
Random random = new Random(MathMan.pair((short) chunkX, (short) chunkZ));
|
||||
try {
|
||||
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
|
||||
@Override public void setBiome(@Range(from = 0, to = 15) int x,
|
||||
@Range(from = 0, to = 15) int z, Biome biome) {
|
||||
result.setBiome(x, z, biome.name());
|
||||
}
|
||||
|
||||
@Override @NotNull public Biome getBiome(int x, int z) {
|
||||
return Biome.FOREST;
|
||||
}
|
||||
};
|
||||
chunkGenerator.generateChunkData(world, random, chunkX, chunkZ, grid);
|
||||
return;
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
for (BlockPopulator populator : chunkGenerator.getDefaultPopulators(world)) {
|
||||
populator.populate(world, random, world.getChunkAt(chunkX, chunkZ));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.generator;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ChunkWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@RequiredArgsConstructor final class PlotBlockPopulator extends BlockPopulator {
|
||||
|
||||
private final IndependentPlotGenerator plotGenerator;
|
||||
private LocalBlockQueue queue;
|
||||
|
||||
@Override public void populate(@NotNull final World world, @NotNull final Random random,
|
||||
@NotNull final Chunk source) {
|
||||
if (this.queue == null) {
|
||||
this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
|
||||
}
|
||||
final PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
|
||||
final ChunkWrapper wrap = new ChunkWrapper(area.worldname, source.getX(), source.getZ());
|
||||
final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z);
|
||||
if (this.plotGenerator.populateChunk(chunk, area)) {
|
||||
this.queue.flush();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
@ -32,8 +32,7 @@ import java.util.HashSet;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ChunkListener implements Listener {
|
||||
@SuppressWarnings("unused") public class ChunkListener implements Listener {
|
||||
|
||||
private RefMethod methodGetHandleChunk;
|
||||
private RefField mustSave;
|
||||
@ -49,7 +48,7 @@ public class ChunkListener implements Listener {
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||
} catch (Throwable ignored) {
|
||||
PlotSquared.debug(PlotSquared.get().IMP.getPluginName()
|
||||
+ "/Server not compatible for chunk processor trim/gc");
|
||||
+ "/Server not compatible for chunk processor trim/gc");
|
||||
|
||||
Settings.Chunk_Processor.AUTO_TRIM = false;
|
||||
}
|
||||
@ -60,48 +59,45 @@ public class ChunkListener implements Listener {
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
world.setAutoSave(false);
|
||||
}
|
||||
TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
HashSet<Chunk> toUnload = new HashSet<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
TaskManager.runTaskRepeat(() -> {
|
||||
try {
|
||||
HashSet<Chunk> toUnload = new HashSet<>();
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
String worldName = world.getName();
|
||||
if (!PlotSquared.get().hasPlotArea(worldName)) {
|
||||
continue;
|
||||
}
|
||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||
Object chunkMap = w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||
Method methodIsChunkInUse =
|
||||
chunkMap.getClass().getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
for (Chunk chunk : chunks) {
|
||||
if ((boolean) methodIsChunkInUse
|
||||
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||
continue;
|
||||
}
|
||||
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
|
||||
Object chunkMap =
|
||||
w.getClass().getDeclaredMethod("getPlayerChunkMap").invoke(w);
|
||||
Method methodIsChunkInUse = chunkMap.getClass()
|
||||
.getDeclaredMethod("isChunkInUse", int.class, int.class);
|
||||
Chunk[] chunks = world.getLoadedChunks();
|
||||
for (Chunk chunk : chunks) {
|
||||
if ((boolean) methodIsChunkInUse
|
||||
.invoke(chunkMap, chunk.getX(), chunk.getZ())) {
|
||||
continue;
|
||||
}
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
if (!shouldSave(worldName, x, z)) {
|
||||
unloadChunk(worldName, chunk, false);
|
||||
continue;
|
||||
}
|
||||
toUnload.add(chunk);
|
||||
int x = chunk.getX();
|
||||
int z = chunk.getZ();
|
||||
if (!shouldSave(worldName, x, z)) {
|
||||
unloadChunk(worldName, chunk, false);
|
||||
continue;
|
||||
}
|
||||
toUnload.add(chunk);
|
||||
}
|
||||
if (toUnload.isEmpty()) {
|
||||
}
|
||||
if (toUnload.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (Chunk chunk : toUnload) {
|
||||
if (System.currentTimeMillis() - start > 5) {
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
for (Chunk chunk : toUnload) {
|
||||
if (System.currentTimeMillis() - start > 5) {
|
||||
return;
|
||||
}
|
||||
chunk.unload(true, false);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
chunk.unload(true);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
@ -112,20 +108,20 @@ public class ChunkListener implements Listener {
|
||||
}
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
RefField.RefExecutor field = this.mustSave.of(c);
|
||||
if ((Boolean) field.get() == true) {
|
||||
if ((Boolean) field.get()) {
|
||||
field.set(false);
|
||||
if (chunk.isLoaded()) {
|
||||
ignoreUnload = true;
|
||||
chunk.unload(false, false);
|
||||
chunk.unload(false);
|
||||
ignoreUnload = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean shouldSave(String world, int X, int Z) {
|
||||
int x = X << 4;
|
||||
int z = Z << 4;
|
||||
public boolean shouldSave(String world, int chunkX, int chunkZ) {
|
||||
int x = chunkX << 4;
|
||||
int z = chunkZ << 4;
|
||||
int x2 = x + 15;
|
||||
int z2 = z + 15;
|
||||
Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
|
||||
@ -148,13 +144,12 @@ public class ChunkListener implements Listener {
|
||||
return plot != null && plot.hasOwner();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
@EventHandler public void onChunkUnload(ChunkUnloadEvent event) {
|
||||
if (ignoreUnload) {
|
||||
return;
|
||||
}
|
||||
Chunk chunk = event.getChunk();
|
||||
if (Settings.Chunk_Processor.AUTO_TRIM) {
|
||||
Chunk chunk = event.getChunk();
|
||||
String world = chunk.getWorld().getName();
|
||||
if (PlotSquared.get().hasPlotArea(world)) {
|
||||
if (unloadChunk(world, chunk, true)) {
|
||||
@ -163,17 +158,15 @@ public class ChunkListener implements Listener {
|
||||
}
|
||||
}
|
||||
if (processChunk(event.getChunk(), true)) {
|
||||
event.setCancelled(true);
|
||||
chunk.setForceLoaded(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
||||
processChunk(event.getChunk(), false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onItemSpawn(ItemSpawnEvent event) {
|
||||
@EventHandler(priority = EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) {
|
||||
Item entity = event.getEntity();
|
||||
Chunk chunk = entity.getLocation().getChunk();
|
||||
if (chunk == this.lastChunk) {
|
||||
@ -226,39 +219,37 @@ public class ChunkListener implements Listener {
|
||||
private void cleanChunk(final Chunk chunk) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override public void run() {
|
||||
if (!chunk.isLoaded()) {
|
||||
Integer task = TaskManager.runTaskRepeat(() -> {
|
||||
if (!chunk.isLoaded()) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
BlockState[] tiles = chunk.getTileEntities();
|
||||
if (tiles.length == 0) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
int i = 0;
|
||||
while (System.currentTimeMillis() - start < 250) {
|
||||
if (i >= tiles.length) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared
|
||||
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true);
|
||||
return;
|
||||
}
|
||||
BlockState[] tiles = chunk.getTileEntities();
|
||||
if (tiles.length == 0) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared
|
||||
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
int i = 0;
|
||||
while (System.currentTimeMillis() - start < 250) {
|
||||
if (i >= tiles.length) {
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
PlotSquared
|
||||
.debug(C.PREFIX.s() + "&aSuccessfully processed and unloaded chunk!");
|
||||
chunk.unload(true, true);
|
||||
return;
|
||||
}
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
i++;
|
||||
}
|
||||
tiles[i].getBlock().setType(Material.AIR, false);
|
||||
i++;
|
||||
}
|
||||
}, 5);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
@ -277,14 +268,14 @@ public class ChunkListener implements Listener {
|
||||
}
|
||||
}
|
||||
PlotSquared.debug(
|
||||
C.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX() << 4)
|
||||
+ "," + (chunk.getX() << 4));
|
||||
Captions.PREFIX.s() + "&a detected unsafe chunk and processed: " + (chunk.getX()
|
||||
<< 4) + "," + (chunk.getX() << 4));
|
||||
}
|
||||
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
|
||||
if (unload) {
|
||||
PlotSquared.debug(
|
||||
C.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
|
||||
chunk.getX() << 4));
|
||||
Captions.PREFIX.s() + "&c detected unsafe chunk: " + (chunk.getX() << 4) + ","
|
||||
+ (chunk.getX() << 4));
|
||||
cleanChunk(chunk);
|
||||
return true;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -18,23 +19,52 @@ 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.event.vehicle.VehicleBlockCollisionEvent;
|
||||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.event.vehicle.VehicleMoveEvent;
|
||||
import org.bukkit.event.vehicle.VehicleUpdateEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
|
||||
public class EntitySpawnListener implements Listener {
|
||||
|
||||
private final static String KEY = "P2";
|
||||
private static boolean ignoreTP = false;
|
||||
private static boolean hasPlotArea = false;
|
||||
private static String areaName = null;
|
||||
|
||||
public static void testNether(Entity entity) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
if (world.getEnvironment() != World.Environment.NETHER
|
||||
&& world.getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
test(entity);
|
||||
}
|
||||
|
||||
public static void testCreate(Entity entity) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
if (areaName == world.getName()) {
|
||||
} else {
|
||||
areaName = world.getName();
|
||||
hasPlotArea = PlotSquared.get().hasPlotArea(areaName);
|
||||
}
|
||||
if (!hasPlotArea)
|
||||
return;
|
||||
test(entity);
|
||||
}
|
||||
|
||||
public static void test(Entity entity) {
|
||||
List<MetadataValue> meta = entity.getMetadata("plotworld");
|
||||
World world = entity.getLocation().getWorld();
|
||||
if (meta == null || meta.isEmpty()) {
|
||||
@NotNull World world = entity.getWorld();
|
||||
List<MetadataValue> meta = entity.getMetadata(KEY);
|
||||
if (meta.isEmpty()) {
|
||||
if (PlotSquared.get().hasPlotArea(world.getName())) {
|
||||
entity.setMetadata("plotworld",
|
||||
entity.setMetadata(KEY,
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
|
||||
}
|
||||
} else {
|
||||
@ -65,16 +95,17 @@ import java.util.List;
|
||||
Entity entity = event.getEntity();
|
||||
Location location = BukkitUtil.getLocation(entity.getLocation());
|
||||
PlotArea area = location.getPlotArea();
|
||||
if (area == null) {
|
||||
if (!location.isPlotArea()) {
|
||||
return;
|
||||
}
|
||||
Plot plot = area.getOwnedPlotAbs(location);
|
||||
Plot plot = location.getOwnedPlotAbs();
|
||||
if (plot == null) {
|
||||
if (!area.MOB_SPAWNING) {
|
||||
EntityType type = entity.getType();
|
||||
switch (type) {
|
||||
case DROPPED_ITEM:
|
||||
if (Settings.Enabled_Components.KILL_ROAD_ITEMS) {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
case PLAYER:
|
||||
@ -95,48 +126,47 @@ import java.util.List;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
case SHULKER:
|
||||
if (!entity.hasMetadata("plot")) {
|
||||
entity.setMetadata("plot",
|
||||
if (!entity.hasMetadata("shulkerPlot")) {
|
||||
entity.setMetadata("shulkerPlot",
|
||||
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
|
||||
@NotNull Chunk chunk = event.getChunk();
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
testCreate(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@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());
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler public void onVehicle(VehicleCreateEvent event) {
|
||||
test(event.getVehicle());
|
||||
testCreate(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
|
||||
test(event.getVehicle());
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler public void onTeleport(EntityTeleportEvent event) {
|
||||
Entity ent = event.getEntity();
|
||||
if (ent instanceof Vehicle || ent instanceof ArmorStand)
|
||||
test(event.getEntity());
|
||||
if (ent instanceof Vehicle || ent instanceof ArmorStand) {
|
||||
testNether(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
|
||||
test(event.getVehicle());
|
||||
public void vehicleMove(VehicleMoveEvent event) {
|
||||
testNether(event.getVehicle());
|
||||
}
|
||||
|
||||
@EventHandler public void spawn(CreatureSpawnEvent event) {
|
||||
switch (event.getEntityType()) {
|
||||
case ARMOR_STAND:
|
||||
test(event.getEntity());
|
||||
if (event.getEntityType() == EntityType.ARMOR_STAND) {
|
||||
testCreate(event.getEntity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ 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.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
@ -85,7 +85,8 @@ import java.util.UUID;
|
||||
if (plot.isAdded(uuid)) {
|
||||
Set<PlotPlayer> players = getNearbyPlayers(player, plot);
|
||||
for (PlotPlayer oPlayer : players) {
|
||||
if (!Permissions.hasPermission(oPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
if (!Permissions
|
||||
.hasPermission(oPlayer, Captions.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
((BukkitPlayer) oPlayer).player
|
||||
.setVelocity(calculateVelocity(plotPlayer, oPlayer));
|
||||
}
|
||||
@ -95,7 +96,8 @@ import java.util.UUID;
|
||||
if (oPlayer == null) {
|
||||
return;
|
||||
}
|
||||
if (!Permissions.hasPermission(plotPlayer, C.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
if (!Permissions
|
||||
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_ENTRY_FORCEFIELD)) {
|
||||
player.setVelocity(calculateVelocity(oPlayer, plotPlayer));
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEve
|
||||
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.flag.IntervalFlag;
|
||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
@ -30,52 +31,49 @@ import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotPlusListener extends PlotListener implements Listener {
|
||||
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
|
||||
|
||||
private static final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
|
||||
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
|
||||
|
||||
public static void startRunnable(JavaPlugin plugin) {
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override public void run() {
|
||||
if (!healRunnable.isEmpty()) {
|
||||
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<UUID, Interval> entry = iterator.next();
|
||||
Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
double level = player.getHealth();
|
||||
if (level != value.max) {
|
||||
player.setHealth(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
|
||||
if (!healRunnable.isEmpty()) {
|
||||
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<UUID, Interval> entry = iterator.next();
|
||||
Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
double level = player.getHealth();
|
||||
if (level != value.max) {
|
||||
player.setHealth(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!feedRunnable.isEmpty()) {
|
||||
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<UUID, Interval> entry = iterator.next();
|
||||
Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
int level = player.getFoodLevel();
|
||||
if (level != value.max) {
|
||||
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
}
|
||||
if (!feedRunnable.isEmpty()) {
|
||||
for (Iterator<Entry<UUID, Interval>> iterator =
|
||||
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
|
||||
Entry<UUID, Interval> entry = iterator.next();
|
||||
Interval value = entry.getValue();
|
||||
++value.count;
|
||||
if (value.count == value.interval) {
|
||||
value.count = 0;
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
int level = player.getFoodLevel();
|
||||
if (level != value.max) {
|
||||
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,8 +81,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
}, 0L, 20L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInteract(BlockDamageEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onInteract(BlockDamageEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||
return;
|
||||
@ -103,13 +100,11 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
|
||||
if (event.getEntityType() != EntityType.PLAYER) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getEntity();
|
||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
Plot plot = BukkitUtil.getLocation(event.getEntity()).getOwnedPlot();
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
@ -118,8 +113,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent event) {
|
||||
@EventHandler public void onItemDrop(PlayerDropItemEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||
@ -134,27 +128,24 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||
@EventHandler public void onPlotEnter(PlayerEnterPlotEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Plot plot = event.getPlot();
|
||||
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
|
||||
feed.ifPresent( value -> feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
|
||||
);
|
||||
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
|
||||
heal.ifPresent( value -> healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20))
|
||||
);
|
||||
Optional<IntervalFlag.Interval> feed = plot.getFlag(Flags.FEED);
|
||||
feed.ifPresent(value -> feedRunnable
|
||||
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
|
||||
Optional<IntervalFlag.Interval> heal = plot.getFlag(Flags.HEAL);
|
||||
heal.ifPresent(value -> healRunnable
|
||||
.put(player.getUniqueId(), new Interval(value.getVal1(), value.getVal2(), 20)));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
feedRunnable.remove(player.getUniqueId());
|
||||
healRunnable.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlotLeave(PlayerLeavePlotEvent event) {
|
||||
@EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
|
||||
Player leaver = event.getPlayer();
|
||||
Plot plot = event.getPlot();
|
||||
if (!plot.hasOwner()) {
|
||||
@ -165,8 +156,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
|
||||
healRunnable.remove(leaver.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemPickup(EntityPickupItemEvent event) {
|
||||
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
|
||||
LivingEntity ent = event.getEntity();
|
||||
if (ent instanceof Player) {
|
||||
Player player = (Player) ent;
|
||||
|
@ -22,17 +22,14 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
@SuppressWarnings("unused") public class SingleWorldListener implements Listener {
|
||||
|
||||
private Method methodGetHandleChunk;
|
||||
private Field mustSave, done, lit, s;
|
||||
private Field mustSave;
|
||||
|
||||
public SingleWorldListener(Plugin plugin) throws Exception {
|
||||
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
|
||||
this.mustSave = classChunk.getField("mustSave").getRealField();
|
||||
try {
|
||||
this.done = classChunk.getField("done").getRealField();
|
||||
this.lit = classChunk.getField("lit").getRealField();
|
||||
this.s = classChunk.getField("s").getRealField();
|
||||
this.mustSave = classChunk.getField("mustSave").getRealField();
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
@ -42,14 +39,9 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
public void markChunkAsClean(Chunk chunk) {
|
||||
try {
|
||||
Object nmsChunk = methodGetHandleChunk.invoke(chunk);
|
||||
if (done != null)
|
||||
this.done.set(nmsChunk, true);
|
||||
if (mustSave != null)
|
||||
if (mustSave != null) {
|
||||
this.mustSave.set(nmsChunk, false);
|
||||
if (lit != null)
|
||||
this.lit.set(nmsChunk, false);
|
||||
if (s != null)
|
||||
this.s.set(nmsChunk, false);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -59,10 +51,12 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
PlotAreaManager man = PlotSquared.get().getPlotAreaManager();
|
||||
if (!(man instanceof SinglePlotAreaManager))
|
||||
if (!(man instanceof SinglePlotAreaManager)) {
|
||||
return;
|
||||
if (!isPlotId(name))
|
||||
}
|
||||
if (!isPlotId(name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
markChunkAsClean(event.getChunk());
|
||||
}
|
||||
|
@ -12,25 +12,26 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.WorldInitEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
@SuppressWarnings("unused") public class WorldEvents implements Listener {
|
||||
@SuppressWarnings("unused")
|
||||
public class WorldEvents implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||
if (manager instanceof SinglePlotAreaManager) {
|
||||
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
|
||||
if (single.isWorld(name)) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof GeneratorWrapper) {
|
||||
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||
} else {
|
||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onWorldInit(WorldInitEvent event) {
|
||||
World world = event.getWorld();
|
||||
String name = world.getName();
|
||||
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
|
||||
if (manager instanceof SinglePlotAreaManager) {
|
||||
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
|
||||
if (single.isWorld(name)) {
|
||||
world.setKeepSpawnInMemory(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
if (gen instanceof GeneratorWrapper) {
|
||||
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
|
||||
} else {
|
||||
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.bukkit.object;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -19,7 +20,7 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override public UUID getUUID() {
|
||||
@NotNull @Override public UUID getUUID() {
|
||||
return this.player.getUniqueId();
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.bukkit.object;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
@ -19,6 +19,7 @@ import org.bukkit.event.EventException;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
@ -28,6 +29,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
|
||||
private static boolean CHECK_EFFECTIVE = true;
|
||||
public final Player player;
|
||||
private boolean offline;
|
||||
private UUID uuid;
|
||||
@ -57,7 +59,7 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return location == null ? BukkitUtil.getLocation(this.player) : location;
|
||||
}
|
||||
|
||||
@Override public UUID getUUID() {
|
||||
@NotNull @Override public UUID getUUID() {
|
||||
if (this.uuid == null) {
|
||||
this.uuid = UUIDHandler.getUUID(this);
|
||||
}
|
||||
@ -82,6 +84,11 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
private void callEvent(final Event event) {
|
||||
Preconditions.checkNotNull(event, "Event cannot be null");
|
||||
|
||||
@ -106,15 +113,15 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
}
|
||||
|
||||
@Override public int hasPermissionRange(final String stub, final int range) {
|
||||
if (hasPermission(C.PERMISSION_ADMIN.s())) {
|
||||
if (hasPermission(Captions.PERMISSION_ADMIN.s())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
final String[] nodes = stub.split("\\.");
|
||||
final StringBuilder n = new StringBuilder();
|
||||
for (int i = 0; i < (nodes.length - 1); i++) {
|
||||
n.append(nodes[i]).append(".");
|
||||
if (!stub.equals(n + C.PERMISSION_STAR.s())) {
|
||||
if (hasPermission(n + C.PERMISSION_STAR.s())) {
|
||||
if (!stub.equals(n + Captions.PERMISSION_STAR.s())) {
|
||||
if (hasPermission(n + Captions.PERMISSION_STAR.s())) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
@ -123,27 +130,43 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
int max = 0;
|
||||
String stubPlus = stub + ".";
|
||||
if (CHECK_EFFECTIVE) {
|
||||
boolean hasAny = false;
|
||||
String stubPlus = stub + ".";
|
||||
final Set<PermissionAttachmentInfo> effective = player.getEffectivePermissions();
|
||||
if (!effective.isEmpty()) {
|
||||
for (PermissionAttachmentInfo attach : effective) {
|
||||
String perm = attach.getPermission();
|
||||
if (perm.startsWith(stubPlus)) {
|
||||
String end = perm.substring(stubPlus.length());
|
||||
if (MathMan.isInteger(end)) {
|
||||
int val = Integer.parseInt(end);
|
||||
if (val > range)
|
||||
return val;
|
||||
if (val > max)
|
||||
max = val;
|
||||
if (!effective.isEmpty()) {
|
||||
for (PermissionAttachmentInfo attach : effective) {
|
||||
String permStr = attach.getPermission();
|
||||
if (permStr.startsWith(stubPlus)) {
|
||||
hasAny = true;
|
||||
String end = permStr.substring(stubPlus.length());
|
||||
if (MathMan.isInteger(end)) {
|
||||
int val = Integer.parseInt(end);
|
||||
if (val > range) {
|
||||
return val;
|
||||
}
|
||||
if (val > max) {
|
||||
max = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
if (hasAny) {
|
||||
return max;
|
||||
}
|
||||
// Workaround
|
||||
for (PermissionAttachmentInfo attach : effective) {
|
||||
String permStr = attach.getPermission();
|
||||
if (permStr.startsWith("plots.") && !permStr.equals("plots.use")) {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
CHECK_EFFECTIVE = false;
|
||||
}
|
||||
}
|
||||
for (int i = range; i > 0; i--) {
|
||||
if (hasPermission(stub + "." + i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return max;
|
||||
@ -202,8 +225,6 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
this.player.setPlayerWeather(WeatherType.DOWNFALL);
|
||||
break;
|
||||
case RESET:
|
||||
this.player.resetPlayerWeather();
|
||||
break;
|
||||
default:
|
||||
this.player.resetPlayerWeather();
|
||||
break;
|
||||
@ -238,8 +259,6 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
this.player.setGameMode(GameMode.SPECTATOR);
|
||||
break;
|
||||
case SURVIVAL:
|
||||
this.player.setGameMode(GameMode.SURVIVAL);
|
||||
break;
|
||||
default:
|
||||
this.player.setGameMode(GameMode.SURVIVAL);
|
||||
break;
|
||||
@ -267,14 +286,15 @@ public class BukkitPlayer extends PlotPlayer {
|
||||
Preconditions.checkNotNull(id, "Specified block cannot be null");
|
||||
if (PlotBlock.isEverything(id) || id.isAir()) {
|
||||
// Let's just stop all the discs because why not?
|
||||
for (final Sound sound : Arrays.stream(Sound.values()).filter(sound -> sound.name().contains("DISC")).collect(
|
||||
Collectors.toList())) {
|
||||
for (final Sound sound : Arrays.stream(Sound.values())
|
||||
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) {
|
||||
player.stopSound(sound);
|
||||
}
|
||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
|
||||
} else {
|
||||
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class));
|
||||
this.player.playSound(BukkitUtil.getLocation(location), Sound.valueOf(id.to(Material.class).name()), Float.MAX_VALUE, 1f);
|
||||
this.player.playSound(BukkitUtil.getLocation(location),
|
||||
Sound.valueOf(id.to(Material.class).name()), Float.MAX_VALUE, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
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.entity.*;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
@ -10,13 +15,15 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
|
||||
private final short depth;
|
||||
private final int hash;
|
||||
private final EntityBaseStats base = new EntityBaseStats();
|
||||
|
||||
public ItemStack[] inventory;
|
||||
private ItemStack[] inventory;
|
||||
// Extended
|
||||
private ItemStack stack;
|
||||
private byte dataByte;
|
||||
@ -38,9 +45,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
if (depth == 0) {
|
||||
return;
|
||||
}
|
||||
Entity passenger = entity.getPassenger();
|
||||
if (passenger != null) {
|
||||
this.base.passenger = new ReplicatingEntityWrapper(passenger, depth);
|
||||
List<Entity> passengers = entity.getPassengers();
|
||||
if (passengers.size() > 0) {
|
||||
this.base.passenger = new ReplicatingEntityWrapper(passengers.get(0), depth);
|
||||
}
|
||||
this.base.fall = entity.getFallDistance();
|
||||
this.base.fire = (short) entity.getFireTicks();
|
||||
@ -61,7 +68,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
|
||||
return;
|
||||
case ARROW:
|
||||
case COMPLEX_PART:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
@ -85,15 +91,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
case MINECART_FURNACE:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case WEATHER:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case TIPPED_ARROW:
|
||||
case SPECTRAL_ARROW:
|
||||
case SHULKER_BULLET:
|
||||
case DRAGON_FIREBALL:
|
||||
case LINGERING_POTION:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case TRIDENT:
|
||||
case LLAMA_SPIT:
|
||||
// Do this stuff later
|
||||
return;
|
||||
// MISC //
|
||||
@ -132,13 +137,21 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE:
|
||||
Horse horse = (Horse) entity;
|
||||
case DONKEY:
|
||||
case LLAMA:
|
||||
case MULE:
|
||||
case SKELETON_HORSE:
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
this.horse = new HorseStats();
|
||||
this.horse.jump = horse.getJumpStrength();
|
||||
this.horse.chest = horse.isCarryingChest();
|
||||
this.horse.variant = horse.getVariant();
|
||||
this.horse.style = horse.getStyle();
|
||||
this.horse.color = horse.getColor();
|
||||
if (horse instanceof ChestedHorse) {
|
||||
ChestedHorse horse1 = (ChestedHorse) horse;
|
||||
this.horse.chest = horse1.isCarryingChest();
|
||||
}
|
||||
//todo these horse features need fixing
|
||||
//this.horse.variant = horse.getVariant();
|
||||
//this.horse.style = horse.getStyle();
|
||||
//this.horse.color = horse.getColor();
|
||||
storeTameable(horse);
|
||||
storeAgeable(horse);
|
||||
storeLiving(horse);
|
||||
@ -152,9 +165,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END TAMEABLE //
|
||||
//todo fix sheep
|
||||
case SHEEP:
|
||||
Sheep sheep = (Sheep) entity;
|
||||
this.dataByte = (byte) (sheep.isSheared() ? 1 : 0);
|
||||
if (sheep.isSheared()) {
|
||||
this.dataByte = (byte) 1;
|
||||
} else {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
this.dataByte2 = sheep.getColor().getDyeData();
|
||||
storeAgeable(sheep);
|
||||
storeLiving(sheep);
|
||||
@ -164,6 +182,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
case COW:
|
||||
case MUSHROOM_COW:
|
||||
case PIG:
|
||||
case TURTLE:
|
||||
case POLAR_BEAR:
|
||||
storeAgeable((Ageable) entity);
|
||||
storeLiving((LivingEntity) entity);
|
||||
@ -174,15 +193,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END AGEABLE //
|
||||
case GUARDIAN:
|
||||
this.dataByte = (byte) (((Guardian) entity).isElder() ? 1 : 0);
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case SKELETON:
|
||||
this.dataByte = getOrdinal(Skeleton.SkeletonType.values(),
|
||||
((Skeleton) entity).getSkeletonType());
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
case ARMOR_STAND:
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
this.inventory =
|
||||
@ -248,6 +258,10 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
EnderDragon entity1 = (EnderDragon) entity;
|
||||
this.dataByte = (byte) entity1.getPhase().ordinal();
|
||||
return;
|
||||
case SKELETON:
|
||||
case WITHER_SKELETON:
|
||||
case GUARDIAN:
|
||||
case ELDER_GUARDIAN:
|
||||
case GHAST:
|
||||
case MAGMA_CUBE:
|
||||
case SQUID:
|
||||
@ -273,6 +287,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
this.dataByte = (byte) 0;
|
||||
}
|
||||
storeLiving((LivingEntity) entity);
|
||||
return;
|
||||
// END LIVING //
|
||||
default:
|
||||
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
|
||||
@ -308,20 +323,23 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
if (this.lived.leashed) {
|
||||
// TODO leashes
|
||||
// World world = entity.getWorld();
|
||||
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) + lived.leashX, Math.floor(y) + lived.leashY, Math
|
||||
// .floor(z) + lived.leashZ), EntityType.LEASH_HITCH);
|
||||
// Entity leash = world.spawnEntity(new Location(world, Math.floor(x) +
|
||||
// lived.leashX, Math.floor(y) + lived.leashY, Math.floor(z) + lived.leashZ),
|
||||
// EntityType.LEASH_HITCH);
|
||||
// entity.setLeashHolder(leash);
|
||||
}
|
||||
}
|
||||
|
||||
void restoreEquipment(LivingEntity entity) {
|
||||
EntityEquipment equipment = entity.getEquipment();
|
||||
equipment.setItemInMainHand(this.lived.mainHand);
|
||||
equipment.setItemInOffHand(this.lived.offHand);
|
||||
equipment.setHelmet(this.lived.helmet);
|
||||
equipment.setChestplate(this.lived.chestplate);
|
||||
equipment.setLeggings(this.lived.leggings);
|
||||
equipment.setBoots(this.lived.boots);
|
||||
if (equipment != null) {
|
||||
equipment.setItemInMainHand(this.lived.mainHand);
|
||||
equipment.setItemInOffHand(this.lived.offHand);
|
||||
equipment.setHelmet(this.lived.helmet);
|
||||
equipment.setChestplate(this.lived.chestplate);
|
||||
equipment.setLeggings(this.lived.leggings);
|
||||
equipment.setBoots(this.lived.boots);
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreInventory(InventoryHolder entity) {
|
||||
@ -332,7 +350,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
public void storeLiving(LivingEntity lived) {
|
||||
private void storeLiving(LivingEntity lived) {
|
||||
this.lived = new LivingEntityStats();
|
||||
this.lived.potions = lived.getActivePotionEffects();
|
||||
this.lived.loot = lived.getCanPickupItems();
|
||||
@ -425,7 +443,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
}
|
||||
if (this.base.passenger != null) {
|
||||
try {
|
||||
entity.setPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
||||
entity.addPassenger(this.base.passenger.spawn(world, xOffset, zOffset));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
@ -454,7 +472,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
((Slime) entity).setSize(this.dataByte);
|
||||
return entity;
|
||||
case ARROW:
|
||||
case COMPLEX_PART:
|
||||
case EGG:
|
||||
case ENDER_CRYSTAL:
|
||||
case ENDER_PEARL:
|
||||
@ -477,15 +494,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
case SNOWBALL:
|
||||
case SPLASH_POTION:
|
||||
case THROWN_EXP_BOTTLE:
|
||||
case WEATHER:
|
||||
case TIPPED_ARROW:
|
||||
case SPECTRAL_ARROW:
|
||||
case SHULKER_BULLET:
|
||||
case LINGERING_POTION:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case DRAGON_FIREBALL:
|
||||
case WITHER_SKULL:
|
||||
case MINECART_FURNACE:
|
||||
case LLAMA_SPIT:
|
||||
case TRIDENT:
|
||||
case UNKNOWN:
|
||||
// Do this stuff later
|
||||
return entity;
|
||||
@ -510,12 +526,19 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
// START AGEABLE //
|
||||
// START TAMEABLE //
|
||||
case HORSE:
|
||||
Horse horse = (Horse) entity;
|
||||
case LLAMA:
|
||||
case SKELETON_HORSE:
|
||||
case DONKEY:
|
||||
case MULE:
|
||||
AbstractHorse horse = (AbstractHorse) entity;
|
||||
horse.setJumpStrength(this.horse.jump);
|
||||
horse.setCarryingChest(this.horse.chest);
|
||||
horse.setVariant(this.horse.variant);
|
||||
horse.setStyle(this.horse.style);
|
||||
horse.setColor(this.horse.color);
|
||||
if (horse instanceof ChestedHorse) {
|
||||
((ChestedHorse) horse).setCarryingChest(this.horse.chest);
|
||||
}
|
||||
//todo broken as of 1.13
|
||||
//horse.setVariant(this.horse.variant);
|
||||
//horse.setStyle(this.horse.style);
|
||||
//horse.setColor(this.horse.color);
|
||||
restoreTameable(horse);
|
||||
restoreAgeable(horse);
|
||||
restoreLiving(horse);
|
||||
@ -543,6 +566,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
case VILLAGER:
|
||||
case CHICKEN:
|
||||
case COW:
|
||||
case TURTLE:
|
||||
case POLAR_BEAR:
|
||||
case MUSHROOM_COW:
|
||||
case PIG:
|
||||
@ -557,19 +581,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
restoreAgeable((Ageable) entity);
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case GUARDIAN:
|
||||
if (this.dataByte != 0) {
|
||||
((Guardian) entity).setElder(true);
|
||||
}
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case SKELETON:
|
||||
if (this.dataByte != 0) {
|
||||
((Skeleton) entity)
|
||||
.setSkeletonType(Skeleton.SkeletonType.values()[this.dataByte]);
|
||||
}
|
||||
storeLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case ARMOR_STAND:
|
||||
// CHECK positions
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
@ -665,6 +676,10 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
|
||||
case BLAZE:
|
||||
case SNOWMAN:
|
||||
case SHULKER:
|
||||
case GUARDIAN:
|
||||
case ELDER_GUARDIAN:
|
||||
case SKELETON:
|
||||
case WITHER_SKELETON:
|
||||
restoreLiving((LivingEntity) entity);
|
||||
return entity;
|
||||
case IRON_GOLEM:
|
||||
|
@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.bukkit.object.schematic;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.sk89q.jnbt.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -132,7 +132,7 @@ public class StateWrapper {
|
||||
.replace("\"underlined\":true,", "&n").replace("\"italic\":true,", "&o")
|
||||
.replace("[{\"text\":\"", "&0").replace("{\"text\":\"", "&0").replace("\"},", "")
|
||||
.replace("\"}]", "").replace("\"}", "");
|
||||
for (Entry<String, String> entry : C.replacements.entrySet()) {
|
||||
for (Entry<String, String> entry : Captions.replacements.entrySet()) {
|
||||
str = str.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return str;
|
||||
|
@ -1,129 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class DefaultTitleManager extends TitleManager {
|
||||
|
||||
/**
|
||||
* 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(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.packetActions = Reflection.getNMSClass("EnumTitleAction");
|
||||
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void clearTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
// 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)
|
||||
.newInstance(actions[3], null);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the title settings.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws SecurityException
|
||||
* @throws ReflectiveOperationException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
@Override public void resetTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
// 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)
|
||||
.newInstance(actions[4], null);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (NoSuchFieldException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && (args.length == 0 || classListEqual(args,
|
||||
m.getParameterTypes()))) {
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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,177 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.chat.Reflection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class HackTitleManager extends TitleManager {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
HackTitleManager(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 = getClass("org.spigotmc.ProtocolInjector$PacketTitle");
|
||||
this.packetActions = getClass("org.spigotmc.ProtocolInjector$PacketTitle$Action");
|
||||
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
|
||||
}
|
||||
|
||||
@Override public void send(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
|
||||
// First reset previous settings
|
||||
resetTitle(player);
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object[] actions = this.packetActions.getEnumConstants();
|
||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||
Object packet = this.packetTitle
|
||||
.getConstructor(this.packetActions, Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
||||
.newInstance(actions[2], this.fadeInTime * (this.ticks ? 1 : 20),
|
||||
this.stayTime * (this.ticks ? 1 : 20),
|
||||
this.fadeOutTime * (this.ticks ? 1 : 20));
|
||||
// Send if set
|
||||
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
// Send title
|
||||
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
|
||||
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
|
||||
+ "\",color:" + this.titleColor.name().toLowerCase() + "}");
|
||||
packet = this.packetTitle
|
||||
.getConstructor(this.packetActions, Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.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,
|
||||
Reflection.getNMSClass("IChatBaseComponent"))
|
||||
.newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void clearTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object[] actions = this.packetActions.getEnumConstants();
|
||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||
Object packet =
|
||||
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[3]);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void resetTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
if ((getProtocolVersion(player) >= 47) && isSpigot()) {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object[] actions = this.packetActions.getEnumConstants();
|
||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||
Object packet =
|
||||
this.packetTitle.getConstructor(this.packetActions).newInstance(actions[4]);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the protocol version of the player.
|
||||
*
|
||||
* @param player Player
|
||||
* @return Protocol version
|
||||
* @throws IllegalArgumentException
|
||||
* @throws ReflectiveOperationException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
private int getProtocolVersion(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object networkManager = getValue("networkManager", connection);
|
||||
return (Integer) getMethod("getVersion", networkManager.getClass()).invoke(networkManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if running spigot.
|
||||
*
|
||||
* @return Spigot
|
||||
*/
|
||||
private boolean isSpigot() {
|
||||
return Bukkit.getVersion().contains("Spigot");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class by url.
|
||||
*
|
||||
* @param namespace Namespace url
|
||||
* @return Class
|
||||
*/
|
||||
private Class<?> getClass(String namespace) {
|
||||
try {
|
||||
return Class.forName(namespace);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Field getField(String name, Class<?> clazz)
|
||||
throws NoSuchFieldException, SecurityException {
|
||||
return clazz.getDeclaredField(name);
|
||||
}
|
||||
|
||||
private Object getValue(String name, Object obj)
|
||||
throws ReflectiveOperationException, SecurityException, IllegalArgumentException {
|
||||
Field f = getField(name, obj.getClass());
|
||||
f.setAccessible(true);
|
||||
return f.get(obj);
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (SecurityException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
for (Method m : clazz.getMethods()) {
|
||||
if (m.getName().equals(name) && ((args.length == 0) || classListEqual(args,
|
||||
m.getParameterTypes()))) {
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,256 +0,0 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.titles;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class TitleManager {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES = new HashMap<>();
|
||||
/* Title packet */ Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */ Class<?> packetActions;
|
||||
/* Chat serializer */ Class<?> nmsChatSerializer;
|
||||
Class<?> chatBaseComponent;
|
||||
ChatColor titleColor = ChatColor.WHITE;
|
||||
ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings */ int fadeInTime = -1;
|
||||
int stayTime = -1;
|
||||
int fadeOutTime = -1;
|
||||
boolean ticks = false;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
TitleManager(String title, String subtitle, int fadeInTime, int stayTime, int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
abstract void loadClasses();
|
||||
|
||||
/**
|
||||
* Gets title text.
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public final String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text for the title.
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public final void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subtitle text.
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public final String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets subtitle text.
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public final void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public final void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subtitle color.
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public final void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title fade in time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title fade out time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets title stay time.
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public final void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets timings to ticks.
|
||||
*/
|
||||
public final void setTimingsToTicks() {
|
||||
this.ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets timings to seconds.
|
||||
*/
|
||||
public final void setTimingsToSeconds() {
|
||||
this.ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the title to a player.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws IllegalArgumentException
|
||||
* @throws ReflectiveOperationException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public abstract void send(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||
|
||||
/**
|
||||
* Broadcasts the title to all players.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public final void broadcast() throws Exception {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
send(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the title.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws IllegalArgumentException
|
||||
* @throws ReflectiveOperationException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public abstract void clearTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||
|
||||
/**
|
||||
* Resets the title settings.
|
||||
*
|
||||
* @param player Player
|
||||
* @throws IllegalArgumentException
|
||||
* @throws ReflectiveOperationException
|
||||
* @throws SecurityException
|
||||
*/
|
||||
public abstract void resetTitle(Player player)
|
||||
throws IllegalArgumentException, ReflectiveOperationException, SecurityException;
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
if (CORRESPONDING_TYPES.containsKey(clazz)) {
|
||||
return CORRESPONDING_TYPES.get(clazz);
|
||||
} else {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a;
|
||||
if (classes != null) {
|
||||
a = classes.length;
|
||||
} else {
|
||||
a = 0;
|
||||
}
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++) {
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
final Object getHandle(Object obj) {
|
||||
try {
|
||||
return getMethod("getHandle", obj.getClass()).invoke(obj);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
final Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||
for (Method m : clazz.getMethods()) {
|
||||
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||
if (m.getName().equals(name) && equalsTypeArray(types, t)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
|
||||
boolean classListEqual(Class<?>[] l1, Class<?>[] l2) {
|
||||
if (l1.length != l2.length) {
|
||||
return false;
|
||||
}
|
||||
boolean equal = true;
|
||||
for (int i = 0; i < l1.length; i++) {
|
||||
if (l1[i] != l2[i]) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
}
|
@ -1,497 +0,0 @@
|
||||
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.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Minecraft 1.8 Title
|
||||
* For 1.11
|
||||
*
|
||||
* @author Maxim Van de Wynckel
|
||||
* @version 1.1.0
|
||||
*/
|
||||
public class TitleManager_1_11 {
|
||||
private static final Map<Class<?>, Class<?>> CORRESPONDING_TYPES =
|
||||
new HashMap<Class<?>, Class<?>>();
|
||||
/* Title packet */
|
||||
private static Class<?> packetTitle;
|
||||
/* Title packet actions ENUM */
|
||||
private static Class<?> packetActions;
|
||||
/* Chat serializer */
|
||||
private static Class<?> nmsChatSerializer;
|
||||
private static Class<?> chatBaseComponent;
|
||||
/* NMS player and connection */
|
||||
private static Class<?> nmsPlayer;
|
||||
private static Class<?> nmsPlayerConnection;
|
||||
private static Field playerConnection;
|
||||
private static Method sendPacket;
|
||||
private static Class<?> obcPlayer;
|
||||
private static Method methodPlayerGetHandle;
|
||||
/* Title text and color */
|
||||
private String title = "";
|
||||
private ChatColor titleColor = ChatColor.WHITE;
|
||||
/* Subtitle text and color */
|
||||
private String subtitle = "";
|
||||
private ChatColor subtitleColor = ChatColor.WHITE;
|
||||
/* Title timings */
|
||||
private int fadeInTime = -1;
|
||||
private int stayTime = -1;
|
||||
private int fadeOutTime = -1;
|
||||
private boolean ticks = false;
|
||||
|
||||
public TitleManager_1_11() {
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public TitleManager_1_11(String title) {
|
||||
this.title = title;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new 1.8 title
|
||||
*
|
||||
* @param title Title text
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public TitleManager_1_11(String title, String subtitle) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy 1.8 title
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public TitleManager_1_11(TitleManager_1_11 title) {
|
||||
// Copy title
|
||||
this.title = title.getTitle();
|
||||
this.subtitle = title.getSubtitle();
|
||||
this.titleColor = title.getTitleColor();
|
||||
this.subtitleColor = title.getSubtitleColor();
|
||||
this.fadeInTime = title.getFadeInTime();
|
||||
this.fadeOutTime = title.getFadeOutTime();
|
||||
this.stayTime = title.getStayTime();
|
||||
this.ticks = title.isTicks();
|
||||
loadClasses();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public TitleManager_1_11(String title, String subtitle, int fadeInTime, int stayTime,
|
||||
int fadeOutTime) {
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.fadeInTime = fadeInTime;
|
||||
this.stayTime = stayTime;
|
||||
this.fadeOutTime = fadeOutTime;
|
||||
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
|
||||
*/
|
||||
private void loadClasses() {
|
||||
if (packetTitle == null) {
|
||||
packetTitle = getNMSClass("PacketPlayOutTitle");
|
||||
packetActions = getNMSClass("PacketPlayOutTitle$EnumTitleAction");
|
||||
chatBaseComponent = getNMSClass("IChatBaseComponent");
|
||||
nmsChatSerializer = getNMSClass("ChatComponentText");
|
||||
nmsPlayer = getNMSClass("EntityPlayer");
|
||||
nmsPlayerConnection = getNMSClass("PlayerConnection");
|
||||
playerConnection = getField(nmsPlayer, "playerConnection");
|
||||
sendPacket = getMethod(nmsPlayerConnection, "sendPacket");
|
||||
obcPlayer = getOBCClass("entity.CraftPlayer");
|
||||
methodPlayerGetHandle = getMethod("getHandle", obcPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title text
|
||||
*
|
||||
* @return Title text
|
||||
*/
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title text
|
||||
*
|
||||
* @param title Title
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subtitle text
|
||||
*
|
||||
* @return Subtitle text
|
||||
*/
|
||||
public String getSubtitle() {
|
||||
return this.subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set subtitle text
|
||||
*
|
||||
* @param subtitle Subtitle text
|
||||
*/
|
||||
public void setSubtitle(String subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to ticks
|
||||
*/
|
||||
public void setTimingsToTicks() {
|
||||
ticks = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timings to seconds
|
||||
*/
|
||||
public void setTimingsToSeconds() {
|
||||
ticks = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the title to a player
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void send(Player player) {
|
||||
if (packetTitle != null) {
|
||||
// First reset previous settings
|
||||
resetTitle(player);
|
||||
try {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = playerConnection.get(handle);
|
||||
Object[] actions = packetActions.getEnumConstants();
|
||||
Object packet = packetTitle
|
||||
.getConstructor(packetActions, chatBaseComponent, Integer.TYPE, Integer.TYPE,
|
||||
Integer.TYPE).newInstance(actions[3], null, fadeInTime * (ticks ? 1 : 20),
|
||||
stayTime * (ticks ? 1 : 20), fadeOutTime * (ticks ? 1 : 20));
|
||||
// Send if set
|
||||
if (fadeInTime != -1 && fadeOutTime != -1 && stayTime != -1)
|
||||
sendPacket.invoke(connection, packet);
|
||||
|
||||
Object serialized;
|
||||
if (!subtitle.equals("")) {
|
||||
// Send subtitle if present
|
||||
serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||
subtitleColor + ChatColor.translateAlternateColorCodes('&', subtitle));
|
||||
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||
.newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
}
|
||||
|
||||
// Send title
|
||||
serialized = nmsChatSerializer.getConstructor(String.class)
|
||||
.newInstance(titleColor + ChatColor.translateAlternateColorCodes('&', title));
|
||||
packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||
.newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTimes(Player player) {
|
||||
if (TitleManager_1_11.packetTitle != null) {
|
||||
try {
|
||||
Object handle = getHandle(player);
|
||||
Object connection = playerConnection.get(handle);
|
||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent, Integer.TYPE,
|
||||
Integer.TYPE, Integer.TYPE})
|
||||
.newInstance(actions[3], null, this.fadeInTime * (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);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTitle(Player player) {
|
||||
if (TitleManager_1_11.packetTitle != null) {
|
||||
try {
|
||||
Object handle = getHandle(player);
|
||||
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
|
||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
|
||||
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||
titleColor + ChatColor.translateAlternateColorCodes('&', this.title));
|
||||
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||
.newInstance(actions[0], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSubtitle(Player player) {
|
||||
if (TitleManager_1_11.packetTitle != null) {
|
||||
try {
|
||||
Object handle = getHandle(player);
|
||||
Object connection = playerConnection.get(handle);
|
||||
Object[] actions = TitleManager_1_11.packetActions.getEnumConstants();
|
||||
Object serialized = nmsChatSerializer.getConstructor(String.class).newInstance(
|
||||
subtitleColor + ChatColor.translateAlternateColorCodes('&', this.subtitle));
|
||||
Object packet = TitleManager_1_11.packetTitle.getConstructor(
|
||||
new Class[] {TitleManager_1_11.packetActions, chatBaseComponent})
|
||||
.newInstance(actions[1], serialized);
|
||||
sendPacket.invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcast the title to all players
|
||||
*/
|
||||
public void broadcast() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
send(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the title
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void clearTitle(Player player) {
|
||||
try {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = playerConnection.get(handle);
|
||||
Object[] actions = packetActions.getEnumConstants();
|
||||
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||
.newInstance(actions[4], null);
|
||||
sendPacket.invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the title settings
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void resetTitle(Player player) {
|
||||
try {
|
||||
// Send timings first
|
||||
Object handle = getHandle(player);
|
||||
Object connection = playerConnection.get(handle);
|
||||
Object[] actions = packetActions.getEnumConstants();
|
||||
Object packet = packetTitle.getConstructor(packetActions, chatBaseComponent)
|
||||
.newInstance(actions[5], null);
|
||||
sendPacket.invoke(connection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> getPrimitiveType(Class<?> clazz) {
|
||||
return CORRESPONDING_TYPES.containsKey(clazz) ? CORRESPONDING_TYPES.get(clazz) : clazz;
|
||||
}
|
||||
|
||||
private Class<?>[] toPrimitiveTypeArray(Class<?>[] classes) {
|
||||
int a = classes != null ? classes.length : 0;
|
||||
Class<?>[] types = new Class<?>[a];
|
||||
for (int i = 0; i < a; i++)
|
||||
types[i] = getPrimitiveType(classes[i]);
|
||||
return types;
|
||||
}
|
||||
|
||||
private Object getHandle(Player player) {
|
||||
try {
|
||||
return methodPlayerGetHandle.invoke(player);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMethod(String name, Class<?> clazz, Class<?>... paramTypes) {
|
||||
Class<?>[] t = toPrimitiveTypeArray(paramTypes);
|
||||
for (Method m : clazz.getMethods()) {
|
||||
Class<?>[] types = toPrimitiveTypeArray(m.getParameterTypes());
|
||||
if (m.getName().equals(name) && equalsTypeArray(types, t))
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String version = name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
return version;
|
||||
}
|
||||
|
||||
private Class<?> getNMSClass(String className) {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private Class<?> getOBCClass(String className) {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = null;
|
||||
try {
|
||||
clazz = Class.forName(fullName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
private Field getField(Class<?> clazz, String name) {
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Method getMethod(Class<?> clazz, String name, Class<?>... args) {
|
||||
for (Method m : clazz.getMethods())
|
||||
if (m.getName().equals(name) && (args.length == 0 || ClassListEqual(args,
|
||||
m.getParameterTypes()))) {
|
||||
m.setAccessible(true);
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean ClassListEqual(Class<?>[] l1, Class<?>[] l2) {
|
||||
boolean equal = true;
|
||||
if (l1.length != l2.length)
|
||||
return false;
|
||||
for (int i = 0; i < l1.length; i++)
|
||||
if (l1[i] != l2[i]) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
public ChatColor getTitleColor() {
|
||||
return titleColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title color
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setTitleColor(ChatColor color) {
|
||||
this.titleColor = color;
|
||||
}
|
||||
|
||||
public ChatColor getSubtitleColor() {
|
||||
return subtitleColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the subtitle color
|
||||
*
|
||||
* @param color Chat color
|
||||
*/
|
||||
public void setSubtitleColor(ChatColor color) {
|
||||
this.subtitleColor = color;
|
||||
}
|
||||
|
||||
public int getFadeInTime() {
|
||||
return fadeInTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade in time
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeInTime(int time) {
|
||||
this.fadeInTime = time;
|
||||
}
|
||||
|
||||
public int getFadeOutTime() {
|
||||
return fadeOutTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title fade out time
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setFadeOutTime(int time) {
|
||||
this.fadeOutTime = time;
|
||||
}
|
||||
|
||||
public int getStayTime() {
|
||||
return stayTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title stay time
|
||||
*
|
||||
* @param time Time
|
||||
*/
|
||||
public void setStayTime(int time) {
|
||||
this.stayTime = time;
|
||||
}
|
||||
|
||||
public boolean isTicks() {
|
||||
return ticks;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ 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.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
|
||||
@ -10,8 +10,9 @@ 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.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||
|
||||
@ -20,14 +21,12 @@ public class BukkitChatManager extends ChatManager<FancyMessage> {
|
||||
}
|
||||
|
||||
@Override public void color(PlotMessage message, String color) {
|
||||
message.$(this).color(ChatColor.getByChar(C.color(color).substring(1)));
|
||||
message.$(this).color(ChatColor.getByChar(Captions.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));
|
||||
}
|
||||
List<FancyMessage> lines =
|
||||
Arrays.stream(tooltips).map(tooltip -> tooltip.$(this)).collect(Collectors.toList());
|
||||
message.$(this).formattedTooltip(lines);
|
||||
}
|
||||
|
||||
|
@ -106,289 +106,11 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
Set<ChunkLoc> chunks = super.getChunkChunks(world);
|
||||
for (Chunk chunk : Bukkit.getWorld(world).getLoadedChunks()) {
|
||||
ChunkLoc loc = new ChunkLoc(chunk.getX() >> 5, chunk.getZ() >> 5);
|
||||
if (!chunks.contains(loc)) {
|
||||
chunks.add(loc);
|
||||
}
|
||||
chunks.add(loc);
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 relZ = newPos.getZ() - pos1.getZ();
|
||||
|
||||
final RegionWrapper region =
|
||||
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld);
|
||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||
final String newWorldName = newWorld.getName();
|
||||
final ContentMap map = new ContentMap();
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
int bx = value[2];
|
||||
int bz = value[3];
|
||||
int tx = value[4];
|
||||
int tz = value[5];
|
||||
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
|
||||
int cxx = loc.x << 4;
|
||||
int czz = loc.z << 4;
|
||||
Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z);
|
||||
map.saveEntitiesIn(chunk, region);
|
||||
for (int x = bx & 15; x <= (tx & 15); x++) {
|
||||
for (int z = bz & 15; z <= (tz & 15); z++) {
|
||||
map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, () -> {
|
||||
for (Entry<PlotLoc, BaseBlock[]> entry : map.allBlocks.entrySet()) {
|
||||
PlotLoc loc = entry.getKey();
|
||||
BaseBlock[] blocks = entry.getValue();
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
if (blocks[y] != null) {
|
||||
BaseBlock block = blocks[y];
|
||||
queue.setBlock(loc.x, y, loc.z, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
queue.enqueue();
|
||||
GlobalBlockQueue.IMP.addTask(() -> {
|
||||
//map.restoreBlocks(newWorld, 0, 0);
|
||||
map.restoreEntities(newWorld, relX, relZ);
|
||||
TaskManager.runTask(whenDone);
|
||||
});
|
||||
}, 5);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean regenerateRegion(
|
||||
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 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 List<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);
|
||||
final BukkitWorld bukkitWorldObj = new BukkitWorld(worldObj);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
||||
final ChunkLoc chunk = chunks.remove(0);
|
||||
int x = chunk.x;
|
||||
int z = chunk.z;
|
||||
int xxb = x << 4;
|
||||
int zzb = z << 4;
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
Chunk chunkObj = worldObj.getChunkAt(x, z);
|
||||
if (!chunkObj.load(false)) {
|
||||
continue;
|
||||
}
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||
RegionWrapper currentPlotClear =
|
||||
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
AugmentedUtils
|
||||
.bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.x, chunk.z));
|
||||
continue;
|
||||
}
|
||||
boolean checkX1 = false;
|
||||
|
||||
int xxb2;
|
||||
|
||||
if (x == bcx) {
|
||||
xxb2 = p1x - 1;
|
||||
checkX1 = true;
|
||||
} else {
|
||||
xxb2 = xxb;
|
||||
}
|
||||
boolean checkX2 = false;
|
||||
int xxt2;
|
||||
if (x == tcx) {
|
||||
xxt2 = p2x + 1;
|
||||
checkX2 = true;
|
||||
} else {
|
||||
xxt2 = xxt;
|
||||
}
|
||||
boolean checkZ1 = false;
|
||||
int zzb2;
|
||||
if (z == bcz) {
|
||||
zzb2 = p1z - 1;
|
||||
checkZ1 = true;
|
||||
} else {
|
||||
zzb2 = zzb;
|
||||
}
|
||||
boolean checkZ2 = false;
|
||||
int zzt2;
|
||||
if (z == tcz) {
|
||||
zzt2 = p2z + 1;
|
||||
checkZ2 = true;
|
||||
} else {
|
||||
zzt2 = zzt;
|
||||
}
|
||||
final ContentMap map = new ContentMap();
|
||||
if (checkX1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb2, zzt2); //
|
||||
}
|
||||
if (checkX2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb2, zzt2); //
|
||||
}
|
||||
if (checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzb, zzb2); //
|
||||
}
|
||||
if (checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzt2, zzt); //
|
||||
}
|
||||
if (checkX1 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb, zzb2); //
|
||||
}
|
||||
if (checkX2 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb, zzb2); // ?
|
||||
}
|
||||
if (checkX1 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzt2, zzt); // ?
|
||||
}
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment,
|
||||
() -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||
@Override public void run(ScopedLocalBlockQueue value) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location min =
|
||||
value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc loc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(loc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1, PlotBlock.get("air"));
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length);
|
||||
y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world, chunk));
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(worldObj, 0, 0);
|
||||
}
|
||||
if (!chunks.isEmpty()) {
|
||||
TaskManager.runTaskLater(this, 1);
|
||||
} else {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllEntities(com.github.intellectualsites.plotsquared.plot.object.Location pos1,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location pos2) {
|
||||
String world = pos1.getWorld();
|
||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||
int bx = pos1.getX();
|
||||
int bz = pos1.getZ();
|
||||
int tx = pos2.getX();
|
||||
int tz = pos2.getZ();
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof Player)) {
|
||||
org.bukkit.Location location = entity.getLocation();
|
||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz
|
||||
&& location.getZ() <= tz) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") @Override
|
||||
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
|
||||
final boolean safe) {
|
||||
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||
TaskManager
|
||||
.runTask(() -> BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe));
|
||||
} else {
|
||||
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void swap(com.github.intellectualsites.plotsquared.plot.object.Location bot1,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location top1,
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location bot2,
|
||||
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());
|
||||
World world2 = Bukkit.getWorld(bot2.getWorld());
|
||||
|
||||
int relX = bot2.getX() - bot1.getX();
|
||||
int relZ = bot2.getZ() - bot1.getZ();
|
||||
|
||||
final ArrayDeque<ContentMap> maps = new ArrayDeque<>();
|
||||
|
||||
for (int x = bot1.getX() >> 4; x <= top1.getX() >> 4; x++) {
|
||||
for (int z = bot1.getZ() >> 4; z <= top1.getZ() >> 4; z++) {
|
||||
Chunk chunk1 = world1.getChunkAt(x, z);
|
||||
Chunk chunk2 = world2.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
|
||||
maps.add(swapChunk(world1, world2, chunk1, chunk2, region1, region2));
|
||||
}
|
||||
}
|
||||
GlobalBlockQueue.IMP.addTask(() -> {
|
||||
for (ContentMap map : maps) {
|
||||
map.restoreEntities(world1, 0, 0);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public int[] countEntities(Plot plot) {
|
||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
|
||||
@ -398,8 +120,8 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
PlotArea area = plot.getArea();
|
||||
World world = BukkitUtil.getWorld(area.worldname);
|
||||
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location bot = plot.getBottomAbs();
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location top = plot.getTopAbs();
|
||||
Location bot = plot.getBottomAbs();
|
||||
Location top = plot.getTopAbs();
|
||||
int bx = bot.getX() >> 4;
|
||||
int bz = bot.getZ() >> 4;
|
||||
|
||||
@ -464,6 +186,271 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override public boolean copyRegion(Location pos1, Location pos2, Location newPos,
|
||||
final Runnable whenDone) {
|
||||
final int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
|
||||
final RegionWrapper region =
|
||||
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
final World oldWorld = Bukkit.getWorld(pos1.getWorld());
|
||||
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld);
|
||||
final World newWorld = Bukkit.getWorld(newPos.getWorld());
|
||||
final String newWorldName = newWorld.getName();
|
||||
final ContentMap map = new ContentMap();
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(newWorldName, false);
|
||||
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
|
||||
@Override public void run(int[] value) {
|
||||
int bx = value[2];
|
||||
int bz = value[3];
|
||||
int tx = value[4];
|
||||
int tz = value[5];
|
||||
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
|
||||
int cxx = loc.x << 4;
|
||||
int czz = loc.z << 4;
|
||||
Chunk chunk = oldWorld.getChunkAt(loc.x, loc.z);
|
||||
map.saveEntitiesIn(chunk, region);
|
||||
for (int x = bx & 15; x <= (tx & 15); x++) {
|
||||
for (int z = bz & 15; z <= (tz & 15); z++) {
|
||||
map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, () -> {
|
||||
for (Entry<PlotLoc, BaseBlock[]> entry : map.allBlocks.entrySet()) {
|
||||
PlotLoc loc = entry.getKey();
|
||||
BaseBlock[] blocks = entry.getValue();
|
||||
for (int y = 0; y < blocks.length; y++) {
|
||||
if (blocks[y] != null) {
|
||||
BaseBlock block = blocks[y];
|
||||
queue.setBlock(loc.getX(), y, loc.getZ(), block);
|
||||
}
|
||||
}
|
||||
}
|
||||
queue.enqueue();
|
||||
GlobalBlockQueue.IMP.addTask(() -> {
|
||||
//map.restoreBlocks(newWorld, 0, 0);
|
||||
map.restoreEntities(newWorld, relX, relZ);
|
||||
TaskManager.runTask(whenDone);
|
||||
});
|
||||
}, 5);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
final boolean ignoreAugment, final Runnable whenDone) {
|
||||
final String world = pos1.getWorld();
|
||||
|
||||
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 List<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);
|
||||
final BukkitWorld bukkitWorldObj = new BukkitWorld(worldObj);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override public void run() {
|
||||
long start = System.currentTimeMillis();
|
||||
while (!chunks.isEmpty() && System.currentTimeMillis() - start < 5) {
|
||||
final ChunkLoc chunk = chunks.remove(0);
|
||||
int x = chunk.x;
|
||||
int z = chunk.z;
|
||||
int xxb = x << 4;
|
||||
int zzb = z << 4;
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
Chunk chunkObj = worldObj.getChunkAt(x, z);
|
||||
if (!chunkObj.load(false)) {
|
||||
continue;
|
||||
}
|
||||
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z
|
||||
&& PlotSquared.imp().getServerVersion()[1] == 13) {
|
||||
AugmentedUtils
|
||||
.bypass(ignoreAugment, () -> queue.regenChunkSafe(chunk.x, chunk.z));
|
||||
continue;
|
||||
}
|
||||
boolean checkX1 = false;
|
||||
|
||||
int xxb2;
|
||||
|
||||
if (x == bcx) {
|
||||
xxb2 = p1x - 1;
|
||||
checkX1 = true;
|
||||
} else {
|
||||
xxb2 = xxb;
|
||||
}
|
||||
boolean checkX2 = false;
|
||||
int xxt2;
|
||||
if (x == tcx) {
|
||||
xxt2 = p2x + 1;
|
||||
checkX2 = true;
|
||||
} else {
|
||||
xxt2 = xxt;
|
||||
}
|
||||
boolean checkZ1 = false;
|
||||
int zzb2;
|
||||
if (z == bcz) {
|
||||
zzb2 = p1z - 1;
|
||||
checkZ1 = true;
|
||||
} else {
|
||||
zzb2 = zzb;
|
||||
}
|
||||
boolean checkZ2 = false;
|
||||
int zzt2;
|
||||
if (z == tcz) {
|
||||
zzt2 = p2z + 1;
|
||||
checkZ2 = true;
|
||||
} else {
|
||||
zzt2 = zzt;
|
||||
}
|
||||
final ContentMap map = new ContentMap();
|
||||
if (checkX1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb2, zzt2); //
|
||||
}
|
||||
if (checkX2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb2, zzt2); //
|
||||
}
|
||||
if (checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzb, zzb2); //
|
||||
}
|
||||
if (checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb2, xxt2, zzt2, zzt); //
|
||||
}
|
||||
if (checkX1 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzb, zzb2); //
|
||||
}
|
||||
if (checkX2 && checkZ1) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzb, zzb2); // ?
|
||||
}
|
||||
if (checkX1 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxb, xxb2, zzt2, zzt); // ?
|
||||
}
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(bukkitWorldObj, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
RegionWrapper currentPlotClear =
|
||||
new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(chunkObj, currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment,
|
||||
() -> setChunkInPlotArea(null, new RunnableVal<ScopedLocalBlockQueue>() {
|
||||
@Override public void run(ScopedLocalBlockQueue value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc loc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(loc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1, PlotBlock.get("air"));
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length);
|
||||
y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world, chunk));
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(worldObj, 0, 0);
|
||||
}
|
||||
if (!chunks.isEmpty()) {
|
||||
TaskManager.runTaskLater(this, 1);
|
||||
} else {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean loadChunk(String world, ChunkLoc loc, boolean force) {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") @Override
|
||||
public void unloadChunk(final String world, final ChunkLoc loc, final boolean save,
|
||||
final boolean safe) {
|
||||
if (!PlotSquared.get().isMainThread(Thread.currentThread())) {
|
||||
TaskManager.runTask(() -> BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save));
|
||||
} else {
|
||||
BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void clearAllEntities(Location pos1, Location pos2) {
|
||||
String world = pos1.getWorld();
|
||||
List<Entity> entities = BukkitUtil.getEntities(world);
|
||||
int bx = pos1.getX();
|
||||
int bz = pos1.getZ();
|
||||
int tx = pos2.getX();
|
||||
int tz = pos2.getZ();
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof Player)) {
|
||||
org.bukkit.Location location = entity.getLocation();
|
||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz
|
||||
&& location.getZ() <= tz) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void swap(Location bot1, Location top1, Location bot2, 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());
|
||||
World world2 = Bukkit.getWorld(bot2.getWorld());
|
||||
|
||||
int relX = bot2.getX() - bot1.getX();
|
||||
int relZ = bot2.getZ() - bot1.getZ();
|
||||
|
||||
final ArrayDeque<ContentMap> maps = new ArrayDeque<>();
|
||||
|
||||
for (int x = bot1.getX() >> 4; x <= top1.getX() >> 4; x++) {
|
||||
for (int z = bot1.getZ() >> 4; z <= top1.getZ() >> 4; z++) {
|
||||
Chunk chunk1 = world1.getChunkAt(x, z);
|
||||
Chunk chunk2 = world2.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
|
||||
maps.add(swapChunk(world1, world2, chunk1, chunk2, region1, region2));
|
||||
}
|
||||
}
|
||||
GlobalBlockQueue.IMP.addTask(() -> {
|
||||
for (ContentMap map : maps) {
|
||||
map.restoreEntities(world1, 0, 0);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void count(int[] count, Entity entity) {
|
||||
switch (entity.getType()) {
|
||||
case PLAYER:
|
||||
@ -478,7 +465,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
case SNOWBALL:
|
||||
case ENDER_PEARL:
|
||||
case ARROW:
|
||||
case TIPPED_ARROW:
|
||||
case TRIDENT:
|
||||
case SHULKER_BULLET:
|
||||
case SPECTRAL_ARROW:
|
||||
case DRAGON_FIREBALL:
|
||||
@ -488,18 +475,15 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
case FALLING_BLOCK:
|
||||
// Block entities
|
||||
case ENDER_CRYSTAL:
|
||||
case COMPLEX_PART:
|
||||
case FISHING_HOOK:
|
||||
case ENDER_SIGNAL:
|
||||
case EXPERIENCE_ORB:
|
||||
case LEASH_HITCH:
|
||||
case FIREWORK:
|
||||
case WEATHER:
|
||||
case LIGHTNING:
|
||||
case WITHER_SKULL:
|
||||
case UNKNOWN:
|
||||
case AREA_EFFECT_CLOUD:
|
||||
case LINGERING_POTION:
|
||||
case EVOKER_FANGS:
|
||||
// non moving / unremovable
|
||||
break;
|
||||
@ -539,6 +523,16 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
case SKELETON_HORSE:
|
||||
case ZOMBIE_HORSE:
|
||||
case MULE:
|
||||
case DOLPHIN:
|
||||
case TURTLE:
|
||||
case COD:
|
||||
case PARROT:
|
||||
case SALMON:
|
||||
case PUFFERFISH:
|
||||
case TROPICAL_FISH:
|
||||
case CAT:
|
||||
case FOX:
|
||||
case PANDA:
|
||||
// animal
|
||||
count[3]++;
|
||||
count[1]++;
|
||||
@ -589,6 +583,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
count[0]++;
|
||||
}
|
||||
|
||||
|
||||
public static class ContentMap {
|
||||
|
||||
final Set<EntityWrapper> entities;
|
||||
@ -617,14 +612,9 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveEntitiesIn(Chunk chunk, RegionWrapper region) {
|
||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||
}
|
||||
|
||||
public void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
||||
void saveEntitiesOut(Chunk chunk, RegionWrapper region) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||
BukkitUtil.getLocation(entity);
|
||||
Location loc = BukkitUtil.getLocation(entity);
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
if (isIn(region, x, z)) {
|
||||
@ -639,11 +629,14 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ,
|
||||
void saveEntitiesIn(Chunk chunk, RegionWrapper region) {
|
||||
saveEntitiesIn(chunk, region, 0, 0, false);
|
||||
}
|
||||
|
||||
void saveEntitiesIn(Chunk chunk, RegionWrapper region, int offsetX, int offsetZ,
|
||||
boolean delete) {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
com.github.intellectualsites.plotsquared.plot.object.Location loc =
|
||||
BukkitUtil.getLocation(entity);
|
||||
Location loc = BukkitUtil.getLocation(entity);
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
if (!isIn(region, x, z)) {
|
||||
@ -665,7 +658,7 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreEntities(World world, int xOffset, int zOffset) {
|
||||
void restoreEntities(World world, int xOffset, int zOffset) {
|
||||
for (EntityWrapper entity : this.entities) {
|
||||
try {
|
||||
entity.spawn(world, xOffset, zOffset);
|
||||
@ -677,8 +670,8 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
this.entities.clear();
|
||||
}
|
||||
|
||||
public void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX,
|
||||
int offsetZ) {
|
||||
//todo optimize maxY
|
||||
void saveBlocks(BukkitWorld world, int maxY, int x, int z, int offsetX, int offsetZ) {
|
||||
maxY = Math.min(255, maxY);
|
||||
BaseBlock[] ids;
|
||||
ids = new BaseBlock[maxY + 1];
|
||||
|
@ -1,9 +1,30 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.*;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerClaimPlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotDeniedEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotHelperEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerPlotTrustedEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlayerTeleportToPlotEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotAutoMergeEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotChangeOwnerEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotClearEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotComponentSetEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotDeleteEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotFlagAddEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotFlagRemoveEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotMergeEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotRateEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.events.PlotUnlinkEvent;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
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 com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Rating;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,99 +37,95 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utility class for handling Bukkit {@link Event events}
|
||||
* Utility class for handling Bukkit Events.
|
||||
*/
|
||||
public final class BukkitEventUtil extends EventUtil {
|
||||
|
||||
@Nullable public Player getPlayer(final PlotPlayer player) {
|
||||
if (player instanceof BukkitPlayer) {
|
||||
return ((BukkitPlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
@Nullable public Player getPlayer(final PlotPlayer player) {
|
||||
if (player instanceof BukkitPlayer) {
|
||||
return ((BukkitPlayer) player).player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean callEvent(@Nonnull final Event event) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||
}
|
||||
private boolean callEvent(@Nonnull final Event event) {
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
return !(event instanceof Cancellable) || !((Cancellable) event).isCancelled();
|
||||
}
|
||||
|
||||
@Override public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
||||
}
|
||||
@Override public boolean callClaim(PlotPlayer player, Plot plot, boolean auto) {
|
||||
return callEvent(new PlayerClaimPlotEvent(getPlayer(player), plot, auto));
|
||||
}
|
||||
|
||||
@Override public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
||||
}
|
||||
@Override public boolean callTeleport(PlotPlayer player, Location from, Plot plot) {
|
||||
return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot));
|
||||
}
|
||||
|
||||
@Override public boolean callComponentSet(Plot plot, String component) {
|
||||
return callEvent(new PlotComponentSetEvent(plot, component));
|
||||
}
|
||||
@Override public boolean callComponentSet(Plot plot, String component) {
|
||||
return callEvent(new PlotComponentSetEvent(plot, component));
|
||||
}
|
||||
|
||||
@Override public boolean callClear(Plot plot) {
|
||||
return callEvent(new PlotClearEvent(plot));
|
||||
}
|
||||
@Override public boolean callClear(Plot plot) {
|
||||
return callEvent(new PlotClearEvent(plot));
|
||||
}
|
||||
|
||||
@Override public boolean callDelete(Plot plot) {
|
||||
return callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
@Override public boolean callDelete(Plot plot) {
|
||||
return callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||
return callEvent(new PlotFlagAddEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
@Override public boolean callFlagRemove(Flag<?> flag, Plot plot, Object value) {
|
||||
return callEvent(new PlotFlagRemoveEvent(flag, plot));
|
||||
}
|
||||
|
||||
@Override public boolean callMerge(Plot plot, int dir, int max) {
|
||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
|
||||
}
|
||||
@Override public boolean callMerge(Plot plot, int dir, int max) {
|
||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
|
||||
}
|
||||
|
||||
@Override public boolean callAutoMerge(Plot plot, List<PlotId> plots) {
|
||||
return callEvent(new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||
}
|
||||
@Override public boolean callAutoMerge(Plot plot, List<PlotId> plots) {
|
||||
return callEvent(new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||
}
|
||||
|
||||
@Override public boolean callUnlink(PlotArea area, List<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
||||
}
|
||||
@Override public boolean callUnlink(PlotArea area, List<PlotId> plots) {
|
||||
return callEvent(new PlotUnlinkEvent(BukkitUtil.getWorld(area.worldname), area, plots));
|
||||
}
|
||||
|
||||
@Override public void callEntry(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
@Override public void callEntry(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerEnterPlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override public void callLeave(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
@Override public void callLeave(PlotPlayer player, Plot plot) {
|
||||
callEvent(new PlayerLeavePlotEvent(getPlayer(player), plot));
|
||||
}
|
||||
|
||||
@Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
@Override public void callDenied(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotDeniedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
@Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotTrustedEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
@Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {
|
||||
callEvent(new PlayerPlotHelperEvent(getPlayer(initiator), plot, player, added));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID oldOwner, UUID newOwner,
|
||||
boolean hasOldOwner) {
|
||||
return callEvent(
|
||||
new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner));
|
||||
}
|
||||
@Override
|
||||
public boolean callOwnerChange(PlotPlayer initiator, Plot plot, UUID oldOwner, UUID newOwner,
|
||||
boolean hasOldOwner) {
|
||||
return callEvent(
|
||||
new PlotChangeOwnerEvent(getPlayer(initiator), plot, oldOwner, newOwner, hasOldOwner));
|
||||
}
|
||||
|
||||
@Override public boolean callFlagRemove(Flag flag, Object object, PlotCluster cluster) {
|
||||
return callEvent(new ClusterFlagRemoveEvent(flag, cluster));
|
||||
}
|
||||
|
||||
@Override @Nullable public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
return event.getRating();
|
||||
@Override @Nullable public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
return event.getRating();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridPlotWorld;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
@ -65,11 +66,13 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
System.gc();
|
||||
final BlockBucket[][][] oldBlocks = new BlockBucket[256][width][length];
|
||||
final PlotBlock[][][] newBlocks = new PlotBlock[256][width][length];
|
||||
final BlockBucket airBucket = BlockBucket.withSingle(StringPlotBlock.EVERYTHING);
|
||||
|
||||
PlotArea area = PlotSquared.get().getPlotArea(world, null);
|
||||
|
||||
if (!(area instanceof HybridPlotWorld))
|
||||
if (!(area instanceof HybridPlotWorld)) {
|
||||
return;
|
||||
}
|
||||
|
||||
HybridPlotWorld hpw = (HybridPlotWorld) area;
|
||||
final BlockBucket[][] result = hpw.getBlockBucketChunk();
|
||||
@ -107,7 +110,12 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
}
|
||||
rz[i] = v;
|
||||
}
|
||||
int minY = Math.min(hpw.PLOT_HEIGHT, hpw.ROAD_HEIGHT);
|
||||
int minY;
|
||||
if (Settings.Schematics.PASTE_ON_TOP) {
|
||||
minY = hpw.SCHEM_Y;
|
||||
} else {
|
||||
minY = 1;
|
||||
}
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
BaseBlock[] blocks = hpw.G_SCH.get(MathMan.pair(rx[x], rz[z]));
|
||||
@ -140,8 +148,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
continue;
|
||||
}
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
oldBlocks[y][x][z] =
|
||||
BlockBucket.withSingle(StringPlotBlock.EVERYTHING);
|
||||
oldBlocks[y][x][z] = airBucket;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -155,9 +162,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
continue;
|
||||
}
|
||||
int y = MainUtil.y_loc[i][j];
|
||||
oldBlocks[y][x][z] = result[i][j] != null ?
|
||||
result[i][j] :
|
||||
BlockBucket.withSingle(StringPlotBlock.EVERYTHING);
|
||||
oldBlocks[y][x][z] = result[i][j] != null ? result[i][j] : airBucket;
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +182,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
BlockBucket old = oldBlocks[y][x][z];
|
||||
try {
|
||||
if (old == null) {
|
||||
old = BlockBucket.withSingle(StringPlotBlock.EVERYTHING);
|
||||
old = airBucket;
|
||||
}
|
||||
PlotBlock now = newBlocks[y][x][z];
|
||||
if (!old.getBlocks().contains(now)) {
|
||||
@ -222,10 +227,6 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
types.add(now);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
PlotSquared.log(old != null ? old.toString() : "old null");
|
||||
PlotSquared.log(x);
|
||||
PlotSquared.log(y);
|
||||
PlotSquared.log(z);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -303,7 +304,7 @@ public class BukkitHybridUtils extends HybridUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
worldObj.unloadChunkRequest(X, Z, true);
|
||||
worldObj.unloadChunkRequest(X, Z);
|
||||
}
|
||||
}, () -> TaskManager.runTaskAsync(run), 5);
|
||||
});
|
||||
|
@ -17,106 +17,108 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitInventoryUtil extends InventoryUtil {
|
||||
|
||||
public static ItemStack getItem(PlotItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack stack = new ItemStack(BukkitUtil.getMaterial(item.getPlotBlock()), item.amount);
|
||||
ItemMeta meta = null;
|
||||
if (item.name != null) {
|
||||
meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item.name));
|
||||
}
|
||||
if (item.lore != null) {
|
||||
if (meta == null) {
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String entry : item.lore) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
}
|
||||
if (meta != null) {
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
return stack;
|
||||
@Override public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.size * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
}
|
||||
bp.player.openInventory(inventory);
|
||||
}
|
||||
|
||||
@Override public void open(PlotInventory inv) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
Inventory inventory = Bukkit.createInventory(null, inv.size * 9, inv.getTitle());
|
||||
PlotItemStack[] items = inv.getItems();
|
||||
for (int i = 0; i < inv.size * 9; i++) {
|
||||
PlotItemStack item = items[i];
|
||||
if (item != null) {
|
||||
inventory.setItem(i, getItem(item));
|
||||
}
|
||||
}
|
||||
bp.player.openInventory(inventory);
|
||||
@Override public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
bp.player.closeInventory();
|
||||
}
|
||||
|
||||
@Override public void close(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
bp.player.closeInventory();
|
||||
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
opened.setItem(index, getItem(item));
|
||||
bp.player.updateInventory();
|
||||
}
|
||||
|
||||
@Override public void setItem(PlotInventory inv, int index, PlotItemStack item) {
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (!inv.isOpen()) {
|
||||
return;
|
||||
}
|
||||
opened.setItem(index, getItem(item));
|
||||
bp.player.updateInventory();
|
||||
private static ItemStack getItem(PlotItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack stack = new ItemStack(BukkitUtil.getMaterial(item.getPlotBlock()), item.amount);
|
||||
ItemMeta meta = null;
|
||||
if (item.name != null) {
|
||||
meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', item.name));
|
||||
}
|
||||
if (item.lore != null) {
|
||||
if (meta == null) {
|
||||
meta = stack.getItemMeta();
|
||||
}
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String entry : item.lore) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', entry));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
}
|
||||
if (meta != null) {
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public PlotItemStack getItem(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
// int id = item.getTypeId();
|
||||
Material id = item.getType();
|
||||
short data = item.getDurability();
|
||||
int amount = item.getAmount();
|
||||
String name = null;
|
||||
String[] lore = null;
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
List<String> itemLore = meta.getLore();
|
||||
lore = itemLore.toArray(new String[itemLore.size()]);
|
||||
}
|
||||
}
|
||||
return new PlotItemStack(id.name(), amount, name, lore);
|
||||
public PlotItemStack getItem(ItemStack item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
// int id = item.getTypeId();
|
||||
Material id = item.getType();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
int amount = item.getAmount();
|
||||
String name = null;
|
||||
String[] lore = null;
|
||||
if (item.hasItemMeta()) {
|
||||
assert meta != null;
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
List<String> itemLore = meta.getLore();
|
||||
lore = itemLore.toArray(new String[0]);
|
||||
}
|
||||
}
|
||||
return new PlotItemStack(id.name(), amount, name, lore);
|
||||
}
|
||||
|
||||
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
BukkitPlayer bp = (BukkitPlayer) player;
|
||||
PlayerInventory inv = bp.player.getInventory();
|
||||
PlotItemStack[] items = new PlotItemStack[36];
|
||||
for (int i = 0; i < 36; i++) {
|
||||
items[i] = getItem(inv.getItem(i));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
@Override public PlotItemStack[] getItems(PlotPlayer player) {
|
||||
BukkitPlayer bp = (BukkitPlayer) player;
|
||||
PlayerInventory inv = bp.player.getInventory();
|
||||
return IntStream.range(0, 36).mapToObj(i -> getItem(inv.getItem(i)))
|
||||
.toArray(PlotItemStack[]::new);
|
||||
}
|
||||
|
||||
@Override public boolean isOpen(PlotInventory inv) {
|
||||
if (!inv.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
return inv.isOpen() && opened.getType() == InventoryType.CRAFTING
|
||||
&& opened.getTitle() == null;
|
||||
@Override public boolean isOpen(PlotInventory plotInventory) {
|
||||
if (!plotInventory.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
BukkitPlayer bp = (BukkitPlayer) plotInventory.player;
|
||||
InventoryView opened = bp.player.getOpenInventory();
|
||||
if (plotInventory.isOpen()) {
|
||||
if (opened.getType() == InventoryType.CRAFTING) {
|
||||
opened.getTitle();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,47 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
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.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
* 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.
|
||||
* 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.
|
||||
* 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/>.
|
||||
* 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 final class BukkitLegacyMappings extends LegacyMappings {
|
||||
|
||||
@ -75,7 +86,7 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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, 1, "sandstone", "chiseled_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"),
|
||||
@ -118,7 +129,7 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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, "step", "stone_slab", "smooth_stone_slab"),
|
||||
new LegacyBlock(44, 1, "step", "sandstone_slab"),
|
||||
new LegacyBlock(44, 2, "step", "petrified_oak_slab"),
|
||||
new LegacyBlock(44, 3, "step", "cobblestone_slab"),
|
||||
@ -139,10 +150,11 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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(63, "sign_post", "sign", "oak_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(68, "wall_sign", "wall_sign", "oak_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"),
|
||||
@ -182,10 +194,10 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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, 1, "monster_eggs", "infested_cobblestone"),
|
||||
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, 4, "monster_eggs", "infested_cracked_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"),
|
||||
@ -208,7 +220,7 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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(101, "iron_fence", "iron_bars"),
|
||||
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"),
|
||||
@ -541,7 +553,7 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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, 27, "monster_egg", "zombie_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"),
|
||||
@ -664,22 +676,24 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
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() {
|
||||
@SuppressWarnings("deprecation") public BukkitLegacyMappings() {
|
||||
this.addAll(Arrays.asList(BLOCKS));
|
||||
// Make sure to add new blocks as well
|
||||
final List<LegacyBlock> missing = new ArrayList<>();
|
||||
for (final Material material : Material.values()) {
|
||||
final String materialName = material.name().toLowerCase(Locale.ENGLISH);
|
||||
if (OLD_STRING_TO_STRING_PLOT_BLOCK.get(materialName) == null) {
|
||||
final LegacyBlock missingBlock =
|
||||
new LegacyBlock(material.getId(), materialName, materialName);
|
||||
missing.add(missingBlock);
|
||||
if (NEW_STRING_TO_LEGACY_PLOT_BLOCK.get(materialName) == null) {
|
||||
try {
|
||||
final LegacyBlock missingBlock =
|
||||
new LegacyBlock(material.getId(), materialName, materialName);
|
||||
missing.add(missingBlock);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
addAll(missing);
|
||||
@ -687,13 +701,6 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
|
||||
private void addAll(@NonNull final Collection<LegacyBlock> blocks) {
|
||||
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());
|
||||
} */
|
||||
LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK
|
||||
.put(new IdDataPair(legacyBlock.getNumericalId(), legacyBlock.getDataValue()),
|
||||
legacyBlock.toStringPlotBlock());
|
||||
@ -705,7 +712,14 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
try {
|
||||
material = Material.valueOf(legacyBlock.getNewName());
|
||||
} catch (final Exception e) {
|
||||
material = Material.getMaterial(legacyBlock.getLegacyName(), true);
|
||||
try {
|
||||
material = Material.getMaterial(legacyBlock.getLegacyName(), true);
|
||||
} catch (NoSuchMethodError error) {
|
||||
PlotSquared.log("You can't use this version of PlotSquared on a server "
|
||||
+ "less than Minecraft 1.13.2");
|
||||
Bukkit.shutdown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
legacyBlock.material = material;
|
||||
}
|
||||
@ -724,13 +738,10 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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
|
||||
@ -741,19 +752,31 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
}
|
||||
String workingString = string;
|
||||
String[] parts = null;
|
||||
IdDataPair idDataPair = null;
|
||||
if (string.contains(":")) {
|
||||
parts = string.split(":");
|
||||
if (parts.length > 1) {
|
||||
if (parts[0].equalsIgnoreCase("minecraft")) {
|
||||
workingString = parts[1];
|
||||
} else {
|
||||
workingString = parts[0];
|
||||
if (parts[0].matches("^\\d+$")) {
|
||||
idDataPair =
|
||||
new IdDataPair(Integer.parseInt(parts[0]), Integer.parseInt(parts[0]));
|
||||
} else {
|
||||
workingString = parts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (string.matches("^\\d+$")) {
|
||||
idDataPair = new IdDataPair(Integer.parseInt(string), 0);
|
||||
}
|
||||
PlotBlock plotBlock;
|
||||
if (NEW_STRING_TO_LEGACY_PLOT_BLOCK.keySet().contains(workingString.toLowerCase())) {
|
||||
if (Material.matchMaterial(workingString) != null) {
|
||||
return PlotBlock.get(workingString);
|
||||
} else if (NEW_STRING_TO_LEGACY_PLOT_BLOCK.keySet().contains(workingString.toLowerCase())) {
|
||||
return PlotBlock.get(workingString);
|
||||
} else if ((plotBlock = fromLegacyToString(idDataPair)) != null) {
|
||||
return plotBlock;
|
||||
} else if ((plotBlock = fromLegacyToString(workingString)) != null) {
|
||||
return plotBlock;
|
||||
} else {
|
||||
@ -775,6 +798,13 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
return LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK.get(new IdDataPair(id, data));
|
||||
}
|
||||
|
||||
public PlotBlock fromLegacyToString(IdDataPair idDataPair) {
|
||||
if (idDataPair == null) {
|
||||
return null;
|
||||
}
|
||||
return LEGACY_ID_AND_DATA_TO_STRING_PLOT_BLOCK.get(idDataPair);
|
||||
}
|
||||
|
||||
public PlotBlock fromLegacyToString(final String id) {
|
||||
return OLD_STRING_TO_STRING_PLOT_BLOCK.get(id);
|
||||
}
|
||||
@ -804,6 +834,20 @@ public final class BukkitLegacyMappings extends LegacyMappings {
|
||||
this(numericalId, dataValue, legacyName, legacyName);
|
||||
}
|
||||
|
||||
LegacyBlock(final int numericalId, final int dataValue, @NonNull final String legacyName,
|
||||
@NonNull final String newName, @NonNull final String new14Name) {
|
||||
this(numericalId, dataValue, legacyName,
|
||||
PlotSquared.get().IMP.getServerVersion()[1] == 13 ? newName : new14Name);
|
||||
}
|
||||
|
||||
LegacyBlock(final int numericalId, @NonNull final String legacyName,
|
||||
@NonNull final String newName, @NonNull final String new14Name) {
|
||||
this(numericalId, 0, legacyName,
|
||||
Bukkit.getBukkitVersion().split("-")[0].split("\\.")[1].equals("13") ?
|
||||
newName :
|
||||
new14Name);
|
||||
}
|
||||
|
||||
LegacyBlock(final int numericalId, @NonNull final String legacyName,
|
||||
@NonNull final String newName) {
|
||||
this(numericalId, 0, legacyName, newName);
|
||||
|
@ -9,8 +9,12 @@ 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.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;
|
||||
@ -61,11 +65,11 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
}
|
||||
if (save) {
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
chunk.unload(true, false);
|
||||
chunk.unload(true);
|
||||
}
|
||||
} else {
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
chunk.unload(false, false);
|
||||
chunk.unload(false);
|
||||
}
|
||||
}
|
||||
Bukkit.unloadWorld(world, false);
|
||||
@ -123,23 +127,28 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
}
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
PlotSquared.get().worlds.set("worlds." + world + ".generator.type", object.type);
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.terrain", object.terrain);
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.plugin", object.plotManager);
|
||||
if (object.setupGenerator != null && !object.setupGenerator
|
||||
.equals(object.plotManager)) {
|
||||
if (!object.plotManager.endsWith(":single")) {
|
||||
if (!PlotSquared.get().worlds.contains(worldPath)) {
|
||||
PlotSquared.get().worlds.createSection(worldPath);
|
||||
}
|
||||
if (steps.length != 0) {
|
||||
ConfigurationSection worldSection =
|
||||
PlotSquared.get().worlds.getConfigurationSection(worldPath);
|
||||
for (ConfigurationNode step : steps) {
|
||||
worldSection.set(step.getConstant(), step.getValue());
|
||||
}
|
||||
}
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.init", object.setupGenerator);
|
||||
.set("worlds." + world + ".generator.type", object.type);
|
||||
PlotSquared.get().worlds
|
||||
.set("worlds." + world + ".generator.terrain", object.terrain);
|
||||
PlotSquared.get().worlds
|
||||
.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);
|
||||
if (gen != null && gen.isFull()) {
|
||||
@ -166,9 +175,9 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("Multiverse-Core");
|
||||
if (object.setupGenerator != null) {
|
||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
if (plugin != null && plugin.isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
"mv create " + world + " normal -g " + object.setupGenerator);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
@ -176,15 +185,6 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
"mw create " + world + " plugin:" + object.setupGenerator);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
WorldCreator wc = new WorldCreator(object.world);
|
||||
wc.generator(object.setupGenerator);
|
||||
wc.environment(Environment.NORMAL);
|
||||
@ -192,22 +192,13 @@ public class BukkitSetupUtils extends SetupUtils {
|
||||
Bukkit.createWorld(wc);
|
||||
setGenerator(world, object.setupGenerator);
|
||||
} else {
|
||||
if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null && Bukkit
|
||||
.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||
if (plugin != null && plugin.isEnabled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
"mv create " + world + " normal");
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
if (Bukkit.getPluginManager().getPlugin("MultiWorld") != null && Bukkit
|
||||
.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||
Bukkit.getServer()
|
||||
.dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + world);
|
||||
if (Bukkit.getWorld(world) != null) {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
World bw =
|
||||
Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL));
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ 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.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
@ -13,7 +13,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@ -174,9 +174,9 @@ import java.util.*;
|
||||
*
|
||||
* @param player the recipient of the message
|
||||
* @param caption the message
|
||||
* @see MainUtil#sendMessage(PlotPlayer, C, String...)
|
||||
* @see MainUtil#sendMessage(com.github.intellectualsites.plotsquared.commands.CommandCaller, Captions, String...)
|
||||
*/
|
||||
public static void sendMessage(Player player, C caption) {
|
||||
public static void sendMessage(Player player, Captions caption) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
|
||||
}
|
||||
|
||||
@ -264,34 +264,28 @@ import java.util.*;
|
||||
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) {
|
||||
BlockFace facing = BlockFace.EAST;
|
||||
if (world.getBlockAt(x, y, z + 1).getType().isSolid())
|
||||
facing = BlockFace.NORTH;
|
||||
else if (world.getBlockAt(x + 1, y, z).getType().isSolid())
|
||||
facing = BlockFace.WEST;
|
||||
else if (world.getBlockAt(x, y, z - 1).getType().isSolid())
|
||||
facing = BlockFace.SOUTH;
|
||||
block.setType(Material.WALL_SIGN, false);
|
||||
final WallSign sign = (WallSign) block.getBlockData();
|
||||
sign.setFacing(facing);
|
||||
block.setBlockData(sign, false);
|
||||
}
|
||||
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]);
|
||||
@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 {
|
||||
if (block.isLiquid()) {
|
||||
return y;
|
||||
}
|
||||
air++;
|
||||
}
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override @Nullable public String[] getSign(@NonNull final Location location) {
|
||||
@ -330,29 +324,39 @@ import java.util.*;
|
||||
}
|
||||
}
|
||||
|
||||
@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++;
|
||||
}
|
||||
@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.LEGACY_SIGN && type != Material.LEGACY_WALL_SIGN) {
|
||||
BlockFace facing = BlockFace.EAST;
|
||||
if (world.getBlockAt(x, y, z + 1).getType().isSolid()) {
|
||||
facing = BlockFace.NORTH;
|
||||
} else if (world.getBlockAt(x + 1, y, z).getType().isSolid()) {
|
||||
facing = BlockFace.WEST;
|
||||
} else if (world.getBlockAt(x, y, z - 1).getType().isSolid()) {
|
||||
facing = BlockFace.SOUTH;
|
||||
}
|
||||
if (PlotSquared.get().IMP.getServerVersion()[1] == 13) {
|
||||
block.setType(Material.valueOf("WALL_SIGN"), false);
|
||||
} else {
|
||||
block.setType(Material.valueOf("OAK_WALL_SIGN"), false);
|
||||
}
|
||||
final Directional sign = (Directional) block.getBlockData();
|
||||
sign.setFacing(facing);
|
||||
block.setBlockData(sign, false);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return bukkitWorld.getMaxHeight() - 1;
|
||||
}
|
||||
|
||||
@Override public int getBiomeFromString(@NonNull final String biomeString) {
|
||||
@ -366,11 +370,7 @@ import java.util.*;
|
||||
|
||||
@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;
|
||||
return Arrays.stream(biomes).map(Enum::name).toArray(String[]::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,695 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* bStats collects some data for plugin authors.
|
||||
* <p>
|
||||
* Check out https://bStats.org/ to learn more about bStats!
|
||||
*/
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
// Maven's Relocate is clever and changes strings, too. So we have to use this little "trick" ... :D
|
||||
final String defaultPackage = new String(
|
||||
new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't'});
|
||||
final String examplePackage = new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||
// We want to make sure nobody just copy & pastes the example and use the wrong package names
|
||||
if (Metrics.class.getPackage().getName().equals(defaultPackage) || Metrics.class.getPackage().getName().equals(examplePackage)) {
|
||||
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
// A list with all custom charts
|
||||
private final List<CustomChart> charts = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param plugin The plugin which stats should be submitted.
|
||||
*/
|
||||
public Metrics(Plugin plugin) {
|
||||
if (plugin == null) {
|
||||
throw new IllegalArgumentException("Plugin cannot be null!");
|
||||
}
|
||||
this.plugin = plugin;
|
||||
|
||||
// Get the config file
|
||||
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||
File configFile = new File(bStatsFolder, "config.yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
// Check if the config file exists
|
||||
if (!config.isSet("serverUuid")) {
|
||||
|
||||
// Add default values
|
||||
config.addDefault("enabled", true);
|
||||
// Every server gets it's unique random id.
|
||||
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||
// Should failed request be logged?
|
||||
config.addDefault("logFailedRequests", false);
|
||||
// Should the sent data be logged?
|
||||
config.addDefault("logSentData", false);
|
||||
// Should the response text be logged?
|
||||
config.addDefault("logResponseStatusText", false);
|
||||
|
||||
// Inform the server owners about bStats
|
||||
config.options().header(
|
||||
"bStats collects some data for plugin authors like how many servers are using their plugins.\n" +
|
||||
"To honor their work, you should not disable it.\n" +
|
||||
"This has nearly no effect on the server performance!\n" +
|
||||
"Check out https://bStats.org/ to learn more :)"
|
||||
).copyDefaults(true);
|
||||
try {
|
||||
config.save(configFile);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
// Load the data
|
||||
enabled = config.getBoolean("enabled", true);
|
||||
serverUUID = config.getString("serverUuid");
|
||||
logFailedRequests = config.getBoolean("logFailedRequests", false);
|
||||
logSentData = config.getBoolean("logSentData", false);
|
||||
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||
|
||||
if (enabled) {
|
||||
boolean found = false;
|
||||
// Search for all other bStats Metrics classes to see if we are the first one
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
found = true; // We aren't the first
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
// Register our service
|
||||
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
|
||||
if (!found) {
|
||||
// We are the first!
|
||||
startSubmitting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
* @return Whether bStats is enabled or not.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom chart.
|
||||
*
|
||||
* @param chart The chart to add.
|
||||
*/
|
||||
public void addCustomChart(CustomChart chart) {
|
||||
if (chart == null) {
|
||||
throw new IllegalArgumentException("Chart cannot be null!");
|
||||
}
|
||||
charts.add(chart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Scheduler which submits our data every 30 minutes.
|
||||
*/
|
||||
private void startSubmitting() {
|
||||
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!plugin.isEnabled()) { // Plugin was disabled
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
|
||||
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> submitData());
|
||||
}
|
||||
}, 1000 * 60 * 5, 1000 * 60 * 30);
|
||||
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
|
||||
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
|
||||
// WARNING: Just don't do it!
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin specific data.
|
||||
* This method is called using Reflection.
|
||||
*
|
||||
* @return The plugin specific data.
|
||||
*/
|
||||
public JSONObject getPluginData() {
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
String pluginName = plugin.getDescription().getName();
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
|
||||
data.put("pluginName", pluginName); // Append the name of the plugin
|
||||
data.put("pluginVersion", pluginVersion); // Append the version of the plugin
|
||||
JSONArray customCharts = new JSONArray();
|
||||
for (CustomChart customChart : charts) {
|
||||
// Add the data of the custom charts
|
||||
JSONObject chart = customChart.getRequestJsonObject();
|
||||
if (chart == null) { // If the chart is null, we skip it
|
||||
continue;
|
||||
}
|
||||
customCharts.add(chart);
|
||||
}
|
||||
data.put("customCharts", customCharts);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server specific data.
|
||||
*
|
||||
* @return The server specific data.
|
||||
*/
|
||||
private JSONObject getServerData() {
|
||||
// Minecraft specific data
|
||||
int playerAmount;
|
||||
try {
|
||||
// Around MC 1.8 the return type was changed to a collection from an array,
|
||||
// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||
} catch (Exception e) {
|
||||
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
|
||||
}
|
||||
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
|
||||
String bukkitVersion = Bukkit.getVersion();
|
||||
|
||||
// OS/Java specific data
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
String osName = System.getProperty("os.name");
|
||||
String osArch = System.getProperty("os.arch");
|
||||
String osVersion = System.getProperty("os.version");
|
||||
int coreCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
data.put("serverUUID", serverUUID);
|
||||
|
||||
data.put("playerAmount", playerAmount);
|
||||
data.put("onlineMode", onlineMode);
|
||||
data.put("bukkitVersion", bukkitVersion);
|
||||
|
||||
data.put("javaVersion", javaVersion);
|
||||
data.put("osName", osName);
|
||||
data.put("osArch", osArch);
|
||||
data.put("osVersion", osVersion);
|
||||
data.put("coreCount", coreCount);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects the data and sends it afterwards.
|
||||
*/
|
||||
private void submitData() {
|
||||
final JSONObject data = getServerData();
|
||||
|
||||
JSONArray pluginData = new JSONArray();
|
||||
// Search for all other bStats Metrics classes to get their plugin data
|
||||
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
|
||||
try {
|
||||
service.getField("B_STATS_VERSION"); // Our identifier :)
|
||||
|
||||
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
|
||||
try {
|
||||
pluginData.add(provider.getService().getMethod("getPluginData").invoke(provider.getProvider()));
|
||||
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { }
|
||||
}
|
||||
} catch (NoSuchFieldException ignored) { }
|
||||
}
|
||||
|
||||
data.put("plugins", pluginData);
|
||||
|
||||
// Create a new thread for the connection to the bStats server
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Send the data
|
||||
sendData(plugin, data);
|
||||
} catch (Exception e) {
|
||||
// Something went wrong! :(
|
||||
if (logFailedRequests) {
|
||||
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JSONObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data.toString());
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
|
||||
outputStream.write(compressedData);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
gzip.close();
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
public static abstract class CustomChart {
|
||||
|
||||
// The id of the chart
|
||||
final String chartId;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
*/
|
||||
CustomChart(String chartId) {
|
||||
if (chartId == null || chartId.isEmpty()) {
|
||||
throw new IllegalArgumentException("ChartId cannot be null or empty!");
|
||||
}
|
||||
this.chartId = chartId;
|
||||
}
|
||||
|
||||
private JSONObject getRequestJsonObject() {
|
||||
JSONObject chart = new JSONObject();
|
||||
chart.put("chartId", chartId);
|
||||
try {
|
||||
JSONObject data = getChartData();
|
||||
if (data == null) {
|
||||
// If the data is null we don't send the chart.
|
||||
return null;
|
||||
}
|
||||
chart.put("data", data);
|
||||
} catch (Throwable t) {
|
||||
if (logFailedRequests) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
|
||||
protected abstract JSONObject getChartData() throws Exception;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple pie.
|
||||
*/
|
||||
public static class SimplePie extends CustomChart {
|
||||
|
||||
private final Callable<String> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimplePie(String chartId, Callable<String> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
String value = callable.call();
|
||||
if (value == null || value.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced pie.
|
||||
*/
|
||||
public static class AdvancedPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom drilldown pie.
|
||||
*/
|
||||
public static class DrilldownPie extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Map<String, Integer>> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean reallyAllSkipped = true;
|
||||
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||
JSONObject value = new JSONObject();
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||
value.put(valueEntry.getKey(), valueEntry.getValue());
|
||||
allSkipped = false;
|
||||
}
|
||||
if (!allSkipped) {
|
||||
reallyAllSkipped = false;
|
||||
values.put(entryValues.getKey(), value);
|
||||
}
|
||||
}
|
||||
if (reallyAllSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom single line chart.
|
||||
*/
|
||||
public static class SingleLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Integer> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
int value = callable.call();
|
||||
if (value == 0) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("value", value);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom multi line chart.
|
||||
*/
|
||||
public static class MultiLineChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
if (entry.getValue() == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
values.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom simple bar chart.
|
||||
*/
|
||||
public static class SimpleBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, Integer>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, Integer> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
categoryValues.add(entry.getValue());
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom advanced bar chart.
|
||||
*/
|
||||
public static class AdvancedBarChart extends CustomChart {
|
||||
|
||||
private final Callable<Map<String, int[]>> callable;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param chartId The id of the chart.
|
||||
* @param callable The callable which is used to request the chart data.
|
||||
*/
|
||||
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||
super(chartId);
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject getChartData() throws Exception {
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject values = new JSONObject();
|
||||
Map<String, int[]> map = callable.call();
|
||||
if (map == null || map.isEmpty()) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
boolean allSkipped = true;
|
||||
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||
if (entry.getValue().length == 0) {
|
||||
continue; // Skip this invalid
|
||||
}
|
||||
allSkipped = false;
|
||||
JSONArray categoryValues = new JSONArray();
|
||||
for (int categoryValue : entry.getValue()) {
|
||||
categoryValues.add(categoryValue);
|
||||
}
|
||||
values.put(entry.getKey(), categoryValues);
|
||||
}
|
||||
if (allSkipped) {
|
||||
// Null = skip the chart
|
||||
return null;
|
||||
}
|
||||
data.put("values", values);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -154,6 +154,7 @@ public class NbtFactory {
|
||||
* @return The decoded NBT compound.
|
||||
* @throws IOException If anything went wrong.
|
||||
*/
|
||||
@SuppressWarnings({"IOResourceOpenedButNotSafelyClosed", "resource"})
|
||||
public static NbtCompound fromStream(InputStream input, StreamOptions option)
|
||||
throws IOException {
|
||||
DataInputStream data = null;
|
||||
@ -189,24 +190,11 @@ public class NbtFactory {
|
||||
*/
|
||||
public static void saveStream(NbtCompound source, ByteSink stream, StreamOptions option)
|
||||
throws IOException {
|
||||
OutputStream output = null;
|
||||
DataOutputStream data = null;
|
||||
boolean suppress = true;
|
||||
|
||||
try {
|
||||
output = stream.openStream();
|
||||
data = new DataOutputStream(
|
||||
option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output);
|
||||
|
||||
try (OutputStream output = stream.openStream();
|
||||
DataOutputStream data = new DataOutputStream(
|
||||
option == StreamOptions.GZIP_COMPRESSION ? new GZIPOutputStream(output) : output)) {
|
||||
invokeMethod(get().SAVE_COMPOUND, null, source.getHandle(), data);
|
||||
suppress = false;
|
||||
|
||||
} finally {
|
||||
if (data != null) {
|
||||
Closeables.close(data, suppress);
|
||||
} else if (output != null) {
|
||||
Closeables.close(output, suppress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,14 +13,6 @@ import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils
|
||||
|
||||
public class OfflinePlayerUtil {
|
||||
|
||||
public static Player loadPlayer(String name) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(name));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(UUID id) {
|
||||
return loadPlayer(Bukkit.getOfflinePlayer(id));
|
||||
}
|
||||
|
||||
public static Player loadPlayer(OfflinePlayer player) {
|
||||
if (player == null) {
|
||||
return null;
|
||||
|
@ -65,11 +65,7 @@ public class SendChunk {
|
||||
int view = Bukkit.getServer().getViewDistance();
|
||||
for (Chunk chunk : chunks) {
|
||||
String world = chunk.getWorld().getName();
|
||||
ArrayList<Chunk> list = map.get(world);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
map.put(world, list);
|
||||
}
|
||||
ArrayList<Chunk> list = map.computeIfAbsent(world, k -> new ArrayList<>());
|
||||
list.add(chunk);
|
||||
Object c = this.methodGetHandleChunk.of(chunk).call();
|
||||
this.methodInitLighting.of(c).call();
|
||||
@ -92,14 +88,14 @@ public class SendChunk {
|
||||
if (location == null) {
|
||||
location = pp.getLocation();
|
||||
}
|
||||
int cx = location.getX() >> 4;
|
||||
int cz = location.getZ() >> 4;
|
||||
int chunkX = location.getX() >> 4;
|
||||
int chunkZ = location.getZ() >> 4;
|
||||
Player player = ((BukkitPlayer) pp).player;
|
||||
Object entity = this.methodGetHandlePlayer.of(player).call();
|
||||
|
||||
for (Chunk chunk : list) {
|
||||
int dx = Math.abs(cx - chunk.getX());
|
||||
int dz = Math.abs(cz - chunk.getZ());
|
||||
int dx = Math.abs(chunkX - chunk.getX());
|
||||
int dz = Math.abs(chunkZ - chunk.getZ());
|
||||
if ((dx > view) || (dz > view)) {
|
||||
continue;
|
||||
}
|
||||
@ -118,20 +114,17 @@ public class SendChunk {
|
||||
}
|
||||
}
|
||||
for (final Chunk chunk : chunks) {
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
chunk.unload(true, false);
|
||||
} catch (Throwable ignored) {
|
||||
String worldName = chunk.getWorld().getName();
|
||||
PlotSquared.debug(
|
||||
"$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";"
|
||||
+ 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)");
|
||||
}
|
||||
TaskManager.runTask(() -> {
|
||||
try {
|
||||
chunk.unload(true);
|
||||
} catch (Throwable ignored) {
|
||||
String worldName = chunk.getWorld().getName();
|
||||
PlotSquared.debug(
|
||||
"$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + 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)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -5,12 +5,10 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SetGenCB {
|
||||
|
||||
@ -45,12 +43,8 @@ public class SetGenCB {
|
||||
}
|
||||
}
|
||||
if (!set) {
|
||||
Iterator<BlockPopulator> iterator = world.getPopulators().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (iterator.next() instanceof BukkitAugmentedGenerator) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
world.getPopulators()
|
||||
.removeIf(blockPopulator -> blockPopulator instanceof BukkitAugmentedGenerator);
|
||||
}
|
||||
PlotSquared.get()
|
||||
.loadWorld(world.getName(), PlotSquared.get().IMP.getGenerator(world.getName(), null));
|
||||
|
@ -6,7 +6,6 @@ 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.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQueue;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
@ -20,21 +19,16 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
|
||||
private Field fieldNeighbors;
|
||||
private Method chunkGetHandle;
|
||||
public class BukkitLocalQueue extends BasicLocalBlockQueue {
|
||||
|
||||
public BukkitLocalQueue(String world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override public LocalChunk<T> getLocalChunk(int x, int z) {
|
||||
return (LocalChunk<T>) new BasicLocalChunk(this, x, z) {
|
||||
@Override public LocalChunk getLocalChunk(int x, int z) {
|
||||
return new BasicLocalChunk(this, x, z) {
|
||||
// Custom stuff?
|
||||
};
|
||||
}
|
||||
@ -45,21 +39,21 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
|
||||
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
if (block == null) {
|
||||
if (worldObj != null) {
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
return PlotBlock.get(block.getType().toString());
|
||||
} else {
|
||||
return PlotBlock.get(0, 0);
|
||||
}
|
||||
// int id = block.getTypeId();
|
||||
// if (id == 0) {
|
||||
// return PlotBlock.get(0, 0);
|
||||
// }
|
||||
// return PlotBlock.get(id, block.getData());
|
||||
return PlotBlock.get(block.getType().toString());
|
||||
}
|
||||
|
||||
@Override public void refreshChunk(int x, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
worldObj.refreshChunk(x, z);
|
||||
if (worldObj != null) {
|
||||
worldObj.refreshChunk(x, z);
|
||||
} else {
|
||||
PlotSquared.debug("Error Refreshing Chunk");
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void fixChunkLighting(int x, int z) {
|
||||
@ -68,15 +62,15 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
|
||||
@Override public final void regenChunk(int x, int z) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
worldObj.regenerateChunk(x, z);
|
||||
if (worldObj != null) {
|
||||
worldObj.regenerateChunk(x, z);
|
||||
} else {
|
||||
PlotSquared.debug("Error Regenerating Chunk");
|
||||
}
|
||||
}
|
||||
|
||||
@Override public final void setComponents(LocalChunk<T> lc) {
|
||||
if (isBaseBlocks()) {
|
||||
setBaseBlocks(lc);
|
||||
} else {
|
||||
setBlocks(lc);
|
||||
}
|
||||
@Override public final void setComponents(LocalChunk lc) {
|
||||
setBaseBlocks(lc);
|
||||
}
|
||||
|
||||
public World getBukkitWorld() {
|
||||
@ -87,31 +81,7 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
return getBukkitWorld().getChunkAt(x, z);
|
||||
}
|
||||
|
||||
public void setBlocks(LocalChunk<T> lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
|
||||
chunk.load(true);
|
||||
for (int layer = 0; layer < lc.blocks.length; layer++) {
|
||||
PlotBlock[] blocksLayer = (PlotBlock[]) lc.blocks[layer];
|
||||
if (blocksLayer != null) {
|
||||
for (int j = 0; j < blocksLayer.length; j++) {
|
||||
if (blocksLayer[j] != null) {
|
||||
PlotBlock block = blocksLayer[j];
|
||||
int x = MainUtil.x_loc[layer][j];
|
||||
int y = MainUtil.y_loc[layer][j];
|
||||
int z = MainUtil.z_loc[layer][j];
|
||||
Block existing = chunk.getBlock(x, y, z);
|
||||
if (equals(block, existing)) {
|
||||
continue;
|
||||
}
|
||||
setMaterial(block, existing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBaseBlocks(LocalChunk<T> lc) {
|
||||
public void setBaseBlocks(LocalChunk lc) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
|
||||
chunk.load(true);
|
||||
@ -182,22 +152,17 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
legacyPlotBlock.id == 0 || legacyPlotBlock.data == block.getData());
|
||||
}
|
||||
|
||||
public void setBiomes(LocalChunk<T> lc) {
|
||||
public void setBiomes(LocalChunk lc) {
|
||||
if (lc.biomes != null) {
|
||||
World worldObj = Bukkit.getWorld(getWorld());
|
||||
int bx = lc.getX() << 4;
|
||||
int bz = lc.getX() << 4;
|
||||
String last = null;
|
||||
Biome biome = null;
|
||||
for (int x = 0; x < lc.biomes.length; x++) {
|
||||
String[] biomes2 = lc.biomes[x];
|
||||
if (biomes2 != null) {
|
||||
for (int y = 0; y < biomes2.length; y++) {
|
||||
String biomeStr = biomes2[y];
|
||||
for (String biomeStr : biomes2) {
|
||||
if (biomeStr != null) {
|
||||
if (last == null || !StringMan.isEqual(last, biomeStr)) {
|
||||
biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
}
|
||||
Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
worldObj.setBiome(bx, bz, biome);
|
||||
}
|
||||
}
|
||||
@ -206,59 +171,4 @@ public class BukkitLocalQueue<T> extends BasicLocalBlockQueue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exploiting a bug in the vanilla lighting algorithm for faster block placement
|
||||
* - Could have been achieved without reflection by force unloading specific chunks
|
||||
* - Much faster just setting the variable manually though
|
||||
*
|
||||
* @param chunk
|
||||
* @return
|
||||
*/
|
||||
protected Object[] disableLighting(Chunk chunk) {
|
||||
try {
|
||||
if (chunkGetHandle == null) {
|
||||
chunkGetHandle = chunk.getClass().getDeclaredMethod("getHandle");
|
||||
chunkGetHandle.setAccessible(true);
|
||||
}
|
||||
Object nmsChunk = chunkGetHandle.invoke(chunk);
|
||||
if (fieldNeighbors == null) {
|
||||
fieldNeighbors = nmsChunk.getClass().getDeclaredField("neighbors");
|
||||
fieldNeighbors.setAccessible(true);
|
||||
}
|
||||
Object value = fieldNeighbors.get(nmsChunk);
|
||||
fieldNeighbors.set(nmsChunk, 0);
|
||||
return new Object[] {nmsChunk, value};
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void disableLighting(Object[] disableResult) {
|
||||
if (disableResult != null) {
|
||||
try {
|
||||
fieldNeighbors.set(disableResult[0], 0);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetLighting(Object[] disableResult) {
|
||||
if (disableResult != null) {
|
||||
try {
|
||||
fieldNeighbors.set(disableResult[0], disableResult[1]);
|
||||
} catch (Throwable ignore) {
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void enableLighting(Object[] disableResult) {
|
||||
if (disableResult != null) {
|
||||
try {
|
||||
fieldNeighbors.set(disableResult[0], 0x739C0);
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,47 +23,47 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
|
||||
public final Biome[] biomes;
|
||||
public PlotBlock[][] result;
|
||||
public BiomeGrid grid;
|
||||
public BiomeGrid biomeGrid;
|
||||
public Chunk chunk;
|
||||
public String world;
|
||||
public int cx;
|
||||
public int cz;
|
||||
@Getter @Setter private ChunkData cd = null;
|
||||
public int chunkX;
|
||||
public int chunkZ;
|
||||
@Getter @Setter private ChunkData chunkData = null;
|
||||
|
||||
public GenChunk(Chunk chunk, ChunkWrapper wrap) {
|
||||
public GenChunk() {
|
||||
super(null, new Location(null, 0, 0, 0), new Location(null, 15, 255, 15));
|
||||
this.biomes = Biome.values();
|
||||
}
|
||||
|
||||
public void setChunk(Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public Chunk getChunk() {
|
||||
if (chunk == null) {
|
||||
World worldObj = BukkitUtil.getWorld(world);
|
||||
if (worldObj != null) {
|
||||
this.chunk = worldObj.getChunkAt(cx, cz);
|
||||
this.chunk = worldObj.getChunkAt(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public void setChunk(Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
public void setChunk(ChunkWrapper wrap) {
|
||||
chunk = null;
|
||||
world = wrap.world;
|
||||
cx = wrap.x;
|
||||
cz = wrap.z;
|
||||
chunkX = wrap.x;
|
||||
chunkZ = wrap.z;
|
||||
}
|
||||
|
||||
@Override public void fillBiome(String biomeName) {
|
||||
if (grid == null) {
|
||||
if (biomeGrid == null) {
|
||||
return;
|
||||
}
|
||||
Biome biome = Biome.valueOf(biomeName.toUpperCase());
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
this.grid.setBiome(x, z, biome);
|
||||
this.biomeGrid.setBiome(x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,13 +82,14 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
Arrays.fill(data, start, end, block);
|
||||
}
|
||||
}
|
||||
int minx = Math.min(pos1.getX(), pos2.getX());
|
||||
int miny = Math.min(pos1.getY(), pos2.getY());
|
||||
int minz = Math.min(pos1.getZ(), pos2.getZ());
|
||||
int maxx = Math.max(pos1.getX(), pos2.getX());
|
||||
int maxy = Math.max(pos1.getY(), pos2.getY());
|
||||
int maxz = Math.max(pos1.getZ(), pos2.getZ());
|
||||
cd.setRegion(minx, miny, minz, maxx, maxy, maxz, block.to(Material.class));
|
||||
int minX = Math.min(pos1.getX(), pos2.getX());
|
||||
int minY = Math.min(pos1.getY(), pos2.getY());
|
||||
int minZ = Math.min(pos1.getZ(), pos2.getZ());
|
||||
int maxX = Math.max(pos1.getX(), pos2.getX());
|
||||
int maxY = Math.max(pos1.getY(), pos2.getY());
|
||||
int maxZ = Math.max(pos1.getZ(), pos2.getZ());
|
||||
chunkData
|
||||
.setRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1, block.to(Material.class));
|
||||
}
|
||||
|
||||
@Override public boolean setBiome(int x, int z, String biome) {
|
||||
@ -96,8 +97,8 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
}
|
||||
|
||||
public boolean setBiome(int x, int z, Biome biome) {
|
||||
if (this.grid != null) {
|
||||
this.grid.setBiome(x, z, biome);
|
||||
if (this.biomeGrid != null) {
|
||||
this.biomeGrid.setBiome(x, z, biome);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -105,10 +106,10 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, PlotBlock id) {
|
||||
if (this.result == null) {
|
||||
this.cd.setBlock(x, y, z, id.to(Material.class));
|
||||
this.chunkData.setBlock(x, y, z, id.to(Material.class));
|
||||
return true;
|
||||
}
|
||||
this.cd.setBlock(x, y, z, id.to(Material.class));
|
||||
this.chunkData.setBlock(x, y, z, id.to(Material.class));
|
||||
this.storeCache(x, y, z, id);
|
||||
return true;
|
||||
}
|
||||
@ -125,10 +126,10 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BaseBlock id) {
|
||||
if (this.result == null) {
|
||||
this.cd.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
return true;
|
||||
}
|
||||
this.cd.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
this.chunkData.setBlock(x, y, z, BukkitAdapter.adapt(id));
|
||||
this.storeCache(x, y, z, PlotBlock.get(id.getBlockType().getId()));
|
||||
return true;
|
||||
}
|
||||
@ -136,7 +137,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
@Override public PlotBlock getBlock(int x, int y, int z) {
|
||||
int i = MainUtil.CACHE_I[y][x][z];
|
||||
if (result == null) {
|
||||
return PlotBlock.get(cd.getType(x, y, z));
|
||||
return PlotBlock.get(chunkData.getType(x, y, z));
|
||||
}
|
||||
PlotBlock[] array = result[i];
|
||||
if (array == null) {
|
||||
@ -147,11 +148,11 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return chunk == null ? cx : chunk.getX();
|
||||
return chunk == null ? chunkX : chunk.getX();
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return chunk == null ? cz : chunk.getZ();
|
||||
return chunk == null ? chunkZ : chunk.getZ();
|
||||
}
|
||||
|
||||
@Override public String getWorld() {
|
||||
@ -167,8 +168,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
}
|
||||
|
||||
public GenChunk clone() {
|
||||
GenChunk toReturn =
|
||||
new GenChunk(chunk, new ChunkWrapper(getWorld(), chunk.getX(), chunk.getZ()));
|
||||
GenChunk toReturn = new GenChunk();
|
||||
if (this.result != null) {
|
||||
for (int i = 0; i < this.result.length; i++) {
|
||||
PlotBlock[] matrix = this.result[i];
|
||||
@ -178,7 +178,7 @@ public class GenChunk extends ScopedLocalBlockQueue {
|
||||
}
|
||||
}
|
||||
}
|
||||
toReturn.cd = this.cd;
|
||||
toReturn.chunkData = this.chunkData;
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,14 @@ 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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@Override public UUID getUUID(PlotPlayer player) {
|
||||
@NotNull @Override public UUID getUUID(PlotPlayer player) {
|
||||
return ((BukkitPlayer) player).player.getUniqueId();
|
||||
}
|
||||
|
||||
@ -30,11 +32,7 @@ public class DefaultUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@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;
|
||||
return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
|
@ -2,7 +2,7 @@ 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.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
@ -47,204 +47,197 @@ public class FileUUIDHandler extends UUIDHandlerImplementation {
|
||||
} else {
|
||||
world = worlds.get(0).getName();
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
PlotSquared.debug(C.PREFIX + "&6Starting player data caching for: " + world);
|
||||
File uuidFile = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (uuidFile.exists()) {
|
||||
try {
|
||||
List<String> lines =
|
||||
Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || (name.length() > 16) || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), uuid);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
PlotSquared.debug(Captions.PREFIX + "&6Starting player data caching for: " + world);
|
||||
File uuidFile = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
|
||||
if (uuidFile.exists()) {
|
||||
try {
|
||||
List<String> lines =
|
||||
Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
try {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
|
||||
String[] split = line.split("\\|");
|
||||
String name = split[0];
|
||||
if (name.isEmpty() || (name.length() > 16) || !StringMan
|
||||
.isAlphanumericUnd(name)) {
|
||||
continue;
|
||||
}
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
if (uuid == null) {
|
||||
continue;
|
||||
}
|
||||
UUIDHandler.add(new StringWrapper(name), uuid);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HashBiMap<StringWrapper, UUID> toAdd =
|
||||
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
||||
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||
PlotSquared.debug("&aFast mode UUID caching enabled!");
|
||||
File playerDataFolder =
|
||||
new File(container, world + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
boolean check = all.isEmpty();
|
||||
if (dat != null) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if (check || all.remove(uuid)) {
|
||||
File file = new File(playerDataFolder, current);
|
||||
NbtFactory.NbtCompound compound = NbtFactory
|
||||
.fromStream(new FileInputStream(file),
|
||||
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
NbtFactory.NbtCompound bukkit =
|
||||
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||
String name = (String) bukkit.get("lastKnownName");
|
||||
long last = (long) bukkit.get("lastPlayed");
|
||||
long first = (long) bukkit.get("firstPlayed");
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
toAdd.put(new StringWrapper(name), uuid);
|
||||
}
|
||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<>());
|
||||
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
|
||||
HashSet<UUID> all = UUIDHandler.getAllUUIDS();
|
||||
PlotSquared.debug("&aFast mode UUID caching enabled!");
|
||||
File playerDataFolder = new File(container, world + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
boolean check = all.isEmpty();
|
||||
if (dat != null) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
if (check || all.remove(uuid)) {
|
||||
File file = new File(playerDataFolder, current);
|
||||
NbtFactory.NbtCompound compound = NbtFactory
|
||||
.fromStream(new FileInputStream(file),
|
||||
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
NbtFactory.NbtCompound bukkit =
|
||||
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||
String name = (String) bukkit.get("lastKnownName");
|
||||
long last = (long) bukkit.get("lastPlayed");
|
||||
long first = (long) bukkit.get("firstPlayed");
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug(C.PREFIX + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
if (all.isEmpty()) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
PlotSquared.debug("Failed to cache: " + all.size()
|
||||
+ " uuids - slowly processing all files");
|
||||
}
|
||||
}
|
||||
HashSet<String> worlds = Sets.newHashSet(world, "world");
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
File playerDataFolder = null;
|
||||
for (String worldName : worlds) {
|
||||
// Getting UUIDs
|
||||
playerDataFolder =
|
||||
new File(container, worldName + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared.debug(C.PREFIX + "Invalid PlayerData: " + current);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Getting names
|
||||
File playersFolder = new File(worldName + File.separator + "players");
|
||||
dat = playersFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
File file =
|
||||
new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
NbtFactory.NbtCompound compound = NbtFactory
|
||||
.fromStream(new FileInputStream(file),
|
||||
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
NbtFactory.NbtCompound bukkit =
|
||||
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||
String name = (String) bukkit.get("lastKnownName");
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
long last = (long) bukkit.get("lastPlayed");
|
||||
long first = (long) bukkit.get("firstPlayed");
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
|
||||
.equals(name)) {
|
||||
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
} else {
|
||||
long most = (long) compound.get("UUIDMost");
|
||||
long least = (long) compound.get("UUIDLeast");
|
||||
uuid = new UUID(most, least);
|
||||
}
|
||||
}
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
toAdd.put(wrap, uuid);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared
|
||||
.debug(C.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
StringWrapper nameWrap = new StringWrapper(name);
|
||||
toAdd.put(nameWrap, uuid);
|
||||
}
|
||||
|
||||
if (getUUIDMap().isEmpty()) {
|
||||
for (OfflinePlotPlayer op : FileUUIDHandler.this.uuidWrapper
|
||||
.getOfflinePlayers()) {
|
||||
long last = op.getLastPlayed();
|
||||
if (last != 0) {
|
||||
String name = op.getName();
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(op);
|
||||
toAdd.put(wrap, uuid);
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
toAdd.put(new StringWrapper(name), uuid);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
PlotSquared.debug(Captions.PREFIX + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
if (all.isEmpty()) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
PlotSquared.debug(
|
||||
"Failed to cache: " + all.size() + " uuids - slowly processing all files");
|
||||
}
|
||||
}
|
||||
HashSet<String> worlds1 = Sets.newHashSet(world, "world");
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
HashSet<String> names = new HashSet<>();
|
||||
File playerDataFolder = null;
|
||||
for (String worldName : worlds1) {
|
||||
// Getting UUIDs
|
||||
playerDataFolder = new File(container, worldName + File.separator + "playerdata");
|
||||
String[] dat = playerDataFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared.debug(Captions.PREFIX + "Invalid PlayerData: " + current);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Getting names
|
||||
File playersFolder = new File(worldName + File.separator + "players");
|
||||
dat = playersFolder.list(new DatFileFilter());
|
||||
if ((dat != null) && (dat.length != 0)) {
|
||||
for (String current : dat) {
|
||||
names.add(current.replaceAll(".dat$", ""));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
try {
|
||||
File file =
|
||||
new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
|
||||
if (!file.exists()) {
|
||||
continue;
|
||||
}
|
||||
NbtFactory.NbtCompound compound = NbtFactory
|
||||
.fromStream(new FileInputStream(file),
|
||||
NbtFactory.StreamOptions.GZIP_COMPRESSION);
|
||||
if (!compound.containsKey("bukkit")) {
|
||||
PlotSquared.debug("ERROR: Player data (" + uuid.toString()
|
||||
+ ".dat) does not contain the the key \"bukkit\"");
|
||||
} else {
|
||||
NbtFactory.NbtCompound bukkit =
|
||||
(NbtFactory.NbtCompound) compound.get("bukkit");
|
||||
String name = (String) bukkit.get("lastKnownName");
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
long last = (long) bukkit.get("lastPlayed");
|
||||
long first = (long) bukkit.get("firstPlayed");
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
|
||||
.equals(name)) {
|
||||
uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
} else {
|
||||
long most = (long) compound.get("UUIDMost");
|
||||
long least = (long) compound.get("UUIDLeast");
|
||||
uuid = new UUID(most, least);
|
||||
}
|
||||
}
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
ExpireManager.IMP.storeAccountAge(uuid, last - first);
|
||||
}
|
||||
toAdd.put(wrap, uuid);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (String name : names) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
StringWrapper nameWrap = new StringWrapper(name);
|
||||
toAdd.put(nameWrap, uuid);
|
||||
}
|
||||
|
||||
if (getUUIDMap().isEmpty()) {
|
||||
for (OfflinePlotPlayer offlinePlotPlayer : FileUUIDHandler.this.uuidWrapper
|
||||
.getOfflinePlayers()) {
|
||||
long last = offlinePlotPlayer.getLastPlayed();
|
||||
if (last != 0) {
|
||||
String name = offlinePlotPlayer.getName();
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
if (!toAdd.containsKey(wrap)) {
|
||||
UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(offlinePlotPlayer);
|
||||
toAdd.putIfAbsent(wrap, uuid);
|
||||
if (ExpireManager.IMP != null) {
|
||||
ExpireManager.IMP.storeDate(uuid, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
TaskManager.runTask(ifFetch);
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
|
||||
TaskManager.runTask(ifFetch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,14 @@ 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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
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));
|
||||
@NotNull @Override public UUID getUUID(PlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName().toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||
|
@ -13,9 +13,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -32,9 +34,8 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(PlotPlayer player) {
|
||||
return UUID
|
||||
.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
@NotNull @Override public UUID getUUID(PlotPlayer player) {
|
||||
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
|
||||
}
|
||||
|
||||
@Override public UUID getUUID(OfflinePlotPlayer player) {
|
||||
@ -70,7 +71,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
public Player[] getOnlinePlayers() {
|
||||
if (this.getOnline == null) {
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
return onlinePlayers.toArray(new Player[0]);
|
||||
}
|
||||
try {
|
||||
Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
|
||||
@ -79,13 +80,13 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
} else {
|
||||
@SuppressWarnings("unchecked") Collection<? extends Player> p =
|
||||
(Collection<? extends Player>) players;
|
||||
return p.toArray(new Player[p.size()]);
|
||||
return p.toArray(new Player[0]);
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
|
||||
PlotSquared.debug("Failed to resolve online players");
|
||||
this.getOnline = null;
|
||||
Collection<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
|
||||
return onlinePlayers.toArray(new Player[onlinePlayers.size()]);
|
||||
return onlinePlayers.toArray(new Player[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,11 +96,7 @@ public class OfflineUUIDWrapper extends UUIDWrapper {
|
||||
|
||||
@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;
|
||||
return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
|
||||
}
|
||||
|
||||
@Override public OfflinePlotPlayer getOfflinePlayer(String name) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
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.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import com.github.intellectualsites.plotsquared.plot.database.SQLite;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
@ -71,135 +71,119 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||
if (!super.startCaching(whenDone)) {
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
HashBiMap<StringWrapper, UUID> toAdd =
|
||||
HashBiMap.create(new HashMap<StringWrapper, UUID>());
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||
ResultSet resultSet = statement.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
StringWrapper username =
|
||||
new StringWrapper(resultSet.getString("username"));
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
toAdd.put(new StringWrapper(username.value), uuid);
|
||||
}
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
HashBiMap<StringWrapper, UUID> toAdd = HashBiMap.create(new HashMap<>());
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
|
||||
ResultSet resultSet = statement.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
StringWrapper username = new StringWrapper(resultSet.getString("username"));
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
toAdd.put(new StringWrapper(username.value), uuid);
|
||||
}
|
||||
add(toAdd);
|
||||
// This should be called as long as there are some unknown plots
|
||||
final ArrayDeque<UUID> toFetch = new ArrayDeque<>();
|
||||
for (UUID u : UUIDHandler.getAllUUIDS()) {
|
||||
if (!uuidExists(u)) {
|
||||
toFetch.add(u);
|
||||
}
|
||||
}
|
||||
add(toAdd);
|
||||
// This should be called as long as there are some unknown plots
|
||||
final ArrayDeque<UUID> toFetch = new ArrayDeque<>();
|
||||
for (UUID u : UUIDHandler.getAllUUIDS()) {
|
||||
if (!uuidExists(u)) {
|
||||
toFetch.add(u);
|
||||
}
|
||||
if (toFetch.isEmpty()) {
|
||||
}
|
||||
if (toFetch.isEmpty()) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
||||
fileHandler.startCaching(() -> {
|
||||
// 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
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
FileUUIDHandler fileHandler =
|
||||
new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
|
||||
fileHandler.startCaching(new Runnable() {
|
||||
@Override public void run() {
|
||||
// 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
|
||||
if (Settings.UUID.OFFLINE) {
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
while (!toFetch.isEmpty()) {
|
||||
try {
|
||||
for (int i = 0;
|
||||
i < Math.min(500, toFetch.size()); i++) {
|
||||
UUID uuid = toFetch.pop();
|
||||
HttpURLConnection connection =
|
||||
(HttpURLConnection) new URL(
|
||||
SQLUUIDHandler.this.PROFILE_URL + uuid
|
||||
.toString().replace("-", ""))
|
||||
.openConnection();
|
||||
try (InputStream con = connection
|
||||
.getInputStream()) {
|
||||
InputStreamReader reader =
|
||||
new InputStreamReader(con);
|
||||
JSONObject response =
|
||||
(JSONObject) SQLUUIDHandler.this.jsonParser
|
||||
.parse(reader);
|
||||
String name = (String) response.get("name");
|
||||
if (name != null) {
|
||||
add(new StringWrapper(name), uuid);
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
PlotSquared.debug(
|
||||
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||
}
|
||||
try {
|
||||
Thread.sleep(INTERVAL * 50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
while (!toFetch.isEmpty()) {
|
||||
try {
|
||||
for (int i = 0; i < Math.min(MAX_REQUESTS, toFetch.size()); i++) {
|
||||
UUID uuid = toFetch.pop();
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(
|
||||
SQLUUIDHandler.this.PROFILE_URL + uuid.toString()
|
||||
.replace("-", "")).openConnection();
|
||||
try (InputStream con = connection.getInputStream()) {
|
||||
InputStreamReader reader = new InputStreamReader(con);
|
||||
JSONObject response =
|
||||
(JSONObject) SQLUUIDHandler.this.jsonParser
|
||||
.parse(reader);
|
||||
String name = (String) response.get("name");
|
||||
if (name != null) {
|
||||
add(new StringWrapper(name), uuid);
|
||||
}
|
||||
}
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
connection.disconnect();
|
||||
}
|
||||
});
|
||||
} catch (IOException | ParseException e) {
|
||||
PlotSquared.debug(
|
||||
"Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
|
||||
}
|
||||
try {
|
||||
Thread.sleep(INTERVAL * 50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (whenDone != null) {
|
||||
whenDone.run();
|
||||
}
|
||||
return;
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
throw new SQLUUIDHandlerException("Couldn't select :s", e);
|
||||
}
|
||||
});
|
||||
} catch (SQLException e) {
|
||||
throw new SQLUUIDHandlerException("Couldn't select :s", e);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void fetchUUID(final String name, final RunnableVal<UUID> ifFetch) {
|
||||
PlotSquared.debug(C.PREFIX + "UUID for '" + name
|
||||
PlotSquared.debug(Captions.PREFIX + "UUID for '" + name
|
||||
+ "' was null. We'll cache this from the Mojang servers!");
|
||||
if (ifFetch == null) {
|
||||
return;
|
||||
}
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
try {
|
||||
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
String body = JSONArray.toJSONString(Collections.singletonList(name));
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser
|
||||
.parse(new InputStreamReader(connection.getInputStream()));
|
||||
JSONObject jsonProfile = (JSONObject) array.get(0);
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name = (String) jsonProfile.get("name");
|
||||
ifFetch.value = UUID.fromString(
|
||||
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
|
||||
+ '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
TaskManager.runTask(ifFetch);
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try {
|
||||
URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setRequestProperty("Content-Type", "application/json");
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(true);
|
||||
String body = JSONArray.toJSONString(Collections.singletonList(name));
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser
|
||||
.parse(new InputStreamReader(connection.getInputStream()));
|
||||
JSONObject jsonProfile = (JSONObject) array.get(0);
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name1 = (String) jsonProfile.get("name");
|
||||
ifFetch.value = UUID.fromString(
|
||||
id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
|
||||
+ '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
TaskManager.runTask(ifFetch);
|
||||
});
|
||||
}
|
||||
|
||||
@ -212,47 +196,43 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean add(final StringWrapper name, final UUID uuid) {
|
||||
// Ignoring duplicates
|
||||
if (super.add(name, uuid)) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
try (PreparedStatement statement = getConnection().prepareStatement(
|
||||
"REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, name.toString());
|
||||
statement.execute();
|
||||
PlotSquared
|
||||
.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is useful for name changes
|
||||
*/
|
||||
@Override public void rename(final UUID uuid, final StringWrapper name) {
|
||||
super.rename(uuid, name);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
||||
statement.setString(1, name.value);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.execute();
|
||||
PlotSquared.debug(
|
||||
Captions.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean add(final StringWrapper name, final UUID uuid) {
|
||||
// Ignoring duplicates
|
||||
if (super.add(name, uuid)) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
try (PreparedStatement statement = getConnection()
|
||||
.prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
|
||||
statement.setString(1, name.value);
|
||||
statement.setString(2, uuid.toString());
|
||||
.prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, name.toString());
|
||||
statement.execute();
|
||||
PlotSquared.debug(
|
||||
C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class SQLUUIDHandlerException extends RuntimeException {
|
||||
|
@ -62,7 +62,6 @@ permissions:
|
||||
plots.set.flag.vehicle-use.*: true
|
||||
plots.set.flag.vehicle-place.*: true
|
||||
plots.set.flag.vehicle-break.*: true
|
||||
plots.set.flag.player-interact.*: true
|
||||
plots.set.flag.place.*: true
|
||||
plots.set.flag.break.*: true
|
||||
plots.set.flag.use.*: true
|
||||
@ -72,19 +71,15 @@ permissions:
|
||||
plots.permpack.basicinbox:
|
||||
default: op
|
||||
children:
|
||||
comments.notifications.enabled : true
|
||||
comments.notifications.enabled: true
|
||||
plots.inbox.read.public: true
|
||||
plots.inbox.modify.public: true
|
||||
plots.inbox.modify.public: true
|
||||
plots.inbox.write.public: true
|
||||
plots.inbox.read.public: true
|
||||
plots.inbox.read.report: true
|
||||
plots.inbox.write.report: true
|
||||
plots.inbox.read.report: true
|
||||
plots.inbox.read.owner: true
|
||||
plots.inbox.modify.owner: true
|
||||
plots.inbox.write.owner: true
|
||||
plots.inbox.read.owner: true
|
||||
plots.comment: true
|
||||
plots.inbox: true
|
||||
plots.permpack.wilderness:
|
||||
@ -256,9 +251,6 @@ permissions:
|
||||
plotme.limit.10:
|
||||
children:
|
||||
plots.plot.10: true
|
||||
plotme.admin.home.other:
|
||||
children:
|
||||
plots.plot.: true
|
||||
plotme.admin.clear:
|
||||
children:
|
||||
plots.admin.command.clear: true
|
||||
|
Reference in New Issue
Block a user