use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class RegionMarker method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (!block.isValid()) {
continue;
}
if (block.getFinal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getFinal().getLocation();
if (optLoc.isPresent()) {
Optional<Region> optRef = service.getSelectedRegion(player);
if (optRef.isPresent()) {
Location<World> loc = optLoc.get();
Region ref = optRef.get();
if (ref.getWorldName().equals(loc.getExtent().getName())) {
if (ref.isMember(player)) {
RegionErrorStatus status = ref.addPoint(new RegionPoint(loc.getPosition()));
if (status == RegionErrorStatus.NONE) {
player.sendMessage(Text.of(TextColors.YELLOW, "Region marker added!"));
continue;
} else if (status == RegionErrorStatus.INTERSECT) {
player.sendMessage(Text.of(TextColors.RED, "No two regions can occupy the same space!"));
} else if (status == RegionErrorStatus.REGION_TOO_LARGE) {
player.sendMessage(Text.of(TextColors.RED, "You do not have enough power to expand your region!"));
}
}
}
}
}
block.setValid(false);
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class RegionMaster method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (!block.isValid()) {
continue;
}
if (block.getFinal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getFinal().getLocation();
if (optLoc.isPresent()) {
Optional<Region> optOriginRef = service.getSelectedRegion(player);
Optional<Region> optRef = service.getOrCreate(optLoc.get(), player);
if (optRef.isPresent()) {
Region ref = optRef.get();
Vector3d masterBlock = ref.getMasterBlock();
Vector3d blockPos = optLoc.get().getPosition();
// Determine if this is a new region or not
if (!masterBlock.equals(blockPos)) {
if (blockPos.equals(recentlyClicked.get(player))) {
// Update the master block
ref.setMasterBlock(new RegionPoint(blockPos));
// Delete the existing master block
optLoc.get().getExtent().setBlockType(masterBlock.toInt(), BlockTypes.AIR, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
player.sendMessage(Text.of(TextColors.YELLOW, "Master block moved."));
} else {
recentlyClicked.put(player, blockPos);
block.setValid(false);
player.sendMessage(Text.of(TextColors.YELLOW, "Place the master block again to move this region's master block."));
}
}
service.setSelectedRegion(player, ref);
if (!ref.equals(optOriginRef.orElse(null))) {
player.sendMessage(Text.of(TextColors.YELLOW, "Active region set!"));
}
}
}
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class RegionMaster method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Primary event, @Root Player player) {
BlockSnapshot targetBlock = event.getTargetBlock();
if (targetBlock.getState().getType() != this) {
return;
}
Optional<Location<World>> optLoc = targetBlock.getLocation();
if (!optLoc.isPresent()) {
return;
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
if (optRef.isPresent()) {
Region ref = optRef.get();
service.setSelectedRegion(player, ref);
player.sendMessage(Text.of(TextColors.YELLOW, "Region selected!"));
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class FocusTeleporter method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
org.spongepowered.api.item.inventory.ItemStack held = optHeldItem.get();
if (held.getItem() != this) {
return;
}
Optional<Location<World>> optDestination = getDestination(held);
if (!optDestination.isPresent()) {
return;
}
Inventory result = player.getInventory().query((ItemType) Sponge.getRegistry().getType(ItemType.class, "skree:ender_focus").get());
if (result.size() > 0) {
Task.builder().execute(() -> {
result.poll(1);
player.setLocation(optDestination.get());
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class BrokenGlass method dropBrokenGlass.
private void dropBrokenGlass(Transaction<BlockSnapshot> block, int variant) {
Optional<Location<World>> optOrigin = block.getOriginal().getLocation();
if (!optOrigin.isPresent()) {
return;
}
new ItemDropper(optOrigin.get()).dropStacks(Collections.singleton(tf(new ItemStack(this, 1, variant))), SpawnTypes.DROPPED_ITEM);
}
Aggregations