Search in sources :

Example 1 with ZoneService

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);
    }
}
Also used : ZoneService(com.skelril.skree.service.ZoneService) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with ZoneService

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;
}
Also used : ZoneService(com.skelril.skree.service.ZoneService) World(org.spongepowered.api.world.World)

Example 3 with ZoneService

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();
}
Also used : ZoneService(com.skelril.skree.service.ZoneService) CommandResult(org.spongepowered.api.command.CommandResult) ZoneService(com.skelril.skree.service.ZoneService) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) Collectors(java.util.stream.Collectors) GenericArguments.choices(org.spongepowered.api.command.args.GenericArguments.choices) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) GenericArguments.onlyOne(org.spongepowered.api.command.args.GenericArguments.onlyOne) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Map(java.util.Map) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) Player(org.spongepowered.api.entity.living.player.Player) TextColors(org.spongepowered.api.text.format.TextColors)

Example 4 with ZoneService

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();
}
Also used : ZoneService(com.skelril.skree.service.ZoneService) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus)

Example 5 with ZoneService

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);
}
Also used : WorldService(com.skelril.skree.service.WorldService) InstanceWorldWrapper(com.skelril.skree.content.world.instance.InstanceWorldWrapper) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) Craftable(com.skelril.nitro.registry.Craftable) SkreePlugin(com.skelril.skree.SkreePlugin) WorldEffectWrapper(com.skelril.skree.service.internal.world.WorldEffectWrapper) Side(net.minecraftforge.fml.relauncher.Side) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) ZoneItemUtil(com.skelril.skree.content.registry.item.zone.ZoneItemUtil) EntityItem(net.minecraft.entity.item.EntityItem) Lightning(org.spongepowered.api.entity.weather.Lightning) Location(org.spongepowered.api.world.Location) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) CustomItem(com.skelril.nitro.registry.item.CustomItem) Sponge(org.spongepowered.api.Sponge) CustomItemTypes(com.skelril.skree.content.registry.item.CustomItemTypes) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Cause(org.spongepowered.api.event.cause.Cause) List(java.util.List) RespawnService(com.skelril.skree.service.RespawnService) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(org.spongepowered.api.world.World) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) First(org.spongepowered.api.event.filter.cause.First) Blocks(net.minecraft.init.Blocks) Getter(org.spongepowered.api.event.filter.Getter) Keys(org.spongepowered.api.data.key.Keys) MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityTypes(org.spongepowered.api.entity.EntityTypes) Text(org.spongepowered.api.text.Text) Task(org.spongepowered.api.scheduler.Task) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) CreativeTabs(net.minecraft.creativetab.CreativeTabs) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TextColors(org.spongepowered.api.text.format.TextColors) ZoneService(com.skelril.skree.service.ZoneService) Items(net.minecraft.init.Items) Item(org.spongepowered.api.entity.Item) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ZoneService(com.skelril.skree.service.ZoneService) ItemStack(net.minecraft.item.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Aggregations

ZoneService (com.skelril.skree.service.ZoneService)5 ZoneStatus (com.skelril.skree.service.internal.zone.ZoneStatus)3 Sponge (org.spongepowered.api.Sponge)2 Player (org.spongepowered.api.entity.living.player.Player)2 Text (org.spongepowered.api.text.Text)2 TextColors (org.spongepowered.api.text.format.TextColors)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 Craftable (com.skelril.nitro.registry.Craftable)1 CustomItem (com.skelril.nitro.registry.item.CustomItem)1 EventAwareContent (com.skelril.nitro.selector.EventAwareContent)1 ForgeTransformer.tf (com.skelril.nitro.transformer.ForgeTransformer.tf)1 SkreePlugin (com.skelril.skree.SkreePlugin)1 CustomItemTypes (com.skelril.skree.content.registry.item.CustomItemTypes)1 ZoneItemUtil (com.skelril.skree.content.registry.item.zone.ZoneItemUtil)1 InstanceWorldWrapper (com.skelril.skree.content.world.instance.InstanceWorldWrapper)1 MainWorldWrapper (com.skelril.skree.content.world.main.MainWorldWrapper)1 RespawnService (com.skelril.skree.service.RespawnService)1 WorldService (com.skelril.skree.service.WorldService)1 WorldEffectWrapper (com.skelril.skree.service.internal.world.WorldEffectWrapper)1 ArrayList (java.util.ArrayList)1