use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.
the class MarketSignListener method onSignPlace.
@Listener(order = Order.POST)
public void onSignPlace(ChangeBlockEvent.Place event, @First Player player) {
if (event.getTransactions().size() > 1 || !module.getEditModeCommand().hasUser(player)) {
return;
}
for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
BlockType type = trans.getFinal().getState().getType();
if (// placed sign
type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
event.setCancelled(true);
i18n.send(player, NEGATIVE, "You are not allowed to create market signs!");
return;
}
MarketSignData data = new MarketSignData();
data.setID(UUID.randomUUID());
data.setOwner(player.getUniqueId());
Location<World> loc = trans.getFinal().getLocation().get();
loc.offer(data);
manager.setSign(loc, player);
Sponge.getCauseStackManager().pushCause(player);
player.closeInventory();
}
}
}
use of org.spongepowered.api.block.BlockType in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method placeBlock.
@Listener(order = Order.PRE)
public void placeBlock(ChangeBlockEvent event) {
if (forceStop) {
return;
}
if (event.getCause().root() instanceof Player) {
Player plr = (Player) event.getCause().root();
if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Break) {
BlockType t = event.getTransactions().get(0).getOriginal().getLocation().get().getBlock().getType();
Location<World> location = event.getTransactions().get(0).getOriginal().getLocation().get();
// System.out.println(event instanceof ChangeBlockEvent.Break);
if (validCrateBlocks.contains(t)) {
if (event instanceof ChangeBlockEvent.Place) {
if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
Optional<Object> tt = plr.getItemInHand(HandTypes.MAIN_HAND).get().toContainer().get(DataQuery.of("UnsafeData", "crateID"));
if (tt.isPresent()) {
String crateID = tt.get().toString();
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
if (!crateUtilities.physicalCrates.containsKey(location))
crateUtilities.physicalCrates.put(location, new PhysicalCrate(location, crateID, this, false));
crateUtilities.physicalCrates.get(location).createHologram();
try {
DBReader.saveHuskyData();
} catch (SQLException e) {
e.printStackTrace();
}
return;
}
}
}
} else if (event instanceof ChangeBlockEvent.Break) {
if (crateUtilities.physicalCrates.containsKey(location)) {
if (!plr.hasPermission("huskycrates.tester")) {
event.setCancelled(true);
return;
}
if (!crateUtilities.physicalCrates.get(location).isEntity)
crateUtilities.physicalCrates.get(location).ent.remove();
crateUtilities.physicalCrates.remove(location);
crateUtilities.brokenCrates.add(location);
try {
DBReader.saveHuskyData();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class TheForgeInstance method runOreCheck.
private void runOreCheck() {
for (Item item : getContained(Item.class)) {
BlockType belowType = item.getLocation().add(0, -1, 0).getBlockType();
if (belowType == BlockTypes.GOLD_BLOCK) {
addResource(item.item().get());
item.remove();
}
}
state.save();
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class TheForgeListener method isFlying.
// Poor man's flight check
private boolean isFlying(Player player) {
BlockType blockBelow = player.getLocation().add(0, -1, 0).getBlockType();
BlockType blockBelowBelow = player.getLocation().add(0, -2, 0).getBlockType();
return blockBelow == BlockTypes.AIR && blockBelowBelow == BlockTypes.AIR;
}
use of org.spongepowered.api.block.BlockType in project Skree by Skelril.
the class MagicWand method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (optHeldItem.get().getItem() != this) {
return;
}
event.setUseBlockResult(Tristate.FALSE);
Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
if (!optLoc.isPresent()) {
return;
}
Location<World> loc = optLoc.get();
BlockType targetType = loc.getBlockType();
if (targetType == CustomBlockTypes.MAGIC_LADDER) {
MagicBlockStateHelper.startLadder(loc);
} else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
MagicBlockStateHelper.startPlatform(loc);
} else {
return;
}
if (!survival) {
MagicBlockStateHelper.resetCounts();
return;
}
MagicBlockStateHelper.dropItems(loc, event.getCause());
}
Aggregations