Search in sources :

Example 46 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowWorld method refreshChunk.

@Override
public boolean refreshChunk(int x, int z) {
    if (!isChunkLoaded(x, z)) {
        return false;
    }
    Key key = GlowChunk.Key.of(x, z);
    boolean result = false;
    for (GlowPlayer player : getRawPlayers()) {
        if (player.canSeeChunk(key)) {
            ChunkDataMessage message = getChunkAt(x, z).toMessage();
            player.getSession().sendAndRelease(message, message.getData());
            result = true;
        }
    }
    return result;
}
Also used : ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) Key(net.glowstone.chunk.GlowChunk.Key) NamespacedKey(org.bukkit.NamespacedKey)

Example 47 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowWorld method spawnParticle.

@Override
public <T> void spawnParticle(Particle particle, Location location, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) {
    checkNotNull(particle);
    checkNotNull(location);
    if (data != null && !particle.getDataType().isInstance(data)) {
        throw new IllegalArgumentException("wrong data type " + data.getClass() + " should be " + particle.getDataType());
    }
    for (GlowPlayer player : getRawPlayers()) {
        if (!player.getWorld().equals(this)) {
            continue;
        }
        player.spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, extra, data);
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer)

Example 48 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowWorld method setStorm.

@Override
public void setStorm(boolean hasStorm) {
    // call event
    WeatherChangeEvent event = new WeatherChangeEvent(this, hasStorm);
    if (EventFactory.getInstance().callEvent(event).isCancelled()) {
        return;
    }
    // change weather
    boolean previouslyRaining = currentlyRaining;
    currentlyRaining = hasStorm;
    // Numbers borrowed from CraftBukkit.
    if (currentlyRaining) {
        setWeatherDuration(ThreadLocalRandom.current().nextInt(TickUtil.TICKS_PER_HALF_DAY) + TickUtil.TICKS_PER_HALF_DAY);
    } else {
        setWeatherDuration(ThreadLocalRandom.current().nextInt(TickUtil.TICKS_PER_WEEK) + TickUtil.TICKS_PER_HALF_DAY);
    }
    // update players
    if (previouslyRaining != currentlyRaining) {
        getRawPlayers().forEach(GlowPlayer::sendWeather);
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent)

Example 49 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class BlockFence method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    super.blockInteract(player, block, face, clickedLoc);
    if (!player.getLeashedEntities().isEmpty()) {
        LeashHitch leashHitch = GlowLeashHitch.getLeashHitchAt(block);
        ImmutableList.copyOf(player.getLeashedEntities()).stream().filter(e -> !(EventFactory.getInstance().callEvent(new PlayerLeashEntityEvent(e, leashHitch, player)).isCancelled())).forEach(e -> e.setLeashHolder(leashHitch));
        return true;
    }
    return false;
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) ImmutableList(com.google.common.collect.ImmutableList) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) MaterialMatcher(net.glowstone.inventory.MaterialMatcher) EventFactory(net.glowstone.EventFactory) PlayerLeashEntityEvent(org.bukkit.event.entity.PlayerLeashEntityEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) LeashHitch(org.bukkit.entity.LeashHitch) Material(org.bukkit.Material) PlayerLeashEntityEvent(org.bukkit.event.entity.PlayerLeashEntityEvent) GlowLeashHitch(net.glowstone.entity.objects.GlowLeashHitch) LeashHitch(org.bukkit.entity.LeashHitch)

Example 50 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class EnchantCommand method execute.

@Override
public boolean execute(CommandSender sender, String label, String[] args, CommandMessages commandMessages) {
    if (!testPermission(sender, commandMessages.getPermissionMessage())) {
        return true;
    }
    if (args.length < 3) {
        sendUsageMessage(sender, commandMessages);
        return false;
    }
    String name = args[0];
    Stream<GlowPlayer> players;
    if (name.startsWith("@")) {
        CommandTarget target = new CommandTarget(sender, name);
        players = Arrays.stream(target.getMatched(CommandUtils.getLocation(sender))).filter(GlowPlayer.class::isInstance).map(GlowPlayer.class::cast);
    } else {
        GlowPlayer player = (GlowPlayer) Bukkit.getPlayerExact(args[0]);
        if (player == null) {
            commandMessages.getGeneric(GenericMessage.NO_SUCH_PLAYER).sendInColor(ChatColor.RED, sender, name);
            return false;
        } else {
            players = Collections.singletonList(player).stream();
        }
    }
    Enchantment enchantment = GlowEnchantment.parseEnchantment(args[1]);
    if (enchantment == null) {
        new LocalizedStringImpl("enchant.unknown", commandMessages.getResourceBundle()).sendInColor(ChatColor.RED, sender, args[1]);
        return false;
    }
    int level;
    try {
        level = Integer.parseInt(args[2]);
    } catch (NumberFormatException exc) {
        commandMessages.getGeneric(GenericMessage.NAN).sendInColor(ChatColor.RED, sender, args[2]);
        return false;
    }
    LocalizedStringImpl successMessage = new LocalizedStringImpl("enchant.done", commandMessages.getResourceBundle());
    players.filter(player -> player.getItemInHand() != null).filter(player -> player.getItemInHand().getData().getItemType() != Material.AIR).filter(player -> enchantment.canEnchantItem(player.getItemInHand())).forEach(player -> {
        ItemStack itemInHand = player.getItemInHand();
        itemInHand.addUnsafeEnchantment(enchantment, level);
        player.setItemInHand(itemInHand);
        successMessage.send(sender);
    });
    return true;
}
Also used : CommandSender(org.bukkit.command.CommandSender) Arrays(java.util.Arrays) NamespacedKey(org.bukkit.NamespacedKey) Enchantment(org.bukkit.enchantments.Enchantment) StringUtil(org.bukkit.util.StringUtil) NonNls(org.jetbrains.annotations.NonNls) GlowPlayer(net.glowstone.entity.GlowPlayer) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) List(java.util.List) Stream(java.util.stream.Stream) ChatColor(org.bukkit.ChatColor) CommandUtils(net.glowstone.command.CommandUtils) CommandTarget(net.glowstone.command.CommandTarget) GlowEnchantment(net.glowstone.constants.GlowEnchantment) Collections(java.util.Collections) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) CommandTarget(net.glowstone.command.CommandTarget) GlowPlayer(net.glowstone.entity.GlowPlayer) LocalizedStringImpl(net.glowstone.i18n.LocalizedStringImpl) Enchantment(org.bukkit.enchantments.Enchantment) GlowEnchantment(net.glowstone.constants.GlowEnchantment) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)69 ItemStack (org.bukkit.inventory.ItemStack)15 Vector (org.bukkit.util.Vector)10 EventFactory (net.glowstone.EventFactory)9 Location (org.bukkit.Location)9 Player (org.bukkit.entity.Player)9 GlowEntity (net.glowstone.entity.GlowEntity)8 Message (com.flowpowered.network.Message)7 ArrayList (java.util.ArrayList)7 GlowBlock (net.glowstone.block.GlowBlock)7 Material (org.bukkit.Material)6 World (org.bukkit.World)6 Entity (org.bukkit.entity.Entity)6 List (java.util.List)5 GlowWorld (net.glowstone.GlowWorld)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 BlockFace (org.bukkit.block.BlockFace)5 CommandTarget (net.glowstone.command.CommandTarget)4 AsyncableMessage (com.flowpowered.network.AsyncableMessage)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3