mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-17 12:54:43 +02:00
Trying to reduce reliance on Bukkit
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user