use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class GoldRushListener method onPlayerInteractEvent.
@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
GoldRushInstance inst = optInst.get();
BlockSnapshot snapshot = event.getTargetBlock();
BlockState state = snapshot.getState();
if (!snapshot.getLocation().isPresent()) {
return;
}
Location<World> targetBlock = snapshot.getLocation().get();
if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
if (!optTileEnt.isPresent()) {
return;
}
TileEntity tileEntity = optTileEnt.get();
Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
if (!optTexts.isPresent()) {
return;
}
List<Text> texts = optTexts.get();
boolean unlocked = false;
String text = texts.get(1).toPlain().toLowerCase();
NonNullList<ItemStack> itemStacks = tf(player).inventory.mainInventory;
for (int i = 0; i < itemStacks.size(); ++i) {
ItemStack is = itemStacks.get(i);
if (is == ItemStack.EMPTY || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
continue;
}
if (text.contains("blue")) {
if (is.getItemDamage() != 1) {
continue;
}
} else if (text.contains("red")) {
if (is.getItemDamage() != 0) {
continue;
}
} else {
continue;
}
unlocked = true;
itemStacks.set(i, ItemStack.EMPTY);
break;
}
if (unlocked) {
tf(player).inventoryContainer.detectAndSendChanges();
texts.set(2, Text.of("Locked"));
texts.set(3, Text.of("- Unlocked -"));
tileEntity.offer(Keys.SIGN_LINES, texts);
}
} else if (state.getType() == BlockTypes.LEVER) {
Task.builder().execute(() -> {
if (inst.checkLevers()) {
inst.completeGame();
}
}).delayTicks(1).submit(SkreePlugin.inst());
} else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
event.setUseItemResult(Tristate.FALSE);
event.setUseBlockResult(Tristate.FALSE);
player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
inst.payPlayer(player);
} else if (!inst.isLocked()) {
if (state.getType() == BlockTypes.STONE_BUTTON) {
inst.tryToStart();
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class JungleRaidEffectListener method onBlockBurn.
@Listener
public void onBlockBurn(ChangeBlockEvent event) {
if (event.getCause().root() instanceof Player) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType finalType = transaction.getFinal().getState().getType();
if (finalType != BlockTypes.FIRE) {
continue;
}
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
if (optInst.isPresent()) {
JungleRaidInstance inst = optInst.get();
if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
event.setCancelled(true);
}
break;
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
event.setCancelled(true);
return;
}
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockType originalType = block.getOriginal().getState().getType();
if (cursedOres.contains(originalType)) {
// we were having some multi-firing problems
if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
/*if (Probability.getChance(3000)) {
ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
}*/
ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
inst.eatFood(player);
inst.poison(player, 6);
inst.ghost(player, originalType);
}
} else if (stealableFluids.contains(originalType)) {
inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
} else {
block.setCustom(block.getOriginal());
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType originalType = transaction.getFinal().getState().getType();
BlockType finalType = transaction.getFinal().getState().getType();
if (isRedstoneTransition(originalType, finalType)) {
continue;
}
event.setCancelled(true);
break;
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onPlayerInteract.
@Listener
public void onPlayerInteract(ChangeBlockEvent event) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockSnapshot snapshot = block.getOriginal();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
optInst.get().activatePumps();
break;
}
}
}
Aggregations