use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionMarker method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break 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.getOriginal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (optLoc.isPresent()) {
Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
if (optRef.isPresent()) {
Region ref = optRef.get();
if (ref.isMember(player)) {
ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
}
}
}
}
}
use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionMaster method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break 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.getOriginal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (!optLoc.isPresent()) {
continue;
}
Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
if (!optRef.isPresent()) {
continue;
}
Region ref = optRef.get();
if (!ref.getFullPoints().isEmpty()) {
block.setValid(false);
player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
} else {
service.rem(optLoc.get());
player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
}
}
}
use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionRemMemberCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
if (!ref.getMembers().contains(player.getUniqueId())) {
player.sendMessage(Text.of(TextColors.RED, "You must be a member of the region to modify it!"));
return CommandResult.empty();
}
List<UUID> oldMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> ref.getMembers().contains(a)).collect(Collectors.toList());
ref.remMember(oldMembers);
player.sendMessage(Text.of(TextColors.YELLOW, "Removed ", oldMembers.size(), " players from the region."));
return CommandResult.success();
}
use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionCleanupCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
int removedCount = service.cleanup();
src.sendMessage(Text.of(TextColors.YELLOW, removedCount, " region components invalidated."));
return CommandResult.success();
}
use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionInfoCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
DecimalFormat countFormat = new DecimalFormat("#,###");
Region ref = optRef.get();
player.sendMessage(Text.of(TextColors.GOLD, "Region information for: ", (ref.isActive() ? TextColors.BLUE : TextColors.RED), ref.getName().toUpperCase()));
player.sendMessage(Text.of(countFormat.format(ref.getPowerLevel()), TextColors.YELLOW, " power cores"));
player.sendMessage(Text.of(countFormat.format(ref.getArea()), TextColors.YELLOW, " block area"));
player.sendMessage(Text.of(countFormat.format(ref.getMaximumArea()), TextColors.YELLOW, " block maximum area"));
player.sendMessage(Text.of(TextActions.runCommand("/region listmembers"), TextActions.showText(Text.of("List the region's members")), countFormat.format(ref.getMembers().size()), TextColors.YELLOW, " members"));
player.sendMessage(Text.of(TextActions.runCommand("/region listmarkers"), TextActions.showText(Text.of("List the region's marker block positions")), countFormat.format(ref.getPoints().size()), TextColors.YELLOW, " active markers"));
return CommandResult.success();
}
Aggregations