use of com.skelril.skree.service.ZoneService in project Skree by Skelril.
the class ZoneItemUtil method setMasterToZone.
public static void setMasterToZone(ItemStack stack, String zone) {
Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
if (optService.isPresent()) {
ZoneService service = optService.get();
if (stack.getTagCompound() == null) {
stack.setTagCompound(new NBTTagCompound());
}
if (!stack.getTagCompound().hasKey("skree_zone_data")) {
stack.getTagCompound().setTag("skree_zone_data", new NBTTagCompound());
}
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("skree_zone_data");
tag.setString("zone", zone);
tag.setInteger("zone_player_count", 1);
tag.setInteger("zone_max_players", service.getMaxGroupSize(zone).orElse(-1));
tag.setString("zone_id", UUID.randomUUID().toString());
attune(stack);
}
}
use of com.skelril.skree.service.ZoneService in project Skree by Skelril.
the class ZoneTransitionalOrb method rejoinInstance.
private boolean rejoinInstance(Player player) {
Optional<ZoneService> optZoneService = Sponge.getServiceManager().provide(ZoneService.class);
if (!optZoneService.isPresent()) {
return false;
}
if (isInInstanceWorld(player)) {
return false;
}
Location<World> priorLocation = player.getLocation();
ZoneService zoneService = optZoneService.get();
switch(zoneService.rejoin(player).getValue()) {
case ADDED:
saveLocation(player, priorLocation);
Task.builder().execute(() -> {
tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
tf(player).inventoryContainer.detectAndSendChanges();
}).delayTicks(1).submit(SkreePlugin.inst());
break;
case NO_REJOIN:
player.sendMessage(Text.of(TextColors.RED, "You cannot rejoin your previous zone."));
break;
case REF_LOST:
player.sendMessage(Text.of(TextColors.RED, "Your connection with your previous zone has been severed."));
break;
case DESPAWNED:
player.sendMessage(Text.of(TextColors.RED, "The your previous zone has despawned."));
break;
default:
player.sendMessage(Text.of(TextColors.RED, "Failed to rejoin your previous zone."));
break;
}
return true;
}
use of com.skelril.skree.service.ZoneService in project Skree by Skelril.
the class ZoneMeCommand method aquireSpec.
public static CommandSpec aquireSpec() {
ZoneService service = Sponge.getServiceManager().provide(ZoneService.class).get();
Map<String, String> options = service.getManagerNames().stream().collect(Collectors.toMap(a -> a, a -> a));
return CommandSpec.builder().description(Text.of("Create a zone")).permission("skree.zone.zoneme").arguments(onlyOne(choices(Text.of("zone"), options))).executor(new ZoneMeCommand()).build();
}
use of com.skelril.skree.service.ZoneService in project Skree by Skelril.
the class ZoneMeCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
ZoneService service = Sponge.getServiceManager().provide(ZoneService.class).get();
service.requestZone(args.<String>getOne("zone").get(), (Player) src, () -> {
src.sendMessage(Text.of(TextColors.YELLOW, "Job completed."));
}, (clause) -> {
if (clause.isPresent()) {
ZoneStatus status = clause.get().getValue();
src.sendMessage(Text.of(status == ZoneStatus.ADDED ? TextColors.GREEN : TextColors.RED, "Added with status: ", status));
}
});
src.sendMessage(Text.of(TextColors.YELLOW, "Creating requested zone."));
return CommandResult.success();
}
use of com.skelril.skree.service.ZoneService in project Skree by Skelril.
the class ZoneMasterOrb method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = tf(optItemStack.get());
if (!isZoneMasterItem(itemStack)) {
return;
}
if (isAttuned(itemStack)) {
if (isInInstanceWorld(player)) {
player.sendMessage(Text.of(TextColors.RED, "You cannot start an instance from within an instance."));
event.setCancelled(true);
return;
}
Optional<ZoneService> optService = Sponge.getServiceManager().provide(ZoneService.class);
if (optService.isPresent()) {
Task.builder().execute(() -> {
ZoneService service = optService.get();
List<Player> group = new ArrayList<>();
group.add(player);
for (Player aPlayer : Sponge.getServer().getOnlinePlayers()) {
ItemStack[] itemStacks = tf(aPlayer).inventory.mainInventory;
for (ItemStack aStack : itemStacks) {
if (!hasSameZoneID(itemStack, aStack)) {
continue;
}
if (isAttuned(aStack) && isZoneSlaveItem(aStack)) {
Optional<Player> optZoneOwner = getGroupOwner(aStack);
if (optZoneOwner.isPresent()) {
group.add(aPlayer);
break;
}
}
}
}
for (int i = group.size() - 1; i >= 0; --i) {
purgeZoneItems(group.get(i), itemStack);
// createLightningStrike(group.get(i)); SpongeCommon/420
saveLocation(group.get(i));
getMainWorldWrapper().getLobby().add(group.get(i));
}
service.requestZone(getZone(itemStack).get(), group, () -> {
getMainWorldWrapper().getLobby().remove(group);
}, result -> {
if (result.isPresent()) {
result.get().stream().filter(entry -> entry.getValue() != ZoneStatus.ADDED).forEach(entry -> {
player.setLocation(getRespawnLocation(player));
player.sendMessage(Text.of(TextColors.RED, "You could not be added to the zone."));
});
}
});
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
event.setUseBlockResult(Tristate.FALSE);
}
Aggregations