2014-06-27 20:14:44 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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
|
2014-06-27 20:14:44 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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.
|
2014-06-27 20:14:44 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-06-27 20:14:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.extension.platform;
|
|
|
|
|
2019-06-06 22:39:51 +00:00
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2018-06-17 07:50:04 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
2014-06-29 05:31:13 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
2014-06-27 20:14:44 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2014-07-07 00:13:27 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
2014-07-28 03:44:05 +00:00
|
|
|
import com.sk89q.worldedit.session.SessionKey;
|
2018-06-17 07:50:04 +00:00
|
|
|
import com.sk89q.worldedit.util.HandSide;
|
2014-06-27 20:14:44 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
2020-03-05 21:07:20 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2014-06-27 20:14:44 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-06-06 22:39:51 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
2018-07-19 12:41:26 +00:00
|
|
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
2014-06-27 20:14:44 +00:00
|
|
|
|
2020-07-14 02:50:59 +00:00
|
|
|
import java.util.Locale;
|
2019-06-30 18:56:32 +00:00
|
|
|
import java.util.UUID;
|
2020-07-14 02:50:59 +00:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-06-27 20:14:44 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public class PlayerProxy extends AbstractPlayerActor {
|
2014-06-27 20:14:44 +00:00
|
|
|
|
|
|
|
private final Player basePlayer;
|
|
|
|
private final Actor permActor;
|
2014-07-07 00:13:27 +00:00
|
|
|
private final Actor cuiActor;
|
2014-06-27 20:14:44 +00:00
|
|
|
private final World world;
|
2019-06-28 15:19:58 +00:00
|
|
|
private Vector3 offset = Vector3.ZERO;
|
2014-06-27 20:14:44 +00:00
|
|
|
|
2019-10-23 04:23:52 +00:00
|
|
|
public PlayerProxy(Player player) {
|
|
|
|
this(player, player, player, player.getWorld());
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
public PlayerProxy(Player basePlayer, Actor permActor, Actor cuiActor, World world) {
|
2019-11-08 22:30:39 +00:00
|
|
|
super(basePlayer.getRawMeta());
|
2014-06-27 20:14:44 +00:00
|
|
|
checkNotNull(basePlayer);
|
|
|
|
checkNotNull(permActor);
|
2014-07-07 00:13:27 +00:00
|
|
|
checkNotNull(cuiActor);
|
2014-06-27 20:14:44 +00:00
|
|
|
checkNotNull(world);
|
|
|
|
this.basePlayer = basePlayer;
|
|
|
|
this.permActor = permActor;
|
2014-07-07 00:13:27 +00:00
|
|
|
this.cuiActor = cuiActor;
|
2014-06-27 20:14:44 +00:00
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
2019-10-23 04:23:52 +00:00
|
|
|
public static Player unwrap(Player player) {
|
|
|
|
if (player instanceof PlayerProxy) {
|
|
|
|
return unwrap(((PlayerProxy) player).getBasePlayer());
|
|
|
|
}
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:19:58 +00:00
|
|
|
public void setOffset(Vector3 position) {
|
|
|
|
this.offset = position;
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
@Override
|
2019-01-31 15:08:58 +00:00
|
|
|
public BaseBlock getBlockInHand(HandSide handSide) throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
return basePlayer.getBlockInHand(handSide);
|
|
|
|
}
|
|
|
|
|
2020-10-08 20:15:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
|
|
|
|
return basePlayer.runAction(ifFree, checkFree, async);
|
|
|
|
}
|
|
|
|
|
2014-07-28 03:44:05 +00:00
|
|
|
@Override
|
|
|
|
public UUID getUniqueId() {
|
|
|
|
return basePlayer.getUniqueId();
|
|
|
|
}
|
|
|
|
|
2014-06-27 20:14:44 +00:00
|
|
|
@Override
|
2018-06-17 07:50:04 +00:00
|
|
|
public BaseItemStack getItemInHand(HandSide handSide) {
|
|
|
|
return basePlayer.getItemInHand(handSide);
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-06-18 07:53:33 +00:00
|
|
|
public void giveItem(BaseItemStack itemStack) {
|
|
|
|
basePlayer.giveItem(itemStack);
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockBag getInventoryBlockBag() {
|
|
|
|
return basePlayer.getInventoryBlockBag();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return basePlayer.getName();
|
|
|
|
}
|
|
|
|
|
2018-12-18 07:36:53 +00:00
|
|
|
@Override
|
|
|
|
public String getDisplayName() {
|
|
|
|
return basePlayer.getDisplayName();
|
|
|
|
}
|
|
|
|
|
2014-06-29 05:31:13 +00:00
|
|
|
@Override
|
|
|
|
public BaseEntity getState() {
|
2019-06-06 22:39:51 +00:00
|
|
|
throw new UnsupportedOperationException("Can't getState() on a player");
|
2014-06-29 05:31:13 +00:00
|
|
|
}
|
|
|
|
|
2014-06-27 20:14:44 +00:00
|
|
|
@Override
|
|
|
|
public Location getLocation() {
|
2019-06-28 15:19:58 +00:00
|
|
|
Location loc = this.basePlayer.getLocation();
|
|
|
|
return new Location(loc.getExtent(), loc.add(offset), loc.getDirection());
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 06:56:10 +00:00
|
|
|
@Override
|
|
|
|
public boolean setLocation(Location location) {
|
|
|
|
return basePlayer.setLocation(location);
|
|
|
|
}
|
|
|
|
|
2014-06-27 20:14:44 +00:00
|
|
|
@Override
|
2020-07-01 15:24:58 +00:00
|
|
|
public boolean trySetPosition(Vector3 pos, float pitch, float yaw) {
|
|
|
|
return basePlayer.trySetPosition(pos, pitch, yaw);
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public World getWorld() {
|
2019-10-23 04:23:52 +00:00
|
|
|
return world == null ? basePlayer.getWorld() : world;
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printRaw(String msg) {
|
2020-03-05 21:07:20 +00:00
|
|
|
basePlayer.print(TextComponent.of(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printDebug(String msg) {
|
|
|
|
basePlayer.printDebug(TextComponent.of(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void print(String msg) {
|
|
|
|
basePlayer.printInfo(TextComponent.of(msg));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void printError(String msg) {
|
|
|
|
basePlayer.printError(TextComponent.of(msg));
|
2014-06-27 20:14:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
@Override
|
|
|
|
public void print(Component component) {
|
|
|
|
basePlayer.print(component);
|
|
|
|
}
|
|
|
|
|
2014-06-27 20:14:44 +00:00
|
|
|
@Override
|
|
|
|
public String[] getGroups() {
|
|
|
|
return permActor.getGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPermission(String perm) {
|
|
|
|
return permActor.hasPermission(perm);
|
|
|
|
}
|
2014-07-07 00:13:27 +00:00
|
|
|
|
2020-09-21 15:07:35 +00:00
|
|
|
@Override
|
|
|
|
public boolean togglePermission(String permission) {
|
|
|
|
return permActor.togglePermission(permission);
|
2019-06-30 18:56:32 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 15:07:35 +00:00
|
|
|
@Override
|
|
|
|
public void setPermission(String permission, boolean value) {
|
2019-06-30 18:56:32 +00:00
|
|
|
permActor.setPermission(permission, value);
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:13:27 +00:00
|
|
|
@Override
|
|
|
|
public void dispatchCUIEvent(CUIEvent event) {
|
|
|
|
cuiActor.dispatchCUIEvent(event);
|
|
|
|
}
|
2014-07-16 02:47:47 +00:00
|
|
|
|
2020-01-08 18:36:12 +00:00
|
|
|
@Override
|
|
|
|
public void sendAnnouncements() {
|
|
|
|
basePlayer.sendAnnouncements();
|
|
|
|
}
|
|
|
|
|
2014-07-16 02:47:47 +00:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public <T> T getFacet(Class<? extends T> cls) {
|
|
|
|
return basePlayer.getFacet(cls);
|
|
|
|
}
|
2014-07-28 03:44:05 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public SessionKey getSessionKey() {
|
|
|
|
return basePlayer.getSessionKey();
|
|
|
|
}
|
2018-07-19 12:41:26 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public GameMode getGameMode() {
|
|
|
|
return basePlayer.getGameMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setGameMode(GameMode gameMode) {
|
|
|
|
basePlayer.setGameMode(gameMode);
|
|
|
|
}
|
2018-12-23 16:19:33 +00:00
|
|
|
|
|
|
|
@Override
|
2018-12-27 00:39:10 +00:00
|
|
|
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
|
2018-12-23 16:19:33 +00:00
|
|
|
basePlayer.sendFakeBlock(pos, block);
|
|
|
|
}
|
2019-04-10 16:17:45 +00:00
|
|
|
|
2019-09-14 03:17:40 +00:00
|
|
|
@Override
|
2019-11-21 19:56:10 +00:00
|
|
|
public void sendTitle(Component title, Component sub) {
|
2019-09-14 03:17:40 +00:00
|
|
|
basePlayer.sendTitle(title, sub);
|
|
|
|
}
|
|
|
|
|
2019-04-10 16:17:45 +00:00
|
|
|
public Player getBasePlayer() {
|
|
|
|
return basePlayer;
|
|
|
|
}
|
2019-11-19 21:23:47 +00:00
|
|
|
|
2019-07-10 22:25:34 +00:00
|
|
|
@Override
|
|
|
|
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
|
|
|
basePlayer.floatAt(x, y, z, alwaysGlass);
|
|
|
|
}
|
2019-10-13 11:47:26 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Locale getLocale() {
|
|
|
|
return basePlayer.getLocale();
|
|
|
|
}
|
2018-12-23 16:19:33 +00:00
|
|
|
}
|