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;
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations