use of com.skelril.skree.service.internal.region.Region 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.internal.region.Region 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.internal.region.Region 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.internal.region.Region 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();
}
use of com.skelril.skree.service.internal.region.Region in project Skree by Skelril.
the class RegionSelectCommand 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<Player> optPlayer = args.getOne("player");
Optional<Location<World>> optLocation = args.getOne("location");
Optional<Region> optRegion;
if (optPlayer.isPresent()) {
Player targPlayer = optPlayer.get();
optRegion = service.get(targPlayer.getLocation());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for ", targPlayer.getName(), "'s local region..."));
} else if (optLocation.isPresent()) {
optRegion = service.get(optLocation.get());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for a region at the given location..."));
} else {
optRegion = service.get(player.getLocation());
player.sendMessage(Text.of(TextColors.YELLOW, "Searching for your local region..."));
}
service.setSelectedRegion(player, optRegion.orElse(null));
if (optRegion.isPresent()) {
player.sendMessage(Text.of(TextColors.YELLOW, "Region found! View information with ", Text.of(TextColors.GREEN, TextActions.runCommand("/region info"), "/region info")));
} else {
player.sendMessage(Text.of(TextColors.YELLOW, "No region found, your region selection has been cleared"));
}
return CommandResult.success();
}
Aggregations