mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-16 20:34:42 +02:00
Refactor + optimizations
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -13,7 +12,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
@ -23,19 +21,16 @@ import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
import com.intellectualcrafters.plot.util.PlotWeather;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
import com.plotsquared.bukkit.util.bukkit.BukkitUtil;
|
||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||
|
||||
public class BukkitPlayer implements PlotPlayer {
|
||||
public class BukkitPlayer extends PlotPlayer {
|
||||
|
||||
public final Player player;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private int op = 0;
|
||||
private long last = 0;
|
||||
public HashSet<String> hasPerm = new HashSet<>();
|
||||
public HashSet<String> noPerm = new HashSet<>();
|
||||
|
||||
private HashMap<String, Object> meta;
|
||||
|
||||
/**
|
||||
* Please do not use this method. Instead use BukkitUtil.getPlayer(Player), as it caches player objects.
|
||||
@ -54,7 +49,8 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return BukkitUtil.getLocation(this.player);
|
||||
Location loc = super.getLocation();
|
||||
return loc == null ? BukkitUtil.getLocation(this.player) : loc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,20 +96,6 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
this.player.teleport(new org.bukkit.Location(BukkitUtil.getWorld(loc.getWorld()), loc.getX() + 0.5, loc.getY(), loc.getZ() + 0.5, loc.getYaw(), loc.getPitch()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
if (this.op != 0) {
|
||||
return this.op != 1;
|
||||
}
|
||||
final boolean result = this.player.isOp();
|
||||
if (!result) {
|
||||
this.op = 1;
|
||||
return false;
|
||||
}
|
||||
this.op = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (this.name == null) {
|
||||
@ -138,34 +120,6 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
return BukkitUtil.getLocationFull(this.player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMeta(String key, Object value) {
|
||||
if (this.meta == null) {
|
||||
this.meta = new HashMap<String, Object>();
|
||||
}
|
||||
this.meta.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMeta(String key) {
|
||||
if (this.meta != null) {
|
||||
return this.meta.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMeta(String key) {
|
||||
if (this.meta != null) {
|
||||
this.meta.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(String key) {
|
||||
key = "plotsquared_user_attributes." + key;
|
||||
@ -202,11 +156,6 @@ public class BukkitPlayer implements PlotPlayer {
|
||||
player.saveData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequiredType getSuperCaller() {
|
||||
return RequiredType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeather(PlotWeather weather) {
|
||||
switch (weather) {
|
||||
|
@ -1,120 +0,0 @@
|
||||
package com.plotsquared.bukkit.object;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
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.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
|
||||
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) {
|
||||
for (short x = 0; x < 16; x++) {
|
||||
for (short z = 0; z < 16; z++) {
|
||||
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
|
||||
final HashMap<Short, Byte> blocks = ChunkManager.GENERATE_DATA.get(loc);
|
||||
for (final Entry<Short, Byte> entry : blocks.entrySet()) {
|
||||
setBlock(x, entry.getKey(), z, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z);
|
||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||
PlotLoc loc;
|
||||
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
|
||||
for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
|
||||
loc = entry.getKey();
|
||||
int xx = loc.x - X;
|
||||
int zz = loc.z - Z;
|
||||
if (xx >= 0 && xx < 16) {
|
||||
if (zz >= 0 && zz < 16) {
|
||||
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz);
|
||||
|
||||
/**
|
||||
* Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param id
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, short id, byte data) {
|
||||
if (data == 0) {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, id);
|
||||
}
|
||||
else {
|
||||
SetBlockQueue.setBlock(worldname, x, y, z, new PlotBlock(id, data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param data
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, byte data) {
|
||||
if (data != 0) {
|
||||
world.getBlockAt(X + x, y, Z + z).setData(data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like setblock, but lacks the data != 0 check
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param data
|
||||
*/
|
||||
public void setBlockAbs(int x, int y, int z, byte data) {
|
||||
world.getBlockAt(X + x, y, Z + z).setData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
|
||||
* @param plot
|
||||
* @param x
|
||||
* @param z
|
||||
* @return
|
||||
*/
|
||||
public boolean contains(final RegionWrapper plot, final int x, final int z) {
|
||||
int xx = X + x;
|
||||
int zz = Z + z;
|
||||
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user