Removal of many prefixes and deprecation of FaweLocation

- Removed some prefixes to help make upstream merging a bit easier.
- Replaced reflection code for titles with the regular bukkit api.
- Removed FAWELocation and FAWEPlayer where it wasn't needed.
- Deprecated FaweLocation since having it in the first place is very stupid.
- FAWEPlayer should also be deprecated soon because the majority of that code is redundant.
This commit is contained in:
MattBDev
2019-06-05 21:17:34 -04:00
parent bf5d2c2788
commit b42553116c
21 changed files with 161 additions and 507 deletions

View File

@ -373,7 +373,7 @@ public class FaweAPI {
long value = aI - bI;
return value == 0 ? 0 : value < 0 ? -1 : 1;
});
RegionWrapper bounds = new RegionWrapper(origin.x - radius, origin.x + radius, origin.z - radius, origin.z + radius);
RegionWrapper bounds = new RegionWrapper(origin.getX() - radius, origin.getX() + radius, origin.getZ() - radius, origin.getZ() + radius);
RegionWrapper boundsPlus = new RegionWrapper(bounds.minX - 64, bounds.maxX + 512, bounds.minZ - 64, bounds.maxZ + 512);
HashSet<RegionWrapper> regionSet = Sets.<RegionWrapper>newHashSet(bounds);
ArrayList<DiskStorageHistory> result = new ArrayList<>();

View File

@ -67,9 +67,9 @@ public class Rollback extends FaweCommand {
long total = 0;
player.sendMessage("&d=| Username | Bounds | Distance | Changes | Age |=");
for (DiskStorageHistory edit : edits) {
DiskStorageHistory.DiskStorageSummary summary = edit.summarize(new RegionWrapper(origin.x, origin.x, origin.z, origin.z), !player.hasPermission("fawe.rollback.deep"));
DiskStorageHistory.DiskStorageSummary summary = edit.summarize(new RegionWrapper(origin.getX(), origin.getX(), origin.getZ(), origin.getZ()), !player.hasPermission("fawe.rollback.deep"));
RegionWrapper region = new RegionWrapper(summary.minX, summary.maxX, summary.minZ, summary.maxZ);
int distance = region.distance(origin.x, origin.z);
int distance = region.distance(origin.getX(), origin.getZ());
String name = Fawe.imp().getName(edit.getUUID());
long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
total += edit.getBDFile().length();
@ -101,7 +101,7 @@ public class Rollback extends FaweCommand {
BBC.NO_PERM.send(player, "fawe.rollback.perform");
return false;
}
final List<DiskStorageHistory> edits = (List<DiskStorageHistory>) player.getMeta(FawePlayer.METADATA_KEYS.ROLLBACK);
final List<DiskStorageHistory> edits = player.getMeta(FawePlayer.METADATA_KEYS.ROLLBACK);
player.deleteMeta(FawePlayer.METADATA_KEYS.ROLLBACK);
if (edits == null) {
BBC.COMMAND_SYNTAX.send(player, "/frb info u:<uuid> r:<radius> t:<time>");
@ -148,7 +148,7 @@ public class Rollback extends FaweCommand {
} else {
user = Fawe.imp().getUUID(split[1]);
}
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
}
if (user == null) {
player.sendMessage("&dInvalid user: " + split[1]);

View File

@ -250,7 +250,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
this.player = player;
if (player != null) {
FaweLocation pos = player.getLocation();
this.chunkOffset = BlockVector2.at(1 + (pos.x >> 4), 1 + (pos.z >> 4));
this.chunkOffset = BlockVector2.at(1 + (pos.getX() >> 4), 1 + (pos.getZ() >> 4));
}
}
@ -292,8 +292,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
int OZ = chunkOffset.getBlockZ();
FaweLocation position = player.getLocation();
int pcx = (position.x >> 4) - OX;
int pcz = (position.z >> 4) - OZ;
int pcx = (position.getX() >> 4) - OX;
int pcz = (position.getZ() >> 4) - OZ;
int scx = Math.max(0, pcx - 15);
int scz = Math.max(0, pcz - 15);
@ -902,8 +902,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr
int OZ = chunkOffset.getBlockZ();
FaweLocation position = player.getLocation();
int pcx = (position.x >> 4) - OX;
int pcz = (position.z >> 4) - OZ;
int pcx = (position.getX() >> 4) - OX;
int pcz = (position.getZ() >> 4) - OZ;
int scx = Math.max(0, pcx - 10);
int scz = Math.max(0, pcz - 10);

View File

@ -1,23 +1,58 @@
package com.boydti.fawe.object;
import com.boydti.fawe.FaweAPI;
import com.sk89q.worldedit.math.*;
import com.sk89q.worldedit.world.World;
import jdk.nashorn.internal.ir.Block;
/**
* @deprecated This is likely to be removed in favor of {@link com.sk89q.worldedit.util.Location}.
*/
@Deprecated
public class FaweLocation {
public final BlockVector3 vector;
@Deprecated
public final int x;
public final int y;
@Deprecated
public final int z;
@Deprecated
public final int y;
public final String world;
public FaweLocation(final String world, final int x, final int y, final int z) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.vector = BlockVector3.at(x,y,z);
this.x = vector.getX();
this.y = vector.getY();
this.z = vector.getZ();
}
/**
* Get the X coordinate.
*
* @return the x coordinate
*/
public int getX() {
return vector.getX();
}
/**
* Get the Y coordinate.
*
* @return the y coordinate
*/
public int getY() {
return vector.getY();
}
/**
* Get the Z coordinate.
*
* @return the z coordinate
*/
public int getZ() {
return vector.getZ();
}
@Override

View File

@ -11,12 +11,10 @@ import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.*;
import com.boydti.fawe.wrappers.FakePlayer;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.*;
@ -63,15 +61,9 @@ public abstract class FawePlayer<T> extends Metadatable {
* @return
*/
public static <V> FawePlayer<V> wrap(Object obj) {
if (obj == null || (obj instanceof String && obj.equals("*"))) {
return FakePlayer.getConsole().toFawePlayer();
}
if (obj instanceof FawePlayer) {
return (FawePlayer<V>) obj;
}
if (obj instanceof FakePlayer) {
return ((FakePlayer) obj).toFawePlayer();
}
if (obj instanceof Player) {
Player actor = LocationMaskedPlayerWrapper.unwrap((Player) obj);
if (obj instanceof PlayerProxy) {
@ -95,9 +87,7 @@ public abstract class FawePlayer<T> extends Metadatable {
if (existing != null) {
return existing;
}
FakePlayer fake = new FakePlayer(actor.getName(), actor.getUniqueId(), actor);
return fake.toFawePlayer();
}
}
if (obj.getClass().getName().contains("CraftPlayer") && !Fawe.imp().getPlatform().equals("bukkit")) {
try {
Method methodGetHandle = obj.getClass().getDeclaredMethod("getHandle");

View File

@ -75,8 +75,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
default BlockState getLazyBlock(int x, int y, int z) {
int combinedId4Data = getCachedCombinedId4Data(x, y, z, BlockTypes.AIR.getInternalId());
try {
BlockState state = BlockState.getFromInternalId(combinedId4Data);
return state;
return BlockState.getFromInternalId(combinedId4Data);
} catch (Throwable e) {
MainUtil.handleError(e);
return BlockTypes.AIR.getDefaultState();
@ -85,7 +84,7 @@ public interface FaweQueue extends HasFaweQueue, Extent {
@Override
default <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
return setBlock(x, y, z, block.getInternalId(), block instanceof BaseBlock ? ((BaseBlock)block).getNbtData() : null);
return setBlock(x, y, z, block.getInternalId(), block instanceof BaseBlock ? block.getNbtData() : null);
}
@Override

View File

@ -214,8 +214,8 @@ public class SchemVis extends ImmutableVirtualWorld {
if (chunks.size() > 225) {
synchronized (SchemVis.this) {
FaweLocation pos = player.getLocation();
int centerX = pos.x >> 4;
int centerZ = pos.z >> 4;
int centerX = pos.getX() >> 4;
int centerZ = pos.getZ() >> 4;
ObjectIterator<Long2ObjectMap.Entry<MCAChunk>> iter = chunks.long2ObjectEntrySet().fastIterator();
while (iter.hasNext()) {
Long2ObjectMap.Entry<MCAChunk> entry = iter.next();
@ -274,7 +274,7 @@ public class SchemVis extends ImmutableVirtualWorld {
}
private Map.Entry<File, Long> getEntry(File file, long position) {
return new AbstractMap.SimpleEntry(file, position);
return new AbstractMap.SimpleEntry<>(file, position);
}
/**
@ -554,8 +554,8 @@ public class SchemVis extends ImmutableVirtualWorld {
int OZ = chunkOffset.getBlockZ();
FaweLocation position = player.getLocation();
int pcx = (position.x >> 4) - OX;
int pcz = (position.z >> 4) - OZ;
int pcx = (position.getX() >> 4) - OX;
int pcz = (position.getZ() >> 4) - OZ;
int scx = pcx - 15;
int scz = pcz - 15;
@ -564,9 +564,7 @@ public class SchemVis extends ImmutableVirtualWorld {
for (int cz = scz; cz <= ecz; cz++) {
for (int cx = scx; cx <= ecx; cx++) {
final int finalCX = cx;
final int finalCZ = cz;
send(packetQueue, finalCX, finalCZ);
send(packetQueue, cx, cz);
}
}
}
@ -607,8 +605,8 @@ public class SchemVis extends ImmutableVirtualWorld {
int OZ = chunkOffset.getBlockZ();
FaweLocation position = player.getLocation();
int pcx = (position.x >> 4) - OX;
int pcz = (position.z >> 4) - OZ;
int pcx = (position.getX() >> 4) - OX;
int pcz = (position.getZ() >> 4) - OZ;
int scx = pcx - 15;
int scz = pcz - 15;

View File

@ -90,7 +90,7 @@ public class WEManager {
return new Region[]{RegionWrapper.GLOBAL()};
}
FaweLocation loc = player.getLocation();
String world = loc.world;
String world = player.getWorld().getName();
if (!world.equals(player.getMeta("lastMaskWorld"))) {
player.deleteMeta("lastMaskWorld");
player.deleteMeta("lastMask");
@ -112,7 +112,7 @@ public class WEManager {
FaweMask mask = iter.next();
if (mask.isValid(player, type)) {
Region region = mask.getRegion();
if (region.contains(loc.x, loc.y, loc.z)) {
if (region.contains(loc.vector)) {
regions.add(region);
} else {
removed = true;
@ -144,12 +144,7 @@ public class WEManager {
}
}
}
if (!tmpMasks.isEmpty()) {
masks = tmpMasks;
regions = masks.stream().map(FaweMask::getRegion).collect(Collectors.toSet());
} else {
regions.addAll(backupRegions);
}
regions.addAll(backupRegions);
if (!masks.isEmpty()) {
player.setMeta("lastMask", masks);
} else {

View File

@ -1,313 +0,0 @@
package com.boydti.fawe.wrappers;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.FaweLocation;
import com.boydti.fawe.object.FawePlayer;
import com.google.common.base.Charsets;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.*;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.NullWorld;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.item.ItemTypes;
import java.util.UUID;
import javax.annotation.Nullable;
/**
* Only really useful for executing commands from console<br>
* - The API itself doesn't any fake player anywhere
*/
public class FakePlayer extends AbstractPlayerActor {
private static FakePlayer CONSOLE;
public static FakePlayer getConsole() {
if (CONSOLE == null) {
CONSOLE = new FakePlayer("#CONSOLE", null, null) {
@Override
public boolean hasPermission(String permission) {
return true;
}
};
}
return CONSOLE;
}
private final Actor parent;
private final String name;
private final UUID uuid;
private World world;
private Location pos;
public static FakePlayer wrap(String name, UUID uuid, Actor parent) {
if (parent != null && parent.getUniqueId().toString().equals("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be")) {
return getConsole();
}
return new FakePlayer(name, uuid, parent);
}
public FakePlayer(String name, UUID uuid, Actor parent) {
this.name = name;
this.uuid = uuid == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)) : uuid;
try {
this.world = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.WORLD_EDITING).getWorlds().get(0);
} catch (NoCapablePlatformException e) {
this.world = NullWorld.getInstance();
}
this.pos = new Location(world, 0, 0, 0);
this.parent = parent;
}
private FawePlayer fp = null;
public FawePlayer toFawePlayer() {
if (fp != null) {
Fawe.get().register(fp);
return fp;
}
FawePlayer existing = Fawe.get().getCachedPlayer(getName());
if (existing != null) {
return fp = existing;
}
final Actor actor = this;
return fp = new FawePlayer(this) {
@Override
public void sendTitle(String head, String sub) {
}
@Override
public void resetTitle() {
}
@Override
public String getName() {
return actor.getName();
}
@Override
public UUID getUUID() {
return actor.getUniqueId();
}
@Override
public boolean hasPermission(String perm) {
return actor.hasPermission(perm) || (Boolean) getMeta("perm." + perm, false);
}
@Override
public void setPermission(String perm, boolean flag) {
setMeta("perm." + perm, true);
}
@Override
public void sendMessage(String message) {
actor.print(message);
}
@Override
public void executeCommand(String substring) {
CommandManager.getInstance().handleCommand(new CommandEvent(actor, substring));
}
@Override
public FaweLocation getLocation() {
Location loc = FakePlayer.this.getLocation();
String world;
if (loc.getExtent() instanceof World) {
world = ((World) loc.getExtent()).getName();
} else {
world = loc.getExtent().toString();
}
return new FaweLocation(world, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
@Override
public Player toWorldEditPlayer() {
return FakePlayer.this;
}
};
}
@Override
public World getWorld() {
return world;
}
@Override
public BaseItemStack getItemInHand(HandSide handSide) {
return new BaseItemStack(ItemTypes.AIR, 0);
}
@Override
public BaseBlock getBlockInHand(HandSide ignore) {
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@Override
public void giveItem(BaseItemStack itemStack) {
}
@Override
public BlockBag getInventoryBlockBag() {
return null;
}
@Override
public void setPosition(Vector3 pos, float pitch, float yaw) {
//TODO: find replacement for following code
// if (pos instanceof Location) {
// Extent extent = ((Location) pos).getExtent();
// if (extent instanceof World) this.world = (World) extent;
// }
this.pos = new Location(world, pos, yaw, pitch);
}
@Nullable
@Override
public BaseEntity getState() {
return null;
}
@Override
public Location getLocation() {
return pos;
}
@Override
public String getName() {
if (parent != null) {
return parent.getName();
}
return name;
}
@Override
public void printRaw(String msg) {
if (parent != null) {
parent.printRaw(msg);
return;
}
Fawe.get().debugPlain(msg);
}
@Override
public void printDebug(String msg) {
if (parent != null) {
parent.printDebug(msg);
return;
}
Fawe.get().debugPlain(msg);
}
@Override
public void print(String msg) {
if (parent != null) {
parent.print(msg);
return;
}
Fawe.get().debugPlain(msg);
}
@Override
public void printError(String msg) {
if (parent != null) {
parent.printError(msg);
return;
}
Fawe.get().debugPlain(msg);
}
private FakeSessionKey key;
@Override
public SessionKey getSessionKey() {
if (parent != null) {
return parent.getSessionKey();
}
if (key == null) {
key = new FakeSessionKey(uuid, name);
}
return key;
}
@Nullable
@Override
public <T> T getFacet(Class<? extends T> cls) {
return null;
}
@Override
public UUID getUniqueId() {
if (parent != null) {
return parent.getUniqueId();
}
return uuid;
}
@Override
public String[] getGroups() {
if (parent != null) {
return parent.getGroups();
}
return new String[0];
}
@Override
public boolean hasPermission(String permission) {
if (parent != null) {
return parent.hasPermission(permission);
}
return true;
}
private static class FakeSessionKey implements SessionKey {
private final UUID uuid;
private final String name;
private FakeSessionKey(UUID uuid, String name) {
this.uuid = uuid;
this.name = name;
}
@Override
public UUID getUniqueId() {
return uuid;
}
@Nullable
@Override
public String getName() {
return name;
}
@Override
public boolean isActive() {
return true;
}
@Override
public boolean isPersistent() {
return true;
}
}
@Override
public boolean setLocation(Location location) {
this.pos = location;
return true;
}
}