use of org.spongepowered.api.item.inventory.Carrier in project Skree by Skelril.
the class CursedMineInstance method drain.
public void drain() {
for (Entity e : getContained(Carrier.class)) {
// TODO Inventory API not fully implemented
if (!(e instanceof Player)) {
continue;
}
Inventory eInventory = ((Carrier) e).getInventory();
if (e instanceof Player) {
Location<World> playerLoc = e.getLocation();
// Emerald
long diff = System.currentTimeMillis() - lastActivation;
if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
PositionRandomizer randomizer = new PositionRandomizer(5);
for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
Vector3i targetPos;
do {
targetPos = randomizer.createPosition3i(playerLoc.getPosition());
} while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
}
}
}
for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
if (e instanceof Player) {
if (Probability.getChance(15) && checkInventory((Player) e)) {
((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
continue;
}
}
// Iron
eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
// Gold
eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
// Redstone
eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
// Lap
eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
// Diamond
eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
}
}
}
use of org.spongepowered.api.item.inventory.Carrier in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onInteractBlock.
// listen all
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
RedProtect.get().logger.debug("player", "RPPlayerListener - InteractBlockEvent canceled? " + event.isCancelled());
BlockSnapshot b = event.getTargetBlock();
BlockState bstate = b.getState();
Location<World> l = null;
if (!b.getState().getType().equals(BlockTypes.AIR)) {
l = b.getLocation().get();
RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent event. The block is " + bstate.getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
ItemType itemInHand = ItemTypes.NONE;
ItemStack stack = ItemStack.of(ItemTypes.NONE, 1);
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.MAIN_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.MAIN_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
stack = p.getItemInHand(HandTypes.OFF_HAND).get();
itemInHand = stack.getItem();
if (RPUtil.removeGuiItem(stack)) {
p.setItemInHand(HandTypes.OFF_HAND, ItemStack.of(ItemTypes.NONE, 1));
event.setCancelled(true);
}
}
if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().cfgs.getString("wands.infoWandID"))) {
r = RedProtect.get().rm.getTopRegion(l);
if (RedProtect.get().ph.hasUserPerm(p, "RedProtect.get().infowand")) {
if (r == null) {
RPLang.sendMessage(p, "playerlistener.noregion.atblock");
} else if (r.canBuild(p)) {
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "--------------- [&e" + r.getName() + RPLang.get("general.color") + "] ---------------"));
p.sendMessage(r.info());
p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
} else {
p.sendMessage(RPUtil.toText(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", RPUtil.UUIDtoPlayer(r.getLeadersDesc()))));
}
event.setCancelled(true);
return;
}
}
// start player checks
if (r == null) {
if (b != null && (bstate instanceof Container || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName()))) {
Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
if (out && !cont.canOpen(b, p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
int x = b.getLocation().get().getBlockX();
int y = b.getLocation().get().getBlockY();
int z = b.getLocation().get().getBlockZ();
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", "X:" + x + " Y:" + y + " Z:" + z));
}
}
}
} else {
// if (r != null) && (b != null) >>
if (b != null) {
if (bstate.getType().equals(BlockTypes.DRAGON_EGG) || bstate.getType().equals(BlockTypes.BED) || bstate.getType().equals(BlockTypes.NOTEBLOCK) || bstate.getType().getName().contains("repeater") || bstate.getType().getName().contains("comparator")) {
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
} else if ((b.getState() instanceof Carrier) || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName())) {
if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantopen");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("lever")) {
if (!r.canLever(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantlever");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.levertoggled").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (bstate.getType().getName().contains("button")) {
if (!r.canButton(p)) {
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantbutton");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.buttonactivated").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
}
}
} else if (RPDoor.isOpenable(b)) {
if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
{
if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
RPLang.sendMessage(p, "playerlistener.region.cantdoor");
event.setCancelled(true);
} else {
RPLang.sendMessage(p, "playerlistener.region.opendoor");
RPDoor.ChangeDoor(b, r);
}
} else {
RPDoor.ChangeDoor(b, r);
}
} else if (bstate.getType().getName().contains("rail")) {
if (!r.canMinecart(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
event.setCancelled(true);
}
} else if (bstate.getType().getName().contains("sign") && !r.canSign(p)) {
if (b.get(Keys.SIGN_LINES).isPresent()) {
List<Text> sign = b.get(Keys.SIGN_LINES).get();
for (String tag : RedProtect.get().cfgs.getStringList("region-settings.allow-sign-interact-tags")) {
// check first rule
if (tag.equalsIgnoreCase(sign.get(0).toPlain())) {
return;
}
// check if tag is leaders or members names
if (tag.equalsIgnoreCase("{membername}")) {
for (String leader : r.getLeaders()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
return;
}
}
for (String member : r.getMembers()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
return;
}
}
for (String admin : r.getAdmins()) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
return;
}
}
}
// check if tag is player name
if (tag.equalsIgnoreCase("{playername}")) {
if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
return;
}
}
}
}
RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
event.setCancelled(true);
} else if ((itemInHand.equals(ItemTypes.FLINT_AND_STEEL) || itemInHand.equals(ItemTypes.WATER_BUCKET) || itemInHand.equals(ItemTypes.BUCKET) || itemInHand.equals(ItemTypes.LAVA_BUCKET) || itemInHand.equals(ItemTypes.ITEM_FRAME) || itemInHand.equals(ItemTypes.PAINTING)) && !r.canBuild(p)) {
RPLang.sendMessage(p, RPLang.get("playerlistener.region.cantuse"));
event.setCancelled(true);
} else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(bstate)) {
RPLang.sendMessage(p, "playerlistener.region.cantinteract");
event.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.
the class AdvancementTest method onChangeInventory.
@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player, @Getter("getTargetInventory") CarriedInventory<?> container) {
if (!container.getName().get().equals("Furnace")) {
return;
}
final Carrier carrier = container.getCarrier().orElse(null);
if (!(carrier instanceof Furnace)) {
return;
}
final Furnace furnace = (Furnace) carrier;
final int passed = furnace.passedBurnTime().get();
final int max = furnace.maxBurnTime().get();
if (max <= 0 || passed >= max) {
return;
}
for (SlotTransaction transaction : event.getTransactions()) {
if (container.getInventoryProperty(transaction.getSlot(), SlotIndex.class).get().getValue() == 0) {
if (transaction.getFinal().getType() == ItemTypes.DIRT) {
player.getProgress(this.cookDirtAdvancement).grant();
} else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT || transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
player.getProgress(this.suicidalAdvancement).grant();
/*
final Explosion explosion = Explosion.builder()
.location(furnace.getLocation())
.shouldBreakBlocks(true)
.canCauseFire(true)
.shouldDamageEntities(true)
.radius(7)
.build();
explosion.getWorld().triggerExplosion(explosion);
*/
}
}
}
}
use of org.spongepowered.api.item.inventory.Carrier in project LanternServer by LanternPowered.
the class EntityProtocol method update.
@Override
protected void update(EntityProtocolUpdateContext context) {
final Vector3d rot = this.entity.getRotation();
final Vector3d headRot = this.entity instanceof Living ? ((Living) this.entity).getHeadRotation() : null;
final Vector3d pos = this.entity.getPosition();
final double x = pos.getX();
final double y = pos.getY();
final double z = pos.getZ();
final long xu = (long) (x * 4096);
final long yu = (long) (y * 4096);
final long zu = (long) (z * 4096);
final byte yaw = wrapAngle(rot.getY());
// All living entities have a head rotation and changing the pitch
// would only affect the head pitch.
final byte pitch = wrapAngle((headRot != null ? headRot : rot).getX());
boolean dirtyPos = xu != this.lastX || yu != this.lastY || zu != this.lastZ;
boolean dirtyRot = yaw != this.lastYaw || pitch != this.lastPitch;
// TODO: On ground state
final int entityId = getRootEntityId();
final boolean passenger = this.entity.getVehicle().isPresent();
if (dirtyRot) {
this.lastYaw = yaw;
this.lastPitch = pitch;
}
if (dirtyPos) {
final long dxu = xu - this.lastX;
final long dyu = yu - this.lastY;
final long dzu = zu - this.lastZ;
this.lastX = xu;
this.lastY = yu;
this.lastZ = zu;
// rule the world.
if (!passenger) {
if (Math.abs(dxu) <= Short.MAX_VALUE && Math.abs(dyu) <= Short.MAX_VALUE && Math.abs(dzu) <= Short.MAX_VALUE) {
if (dirtyRot) {
context.sendToAllExceptSelf(new MessagePlayOutEntityLookAndRelativeMove(entityId, (int) dxu, (int) dyu, (int) dzu, yaw, pitch, this.entity.isOnGround()));
// The rotation is already send
dirtyRot = false;
} else {
context.sendToAllExceptSelf(new MessagePlayOutEntityRelativeMove(entityId, (int) dxu, (int) dyu, (int) dzu, this.entity.isOnGround()));
}
} else {
context.sendToAllExceptSelf(new MessagePlayOutEntityTeleport(entityId, x, y, z, yaw, pitch, this.entity.isOnGround()));
// The rotation is already send
dirtyRot = false;
}
}
}
if (dirtyRot) {
context.sendToAllExceptSelf(() -> new MessagePlayOutEntityLook(entityId, yaw, pitch, this.entity.isOnGround()));
} else if (!passenger) {
if (headRot != null) {
final byte headYaw = wrapAngle(headRot.getY());
if (headYaw != this.lastHeadYaw) {
context.sendToAllExceptSelf(() -> new MessagePlayOutEntityHeadLook(entityId, headYaw));
this.lastHeadYaw = headYaw;
}
}
}
final Vector3d velocity = this.entity.getVelocity();
final double vx = velocity.getX();
final double vy = velocity.getY();
final double vz = velocity.getZ();
if (vx != this.lastVelX || vy != this.lastVelY || vz != this.lastVelZ) {
context.sendToAll(() -> new MessagePlayOutEntityVelocity(entityId, vx, vy, vz));
this.lastVelX = vx;
this.lastVelY = vy;
this.lastVelZ = vz;
}
final ParameterList parameterList = context == EntityProtocolUpdateContext.empty() ? fillParameters(false, EmptyParameterList.INSTANCE) : fillParameters(false);
// There were parameters applied
if (!parameterList.isEmpty()) {
context.sendToAll(() -> new MessagePlayOutEntityMetadata(entityId, parameterList));
}
if (hasEquipment() && this.entity instanceof Carrier) {
final Inventory inventory = ((Carrier) this.entity).getInventory();
for (int i = 0; i < Holder.EQUIPMENT_TYPES.length; i++) {
final ItemStack itemStack = inventory.query(Holder.EQUIPMENT_QUERIES[i]).first().peek().orElse(null);
final ItemStack oldItemStack = this.lastEquipment.get(i);
if (!LanternItemStack.areSimilar(itemStack, oldItemStack)) {
this.lastEquipment.put(i, itemStack);
final int slotIndex = i;
context.sendToAllExceptSelf(() -> new MessagePlayOutEntityEquipment(getRootEntityId(), slotIndex, itemStack));
}
}
}
// TODO: Update attributes
}
use of org.spongepowered.api.item.inventory.Carrier in project modules-extra by CubeEngine.
the class ItemDuctListener method isDuctInteraction.
private static boolean isDuctInteraction(InteractBlockEvent event) {
if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand)) {
return false;
}
if (!event.getTargetBlock().getLocation().isPresent()) {
return false;
}
Location<World> loc = event.getTargetBlock().getLocation().get();
BlockType type = loc.getBlockType();
if (!isEndPointType(type)) {
return false;
}
Direction dir = loc.get(Keys.DIRECTION).orElse(Direction.NONE);
Optional<TileEntity> te = loc.getRelative(dir).getTileEntity();
return te.isPresent() && te.get() instanceof Carrier;
}
Aggregations