mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 22:26:45 +01:00
Updated Gradle
This commit is contained in:
parent
7b15d50674
commit
b69e31129d
26
Bukkit/build.gradle
Normal file
26
Bukkit/build.gradle
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
apply plugin: 'eclipse'
|
||||||
|
apply plugin: 'idea'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile project(':Core')
|
||||||
|
compile 'org.bukkit:bukkit:1.8.8-R0.1-SNAPSHOT'
|
||||||
|
compile 'net.milkbowl.vault:VaultAPI:1.5'
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
from('src/main/resources') {
|
||||||
|
include 'plugin.yml'
|
||||||
|
expand(
|
||||||
|
name: project.parent.name,
|
||||||
|
version: project.parent.version
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shadowJar {
|
||||||
|
dependencies {
|
||||||
|
include(dependency(':Core'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build.dependsOn(shadowJar)
|
File diff suppressed because it is too large
Load Diff
@ -1,404 +1,404 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||||
// /
|
// /
|
||||||
// This program is free software; you can redistribute it and/or modify /
|
// 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 /
|
// it under the terms of the GNU General Public License as published by /
|
||||||
// the Free Software Foundation; either version 3 of the License, or /
|
// the Free Software Foundation; either version 3 of the License, or /
|
||||||
// (at your option) any later version. /
|
// (at your option) any later version. /
|
||||||
// /
|
// /
|
||||||
// This program is distributed in the hope that it will be useful, /
|
// This program is distributed in the hope that it will be useful, /
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||||
// GNU General Public License for more details. /
|
// GNU General Public License for more details. /
|
||||||
// /
|
// /
|
||||||
// You should have received a copy of the GNU General Public License /
|
// You should have received a copy of the GNU General Public License /
|
||||||
// along with this program; if not, write to the Free Software Foundation, /
|
// along with this program; if not, write to the Free Software Foundation, /
|
||||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.database.plotme;
|
package com.plotsquared.bukkit.database.plotme;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
|
|
||||||
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
import com.intellectualcrafters.configuration.file.FileConfiguration;
|
||||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.DBFunc;
|
import com.intellectualcrafters.plot.database.DBFunc;
|
||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotArea;
|
import com.intellectualcrafters.plot.object.PlotArea;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-08-17 for PlotSquared
|
* Created 2014-08-17 for PlotSquared
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class LikePlotMeConverter {
|
public class LikePlotMeConverter {
|
||||||
private final String plugin;
|
private final String plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param plugin Plugin Used to run the converter
|
* @param plugin Plugin Used to run the converter
|
||||||
*/
|
*/
|
||||||
public LikePlotMeConverter(final String plugin) {
|
public LikePlotMeConverter(final String plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getWorld(final String world) {
|
public static String getWorld(final String world) {
|
||||||
for (final World newworld : Bukkit.getWorlds()) {
|
for (final World newworld : Bukkit.getWorlds()) {
|
||||||
if (newworld.getName().equalsIgnoreCase(world)) {
|
if (newworld.getName().equalsIgnoreCase(world)) {
|
||||||
return newworld.getName();
|
return newworld.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(final String message) {
|
private void sendMessage(final String message) {
|
||||||
PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
PS.debug("&3PlotMe&8->&3PlotSquared&8: &7" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlotMePath() {
|
public String getPlotMePath() {
|
||||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAthionPlotsPath() {
|
public String getAthionPlotsPath() {
|
||||||
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
return new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + plugin + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getPlotMeConfig(final String dataFolder) {
|
public FileConfiguration getPlotMeConfig(final String dataFolder) {
|
||||||
final File plotMeFile = new File(dataFolder + "config.yml");
|
final File plotMeFile = new File(dataFolder + "config.yml");
|
||||||
if (!plotMeFile.exists()) {
|
if (!plotMeFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return YamlConfiguration.loadConfiguration(plotMeFile);
|
return YamlConfiguration.loadConfiguration(plotMeFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPlotMeWorlds(final FileConfiguration plotConfig) {
|
public Set<String> getPlotMeWorlds(final FileConfiguration plotConfig) {
|
||||||
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
return plotConfig.getConfigurationSection("worlds").getKeys(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mergeWorldYml(final String plugin, FileConfiguration plotConfig) {
|
public void mergeWorldYml(final String plugin, FileConfiguration plotConfig) {
|
||||||
try {
|
try {
|
||||||
File genConfig = new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
File genConfig = new File("plugins" + File.separator + plugin + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||||
if (genConfig.exists()) {
|
if (genConfig.exists()) {
|
||||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
YamlConfiguration yml = YamlConfiguration.loadConfiguration(genConfig);
|
||||||
for (String key : yml.getKeys(true)) {
|
for (String key : yml.getKeys(true)) {
|
||||||
if (!plotConfig.contains(key)) {
|
if (!plotConfig.contains(key)) {
|
||||||
plotConfig.set(key, yml.get(key));
|
plotConfig.set(key, yml.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
genConfig.delete();
|
genConfig.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateWorldYml(final String plugin, final String location) {
|
public void updateWorldYml(final String plugin, final String location) {
|
||||||
try {
|
try {
|
||||||
final Path path = Paths.get(location);
|
final Path path = Paths.get(location);
|
||||||
final File file = new File(location);
|
final File file = new File(location);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Charset charset = StandardCharsets.UTF_8;
|
final Charset charset = StandardCharsets.UTF_8;
|
||||||
String content = new String(Files.readAllBytes(path), charset);
|
String content = new String(Files.readAllBytes(path), charset);
|
||||||
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
content = content.replaceAll("PlotMe-DefaultGenerator", "PlotSquared");
|
||||||
content = content.replaceAll(plugin, "PlotSquared");
|
content = content.replaceAll(plugin, "PlotSquared");
|
||||||
Files.write(path, content.getBytes(charset));
|
Files.write(path, content.getBytes(charset));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean run(final APlotMeConnector connector) {
|
public boolean run(final APlotMeConnector connector) {
|
||||||
try {
|
try {
|
||||||
final String dataFolder = getPlotMePath();
|
final String dataFolder = getPlotMePath();
|
||||||
final FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
final FileConfiguration plotConfig = getPlotMeConfig(dataFolder);
|
||||||
if (plotConfig == null) {
|
if (plotConfig == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String version = plotConfig.getString("Version");
|
String version = plotConfig.getString("Version");
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
version = plotConfig.getString("version");
|
version = plotConfig.getString("version");
|
||||||
}
|
}
|
||||||
if (!connector.accepts(version)) {
|
if (!connector.accepts(version)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
|
PS.debug("&3Using connector: " + connector.getClass().getCanonicalName());
|
||||||
|
|
||||||
final Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
final Connection connection = connector.getPlotMeConnection(plugin, plotConfig, dataFolder);
|
||||||
|
|
||||||
if (!connector.isValidConnection(connection)) {
|
if (!connector.isValidConnection(connection)) {
|
||||||
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
sendMessage("Cannot connect to PlotMe DB. Conversion process will not continue");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
|
sendMessage(plugin + " conversion has started. To disable this, please set 'plotme-convert.enabled' to false in the 'settings.yml'");
|
||||||
|
|
||||||
mergeWorldYml(plugin, plotConfig);
|
mergeWorldYml(plugin, plotConfig);
|
||||||
|
|
||||||
sendMessage("Connecting to " + plugin + " DB");
|
sendMessage("Connecting to " + plugin + " DB");
|
||||||
|
|
||||||
int plotCount = 0;
|
int plotCount = 0;
|
||||||
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
final ArrayList<Plot> createdPlots = new ArrayList<>();
|
||||||
|
|
||||||
sendMessage("Collecting plot data");
|
sendMessage("Collecting plot data");
|
||||||
|
|
||||||
final String dbPrefix = plugin.toLowerCase();
|
final String dbPrefix = plugin.toLowerCase();
|
||||||
sendMessage(" - " + dbPrefix + "Plots");
|
sendMessage(" - " + dbPrefix + "Plots");
|
||||||
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
final Set<String> worlds = getPlotMeWorlds(plotConfig);
|
||||||
|
|
||||||
if (Settings.CONVERT_PLOTME) {
|
if (Settings.CONVERT_PLOTME) {
|
||||||
sendMessage("Updating bukkit.yml");
|
sendMessage("Updating bukkit.yml");
|
||||||
updateWorldYml(plugin, "bukkit.yml");
|
updateWorldYml(plugin, "bukkit.yml");
|
||||||
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
updateWorldYml(plugin, "plugins/Multiverse-Core/worlds.yml");
|
||||||
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
for (final String world : plotConfig.getConfigurationSection("worlds").getKeys(false)) {
|
||||||
sendMessage("Copying config for: " + world);
|
sendMessage("Copying config for: " + world);
|
||||||
try {
|
try {
|
||||||
final String actualWorldName = getWorld(world);
|
final String actualWorldName = getWorld(world);
|
||||||
connector.copyConfig(plotConfig, world, actualWorldName);
|
connector.copyConfig(plotConfig, world, actualWorldName);
|
||||||
PS.get().config.save(PS.get().configFile);
|
PS.get().config.save(PS.get().configFile);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
sendMessage("&c-- &lFailed to save configuration for world '" + world + "'\nThis will need to be done using the setup command, or manually");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
final HashMap<String, HashMap<PlotId, Plot>> plots = connector.getPlotMePlots(connection);
|
||||||
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
for (final Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||||
plotCount += entry.getValue().size();
|
plotCount += entry.getValue().size();
|
||||||
}
|
}
|
||||||
if (!Settings.CONVERT_PLOTME) {
|
if (!Settings.CONVERT_PLOTME) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(" - " + dbPrefix + "Allowed");
|
sendMessage(" - " + dbPrefix + "Allowed");
|
||||||
|
|
||||||
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
sendMessage("Collected " + plotCount + " plots from PlotMe");
|
||||||
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
final File PLOTME_DG_FILE = new File(dataFolder + File.separator + "PlotMe-DefaultGenerator" + File.separator + "config.yml");
|
||||||
if (PLOTME_DG_FILE.exists()) {
|
if (PLOTME_DG_FILE.exists()) {
|
||||||
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
final YamlConfiguration PLOTME_DG_YML = YamlConfiguration.loadConfiguration(PLOTME_DG_FILE);
|
||||||
try {
|
try {
|
||||||
for (final String world : plots.keySet()) {
|
for (final String world : plots.keySet()) {
|
||||||
final String actualWorldName = getWorld(world);
|
final String actualWorldName = getWorld(world);
|
||||||
final String plotMeWorldName = world.toLowerCase();
|
final String plotMeWorldName = world.toLowerCase();
|
||||||
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
Integer pathwidth = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PathWidth"); //
|
||||||
/*
|
/*
|
||||||
* TODO: dead code
|
* TODO: dead code
|
||||||
*
|
*
|
||||||
if (pathwidth == null) {
|
if (pathwidth == null) {
|
||||||
pathwidth = 7;
|
pathwidth = 7;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
PS.get().config.set("worlds." + world + ".road.width", pathwidth);
|
||||||
|
|
||||||
Integer pathheight = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
Integer pathheight = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||||
if ((pathheight == null) || (pathheight == 0)) {
|
if ((pathheight == null) || (pathheight == 0)) {
|
||||||
pathheight = 64;
|
pathheight = 64;
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".road.height", pathheight);
|
PS.get().config.set("worlds." + world + ".road.height", pathheight);
|
||||||
PS.get().config.set("worlds." + world + ".wall.height", pathheight);
|
PS.get().config.set("worlds." + world + ".wall.height", pathheight);
|
||||||
PS.get().config.set("worlds." + world + ".plot.height", pathheight);
|
PS.get().config.set("worlds." + world + ".plot.height", pathheight);
|
||||||
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
Integer plotsize = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".PlotSize"); //
|
||||||
if ((plotsize == null) || (plotsize == 0)) {
|
if ((plotsize == null) || (plotsize == 0)) {
|
||||||
plotsize = 32;
|
plotsize = 32;
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
PS.get().config.set("worlds." + world + ".plot.size", plotsize);
|
||||||
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
String wallblock = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".WallBlock"); //
|
||||||
if (wallblock == null) {
|
if (wallblock == null) {
|
||||||
wallblock = "44";
|
wallblock = "44";
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
PS.get().config.set("worlds." + world + ".wall.block", wallblock);
|
||||||
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
String floor = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".PlotFloorBlock"); //
|
||||||
if (floor == null) {
|
if (floor == null) {
|
||||||
floor = "2";
|
floor = "2";
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
PS.get().config.set("worlds." + world + ".plot.floor", Collections.singletonList(floor));
|
||||||
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
String filling = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".FillBlock"); //
|
||||||
if (filling == null) {
|
if (filling == null) {
|
||||||
filling = "3";
|
filling = "3";
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
PS.get().config.set("worlds." + world + ".plot.filling", Collections.singletonList(filling));
|
||||||
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
String road = PLOTME_DG_YML.getString("worlds." + plotMeWorldName + ".RoadMainBlock");
|
||||||
if (road == null) {
|
if (road == null) {
|
||||||
road = "5";
|
road = "5";
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + world + ".road.block", road);
|
PS.get().config.set("worlds." + world + ".road.block", road);
|
||||||
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
Integer height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".RoadHeight"); //
|
||||||
if (height == 0) {
|
if (height == 0) {
|
||||||
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
height = PLOTME_DG_YML.getInt("worlds." + plotMeWorldName + ".GroundHeight"); //
|
||||||
if (height == 0) {
|
if (height == 0) {
|
||||||
height = 64;
|
height = 64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
PS.get().config.set("worlds." + actualWorldName + ".road.height", height);
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
PS.get().config.set("worlds." + actualWorldName + ".plot.height", height);
|
||||||
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
PS.get().config.set("worlds." + actualWorldName + ".wall.height", height);
|
||||||
PS.get().config.save(PS.get().configFile);
|
PS.get().config.save(PS.get().configFile);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
for (Entry<String, HashMap<PlotId, Plot>> entry : plots.entrySet()) {
|
||||||
String world = entry.getKey();
|
String world = entry.getKey();
|
||||||
PlotArea area = PS.get().getPlotArea(world, null);
|
PlotArea area = PS.get().getPlotArea(world, null);
|
||||||
int duplicate = 0;
|
int duplicate = 0;
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
if (area.getOwnedPlotAbs(entry2.getKey()) != null) {
|
if (area.getOwnedPlotAbs(entry2.getKey()) != null) {
|
||||||
duplicate++;
|
duplicate++;
|
||||||
} else {
|
} else {
|
||||||
createdPlots.add(entry2.getValue());
|
createdPlots.add(entry2.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (PS.get().plots_tmp != null) {
|
if (PS.get().plots_tmp != null) {
|
||||||
HashMap<PlotId, Plot> map = PS.get().plots_tmp.get(world);
|
HashMap<PlotId, Plot> map = PS.get().plots_tmp.get(world);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
|
||||||
if (map.containsKey(entry2.getKey())) {
|
if (map.containsKey(entry2.getKey())) {
|
||||||
duplicate++;
|
duplicate++;
|
||||||
} else {
|
} else {
|
||||||
createdPlots.add(entry2.getValue());
|
createdPlots.add(entry2.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (duplicate > 0) {
|
if (duplicate > 0) {
|
||||||
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
PS.debug("&c[WARNING] Found " + duplicate + " duplicate plots already in DB for world: '" + world + "'. Have you run the converter already?");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createdPlots.addAll(entry.getValue().values());
|
createdPlots.addAll(entry.getValue().values());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessage("Creating plot DB");
|
sendMessage("Creating plot DB");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
final AtomicBoolean done = new AtomicBoolean(false);
|
final AtomicBoolean done = new AtomicBoolean(false);
|
||||||
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
DBFunc.createPlotsAndData(createdPlots, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (done.get()) {
|
if (done.get()) {
|
||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PS.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
PS.debug("&c - Start the server");
|
PS.debug("&c - Start the server");
|
||||||
PS.get().setPlots(DBFunc.getPlots());
|
PS.get().setPlots(DBFunc.getPlots());
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sendMessage("Saving configuration...");
|
sendMessage("Saving configuration...");
|
||||||
try {
|
try {
|
||||||
PS.get().config.save(PS.get().configFile);
|
PS.get().config.save(PS.get().configFile);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
sendMessage(" - &cFailed to save configuration.");
|
sendMessage(" - &cFailed to save configuration.");
|
||||||
}
|
}
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
boolean MV = false;
|
boolean MV = false;
|
||||||
boolean MW = false;
|
boolean MW = false;
|
||||||
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
if ((Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) && Bukkit.getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
|
||||||
MV = true;
|
MV = true;
|
||||||
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
} else if ((Bukkit.getPluginManager().getPlugin("MultiWorld") != null) && Bukkit.getPluginManager().getPlugin("MultiWorld").isEnabled()) {
|
||||||
MW = true;
|
MW = true;
|
||||||
}
|
}
|
||||||
for (final String worldname : worlds) {
|
for (final String worldname : worlds) {
|
||||||
final World world = Bukkit.getWorld(getWorld(worldname));
|
final World world = Bukkit.getWorld(getWorld(worldname));
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
sendMessage("&cInvalid world in PlotMe configuration: " + worldname);
|
||||||
}
|
}
|
||||||
final String actualWorldName = world.getName();
|
final String actualWorldName = world.getName();
|
||||||
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
sendMessage("Reloading generator for world: '" + actualWorldName + "'...");
|
||||||
PS.get().removePlotAreas(actualWorldName);
|
PS.get().removePlotAreas(actualWorldName);
|
||||||
if (MV) {
|
if (MV) {
|
||||||
// unload world with MV
|
// unload world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (final InterruptedException ex) {
|
} catch (final InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MV
|
// load world with MV
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mv import " + actualWorldName + " normal -g PlotSquared");
|
||||||
} else if (MW) {
|
} else if (MW) {
|
||||||
// unload world with MW
|
// unload world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw unload " + actualWorldName);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (final InterruptedException ex) {
|
} catch (final InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
// load world with MW
|
// load world with MW
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||||
} else {
|
} else {
|
||||||
// Load using Bukkit API
|
// Load using Bukkit API
|
||||||
// - User must set generator manually
|
// - User must set generator manually
|
||||||
Bukkit.getServer().unloadWorld(world, true);
|
Bukkit.getServer().unloadWorld(world, true);
|
||||||
final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
|
final World myworld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
|
||||||
myworld.save();
|
myworld.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (done.get()) {
|
if (done.get()) {
|
||||||
done();
|
done();
|
||||||
sendMessage("&aDatabase conversion is now complete!");
|
sendMessage("&aDatabase conversion is now complete!");
|
||||||
PS.debug("&c - Stop the server");
|
PS.debug("&c - Stop the server");
|
||||||
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
PS.debug("&c - Disable 'plotme-convert.enabled' and 'plotme-convert.cache-uuids' in the settings.yml");
|
||||||
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
PS.debug("&c - Correct any generator settings that haven't copied to 'settings.yml' properly");
|
||||||
PS.debug("&c - Start the server");
|
PS.debug("&c - Start the server");
|
||||||
} else {
|
} else {
|
||||||
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
sendMessage("&cPlease wait until database conversion is complete. You will be notified with instructions when this happens!");
|
||||||
done.set(true);
|
done.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
PS.debug("&/end/");
|
PS.debug("&/end/");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void done() {
|
public void done() {
|
||||||
PS.get().setPlots(DBFunc.getPlots());
|
PS.get().setPlots(DBFunc.getPlots());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,89 +1,89 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||||
// /
|
// /
|
||||||
// This program is free software; you can redistribute it and/or modify /
|
// 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 /
|
// it under the terms of the GNU General Public License as published by /
|
||||||
// the Free Software Foundation; either version 3 of the License, or /
|
// the Free Software Foundation; either version 3 of the License, or /
|
||||||
// (at your option) any later version. /
|
// (at your option) any later version. /
|
||||||
// /
|
// /
|
||||||
// This program is distributed in the hope that it will be useful, /
|
// This program is distributed in the hope that it will be useful, /
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||||
// GNU General Public License for more details. /
|
// GNU General Public License for more details. /
|
||||||
// /
|
// /
|
||||||
// You should have received a copy of the GNU General Public License /
|
// You should have received a copy of the GNU General Public License /
|
||||||
// along with this program; if not, write to the Free Software Foundation, /
|
// along with this program; if not, write to the Free Software Foundation, /
|
||||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.events;
|
package com.plotsquared.bukkit.events;
|
||||||
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a flag is removed from a plot
|
* Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
public class ClusterFlagRemoveEvent extends Event implements Cancellable {
|
||||||
private static HandlerList handlers = new HandlerList();
|
private static HandlerList handlers = new HandlerList();
|
||||||
private final PlotCluster cluster;
|
private final PlotCluster cluster;
|
||||||
private final Flag flag;
|
private final Flag flag;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
|
||||||
*
|
*
|
||||||
* @param flag Flag that was removed
|
* @param flag Flag that was removed
|
||||||
* @param cluster PlotCluster from which the flag was removed
|
* @param cluster PlotCluster from which the flag was removed
|
||||||
*/
|
*/
|
||||||
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
public ClusterFlagRemoveEvent(final Flag flag, final PlotCluster cluster) {
|
||||||
this.cluster = cluster;
|
this.cluster = cluster;
|
||||||
this.flag = flag;
|
this.flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the cluster involved
|
* Get the cluster involved
|
||||||
*
|
*
|
||||||
* @return PlotCluster
|
* @return PlotCluster
|
||||||
*/
|
*/
|
||||||
public PlotCluster getCluster() {
|
public PlotCluster getCluster() {
|
||||||
return cluster;
|
return cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the flag involved
|
* Get the flag involved
|
||||||
*
|
*
|
||||||
* @return Flag
|
* @return Flag
|
||||||
*/
|
*/
|
||||||
public Flag getFlag() {
|
public Flag getFlag() {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(final boolean b) {
|
public void setCancelled(final boolean b) {
|
||||||
cancelled = b;
|
cancelled = b;
|
||||||
}
|
}
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,251 +1,251 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||||
// /
|
// /
|
||||||
// This program is free software; you can redistribute it and/or modify /
|
// 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 /
|
// it under the terms of the GNU General Public License as published by /
|
||||||
// the Free Software Foundation; either version 3 of the License, or /
|
// the Free Software Foundation; either version 3 of the License, or /
|
||||||
// (at your option) any later version. /
|
// (at your option) any later version. /
|
||||||
// /
|
// /
|
||||||
// This program is distributed in the hope that it will be useful, /
|
// This program is distributed in the hope that it will be useful, /
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||||
// GNU General Public License for more details. /
|
// GNU General Public License for more details. /
|
||||||
// /
|
// /
|
||||||
// You should have received a copy of the GNU General Public License /
|
// You should have received a copy of the GNU General Public License /
|
||||||
// along with this program; if not, write to the Free Software Foundation, /
|
// along with this program; if not, write to the Free Software Foundation, /
|
||||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.listeners;
|
package com.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.flag.Flag;
|
import com.intellectualcrafters.plot.flag.Flag;
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
|
||||||
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
import com.plotsquared.bukkit.events.PlayerLeavePlotEvent;
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.listener.PlotListener;
|
import com.plotsquared.listener.PlotListener;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockDamageEvent;
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2014-10-30 for PlotSquared
|
* Created 2014-10-30 for PlotSquared
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "deprecation" })
|
@SuppressWarnings({ "deprecation" })
|
||||||
public class PlotPlusListener extends PlotListener implements Listener {
|
public class PlotPlusListener extends PlotListener implements Listener {
|
||||||
private final static HashMap<String, Interval> feedRunnable = new HashMap<>();
|
private final static HashMap<String, Interval> feedRunnable = new HashMap<>();
|
||||||
private final static HashMap<String, Interval> healRunnable = new HashMap<>();
|
private final static HashMap<String, Interval> healRunnable = new HashMap<>();
|
||||||
|
|
||||||
public static void startRunnable(final JavaPlugin plugin) {
|
public static void startRunnable(final JavaPlugin plugin) {
|
||||||
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!healRunnable.isEmpty()) {
|
if (!healRunnable.isEmpty()) {
|
||||||
for (final Iterator<Entry<String, Interval>> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
|
for (final Iterator<Entry<String, Interval>> iter = healRunnable.entrySet().iterator(); iter.hasNext();) {
|
||||||
final Entry<String, Interval> entry = iter.next();
|
final Entry<String, Interval> entry = iter.next();
|
||||||
final Interval value = entry.getValue();
|
final Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
final Player player = Bukkit.getPlayer(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final double level = player.getHealth();
|
final double level = player.getHealth();
|
||||||
if (level != value.max) {
|
if (level != value.max) {
|
||||||
player.setHealth(Math.min(level + value.amount, value.max));
|
player.setHealth(Math.min(level + value.amount, value.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!feedRunnable.isEmpty()) {
|
if (!feedRunnable.isEmpty()) {
|
||||||
for (final Iterator<Entry<String, Interval>> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
|
for (final Iterator<Entry<String, Interval>> iter = feedRunnable.entrySet().iterator(); iter.hasNext();) {
|
||||||
final Entry<String, Interval> entry = iter.next();
|
final Entry<String, Interval> entry = iter.next();
|
||||||
final Interval value = entry.getValue();
|
final Interval value = entry.getValue();
|
||||||
++value.count;
|
++value.count;
|
||||||
if (value.count == value.interval) {
|
if (value.count == value.interval) {
|
||||||
value.count = 0;
|
value.count = 0;
|
||||||
final Player player = Bukkit.getPlayer(entry.getKey());
|
final Player player = Bukkit.getPlayer(entry.getKey());
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
iter.remove();
|
iter.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int level = player.getFoodLevel();
|
final int level = player.getFoodLevel();
|
||||||
if (level != value.max) {
|
if (level != value.max) {
|
||||||
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
player.setFoodLevel(Math.min(level + value.amount, value.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 0l, 20l);
|
}, 0l, 20l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onInteract(final BlockDamageEvent event) {
|
public void onInteract(final BlockDamageEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
|
if (FlagManager.isBooleanFlag(plot, "instabreak", false)) {
|
||||||
event.getBlock().breakNaturally();
|
event.getBlock().breakNaturally();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onDamage(final EntityDamageEvent event) {
|
public void onDamage(final EntityDamageEvent event) {
|
||||||
if (event.getEntityType() != EntityType.PLAYER) {
|
if (event.getEntityType() != EntityType.PLAYER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Player player = (Player) event.getEntity();
|
final Player player = (Player) event.getEntity();
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
|
if (FlagManager.isBooleanFlag(plot, "invincible", false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemPickup(final PlayerPickupItemEvent event) {
|
public void onItemPickup(final PlayerPickupItemEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final UUID uuid = pp.getUUID();
|
final UUID uuid = pp.getUUID();
|
||||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
|
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "drop-protection", false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onItemDrop(final PlayerDropItemEvent event) {
|
public void onItemDrop(final PlayerDropItemEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
final PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
final Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
|
||||||
if (plot == null) {
|
if (plot == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final UUID uuid = pp.getUUID();
|
final UUID uuid = pp.getUUID();
|
||||||
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
|
if (plot.isAdded(uuid) && FlagManager.isBooleanFlag(plot, "item-drop", false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlotEnter(final PlayerEnterPlotEvent event) {
|
public void onPlotEnter(final PlayerEnterPlotEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final Plot plot = event.getPlot();
|
final Plot plot = event.getPlot();
|
||||||
final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
final Flag feed = FlagManager.getPlotFlagRaw(plot, "feed");
|
||||||
if (feed != null) {
|
if (feed != null) {
|
||||||
final Integer[] value = (Integer[]) feed.getValue();
|
final Integer[] value = (Integer[]) feed.getValue();
|
||||||
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
final Flag heal = FlagManager.getPlotFlagRaw(plot, "heal");
|
||||||
if (heal != null) {
|
if (heal != null) {
|
||||||
final Integer[] value = (Integer[]) heal.getValue();
|
final Integer[] value = (Integer[]) heal.getValue();
|
||||||
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
feedRunnable.remove(name);
|
feedRunnable.remove(name);
|
||||||
healRunnable.remove(name);
|
healRunnable.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlotLeave(final PlayerLeavePlotEvent event) {
|
public void onPlotLeave(final PlayerLeavePlotEvent event) {
|
||||||
final Player leaver = event.getPlayer();
|
final Player leaver = event.getPlayer();
|
||||||
final Plot plot = event.getPlot();
|
final Plot plot = event.getPlot();
|
||||||
if (!plot.hasOwner()) {
|
if (!plot.hasOwner()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BukkitUtil.getPlayer(leaver);
|
BukkitUtil.getPlayer(leaver);
|
||||||
final String name = leaver.getName();
|
final String name = leaver.getName();
|
||||||
feedRunnable.remove(name);
|
feedRunnable.remove(name);
|
||||||
healRunnable.remove(name);
|
healRunnable.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Interval {
|
public static class Interval {
|
||||||
public final int interval;
|
public final int interval;
|
||||||
public final int amount;
|
public final int amount;
|
||||||
public final int max;
|
public final int max;
|
||||||
public int count = 0;
|
public int count = 0;
|
||||||
|
|
||||||
public Interval(final int interval, final int amount, final int max) {
|
public Interval(final int interval, final int amount, final int max) {
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Record Meta Class
|
* Record Meta Class
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public static class RecordMeta {
|
public static class RecordMeta {
|
||||||
public final static List<RecordMeta> metaList = new ArrayList<>();
|
public final static List<RecordMeta> metaList = new ArrayList<>();
|
||||||
static {
|
static {
|
||||||
for (int x = 3; x < 12; x++) {
|
for (int x = 3; x < 12; x++) {
|
||||||
metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
|
metaList.add(new RecordMeta(x + "", Material.valueOf("RECORD_" + x)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Material material;
|
private final Material material;
|
||||||
|
|
||||||
public RecordMeta(final String name, final Material material) {
|
public RecordMeta(final String name, final Material material) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return name.hashCode();
|
return name.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,108 +1,108 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||||
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.Permissions;
|
import com.intellectualcrafters.plot.util.Permissions;
|
||||||
import com.intellectualcrafters.plot.util.StringComparison;
|
import com.intellectualcrafters.plot.util.StringComparison;
|
||||||
import com.plotsquared.bukkit.commands.DebugUUID;
|
import com.plotsquared.bukkit.commands.DebugUUID;
|
||||||
import com.plotsquared.general.commands.Command;
|
import com.plotsquared.general.commands.Command;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 2015-02-20 for PlotSquared
|
* Created 2015-02-20 for PlotSquared
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
public BukkitCommand() {
|
public BukkitCommand() {
|
||||||
MainCommand.getInstance().addCommand(new DebugUUID());
|
MainCommand.getInstance().addCommand(new DebugUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
|
public boolean onCommand(final CommandSender commandSender, final org.bukkit.command.Command command, final String commandLabel,
|
||||||
final String[] args) {
|
final String[] args) {
|
||||||
if (commandSender instanceof Player) {
|
if (commandSender instanceof Player) {
|
||||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
||||||
}
|
}
|
||||||
if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
|
if (commandSender == null || commandSender.getClass() == Bukkit.getConsoleSender().getClass()) {
|
||||||
return MainCommand.onCommand(ConsolePlayer.getConsole(), commandLabel, args);
|
return MainCommand.onCommand(ConsolePlayer.getConsole(), commandLabel, args);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
ConsolePlayer sender = new ConsolePlayer() {
|
ConsolePlayer sender = new ConsolePlayer() {
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
commandSender.sendMessage(commandLabel);
|
commandSender.sendMessage(commandLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String perm) {
|
public boolean hasPermission(String perm) {
|
||||||
return commandSender.hasPermission(commandLabel);
|
return commandSender.hasPermission(commandLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (commandSender.getName().equals("CONSOLE")) {
|
if (commandSender.getName().equals("CONSOLE")) {
|
||||||
return "*";
|
return "*";
|
||||||
}
|
}
|
||||||
return commandSender.getName();
|
return commandSender.getName();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sender.teleport(ConsolePlayer.getConsole().getLocationFull());
|
sender.teleport(ConsolePlayer.getConsole().getLocationFull());
|
||||||
boolean result = MainCommand.onCommand(sender, commandLabel, args);
|
boolean result = MainCommand.onCommand(sender, commandLabel, args);
|
||||||
ConsolePlayer.getConsole().teleport(sender.getLocationFull());
|
ConsolePlayer.getConsole().teleport(sender.getLocationFull());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
|
public List<String> onTabComplete(final CommandSender commandSender, final org.bukkit.command.Command command, final String s,
|
||||||
final String[] strings) {
|
final String[] strings) {
|
||||||
if (!(commandSender instanceof Player)) {
|
if (!(commandSender instanceof Player)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||||
if (strings.length < 1) {
|
if (strings.length < 1) {
|
||||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||||
return Collections.singletonList("plots");
|
return Collections.singletonList("plots");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strings.length > 1) {
|
if (strings.length > 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Set<String> tabOptions = new HashSet<>();
|
final Set<String> tabOptions = new HashSet<>();
|
||||||
final String arg = strings[0].toLowerCase();
|
final String arg = strings[0].toLowerCase();
|
||||||
ArrayList<String> labels = new ArrayList<>();
|
ArrayList<String> labels = new ArrayList<>();
|
||||||
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
for (final Command<PlotPlayer> cmd : MainCommand.getInstance().getCommands()) {
|
||||||
final String label = cmd.getCommand();
|
final String label = cmd.getCommand();
|
||||||
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
HashSet<String> aliases = new HashSet<>(cmd.getAliases());
|
||||||
aliases.add(label);
|
aliases.add(label);
|
||||||
for (String alias : aliases) {
|
for (String alias : aliases) {
|
||||||
labels.add(alias);
|
labels.add(alias);
|
||||||
if (alias.startsWith(arg)) {
|
if (alias.startsWith(arg)) {
|
||||||
if (Permissions.hasPermission(player, cmd.getPermission())) {
|
if (Permissions.hasPermission(player, cmd.getPermission())) {
|
||||||
tabOptions.add(label);
|
tabOptions.add(label);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String best = new StringComparison<>(arg, labels).getBestMatch();
|
String best = new StringComparison<>(arg, labels).getBestMatch();
|
||||||
tabOptions.add(best);
|
tabOptions.add(best);
|
||||||
if (!tabOptions.isEmpty()) {
|
if (!tabOptions.isEmpty()) {
|
||||||
return new ArrayList<>(tabOptions);
|
return new ArrayList<>(tabOptions);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,340 +1,340 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||||
// /
|
// /
|
||||||
// This program is free software; you can redistribute it and/or modify /
|
// 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 /
|
// it under the terms of the GNU General Public License as published by /
|
||||||
// the Free Software Foundation; either version 3 of the License, or /
|
// the Free Software Foundation; either version 3 of the License, or /
|
||||||
// (at your option) any later version. /
|
// (at your option) any later version. /
|
||||||
// /
|
// /
|
||||||
// This program is distributed in the hope that it will be useful, /
|
// This program is distributed in the hope that it will be useful, /
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||||
// GNU General Public License for more details. /
|
// GNU General Public License for more details. /
|
||||||
// /
|
// /
|
||||||
// You should have received a copy of the GNU General Public License /
|
// You should have received a copy of the GNU General Public License /
|
||||||
// along with this program; if not, write to the Free Software Foundation, /
|
// along with this program; if not, write to the Free Software Foundation, /
|
||||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||||
// /
|
// /
|
||||||
// You can contact us via: support@intellectualsites.com /
|
// You can contact us via: support@intellectualsites.com /
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
|
|
||||||
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
||||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||||
import com.intellectualcrafters.jnbt.IntTag;
|
import com.intellectualcrafters.jnbt.IntTag;
|
||||||
import com.intellectualcrafters.jnbt.ListTag;
|
import com.intellectualcrafters.jnbt.ListTag;
|
||||||
import com.intellectualcrafters.jnbt.ShortTag;
|
import com.intellectualcrafters.jnbt.ShortTag;
|
||||||
import com.intellectualcrafters.jnbt.StringTag;
|
import com.intellectualcrafters.jnbt.StringTag;
|
||||||
import com.intellectualcrafters.jnbt.Tag;
|
import com.intellectualcrafters.jnbt.Tag;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||||
import com.intellectualcrafters.plot.util.MainUtil;
|
import com.intellectualcrafters.plot.util.MainUtil;
|
||||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.plotsquared.bukkit.object.schematic.StateWrapper;
|
import com.plotsquared.bukkit.object.schematic.StateWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schematic Handler
|
* Schematic Handler
|
||||||
*
|
*
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class BukkitSchematicHandler extends SchematicHandler {
|
public class BukkitSchematicHandler extends SchematicHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
|
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
|
||||||
// async
|
// async
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Main positions
|
// Main positions
|
||||||
Location[] corners = MainUtil.getCorners(world, regions);
|
Location[] corners = MainUtil.getCorners(world, regions);
|
||||||
final Location bot = corners[0];
|
final Location bot = corners[0];
|
||||||
final Location top = corners[1];
|
final Location top = corners[1];
|
||||||
|
|
||||||
final int width = (top.getX() - bot.getX()) + 1;
|
final int width = (top.getX() - bot.getX()) + 1;
|
||||||
final int height = (top.getY() - bot.getY()) + 1;
|
final int height = (top.getY() - bot.getY()) + 1;
|
||||||
final int length = (top.getZ() - bot.getZ()) + 1;
|
final int length = (top.getZ() - bot.getZ()) + 1;
|
||||||
// Main Schematic tag
|
// Main Schematic tag
|
||||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||||
schematic.put("Width", new ShortTag("Width", (short) width));
|
schematic.put("Width", new ShortTag("Width", (short) width));
|
||||||
schematic.put("Length", new ShortTag("Length", (short) length));
|
schematic.put("Length", new ShortTag("Length", (short) length));
|
||||||
schematic.put("Height", new ShortTag("Height", (short) height));
|
schematic.put("Height", new ShortTag("Height", (short) height));
|
||||||
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
||||||
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
|
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
|
||||||
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
|
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
|
||||||
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
|
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
|
||||||
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
|
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
|
||||||
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
|
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
|
||||||
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
|
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
|
||||||
// Arrays of data types
|
// Arrays of data types
|
||||||
final List<Tag> tileEntities = new ArrayList<>();
|
final List<Tag> tileEntities = new ArrayList<>();
|
||||||
final byte[] blocks = new byte[width * height * length];
|
final byte[] blocks = new byte[width * height * length];
|
||||||
final byte[] blockData = new byte[width * height * length];
|
final byte[] blockData = new byte[width * height * length];
|
||||||
// Queue
|
// Queue
|
||||||
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (queue.isEmpty()) {
|
if (queue.isEmpty()) {
|
||||||
TaskManager.runTaskAsync(new Runnable() {
|
TaskManager.runTaskAsync(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||||
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
|
||||||
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
|
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
|
||||||
whenDone.value = new CompoundTag("Schematic", schematic);
|
whenDone.value = new CompoundTag("Schematic", schematic);
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
System.gc();
|
System.gc();
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Runnable regionTask = this;
|
final Runnable regionTask = this;
|
||||||
RegionWrapper region = queue.poll();
|
RegionWrapper region = queue.poll();
|
||||||
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
|
||||||
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
|
||||||
final int bx = bot.getX();
|
final int bx = bot.getX();
|
||||||
final int bz = bot.getZ();
|
final int bz = bot.getZ();
|
||||||
final int p1x = pos1.getX();
|
final int p1x = pos1.getX();
|
||||||
final int p1z = pos1.getZ();
|
final int p1z = pos1.getZ();
|
||||||
final int p2x = pos2.getX();
|
final int p2x = pos2.getX();
|
||||||
final int p2z = pos2.getZ();
|
final int p2z = pos2.getZ();
|
||||||
final int bcx = p1x >> 4;
|
final int bcx = p1x >> 4;
|
||||||
final int bcz = p1z >> 4;
|
final int bcz = p1z >> 4;
|
||||||
final int tcx = p2x >> 4;
|
final int tcx = p2x >> 4;
|
||||||
final int tcz = p2z >> 4;
|
final int tcz = p2z >> 4;
|
||||||
final int sy = pos1.getY();
|
final int sy = pos1.getY();
|
||||||
final int ey = pos2.getY();
|
final int ey = pos2.getY();
|
||||||
// Generate list of chunks
|
// Generate list of chunks
|
||||||
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
|
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
|
||||||
for (int x = bcx; x <= tcx; x++) {
|
for (int x = bcx; x <= tcx; x++) {
|
||||||
for (int z = bcz; z <= tcz; z++) {
|
for (int z = bcz; z <= tcz; z++) {
|
||||||
chunks.add(new ChunkLoc(x, z));
|
chunks.add(new ChunkLoc(x, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final World worldObj = Bukkit.getWorld(world);
|
final World worldObj = Bukkit.getWorld(world);
|
||||||
// Main thread
|
// Main thread
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final long start = System.currentTimeMillis();
|
final long start = System.currentTimeMillis();
|
||||||
while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
|
while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) {
|
||||||
// save schematics
|
// save schematics
|
||||||
final ChunkLoc chunk = chunks.remove(0);
|
final ChunkLoc chunk = chunks.remove(0);
|
||||||
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
|
||||||
if (!bc.load(false)) {
|
if (!bc.load(false)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final int X = chunk.x;
|
final int X = chunk.x;
|
||||||
final int Z = chunk.z;
|
final int Z = chunk.z;
|
||||||
int xxb = X << 4;
|
int xxb = X << 4;
|
||||||
int zzb = Z << 4;
|
int zzb = Z << 4;
|
||||||
int xxt = xxb + 15;
|
int xxt = xxb + 15;
|
||||||
int zzt = zzb + 15;
|
int zzt = zzb + 15;
|
||||||
|
|
||||||
if (X == bcx) {
|
if (X == bcx) {
|
||||||
xxb = p1x;
|
xxb = p1x;
|
||||||
}
|
}
|
||||||
if (X == tcx) {
|
if (X == tcx) {
|
||||||
xxt = p2x;
|
xxt = p2x;
|
||||||
}
|
}
|
||||||
if (Z == bcz) {
|
if (Z == bcz) {
|
||||||
zzb = p1z;
|
zzb = p1z;
|
||||||
}
|
}
|
||||||
if (Z == tcz) {
|
if (Z == tcz) {
|
||||||
zzt = p2z;
|
zzt = p2z;
|
||||||
}
|
}
|
||||||
for (int y = sy; y <= Math.min(255, ey); y++) {
|
for (int y = sy; y <= Math.min(255, ey); y++) {
|
||||||
final int ry = y - sy;
|
final int ry = y - sy;
|
||||||
final int i1 = (ry * width * length);
|
final int i1 = (ry * width * length);
|
||||||
for (int z = zzb; z <= zzt; z++) {
|
for (int z = zzb; z <= zzt; z++) {
|
||||||
final int rz = z - bz;
|
final int rz = z - bz;
|
||||||
final int i2 = i1 + (rz * width);
|
final int i2 = i1 + (rz * width);
|
||||||
for (int x = xxb; x <= xxt; x++) {
|
for (int x = xxb; x <= xxt; x++) {
|
||||||
final int rx = x - bx;
|
final int rx = x - bx;
|
||||||
final int index = i2 + rx;
|
final int index = i2 + rx;
|
||||||
final Block block = worldObj.getBlockAt(x, y, z);
|
final Block block = worldObj.getBlockAt(x, y, z);
|
||||||
final int id = block.getTypeId();
|
final int id = block.getTypeId();
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
case 2:
|
case 2:
|
||||||
case 4:
|
case 4:
|
||||||
case 13:
|
case 13:
|
||||||
case 14:
|
case 14:
|
||||||
case 15:
|
case 15:
|
||||||
case 20:
|
case 20:
|
||||||
case 21:
|
case 21:
|
||||||
case 22:
|
case 22:
|
||||||
case 24:
|
case 24:
|
||||||
case 30:
|
case 30:
|
||||||
case 32:
|
case 32:
|
||||||
case 37:
|
case 37:
|
||||||
case 39:
|
case 39:
|
||||||
case 40:
|
case 40:
|
||||||
case 41:
|
case 41:
|
||||||
case 42:
|
case 42:
|
||||||
case 45:
|
case 45:
|
||||||
case 46:
|
case 46:
|
||||||
case 47:
|
case 47:
|
||||||
case 48:
|
case 48:
|
||||||
case 49:
|
case 49:
|
||||||
case 51:
|
case 51:
|
||||||
case 55:
|
case 55:
|
||||||
case 56:
|
case 56:
|
||||||
case 57:
|
case 57:
|
||||||
case 58:
|
case 58:
|
||||||
case 60:
|
case 60:
|
||||||
case 7:
|
case 7:
|
||||||
case 8:
|
case 8:
|
||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11:
|
||||||
case 73:
|
case 73:
|
||||||
case 74:
|
case 74:
|
||||||
case 78:
|
case 78:
|
||||||
case 79:
|
case 79:
|
||||||
case 80:
|
case 80:
|
||||||
case 81:
|
case 81:
|
||||||
case 82:
|
case 82:
|
||||||
case 83:
|
case 83:
|
||||||
case 85:
|
case 85:
|
||||||
case 87:
|
case 87:
|
||||||
case 88:
|
case 88:
|
||||||
case 101:
|
case 101:
|
||||||
case 102:
|
case 102:
|
||||||
case 103:
|
case 103:
|
||||||
case 110:
|
case 110:
|
||||||
case 112:
|
case 112:
|
||||||
case 113:
|
case 113:
|
||||||
case 121:
|
case 121:
|
||||||
case 122:
|
case 122:
|
||||||
case 129:
|
case 129:
|
||||||
case 133:
|
case 133:
|
||||||
case 165:
|
case 165:
|
||||||
case 166:
|
case 166:
|
||||||
case 169:
|
case 169:
|
||||||
case 170:
|
case 170:
|
||||||
case 172:
|
case 172:
|
||||||
case 173:
|
case 173:
|
||||||
case 174:
|
case 174:
|
||||||
case 181:
|
case 181:
|
||||||
case 182:
|
case 182:
|
||||||
case 188:
|
case 188:
|
||||||
case 189:
|
case 189:
|
||||||
case 190:
|
case 190:
|
||||||
case 191:
|
case 191:
|
||||||
case 192: {
|
case 192: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 54:
|
case 54:
|
||||||
case 130:
|
case 130:
|
||||||
case 142:
|
case 142:
|
||||||
case 27:
|
case 27:
|
||||||
case 137:
|
case 137:
|
||||||
case 52:
|
case 52:
|
||||||
case 154:
|
case 154:
|
||||||
case 84:
|
case 84:
|
||||||
case 25:
|
case 25:
|
||||||
case 144:
|
case 144:
|
||||||
case 138:
|
case 138:
|
||||||
case 176:
|
case 176:
|
||||||
case 177:
|
case 177:
|
||||||
case 63:
|
case 63:
|
||||||
case 68:
|
case 68:
|
||||||
case 323:
|
case 323:
|
||||||
case 117:
|
case 117:
|
||||||
case 116:
|
case 116:
|
||||||
case 28:
|
case 28:
|
||||||
case 66:
|
case 66:
|
||||||
case 157:
|
case 157:
|
||||||
case 61:
|
case 61:
|
||||||
case 62:
|
case 62:
|
||||||
case 140:
|
case 140:
|
||||||
case 146:
|
case 146:
|
||||||
case 149:
|
case 149:
|
||||||
case 150:
|
case 150:
|
||||||
case 158:
|
case 158:
|
||||||
case 23:
|
case 23:
|
||||||
case 123:
|
case 123:
|
||||||
case 124:
|
case 124:
|
||||||
case 29:
|
case 29:
|
||||||
case 33:
|
case 33:
|
||||||
case 151:
|
case 151:
|
||||||
case 178: {
|
case 178: {
|
||||||
// TODO implement fully
|
// TODO implement fully
|
||||||
final BlockState state = block.getState();
|
final BlockState state = block.getState();
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
final StateWrapper wrapper = new StateWrapper(state);
|
final StateWrapper wrapper = new StateWrapper(state);
|
||||||
final CompoundTag rawTag = wrapper.getTag();
|
final CompoundTag rawTag = wrapper.getTag();
|
||||||
if (rawTag != null) {
|
if (rawTag != null) {
|
||||||
final Map<String, Tag> values = new HashMap<String, Tag>();
|
final Map<String, Tag> values = new HashMap<String, Tag>();
|
||||||
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
for (final Entry<String, Tag> entry : rawTag.getValue().entrySet()) {
|
||||||
values.put(entry.getKey(), entry.getValue());
|
values.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
values.put("id", new StringTag("id", wrapper.getId()));
|
values.put("id", new StringTag("id", wrapper.getId()));
|
||||||
values.put("x", new IntTag("x", x));
|
values.put("x", new IntTag("x", x));
|
||||||
values.put("y", new IntTag("y", y));
|
values.put("y", new IntTag("y", y));
|
||||||
values.put("z", new IntTag("z", z));
|
values.put("z", new IntTag("z", z));
|
||||||
final CompoundTag tileEntityTag = new CompoundTag(values);
|
final CompoundTag tileEntityTag = new CompoundTag(values);
|
||||||
tileEntities.add(tileEntityTag);
|
tileEntities.add(tileEntityTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
blockData[index] = block.getData();
|
blockData[index] = block.getData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For optimization reasons, we are not supporting custom data types
|
// For optimization reasons, we are not supporting custom data types
|
||||||
// Especially since the most likely reason beyond this range is modded servers in which the blocks
|
// Especially since the most likely reason beyond this range is modded servers in which the blocks
|
||||||
// have NBT
|
// have NBT
|
||||||
// if (type > 255) {
|
// if (type > 255) {
|
||||||
// if (addBlocks == null) {
|
// if (addBlocks == null) {
|
||||||
// addBlocks = new byte[(blocks.length >> 1) + 1];
|
// addBlocks = new byte[(blocks.length >> 1) + 1];
|
||||||
// }
|
// }
|
||||||
// addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
|
// addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
|
||||||
// (addBlocks[index >> 1] & 0xF0) | ((type >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((type
|
// (addBlocks[index >> 1] & 0xF0) | ((type >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((type
|
||||||
// >> 8) & 0xF) << 4));
|
// >> 8) & 0xF) << 4));
|
||||||
// }
|
// }
|
||||||
blocks[index] = (byte) id;
|
blocks[index] = (byte) id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!chunks.isEmpty()) {
|
if (!chunks.isEmpty()) {
|
||||||
TaskManager.runTaskLater(this, 1);
|
TaskManager.runTaskLater(this, 1);
|
||||||
} else {
|
} else {
|
||||||
regionTask.run();
|
regionTask.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
|
public void restoreTag(CompoundTag ct, short x, short y, short z, Schematic schem) {
|
||||||
new StateWrapper(ct).restoreTag(x, y, z, schem);
|
new StateWrapper(ct).restoreTag(x, y, z, schem);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,193 +1,193 @@
|
|||||||
package com.plotsquared.bukkit.util;
|
package com.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefField;
|
||||||
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
|
||||||
import com.intellectualcrafters.plot.util.TaskManager;
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
|
* An utility that can be used to send chunks, rather than using bukkit code to do so (uses heavy NMS)
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class SendChunk {
|
public class SendChunk {
|
||||||
|
|
||||||
// // Ref Class
|
// // Ref Class
|
||||||
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
private final RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
|
||||||
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
private final RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
|
||||||
private final RefClass classPacket = getRefClass("{nms}.Packet");
|
private final RefClass classPacket = getRefClass("{nms}.Packet");
|
||||||
private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
private final RefClass classConnection = getRefClass("{nms}.PlayerConnection");
|
||||||
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
private final RefClass classChunk = getRefClass("{nms}.Chunk");
|
||||||
private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
private final RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
|
||||||
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
private final RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
|
||||||
private final RefMethod methodGetHandlePlayer;
|
private final RefMethod methodGetHandlePlayer;
|
||||||
private final RefMethod methodGetHandleChunk;
|
private final RefMethod methodGetHandleChunk;
|
||||||
private final RefConstructor MapChunk;
|
private final RefConstructor MapChunk;
|
||||||
private final RefField connection;
|
private final RefField connection;
|
||||||
private final RefMethod send;
|
private final RefMethod send;
|
||||||
private final RefMethod methodInitLighting;
|
private final RefMethod methodInitLighting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public SendChunk() {
|
public SendChunk() {
|
||||||
methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
|
||||||
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
|
||||||
methodInitLighting = classChunk.getMethod("initLighting");
|
methodInitLighting = classChunk.getMethod("initLighting");
|
||||||
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
MapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
|
||||||
connection = classEntityPlayer.getField("playerConnection");
|
connection = classEntityPlayer.getField("playerConnection");
|
||||||
send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChunk(final Collection<Chunk> input) {
|
public void sendChunk(final Collection<Chunk> input) {
|
||||||
final HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
final HashSet<Chunk> chunks = new HashSet<Chunk>(input);
|
||||||
final HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
final HashMap<String, ArrayList<Chunk>> map = new HashMap<>();
|
||||||
final int view = Bukkit.getServer().getViewDistance();
|
final int view = Bukkit.getServer().getViewDistance();
|
||||||
for (final Chunk chunk : chunks) {
|
for (final Chunk chunk : chunks) {
|
||||||
final String world = chunk.getWorld().getName();
|
final String world = chunk.getWorld().getName();
|
||||||
ArrayList<Chunk> list = map.get(world);
|
ArrayList<Chunk> list = map.get(world);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
map.put(world, list);
|
map.put(world, list);
|
||||||
}
|
}
|
||||||
list.add(chunk);
|
list.add(chunk);
|
||||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||||
methodInitLighting.of(c).call();
|
methodInitLighting.of(c).call();
|
||||||
}
|
}
|
||||||
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
|
||||||
PlotPlayer pp = entry.getValue();
|
PlotPlayer pp = entry.getValue();
|
||||||
final Plot plot = pp.getCurrentPlot();
|
final Plot plot = pp.getCurrentPlot();
|
||||||
Location loc = null;
|
Location loc = null;
|
||||||
String world;
|
String world;
|
||||||
if (plot != null) {
|
if (plot != null) {
|
||||||
world = plot.getArea().worldname;
|
world = plot.getArea().worldname;
|
||||||
} else {
|
} else {
|
||||||
loc = pp.getLocation();
|
loc = pp.getLocation();
|
||||||
world = loc.getWorld();
|
world = loc.getWorld();
|
||||||
}
|
}
|
||||||
final ArrayList<Chunk> list = map.get(world);
|
final ArrayList<Chunk> list = map.get(world);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
loc = pp.getLocation();
|
loc = pp.getLocation();
|
||||||
}
|
}
|
||||||
final int cx = loc.getX() >> 4;
|
final int cx = loc.getX() >> 4;
|
||||||
final int cz = loc.getZ() >> 4;
|
final int cz = loc.getZ() >> 4;
|
||||||
final Player player = ((BukkitPlayer) pp).player;
|
final Player player = ((BukkitPlayer) pp).player;
|
||||||
final Object entity = methodGetHandlePlayer.of(player).call();
|
final Object entity = methodGetHandlePlayer.of(player).call();
|
||||||
|
|
||||||
for (final Chunk chunk : list) {
|
for (final Chunk chunk : list) {
|
||||||
final int dx = Math.abs(cx - chunk.getX());
|
final int dx = Math.abs(cx - chunk.getX());
|
||||||
final int dz = Math.abs(cz - chunk.getZ());
|
final int dz = Math.abs(cz - chunk.getZ());
|
||||||
if ((dx > view) || (dz > view)) {
|
if ((dx > view) || (dz > view)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Object c = methodGetHandleChunk.of(chunk).call();
|
final Object c = methodGetHandleChunk.of(chunk).call();
|
||||||
chunks.remove(chunk);
|
chunks.remove(chunk);
|
||||||
final Object con = connection.of(entity).get();
|
final Object con = connection.of(entity).get();
|
||||||
// if (dx != 0 || dz != 0) {
|
// if (dx != 0 || dz != 0) {
|
||||||
// Object packet = MapChunk.create(c, true, 0);
|
// Object packet = MapChunk.create(c, true, 0);
|
||||||
// send.of(con).call(packet);
|
// send.of(con).call(packet);
|
||||||
// }
|
// }
|
||||||
final Object packet = MapChunk.create(c, true, 65535);
|
final Object packet = MapChunk.create(c, true, 65535);
|
||||||
send.of(con).call(packet);
|
send.of(con).call(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final Chunk chunk : chunks) {
|
for (final Chunk chunk : chunks) {
|
||||||
TaskManager.runTask(new Runnable() {
|
TaskManager.runTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
chunk.unload(true, false);
|
chunk.unload(true, false);
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
final String worldname = chunk.getWorld().getName();
|
final String worldname = chunk.getWorld().getName();
|
||||||
PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
||||||
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname
|
PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname
|
||||||
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
+ "/level_old.dat may be corrupt (try repairing or removing these)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// int diffx, diffz;
|
// int diffx, diffz;
|
||||||
// << 4;
|
// << 4;
|
||||||
// for (final Chunk chunk : chunks) {
|
// for (final Chunk chunk : chunks) {
|
||||||
// if (!chunk.isLoaded()) {
|
// if (!chunk.isLoaded()) {
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
// boolean unload = true;
|
// boolean unload = true;
|
||||||
// final Object c = methodGetHandle.of(chunk).call();
|
// final Object c = methodGetHandle.of(chunk).call();
|
||||||
// final Object w = world.of(c).get();
|
// final Object w = world.of(c).get();
|
||||||
// final Object p = players.of(w).get();
|
// final Object p = players.of(w).get();
|
||||||
// for (final Object ep : (List<Object>) p) {
|
// for (final Object ep : (List<Object>) p) {
|
||||||
// final int x = ((Double) locX.of(ep).get()).intValue();
|
// final int x = ((Double) locX.of(ep).get()).intValue();
|
||||||
// final int z = ((Double) locZ.of(ep).get()).intValue();
|
// final int z = ((Double) locZ.of(ep).get()).intValue();
|
||||||
// diffx = Math.abs(x - (chunk.getX() << 4));
|
// diffx = Math.abs(x - (chunk.getX() << 4));
|
||||||
// diffz = Math.abs(z - (chunk.getZ() << 4));
|
// diffz = Math.abs(z - (chunk.getZ() << 4));
|
||||||
// if ((diffx <= view) && (diffz <= view)) {
|
// if ((diffx <= view) && (diffz <= view)) {
|
||||||
// unload = false;
|
// unload = false;
|
||||||
// if (v1_7_10) {
|
// if (v1_7_10) {
|
||||||
// chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
// chunk.getWorld().refreshChunk(chunk.getX(), chunk.getZ());
|
||||||
// chunk.load(true);
|
// chunk.load(true);
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
// final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ());
|
// final Object pair = ChunkCoordIntPairCon.create(chunk.getX(), chunk.getZ());
|
||||||
// final Object pq = chunkCoordIntPairQueue.of(ep).get();
|
// final Object pq = chunkCoordIntPairQueue.of(ep).get();
|
||||||
// ((List) pq).add(pair);
|
// ((List) pq).add(pair);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// if (unload) {
|
// if (unload) {
|
||||||
// TaskManager.runTask(new Runnable() {
|
// TaskManager.runTask(new Runnable() {
|
||||||
// @Override
|
// @Override
|
||||||
// public void run() {
|
// public void run() {
|
||||||
// try {
|
// try {
|
||||||
// chunk.unload(true, true);
|
// chunk.unload(true, true);
|
||||||
// }
|
// }
|
||||||
// catch (Exception e) {
|
// catch (Exception e) {
|
||||||
// String worldname = chunk.getWorld().getName();
|
// String worldname = chunk.getWorld().getName();
|
||||||
// PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
// PS.debug("$4Could not save chunk: " + worldname + ";" + chunk.getX() + ";" + chunk.getZ());
|
||||||
// PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
// PS.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
|
||||||
// PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname + "level_old.dat may be corrupt (try repairing
|
// PS.debug("$3 - $4" + worldname + "/level.dat or " + worldname + "level_old.dat may be corrupt (try repairing
|
||||||
// or removing these)");
|
// or removing these)");
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
|
public void sendChunk(final String worldname, final List<ChunkLoc> locs) {
|
||||||
final World myworld = Bukkit.getWorld(worldname);
|
final World myworld = Bukkit.getWorld(worldname);
|
||||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||||
for (final ChunkLoc loc : locs) {
|
for (final ChunkLoc loc : locs) {
|
||||||
chunks.add(myworld.getChunkAt(loc.x, loc.z));
|
chunks.add(myworld.getChunkAt(loc.x, loc.z));
|
||||||
}
|
}
|
||||||
sendChunk(chunks);
|
sendChunk(chunks);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
name: ${project.name}
|
name: $name
|
||||||
main: com.plotsquared.bukkit.BukkitMain
|
main: com.plotsquared.bukkit.BukkitMain
|
||||||
version: ${project.version}
|
version: $version
|
||||||
load: STARTUP
|
load: STARTUP
|
||||||
description: >
|
description: >
|
||||||
Easy, yet powerful Plot World generation and management.
|
Easy, yet powerful Plot World generation and management.
|
2
Core/build.gradle
Normal file
2
Core/build.gradle
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
apply plugin: 'eclipse'
|
||||||
|
apply plugin: 'idea'
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user