use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class UseItemHandler method handle.
@Override
public void handle(GlowSession session, UseItemMessage message) {
GlowPlayer player = session.getPlayer();
ItemStack holding = player.getItemInHand();
if (holding != null) {
ItemType type = ItemTable.instance().getItem(holding.getType());
if (type != null) {
if (type.canOnlyUseSelf()) {
type.rightClickAir(player, holding);
} else {
if (holding.getType() == Material.WATER_BUCKET || holding.getType() == Material.LAVA_BUCKET) {
holding.setType(Material.BUCKET);
}
}
}
}
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class UpdateSignHandler method handle.
@Override
public void handle(GlowSession session, UpdateSignMessage message) {
GlowPlayer player = session.getPlayer();
Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
if (!player.checkSignLocation(location)) {
GlowServer.logger.warning(session + " tried to edit sign at " + location);
return;
}
// filter out json messages that aren't plaintext
String[] lines = new String[4];
for (int i = 0; i < lines.length; ++i) {
lines[i] = message.getMessage()[i].asPlaintext();
}
SignChangeEvent event = new SignChangeEvent(location.getBlock(), player, lines);
EventFactory.callEvent(event);
if (event.isCancelled()) {
GlowServer.logger.warning("Sign was cancelled");
return;
}
// update the sign if it's actually still there
BlockState state = location.getBlock().getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
for (int i = 0; i < lines.length; ++i) {
sign.setLine(i, lines[i]);
}
sign.update();
}
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class HeldItemHandler method handle.
@Override
public void handle(GlowSession session, HeldItemMessage message) {
int slot = message.getSlot();
if (slot < 0 || slot > 8) {
// sanity check
return;
}
GlowPlayer player = session.getPlayer();
int oldSlot = player.getInventory().getHeldItemSlot();
if (slot == oldSlot) {
// ignore
return;
}
PlayerItemHeldEvent event = new PlayerItemHeldEvent(player, oldSlot, slot);
EventFactory.callEvent(event);
if (!event.isCancelled()) {
player.getInventory().setRawHeldItemSlot(slot);
} else {
// sends a packet to switch back to the previous held slot
player.getInventory().setHeldItemSlot(oldSlot);
}
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class PlayerActionHandler method handle.
@Override
public void handle(GlowSession session, PlayerActionMessage message) {
GlowPlayer player = session.getPlayer();
switch(message.getAction()) {
case // crouch
0:
player.setSneaking(true);
break;
case // uncrouch
1:
player.setSneaking(false);
break;
case // leave bed
2:
if (player.isSleeping()) {
player.leaveBed(true);
}
break;
case // start sprinting
3:
player.setSprinting(true);
break;
case // stop sprinting
4:
player.setSprinting(false);
break;
case // start jump with horse
5:
break;
case // stop jump with horse
6:
break;
case // open horse inventory
7:
break;
case // start gliding
8:
ItemStack chestplate = player.getInventory().getChestplate();
boolean hasElytra = chestplate != null && chestplate.getType() == Material.ELYTRA && chestplate.getDurability() < chestplate.getType().getMaxDurability();
if (!player.isOnGround() && !player.isGliding() && !player.isInWater() && hasElytra) {
player.setGliding(true);
}
}
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class GlowArmorStand method damage.
@Override
public void damage(double amount, Entity source, DamageCause cause) {
if (getNoDamageTicks() > 0 || health <= 0 || !canTakeDamage(cause)) {
return;
}
if (source instanceof Projectile && !(source instanceof Arrow)) {
return;
}
EntityDamageEvent event;
if (source == null) {
event = new EntityDamageEvent(this, cause, amount);
} else {
event = new EntityDamageByEntityEvent(source, this, cause, amount);
}
EventFactory.callEvent(event);
if (event.isCancelled()) {
return;
}
boolean drop = false;
if (source instanceof GlowPlayer || source instanceof Arrow && ((Projectile) source).getShooter() instanceof GlowPlayer) {
GlowPlayer damager = (GlowPlayer) (source instanceof GlowPlayer ? source : ((Arrow) source).getShooter());
if (damager.getGameMode() == GameMode.ADVENTURE)
return;
else if (damager.getGameMode() == GameMode.CREATIVE) {
//Instantly kill the entity
amount = 2;
} else {
//Needs two hits
amount = 1;
drop = true;
}
}
setLastDamage(amount);
setHealth(health - amount, drop);
}
Aggregations