mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-27 19:24:43 +02:00
Trying to reduce reliance on Bukkit
This commit is contained in:
@ -1,5 +1,19 @@
|
||||
package com.plotsquared.bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.intellectualcrafters.plot.IPlotMain;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.commands.MainCommand;
|
||||
@ -7,14 +21,20 @@ import com.intellectualcrafters.plot.commands.WE_Anywhere;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ConsoleColors;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.InventoryUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandlerImplementation;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
import com.plotsquared.bukkit.commands.BukkitCommand;
|
||||
import com.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
||||
@ -22,33 +42,44 @@ import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
||||
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
|
||||
import com.plotsquared.bukkit.generator.HybridGen;
|
||||
import com.plotsquared.bukkit.listeners.*;
|
||||
import com.plotsquared.bukkit.listeners.APlotListener;
|
||||
import com.plotsquared.bukkit.listeners.ChunkListener;
|
||||
import com.plotsquared.bukkit.listeners.ForceFieldListener;
|
||||
import com.plotsquared.bukkit.listeners.PlayerEvents;
|
||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
|
||||
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8_3;
|
||||
import com.plotsquared.bukkit.listeners.PlotListener;
|
||||
import com.plotsquared.bukkit.listeners.PlotPlusListener;
|
||||
import com.plotsquared.bukkit.listeners.TNTListener;
|
||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
|
||||
import com.plotsquared.bukkit.listeners.worldedit.WESubscriber;
|
||||
import com.plotsquared.bukkit.titles.AbstractTitle;
|
||||
import com.plotsquared.bukkit.titles.DefaultTitle;
|
||||
import com.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
import com.plotsquared.bukkit.util.bukkit.*;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitEconHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitEventUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitInventoryUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitPlayerManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitSetBlockManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitSetupUtils;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitTaskManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.Metrics;
|
||||
import com.plotsquared.bukkit.util.bukkit.SendChunk;
|
||||
import com.plotsquared.bukkit.util.bukkit.SetBlockFast;
|
||||
import com.plotsquared.bukkit.util.bukkit.SetBlockFast_1_8;
|
||||
import com.plotsquared.bukkit.util.bukkit.SetBlockSlow;
|
||||
import com.plotsquared.bukkit.util.bukkit.SetGenCB;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.FileUUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.uuid.SQLUUIDHandler;
|
||||
import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@ -79,29 +110,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public void onEnable() {
|
||||
THIS = this;
|
||||
PS.instance = new PS(this);
|
||||
if (Settings.METRICS) {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
} else {
|
||||
log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
|
||||
}
|
||||
List<World> worlds = Bukkit.getWorlds();
|
||||
if (worlds.size() > 0) {
|
||||
UUIDHandler.startCaching(null);
|
||||
for (World world : worlds) {
|
||||
try {
|
||||
SetGenCB.setGenerator(world);
|
||||
} catch (Exception e) {
|
||||
log("Failed to reload world: " + world.getName());
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,15 +150,6 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKick(UUID uuid, C c) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player != null && player.isOnline()) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), c);
|
||||
player.teleport(player.getWorld().getSpawnLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands() {
|
||||
final BukkitCommand bcmd = new BukkitCommand();
|
||||
@ -323,7 +322,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Override
|
||||
public void registerInventoryEvents() {
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
|
||||
// Part of PlayerEvents - can be moved if necessary
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -522,4 +523,25 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
public String getServerName() {
|
||||
return Bukkit.getServerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
log(C.PREFIX.s() + "&6Metrics enabled.");
|
||||
} catch (final Exception e) {
|
||||
log(C.PREFIX.s() + "&cFailed to load up metrics.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(String world) {
|
||||
try {
|
||||
SetGenCB.setGenerator(BukkitUtil.getWorld(world));
|
||||
} catch (Exception e) {
|
||||
log("Failed to reload world: " + world);
|
||||
Bukkit.getServer().unloadWorld(world, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.object.BlockWrapper;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitChunkManager;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitSetBlockManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.plotsquared.bukkit.object.PlotPopulator;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
@ -226,7 +226,7 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
|
||||
*/
|
||||
public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes);
|
||||
|
||||
public abstract List<PlotPopulator> getPopulators(String world);
|
||||
public abstract List<BukkitPlotPopulator> getPopulators(String world);
|
||||
|
||||
/**
|
||||
* This is called when the generator is initialized.
|
||||
|
@ -24,7 +24,7 @@ import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridPop;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.plotsquared.bukkit.object.PlotPopulator;
|
||||
import com.plotsquared.bukkit.object.BukkitPlotPopulator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -169,10 +169,10 @@ public class HybridGen extends BukkitPlotGenerator {
|
||||
/**
|
||||
* Return the block populator
|
||||
*/
|
||||
public List<PlotPopulator> getPopulators(final String world) {
|
||||
public List<BukkitPlotPopulator> getPopulators(final String world) {
|
||||
// You can have as many populators as you would like, e.g. tree
|
||||
// populator, ore populator
|
||||
return Arrays.asList((PlotPopulator) new HybridPop(this.plotworld));
|
||||
return Arrays.asList((BukkitPlotPopulator) new HybridPop(this.plotworld));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,43 +0,0 @@
|
||||
package com.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.plotsquared.bukkit.object.InfoInventory;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
/**
|
||||
* Created 2014-11-18 for PlotSquared
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class InventoryListener implements Listener {
|
||||
@EventHandler
|
||||
public void onInventoryAction(final InventoryInteractEvent event) {
|
||||
if (event.getInventory().getHolder() instanceof InfoInventory) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryClickEvent event) {
|
||||
final Inventory inventory = event.getInventory();
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
if (inventory.getHolder() instanceof InfoInventory) {
|
||||
switch (event.getSlot()) {
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), "This is not implemented yet");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -242,7 +242,7 @@ public class PlayerEvents extends com.plotsquared.bukkit.listeners.PlotListener
|
||||
|
||||
Player player = event.getPlayer();
|
||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||
|
||||
Location loc = pp.getLocation();
|
||||
if (!PS.get().isPlotWorld(BukkitUtil.getWorld(player))) {
|
||||
return;
|
||||
}
|
||||
|
@ -46,6 +46,10 @@ import java.util.UUID;
|
||||
* @author Empire92
|
||||
*/
|
||||
public class PlotListener extends APlotListener {
|
||||
|
||||
// FIXME if we add a few more functions to PlotPlayer, we could make this generic and not implementation specific
|
||||
// TODO Alternatively we could move functions into BukkitPlayerManager which seems to be heavily lacking
|
||||
|
||||
public void textures(final Player p) {
|
||||
if ((Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1) && PS.get().isPlotWorld(p.getWorld().getName())) {
|
||||
p.setResourcePack(Settings.PLOT_SPECIFIC_RESOURCE_PACK);
|
||||
|
@ -92,7 +92,7 @@ public class TNTListener implements Listener {
|
||||
}
|
||||
|
||||
Location landing = loc.add(shortest.getBlockX() + 1, 0, shortest.getBlockZ() + 1);
|
||||
int ty = BukkitUtil.getHeighestBlock(worldname, landing.getX(), landing.getZ());
|
||||
int ty = MainUtil.getHeighestBlock(worldname, landing.getX(), landing.getZ());
|
||||
int diff = ty - loc.getY();
|
||||
double calcDiff = getY(velocity, Math.sqrt(shortest.getBlockX() * shortest.getBlockX() + shortest.getBlockZ() * shortest.getBlockZ()));
|
||||
if (calcDiff > diff) {
|
||||
|
@ -40,9 +40,4 @@ public class WorldEvents implements Listener {
|
||||
}
|
||||
lastWorld = null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void worldLoad(final WorldLoadEvent event) {
|
||||
UUIDHandler.startCaching(null);
|
||||
}
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
||||
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
||||
// /
|
||||
// This program is free software; you can redistribute it and/or modify /
|
||||
// it under the terms of the GNU General Public License as published by /
|
||||
// the Free Software Foundation; either version 3 of the License, or /
|
||||
// (at your option) any later version. /
|
||||
// /
|
||||
// This program is distributed in the hope that it will be useful, /
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
|
||||
// GNU General Public License for more details. /
|
||||
// /
|
||||
// You should have received a copy of the GNU General Public License /
|
||||
// along with this program; if not, write to the Free Software Foundation, /
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
||||
// /
|
||||
// You can contact us via: support@intellectualsites.com /
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Wrapper class for blocks, using pure data rather than the object.
|
||||
*
|
||||
* Useful for NMS
|
||||
*
|
||||
* @author Empire92
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class BlockWrapper {
|
||||
/**
|
||||
* X Coordinate
|
||||
*/
|
||||
public final int x;
|
||||
/**
|
||||
* Y Coordinate
|
||||
*/
|
||||
public final int y;
|
||||
/**
|
||||
* Z Coordinate
|
||||
*/
|
||||
public final int z;
|
||||
/**
|
||||
* Block ID
|
||||
*/
|
||||
public final int id;
|
||||
/**
|
||||
* Block Data Value
|
||||
*/
|
||||
public final byte data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param x X Loc Value
|
||||
* @param y Y Loc Value
|
||||
* @param z Z Loc Value
|
||||
* @param id Material ID
|
||||
* @param data Data Value
|
||||
*/
|
||||
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative Constructor Uses block data, rather than typed data
|
||||
*
|
||||
* @param block Block from which we get the data
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public BlockWrapper(final Block block) {
|
||||
this.x = block.getX();
|
||||
this.y = block.getY();
|
||||
this.z = block.getZ();
|
||||
this.id = block.getTypeId();
|
||||
this.data = block.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a block based on the block wrapper
|
||||
*
|
||||
* @param world World in which the block is/will be, located
|
||||
*
|
||||
* @return block created/fetched from settings
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "deprecation" })
|
||||
public Block toBlock(final World world) {
|
||||
final Block block = world.getBlockAt(this.x, this.y, this.z);
|
||||
block.setTypeIdAndData(this.id, this.data, true);
|
||||
return block;
|
||||
}
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PseudoRandom;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.bukkit.SetBlockFast;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
@ -13,17 +19,20 @@ import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class PlotPopulator extends BlockPopulator {
|
||||
public abstract class BukkitPlotPopulator extends BlockPopulator {
|
||||
|
||||
private PseudoRandom random = new PseudoRandom();
|
||||
|
||||
public int X;
|
||||
public int Z;
|
||||
public String worldname;
|
||||
private World world;
|
||||
|
||||
|
||||
@Override
|
||||
public void populate(World world, Random rand, Chunk chunk) {
|
||||
this.world = world;
|
||||
this.worldname = world.getName();
|
||||
this.X = chunk.getX() << 4;
|
||||
this.Z = chunk.getZ() << 4;
|
||||
if (ChunkManager.FORCE_PASTE) {
|
||||
@ -67,7 +76,12 @@ public abstract class PlotPopulator extends BlockPopulator {
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, short id, byte data) {
|
||||
BukkitUtil.setBlock(world, X + x, y, Z + z, id, data);
|
||||
if (data == 0) {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, id);
|
||||
}
|
||||
else {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, new PlotBlock(id, data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
@ -1,87 +0,0 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created 2014-11-18 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class InfoInventory implements InventoryHolder {
|
||||
private final Plot plot;
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plot from which we take information
|
||||
*/
|
||||
public InfoInventory(final Plot plot, final PlotPlayer plr) {
|
||||
this.plot = plot;
|
||||
this.player = ((BukkitPlayer) plr).player;
|
||||
this.inventory = Bukkit.createInventory(this, 9, "Plot: " + plot.id.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public String getName(final UUID uuid) {
|
||||
final String name = UUIDHandler.getName(this.plot.owner);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public InfoInventory build() {
|
||||
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player));
|
||||
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner), "&cAlias: &6" + this.plot.getSettings().getAlias(), "&cBiome: &6" + this.plot.getSettings().getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
|
||||
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.getTrusted().size(), "&8Click to view a list of the trusted users");
|
||||
final ItemStack members = getItem(Material.EMERALD, "&cMembers", "&cAmount: &6" + this.plot.getMembers().size(), "&8Click to view a list of plot members");
|
||||
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.getDenied().size(), "&8Click to view a list of denied players");
|
||||
final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.getSettings().flags.size(), "&8Click to view a list of plot flags");
|
||||
this.inventory.setItem(2, generalInfo);
|
||||
this.inventory.setItem(3, trusted);
|
||||
this.inventory.setItem(4, members);
|
||||
this.inventory.setItem(5, denied);
|
||||
this.inventory.setItem(6, flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public InfoInventory display() {
|
||||
this.player.closeInventory();
|
||||
this.player.openInventory(this.inventory);
|
||||
return this;
|
||||
}
|
||||
|
||||
private ItemStack getItem(final Material material, final String name, final String... lore) {
|
||||
final ItemStack stack = new ItemStack(material);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
final List<String> lList = new ArrayList<>();
|
||||
for (final String l : lore) {
|
||||
lList.add(ChatColor.translateAlternateColorCodes('&', l));
|
||||
}
|
||||
meta.setLore(lList);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
483
src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java
Normal file
483
src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java
Normal file
@ -0,0 +1,483 @@
|
||||
package com.plotsquared.bukkit.util;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.ClassicPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.plotsquared.bukkit.BukkitMain;
|
||||
import com.plotsquared.bukkit.generator.AugmentedPopulator;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.bukkit.material.Directional;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BukkitHybridUtils extends HybridUtils {
|
||||
|
||||
public static List<ChunkLoc> regions;
|
||||
public static List<ChunkLoc> chunks = new ArrayList<>();
|
||||
public static String world;
|
||||
private static boolean UPDATE = false;
|
||||
public int task;
|
||||
private long last;
|
||||
|
||||
@Override
|
||||
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
|
||||
// TODO Auto-generated method stub
|
||||
// int diff, int variety, int verticies, int rotation, int height_sd
|
||||
|
||||
/*
|
||||
* diff: compare to base by looping through all blocks
|
||||
* variety: add to hashset for each plotblock
|
||||
* height_sd: loop over all blocks and get top block
|
||||
*
|
||||
* verticies: store air map and compare with neighbours
|
||||
* for each block check the adjacent
|
||||
* - Store all blocks then go through in second loop
|
||||
* - recheck each block
|
||||
*
|
||||
*/
|
||||
final World world = Bukkit.getWorld(plot.world);
|
||||
final ChunkGenerator gen = world.getGenerator();
|
||||
if (gen == null) {
|
||||
return;
|
||||
}
|
||||
final BiomeGrid base = new BiomeGrid() { @Override public void setBiome(int a, int b, Biome c) {} @Override public Biome getBiome(int a, int b) {return null;}};
|
||||
Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
final int bx = bot.getX();
|
||||
final int bz = bot.getZ();
|
||||
final int tx = top.getX();
|
||||
final int tz = top.getZ();
|
||||
final int cbx = bx >> 4;
|
||||
final int cbz = bz >> 4;
|
||||
final int ctx = tx >> 4;
|
||||
final int ctz = tz >> 4;
|
||||
final Random r = new Random();
|
||||
AugmentedPopulator.initCache();
|
||||
final int width = tx - bx + 1;
|
||||
final int length = tz - bz + 1;
|
||||
|
||||
System.gc();
|
||||
System.gc();
|
||||
final short[][][] oldblocks = new short[256][width][length];
|
||||
final short[][][] newblocks = new short[256][width][length];
|
||||
|
||||
final List<ChunkLoc> chunks = new ArrayList<>();
|
||||
final List<ChunkLoc> processed_chunks = new ArrayList<>();
|
||||
|
||||
for (int X = cbx; X <= ctx; X++) {
|
||||
for (int Z = cbz; Z <= ctz; Z++) {
|
||||
// Chunk chunk = world.getChunkAt(X, Z);
|
||||
chunks.add(new ChunkLoc(X, Z));
|
||||
}
|
||||
}
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (ChunkLoc chunk : processed_chunks) {
|
||||
short[][] result = gen.generateExtBlockSections(world, r, chunk.x, chunk.z, base);
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
int xb = ((X) << 4) - bx;
|
||||
int zb = ((Z) << 4) - bz;
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
if (result[i] == null) {
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < result[i].length; j++) {
|
||||
int x = AugmentedPopulator.x_loc[i][j] + xb;
|
||||
if (x < 0 || x >= width) continue;
|
||||
int z = AugmentedPopulator.z_loc[i][j] + zb;
|
||||
if (z < 0 || z >= length) continue;
|
||||
int y = AugmentedPopulator.y_loc[i][j];
|
||||
oldblocks[y][x][z] = result[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
int size = width * length;
|
||||
int[] changes = new int[size];
|
||||
int[] faces = new int[size];
|
||||
int[] data = new int[size];
|
||||
int[] air = new int[size];
|
||||
int[] variety = new int[size];
|
||||
|
||||
int i = 0;
|
||||
for (int x = 0; x < width;x++) {
|
||||
for (int z = 0; z < length;z++) {
|
||||
HashSet<Short> types = new HashSet<>();
|
||||
for (int y = 0; y < 256; y++) {
|
||||
short old = oldblocks[y][x][z];
|
||||
short now = newblocks[y][x][z];
|
||||
if (old != now) {
|
||||
changes[i]++;
|
||||
}
|
||||
if (now == 0) {
|
||||
air[i]++;
|
||||
}
|
||||
else {
|
||||
// check verticies
|
||||
// modifications_adjacent
|
||||
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
|
||||
if (newblocks[y - 1][x][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x - 1][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x][z - 1] == 0) faces[i]++;
|
||||
if (newblocks[y + 1][x][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x + 1][z] == 0) faces[i]++;
|
||||
if (newblocks[y][x][z + 1] == 0) faces[i]++;
|
||||
}
|
||||
|
||||
Material material = Material.getMaterial(now);
|
||||
Class<? extends MaterialData> md = material.getData();
|
||||
if (md.equals(Directional.class)) {
|
||||
data[i] += 8;
|
||||
}
|
||||
else if (!md.equals(MaterialData.class)) {
|
||||
data[i]++;
|
||||
}
|
||||
types.add(now);
|
||||
}
|
||||
}
|
||||
variety[i] = types.size();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// analyze plot
|
||||
// put in analysis obj
|
||||
|
||||
// run whenDone
|
||||
PlotAnalysis analysis = new PlotAnalysis();
|
||||
analysis.changes = (int) (MathMan.getMean(changes) * 100);
|
||||
analysis.faces = (int) (MathMan.getMean(faces) * 100);
|
||||
analysis.data = (int) (MathMan.getMean(data) * 100);
|
||||
analysis.air = (int) (MathMan.getMean(air) * 100);
|
||||
analysis.variety = (int) (MathMan.getMean(variety) * 100);
|
||||
|
||||
analysis.changes_sd = (int) (MathMan.getSD(changes, analysis.changes));
|
||||
analysis.faces_sd = (int) (MathMan.getSD(faces, analysis.faces));
|
||||
analysis.data_sd = (int) (MathMan.getSD(data, analysis.data));
|
||||
analysis.air_sd = (int) (MathMan.getSD(air, analysis.air));
|
||||
analysis.variety_sd = (int) (MathMan.getSD(variety, analysis.variety));
|
||||
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(analysis.changes);
|
||||
result.add(analysis.faces);
|
||||
result.add(analysis.data);
|
||||
result.add(analysis.air);
|
||||
result.add(analysis.variety);
|
||||
|
||||
result.add(analysis.changes_sd);
|
||||
result.add(analysis.faces_sd);
|
||||
result.add(analysis.data_sd);
|
||||
result.add(analysis.air_sd);
|
||||
result.add(analysis.variety_sd);
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
System.gc();
|
||||
System.gc();
|
||||
whenDone.value = analysis;
|
||||
whenDone.run();
|
||||
}
|
||||
};
|
||||
System.gc();
|
||||
AugmentedPopulator.initCache();
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int index = chunks.size() - 1;
|
||||
if (index == -1) {
|
||||
PS.get().TASK.cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.runTaskAsync(run);
|
||||
return;
|
||||
}
|
||||
ChunkLoc chunk = chunks.remove(0);
|
||||
world.loadChunk(chunk.x, chunk.z);
|
||||
processed_chunks.add(chunk);
|
||||
int X = chunk.x;
|
||||
int Z = chunk.z;
|
||||
int minX;
|
||||
int minZ;
|
||||
int maxX;
|
||||
int maxZ;
|
||||
if (X == cbx) minX = bx & 0x0f;
|
||||
else minX = 0;
|
||||
if (Z == cbz) minZ = bz & 0x0f;
|
||||
else minZ = 0;
|
||||
if (X == ctx) maxX = tx & 0x0f;
|
||||
else maxX = 16;
|
||||
if (Z == ctz) maxZ = tz & 0x0f;
|
||||
else maxZ = 16;
|
||||
|
||||
int cbx = X << 4;
|
||||
int cbz = Z << 4;
|
||||
|
||||
int xb = (cbx) - bx;
|
||||
int zb = (cbz) - bz;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
int xx = cbx + cbz;
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
int zz = cbz + z;
|
||||
for (int y = 0; y < 256; y++) {
|
||||
Block block = world.getBlockAt(xx, y, zz);
|
||||
int xr = xb + x;
|
||||
int zr = zb + z;
|
||||
newblocks[y][xr][zr] = (short) block.getTypeId();
|
||||
}
|
||||
}
|
||||
}
|
||||
world.unloadChunkRequest(chunk.x, chunk.z, true);
|
||||
}
|
||||
}, 1);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
}
|
||||
|
||||
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
|
||||
TaskManager.index.incrementAndGet();
|
||||
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
int bx = bot.getX() >> 4;
|
||||
int bz = bot.getZ() >> 4;
|
||||
int tx = top.getX() >> 4;
|
||||
int tz = top.getZ() >> 4;
|
||||
World world = BukkitUtil.getWorld(plot.world);
|
||||
final HashSet<Chunk> chunks = new HashSet<>();
|
||||
for (int X = bx; X <= tx; X++) {
|
||||
for (int Z = bz; Z <= tz; Z++) {
|
||||
chunks.add(world.getChunkAt(X,Z));
|
||||
}
|
||||
}
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
if (!(plotworld instanceof ClassicPlotWorld)) {
|
||||
whenDone.value = -1;
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
|
||||
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
|
||||
final Integer currentIndex = TaskManager.index.get();
|
||||
final Integer task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (chunks.size() == 0) {
|
||||
whenDone.value = count.intValue();
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
||||
TaskManager.tasks.remove(currentIndex);
|
||||
return;
|
||||
}
|
||||
Iterator<Chunk> iter = chunks.iterator();
|
||||
final Chunk chunk = iter.next();
|
||||
iter.remove();
|
||||
int bx = Math.max(chunk.getX() << 4, bot.getX());
|
||||
int bz = Math.max(chunk.getZ() << 4, bot.getZ());
|
||||
int ex = Math.min((chunk.getX() << 4) + 15, top.getX());
|
||||
int ez = Math.min((chunk.getZ() << 4) + 15, top.getZ());
|
||||
// count changes
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez, cpw.MAIN_BLOCK));
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK));
|
||||
count.addAndGet(checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) }));
|
||||
}
|
||||
}, 1);
|
||||
TaskManager.tasks.put(currentIndex, task);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkModified(final String worldname, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
int count = 0;
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int z = z1; z <= z2; z++) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
final int id = block.getTypeId();
|
||||
boolean same = false;
|
||||
for (final PlotBlock p : blocks) {
|
||||
if (id == p.id) {
|
||||
same = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!same) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get_ey(final String worldname, final int sx, final int ex, final int sz, final int ez, final int sy) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
final int maxY = world.getMaxHeight();
|
||||
int ey = sy;
|
||||
for (int x = sx; x <= ex; x++) {
|
||||
for (int z = sz; z <= ez; z++) {
|
||||
for (int y = sy; y < maxY; y++) {
|
||||
if (y > ey) {
|
||||
final Block block = world.getBlockAt(x, y, z);
|
||||
if (block.getTypeId() != 0) {
|
||||
ey = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ey;
|
||||
}
|
||||
|
||||
public void regenerateChunkChunk(final String worldname, final ChunkLoc loc) {
|
||||
final World world = BukkitUtil.getWorld(worldname);
|
||||
final int sx = loc.x << 5;
|
||||
final int sz = loc.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
final Chunk chunk = world.getChunkAt(x, z);
|
||||
chunk.load(false);
|
||||
}
|
||||
}
|
||||
final ArrayList<Chunk> chunks2 = new ArrayList<>();
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
final Chunk chunk = world.getChunkAt(x, z);
|
||||
chunks2.add(chunk);
|
||||
regenerateRoad(worldname, new ChunkLoc(x, z), 0);
|
||||
MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final ArrayList<ChunkLoc> getChunks(ChunkLoc region) {
|
||||
ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
|
||||
final int sx = region.x << 5;
|
||||
final int sz = region.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
chunks.add(new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean scheduleRoadUpdate(final String world, int extend) {
|
||||
if (BukkitHybridUtils.UPDATE) {
|
||||
return false;
|
||||
}
|
||||
BukkitHybridUtils.UPDATE = true;
|
||||
final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
|
||||
return scheduleRoadUpdate(world, regions, extend);
|
||||
}
|
||||
|
||||
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
|
||||
BukkitHybridUtils.regions = rgs;
|
||||
BukkitHybridUtils.world = world;
|
||||
chunks = new ArrayList<ChunkLoc>();
|
||||
final Plugin plugin = BukkitMain.THIS;
|
||||
final AtomicInteger count = new AtomicInteger(0);
|
||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
count.incrementAndGet();
|
||||
if (count.intValue() % 20 == 0) {
|
||||
PS.log("PROGRESS: " + ((100 * (2048 - chunks.size())) / 2048) + "%");
|
||||
}
|
||||
if (regions.size() == 0 && chunks.size() == 0) {
|
||||
BukkitHybridUtils.UPDATE = false;
|
||||
PS.log(C.PREFIX.s() + "Finished road conversion");
|
||||
Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
if (chunks.size() < 1024) {
|
||||
if (regions.size() > 0) {
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.log("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
|
||||
PS.log(" - Remaining: " + regions.size());
|
||||
chunks.addAll(getChunks(loc));
|
||||
regions.remove(0);
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
if (chunks.size() > 0) {
|
||||
long diff = System.currentTimeMillis() + 25;
|
||||
if (System.currentTimeMillis() - last > 1200 && last != 0) {
|
||||
last = 0;
|
||||
PS.log(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s");
|
||||
while (chunks.size() > 0) {
|
||||
ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
regenerateRoad(world, chunk, extend);
|
||||
ChunkManager.manager.unloadChunk(world, chunk, true, true);
|
||||
}
|
||||
Bukkit.getScheduler().cancelTask(BukkitHybridUtils.this.task);
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scheduleRoadUpdate(world, regions, extend);
|
||||
}
|
||||
}, 600);
|
||||
return;
|
||||
}
|
||||
if (System.currentTimeMillis() - last < 1000) {
|
||||
while (System.currentTimeMillis() < diff && chunks.size() > 0) {
|
||||
ChunkLoc chunk = chunks.get(0);
|
||||
chunks.remove(0);
|
||||
regenerateRoad(world, chunk, extend);
|
||||
ChunkManager.manager.unloadChunk(world, chunk, true, true);
|
||||
}
|
||||
}
|
||||
last = System.currentTimeMillis();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
final ChunkLoc loc = regions.get(0);
|
||||
PS.log("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
|
||||
final int sx = loc.x << 5;
|
||||
final int sz = loc.z << 5;
|
||||
for (int x = sx; x < (sx + 32); x++) {
|
||||
for (int z = sz; z < (sz + 32); z++) {
|
||||
ChunkManager.manager.unloadChunk(world, new ChunkLoc(x, z), true, true);
|
||||
}
|
||||
}
|
||||
PS.log("&d - Potentially skipping 1024 chunks");
|
||||
PS.log("&d - TODO: recommend chunkster if corrupt");
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20, 20);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -929,13 +929,13 @@ public class BukkitChunkManager extends ChunkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc) {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(false);
|
||||
public boolean loadChunk(final String world, final ChunkLoc loc, boolean force) {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).load(force);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc) {
|
||||
return BukkitUtil.getWorld(world).getChunkAt(loc.x, loc.z).unload(true, true);
|
||||
public boolean unloadChunk(final String world, final ChunkLoc loc, boolean save, boolean safe) {
|
||||
return BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
|
||||
}
|
||||
|
||||
public static void swapChunk(final World world, final Chunk pos1, final Chunk pos2, final RegionWrapper r1, final RegionWrapper r2) {
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.plotsquared.bukkit.util.bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import org.bukkit.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -17,11 +17,22 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.*;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Sandstone;
|
||||
import org.bukkit.material.Step;
|
||||
import org.bukkit.material.Tree;
|
||||
import org.bukkit.material.WoodenStep;
|
||||
import org.bukkit.material.Wool;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.object.BukkitPlayer;
|
||||
|
||||
public class BukkitUtil extends BlockManager {
|
||||
private static HashMap<String, World> worlds = new HashMap<>();
|
||||
@ -36,12 +47,71 @@ public class BukkitUtil extends BlockManager {
|
||||
lastPlotPlayer = null;
|
||||
UUIDHandler.getPlayers().remove(plr);
|
||||
}
|
||||
|
||||
// These weren't being used, but they might be useful later, so I'm just commenting them out
|
||||
// private static int getMaxHeight(final String world) {
|
||||
// return getWorld(world).getMaxHeight();
|
||||
// }
|
||||
//
|
||||
// private static void unloadChunkAt(String worldname, int X, int Z, boolean save, boolean safe) {
|
||||
// final World world = getWorld(worldname);
|
||||
// world.unloadChunk(X, Z, save, safe);
|
||||
// }
|
||||
//
|
||||
// private static void loadChunkAt(final String worldname, int X, int Z, boolean force) {
|
||||
// final World world = getWorld(worldname);
|
||||
// world.loadChunk(X, Z, force);
|
||||
// }
|
||||
//
|
||||
// private static Chunk getChunkAt(final String worldname, final int x, final int z) {
|
||||
// final World world = getWorld(worldname);
|
||||
// return world.getChunkAt(x, z);
|
||||
// }
|
||||
//
|
||||
// private static void teleportPlayer(final Player player, final Location loc) {
|
||||
// final org.bukkit.Location bukkitLoc = new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ());
|
||||
// player.teleport(bukkitLoc);
|
||||
// }
|
||||
//
|
||||
// private static void setBiome(final String worldname, final int pos1_x, final int pos1_z, final int pos2_x, final int pos2_z, final String biome) {
|
||||
// final Biome b = Biome.valueOf(biome.toUpperCase());
|
||||
// final World world = getWorld(worldname);
|
||||
// for (int x = pos1_x; x <= pos2_x; x++) {
|
||||
// for (int z = pos1_z; z <= pos2_z; z++) {
|
||||
// if (world.getBiome(x, z) == b) {
|
||||
// continue;
|
||||
// }
|
||||
// world.setBiome(x, z, b);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void refreshChunk(final String name, final int x, final int z) {
|
||||
// World world = getWorld(name);
|
||||
// world.refreshChunk(x, z);
|
||||
// world.loadChunk(x, z);
|
||||
// }
|
||||
//
|
||||
// private static void regenerateChunk(final String world, final int x, final int z) {
|
||||
// World worldObj = getWorld(world);
|
||||
// Chunk chunk = worldObj.getChunkAt(x, z);
|
||||
// if (chunk.isLoaded() || chunk.load(false)) {
|
||||
// ChunkManager.manager.regenerateChunk(world, new ChunkLoc(x, z));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static Location getLocationFull(final org.bukkit.Location loc) {
|
||||
// final String world = loc.getWorld().getName();
|
||||
// return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch());
|
||||
// }
|
||||
//
|
||||
// private static int getViewDistance() {
|
||||
// return Bukkit.getViewDistance();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world) {
|
||||
return getWorld(world) != null;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/////////////////// USED BY EVENT SYSTEM AND SUCH //////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
public static PlotPlayer getPlayer(final OfflinePlayer op) {
|
||||
if (op.isOnline()) {
|
||||
return getPlayer(op.getPlayer());
|
||||
@ -66,11 +136,6 @@ public class BukkitUtil extends BlockManager {
|
||||
return lastPlotPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBiome(final Location loc) {
|
||||
return getWorld(loc.getWorld()).getBiome(loc.getX(), loc.getZ()).name();
|
||||
}
|
||||
|
||||
public static Location getLocation(final org.bukkit.Location loc) {
|
||||
return new Location(loc.getWorld().getName(), (int) loc.getX(), (int) loc.getY(), (int) loc.getZ());
|
||||
}
|
||||
@ -91,99 +156,14 @@ public class BukkitUtil extends BlockManager {
|
||||
return world;
|
||||
}
|
||||
|
||||
public static int getMaxHeight(final String world) {
|
||||
return getWorld(world).getMaxHeight();
|
||||
}
|
||||
|
||||
public static int getHeighestBlock(final String world, final int x, final int z) {
|
||||
return getWorld(world).getHighestBlockYAt(x, z);
|
||||
}
|
||||
|
||||
public static void unloadChunkAt(String worldname, int X, int Z, boolean save, boolean safe) {
|
||||
final World world = getWorld(worldname);
|
||||
world.unloadChunk(X, Z, save, safe);
|
||||
}
|
||||
|
||||
public static void loadChunkAt(final String worldname, int X, int Z, boolean force) {
|
||||
final World world = getWorld(worldname);
|
||||
world.loadChunk(X, Z, force);
|
||||
}
|
||||
|
||||
public static Chunk getChunkAt(final String worldname, final int x, final int z) {
|
||||
final World world = getWorld(worldname);
|
||||
return world.getChunkAt(x, z);
|
||||
}
|
||||
|
||||
// public static void update(final String world, final int x, final int z) {
|
||||
// final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
// final int distance = Bukkit.getViewDistance();
|
||||
// for (int cx = -distance; cx < distance; cx++) {
|
||||
// for (int cz = -distance; cz < distance; cz++) {
|
||||
// final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz);
|
||||
// chunks.add(chunk);
|
||||
// }
|
||||
// }
|
||||
// BukkitSetBlockManager.setBlockManager.update(chunks);
|
||||
// }
|
||||
|
||||
public static String getWorld(final Entity entity) {
|
||||
return entity.getWorld().getName();
|
||||
}
|
||||
|
||||
public static void teleportPlayer(final Player player, final Location loc) {
|
||||
final org.bukkit.Location bukkitLoc = new org.bukkit.Location(getWorld(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ());
|
||||
player.teleport(bukkitLoc);
|
||||
}
|
||||
|
||||
public static List<Entity> getEntities(final String worldname) {
|
||||
return getWorld(worldname).getEntities();
|
||||
}
|
||||
|
||||
public static void setBlock(final World world, final int x, final int y, final int z, final int id, final byte data) {
|
||||
try {
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
} catch (final Throwable e) {
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBiome(final String worldname, final int pos1_x, final int pos1_z, final int pos2_x, final int pos2_z, final String biome) {
|
||||
final Biome b = Biome.valueOf(biome.toUpperCase());
|
||||
final World world = getWorld(worldname);
|
||||
for (int x = pos1_x; x <= pos2_x; x++) {
|
||||
for (int z = pos1_z; z <= pos2_z; z++) {
|
||||
if (world.getBiome(x, z) == b) {
|
||||
continue;
|
||||
}
|
||||
world.setBiome(x, z, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshChunk(final String name, final int x, final int z) {
|
||||
World world = getWorld(name);
|
||||
world.refreshChunk(x, z);
|
||||
world.loadChunk(x, z);
|
||||
}
|
||||
|
||||
public static void regenerateChunk(final String world, final int x, final int z) {
|
||||
World worldObj = getWorld(world);
|
||||
Chunk chunk = worldObj.getChunkAt(x, z);
|
||||
if (chunk.isLoaded() || chunk.load(false)) {
|
||||
ChunkManager.manager.regenerateChunk(world, new ChunkLoc(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
public static PlotBlock getBlock(final Location loc) {
|
||||
final World world = getWorld(loc.getWorld());
|
||||
final Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (block == null) {
|
||||
return new PlotBlock((short) 0, (byte) 0);
|
||||
}
|
||||
return new PlotBlock((short) block.getTypeId(), block.getData());
|
||||
}
|
||||
|
||||
|
||||
public static Location getLocation(final Entity entity) {
|
||||
final org.bukkit.Location loc = entity.getLocation();
|
||||
final String world = loc.getWorld().getName();
|
||||
@ -193,10 +173,31 @@ public class BukkitUtil extends BlockManager {
|
||||
public static Location getLocationFull(final Entity entity) {
|
||||
return getLocation(entity.getLocation());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public static Location getLocationFull(final org.bukkit.Location loc) {
|
||||
final String world = loc.getWorld().getName();
|
||||
return new Location(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getYaw(), loc.getPitch());
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////// CLASS ONLY METHODS //////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
private static void setBlock(final World world, final int x, final int y, final int z, final int id, final byte data) {
|
||||
try {
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
} catch (final Throwable e) {
|
||||
BukkitSetBlockManager.setBlockManager = new SetBlockSlow();
|
||||
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id, data);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public boolean isWorld(final String world) {
|
||||
return getWorld(world) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBiome(String world, int x, int z) {
|
||||
return getWorld(world).getBiome(x, z).name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -222,16 +223,12 @@ public class BukkitUtil extends BlockManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getViewDistance() {
|
||||
return Bukkit.getViewDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void functionSetBiomes(final String worldname, final int[] x, final int[] z, final int[] biome) {
|
||||
public void functionSetBiomes(final String worldname, final int[] x, final int[] z, final String biomeStr) {
|
||||
final World world = getWorld(worldname);
|
||||
final Biome[] biomes = Biome.values();
|
||||
final Biome biome = Biome.valueOf(biomeStr.toUpperCase());
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
world.setBiome(x[i], z[i], biomes[biome[i]]);
|
||||
world.setBiome(x[i], z[i], biome);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,8 +256,8 @@ public class BukkitUtil extends BlockManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeighestBlock(final Location loc) {
|
||||
return getWorld(loc.getWorld()).getHighestBlockAt(loc.getX(), loc.getZ()).getY();
|
||||
public int getHeighestBlock(String world, int x, int z) {
|
||||
return getWorld(world).getHighestBlockAt(x, z).getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -383,4 +380,14 @@ public class BukkitUtil extends BlockManager {
|
||||
catch (Exception e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlotBlock getBlock(Location loc) {
|
||||
final World world = getWorld(loc.getWorld());
|
||||
final Block block = world.getBlockAt(loc.getX(), loc.getY(), loc.getZ());
|
||||
if (block == null) {
|
||||
return new PlotBlock((short) 0, (byte) 0);
|
||||
}
|
||||
return new PlotBlock((short) block.getTypeId(), block.getData());
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ public class CommandManager<T extends CommandCaller> {
|
||||
}
|
||||
|
||||
final public void addCommand(final Command<T> command) {
|
||||
if (command.getCommand() == null) {
|
||||
command.create();
|
||||
}
|
||||
this.commands.put(command.getCommand().toLowerCase(), command);
|
||||
for (String alias : command.getAliases()) {
|
||||
this.commands.put(alias.toLowerCase(), command);
|
||||
|
@ -11,6 +11,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.plotsquared.bukkit.listeners.APlotListener;
|
||||
import com.plotsquared.bukkit.util.SetupUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Server;
|
||||
@ -172,12 +173,6 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleKick(UUID uuid, C c) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskManager getTaskManager() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -327,4 +322,16 @@ public class SpongeMain implements IPlotMain, PluginContainer {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMetrics() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenerator(String world) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user