use of com.skelril.skree.service.RegionService 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();
}
use of com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionSetNameCommand 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();
}
String newName = args.<String>getOne("name").get();
try {
ref.setName(newName);
} catch (IllegalArgumentException ex) {
player.sendMessage(Text.of(TextColors.RED, "Invalid region name!"));
return CommandResult.empty();
}
player.sendMessage(Text.of(TextColors.YELLOW, "Region name set to ", Text.of(TextColors.BLUE, newName.toUpperCase()), "."));
return CommandResult.success();
}
use of com.skelril.skree.service.RegionService 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 com.skelril.skree.service.RegionService 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 com.skelril.skree.service.RegionService in project Skree by Skelril.
the class RegionAddMemberCommand 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> newMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> !ref.getMembers().contains(a)).collect(Collectors.toList());
ref.addMember(newMembers);
player.sendMessage(Text.of(TextColors.YELLOW, "Added ", newMembers.size(), " players to the region."));
return CommandResult.success();
}
Aggregations