cn.nukkit.level.Location Java Examples

The following examples show how to use cn.nukkit.level.Location. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BackCommand.java    From EssentialsNK with GNU General Public License v3.0 6 votes vote down vote up
public boolean execute(CommandSender sender, String label, String[] args) {
    if (!this.testPermission(sender)) {
        return false;
    }
    if (!this.testIngame(sender)) {
        return false;
    }
    if (args.length != 0) {
        this.sendUsage(sender);
        return false;
    }
    Player player = (Player) sender;
    Location pos = api.getLastLocation(player);
    if (pos == null) {
        sender.sendMessage(TextFormat.RED + Language.translate("commands.back.notavalible"));
        return false;
    }
    player.teleport(pos);
    sender.sendMessage(Language.translate("commands.generic.teleporting"));
    return true;
}
 
Example #2
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static CompoundTag getDefaultNBT(Vector3 pos) {
    Location loc = pos instanceof Location ? (Location) pos : null;

    return new CompoundTag()
            .putList(new ListTag<DoubleTag>("Pos")
                    .add(new DoubleTag("", pos.x))
                    .add(new DoubleTag("", pos.y))
                    .add(new DoubleTag("", pos.z)))
            .putList(new ListTag<DoubleTag>("Motion")
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0))
                    .add(new DoubleTag("", 0)))
            .putList(new ListTag<FloatTag>("Rotation")
                    .add(new FloatTag("", (float) (loc != null ? loc.getYaw() : 0)))
                    .add(new FloatTag("", (float) (loc != null ? loc.getPitch() : 0))));
}
 
Example #3
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public boolean setWarp(String name, Location pos) {
    this.warpConfig.reload();
    boolean replaced = warpConfig.exists(name);
    Object[] home = new Object[]{pos.level.getName(), pos.x, pos.y, pos.z, pos.yaw, pos.pitch};
    this.warpConfig.set(name, home);
    this.warpConfig.save();
    return replaced;
}
 
Example #4
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static CompoundTag getDefaultNBT(Vector3 pos, Vector3 motion) {
    Location loc = pos instanceof Location ? (Location) pos : null;

    if (loc != null) {
        return getDefaultNBT(pos, motion, (float) loc.getYaw(), (float) loc.getPitch());
    }

    return getDefaultNBT(pos, motion, 0, 0);
}
 
Example #5
Source File: NukkitPlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public com.sk89q.worldedit.util.Location getLocation() {
    Location nativeLocation = player.getLocation();
    Vector position = NukkitUtil.toVector(nativeLocation);
    return new com.sk89q.worldedit.util.Location(
            getWorld(),
            position,
            (float) nativeLocation.getYaw(),
            (float) nativeLocation.getPitch());
}
 
Example #6
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public Location getWarp(String name) {
    this.warpConfig.reload();
    List warp = this.warpConfig.getList(name);
    if (warp == null || warp.size() != 6) {
        return null;
    }
    return new Location((double) warp.get(1), (double) warp.get(2), (double) warp.get(3), (double) warp.get(4), (double) warp.get(5), this.getServer().getLevelByName((String) warp.get(0)));
}
 
Example #7
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
    double yaw = location.yaw;
    double pitch = location.pitch;

    Location from = this.getLocation();
    Location to = location;
    if (cause != null) {
        EntityTeleportEvent ev = new EntityTeleportEvent(this, from, to);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return false;
        }
        to = ev.getTo();
    }

    this.ySize = 0;

    this.setMotion(this.temporalVector.setComponents(0, 0, 0));

    if (this.setPositionAndRotation(to, yaw, pitch)) {
        this.resetFallDistance();
        this.onGround = true;

        this.updateMovement();

        return true;
    }

    return false;
}
 
Example #8
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public Location getHome(Player player, String name) {
    this.homeConfig.reload();
    Map<String, ArrayList<Object>> map = (Map<String, ArrayList<Object>>) this.homeConfig.get(player.getName().toLowerCase());
    if (map == null) {
        return null;
    }
    List<Object> home = map.get(name);
    if (home == null || home.size() != 6) {
        return null;
    }
    return new Location((double) home.get(1), (double) home.get(2), (double) home.get(3), (double) home.get(4), (double) home.get(5), this.getServer().getLevelByName((String) home.get(0)));
}
 
Example #9
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
public boolean setHome(Player player, String name, Location pos) {
    this.homeConfig.reload();
    Map<String, Object> map = (Map<String, Object>) this.homeConfig.get(player.getName().toLowerCase());
    if (map == null) {
        map = new HashMap<>();
    }
    boolean replaced = map.containsKey(name);
    Object[] home = new Object[]{pos.level.getName(), pos.x, pos.y, pos.z, pos.yaw, pos.pitch};
    map.put(name, home);
    this.homeConfig.set(player.getName().toLowerCase(), map);
    this.homeConfig.save();
    return replaced;
}
 
Example #10
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
    double yaw = location.yaw;
    double pitch = location.pitch;

    Location from = this.getLocation();
    Location to = location;
    if (cause != null) {
        EntityTeleportEvent ev = new EntityTeleportEvent(this, from, to);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return false;
        }
        to = ev.getTo();
    }

    this.ySize = 0;

    this.setMotion(this.temporalVector.setComponents(0, 0, 0));

    if (this.setPositionAndRotation(to, yaw, pitch)) {
        this.resetFallDistance();
        this.onGround = true;

        this.updateMovement();

        return true;
    }

    return false;
}
 
Example #11
Source File: TeleportCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 1 || args.length > 6) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    CommandSender target;
    CommandSender origin = sender;
    if (args.length == 1 || args.length == 3) {
        if (sender instanceof Player) {
            target = sender;
        } else {
            sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
            return true;
        }
        if (args.length == 1) {
            target = sender.getServer().getPlayer(args[0]);
            if (target == null) {
                sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
                return true;
            }
        }
    } else {
        target = sender.getServer().getPlayer(args[0]);
        if (target == null) {
            sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
            return true;
        }
        if (args.length == 2) {
            origin = target;
            target = sender.getServer().getPlayer(args[1]);
            if (target == null) {
                sender.sendMessage(TextFormat.RED + "Can't find player " + args[1]);
                return true;
            }
        }
    }
    if (args.length < 3) {
        ((Player) origin).teleport((Player) target, PlayerTeleportEvent.TeleportCause.COMMAND);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success", new String[]{origin.getName(), target.getName()}));
        return true;
    } else if (((Player) target).getLevel() != null) {
        int pos;
        if (args.length == 4 || args.length == 6) {
            pos = 1;
        } else {
            pos = 0;
        }
        double x;
        double y;
        double z;
        double yaw;
        double pitch;
        try {
            x = Double.parseDouble(args[pos++]);
            y = Double.parseDouble(args[pos++]);
            z = Double.parseDouble(args[pos++]);
            yaw = ((Player) target).getYaw();
            pitch = ((Player) target).getPitch();
        } catch (NumberFormatException e1) {
            sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
            return true;
        }
        if (y < 0) y = 0;
        if (y > 256) y = 256;
        if (args.length == 6 || (args.length == 5 && pos == 3)) {
            yaw = Integer.parseInt(args[pos++]);
            pitch = Integer.parseInt(args[pos++]);
        }
        ((Player) target).teleport(new Location(x, y, z, yaw, pitch, ((Player) target).getLevel()), PlayerTeleportEvent.TeleportCause.COMMAND);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success.coordinates", new String[]{target.getName(), String.valueOf(NukkitMath.round(x, 2)), String.valueOf(NukkitMath.round(y, 2)), String.valueOf(NukkitMath.round(z, 2))}));
        return true;
    }
    sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
    return true;
}
 
Example #12
Source File: EntityTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EntityTeleportEvent(Entity entity, Location from, Location to) {
    this.entity = entity;
    this.from = from;
    this.to = to;
}
 
Example #13
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean teleport(Vector3 pos, PlayerTeleportEvent.TeleportCause cause) {
    return this.teleport(Location.fromObject(pos, this.level, this.yaw, this.pitch), cause);
}
 
Example #14
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean teleport(Position pos, PlayerTeleportEvent.TeleportCause cause) {
    return this.teleport(Location.fromObject(pos, pos.level, this.yaw, this.pitch), cause);
}
 
Example #15
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 4 votes vote down vote up
public Location getLastLocation(Player player) {
    return this.playerLastLocation.get(player);
}
 
Example #16
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean teleport(Location location) {
    return this.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
}
 
Example #17
Source File: EssentialsAPI.java    From EssentialsNK with GNU General Public License v3.0 4 votes vote down vote up
public void setLastLocation(Player player, Location pos) {
    this.playerLastLocation.put(player, pos);
}
 
Example #18
Source File: EntityTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setFrom(Location from) {
    this.from = from;
}
 
Example #19
Source File: TeleportCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 1 || args.length > 6) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    CommandSender target;
    CommandSender origin = sender;
    if (args.length == 1 || args.length == 3) {
        if (sender instanceof Player) {
            target = sender;
        } else {
            sender.sendMessage(new TranslationContainer("commands.generic.ingame"));
            return true;
        }
        if (args.length == 1) {
            target = sender.getServer().getPlayer(args[0].replace("@s", sender.getName()));
            if (target == null) {
                sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
                return true;
            }
        }
    } else {
        target = sender.getServer().getPlayer(args[0].replace("@s", sender.getName()));
        if (target == null) {
            sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]);
            return true;
        }
        if (args.length == 2) {
            origin = target;
            target = sender.getServer().getPlayer(args[1].replace("@s", sender.getName()));
            if (target == null) {
                sender.sendMessage(TextFormat.RED + "Can't find player " + args[1]);
                return true;
            }
        }
    }
    if (args.length < 3) {
        ((Player) origin).teleport((Player) target, PlayerTeleportEvent.TeleportCause.COMMAND);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success", origin.getName(), target.getName()));
        return true;
    } else if (((Player) target).getLevel() != null) {
        int pos;
        if (args.length == 4 || args.length == 6) {
            pos = 1;
        } else {
            pos = 0;
        }
        double x;
        double y;
        double z;
        double yaw;
        double pitch;
        try {
            x = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).x));
            y = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).y));
            z = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).z));
            yaw = ((Player) target).getYaw();
            pitch = ((Player) target).getPitch();
        } catch (NumberFormatException e1) {
            sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
            return true;
        }
        if (y < 0) y = 0;
        if (y > 256) y = 256;
        if (args.length == 6 || (args.length == 5 && pos == 3)) {
            yaw = Integer.parseInt(args[pos++]);
            pitch = Integer.parseInt(args[pos++]);
        }
        ((Player) target).teleport(new Location(x, y, z, yaw, pitch, ((Player) target).getLevel()), PlayerTeleportEvent.TeleportCause.COMMAND);
        Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success.coordinates", target.getName(), String.valueOf(NukkitMath.round(x, 2)), String.valueOf(NukkitMath.round(y, 2)), String.valueOf(NukkitMath.round(z, 2))));
        return true;
    }
    sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
    return true;
}
 
Example #20
Source File: EventListener.java    From EssentialsNK with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
    Block bed = event.getBed();
    api.setHome(event.getPlayer(), "bed", Location.fromObject(bed, bed.level, 0, 0));
}
 
Example #21
Source File: PlayerMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getTo() {
    return to;
}
 
Example #22
Source File: PlayerMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setFrom(Location from) {
    this.from = from;
}
 
Example #23
Source File: PlayerMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getFrom() {
    return from;
}
 
Example #24
Source File: PlayerMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerMoveEvent(Player player, Location from, Location to, boolean resetBlocks) {
    this.player = player;
    this.from = from;
    this.to = to;
    this.resetBlocksAround = resetBlocks;
}
 
Example #25
Source File: PlayerMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerMoveEvent(Player player, Location from, Location to) {
    this(player, from, to, true);
}
 
Example #26
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private Location vectorToLocation(Level baseLevel, Vector3 vector) {
    if (vector instanceof Location) return (Location) vector;
    if (vector instanceof Position) return ((Position) vector).getLocation();
    return new Location(vector.getX(), vector.getY(), vector.getZ(), 0, 0, baseLevel);
}
 
Example #27
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getTo() {
    return to;
}
 
Example #28
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getFrom() {
    return from;
}
 
Example #29
Source File: PlayerTeleportEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerTeleportEvent(Player player, Location from, Location to, TeleportCause cause) {
    this(player);
    this.from = from;
    this.to = to;
    this.cause = cause;
}
 
Example #30
Source File: VehicleMoveEvent.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public Location getTo() {
    return to;
}