Search in sources :

Example 16 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData in project modules-extra by CubeEngine.

the class EditModeCommand method admin.

@Command(desc = "Changes the sign to an admin-sign")
public void admin(Player context) {
    if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
        throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setOwner(IMarketSignData.ADMIN_SIGN);
    Location<World> loc = manager.updateData(data, context);
    manager.executeShowInfo(data, context, loc);
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) PermissionDeniedException(org.cubeengine.libcube.service.command.exception.PermissionDeniedException) World(org.spongepowered.api.world.World) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Example 17 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData in project modules-extra by CubeEngine.

the class EditModeCommand method size.

@Command(desc = "Sets the signs inventory size")
public void size(Player context, @org.cubeengine.butler.parametric.Optional Integer size, @ParameterPermission @Flag boolean infinite) {
    if (size == null || size < 0) {
        size = infinite ? -1 : 0;
    }
    if (size == 0 || size > 6) {
        i18n.send(context, NEGATIVE, "Invalid size! Use -i for infinite OR 1-6 inventory-lines!");
        return;
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setSize(size);
    Location<World> loc = manager.updateData(data, context);
    manager.executeShowInfo(data, context, loc);
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Example 18 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData in project modules-extra by CubeEngine.

the class EditModeCommand method nodemand.

@Command(desc = "Changes the demand of a sign")
public void nodemand(Player context) {
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setDemand(null);
    Location<World> loc = manager.updateData(data, context);
    manager.executeShowInfo(data, context, loc);
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Example 19 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData in project modules-extra by CubeEngine.

the class MarketSignListener method onClick.

@Listener
public void onClick(InteractBlockEvent event, @First Player player) {
    if (!event.getTargetBlock().getLocation().isPresent()) {
        return;
    }
    Location<World> loc = event.getTargetBlock().getLocation().get();
    BlockType blockType = loc.getBlockType();
    if (!Arrays.asList(STANDING_SIGN, WALL_SIGN).contains(blockType)) {
        // Not even a sign -> ignore
        return;
    }
    boolean editMode = module.getEditModeCommand().hasUser(player);
    Boolean sneaking = player.get(Keys.IS_SNEAKING).get();
    boolean punch = event instanceof Primary;
    Optional<MarketSignData> mSignData = event.getTargetBlock().get(ImmutableMarketSignData.class).map(ImmutableMarketSignData::asMutable);
    if (mSignData.isPresent()) {
        manager.updateSignText(mSignData.get(), loc);
    }
    if (editMode) {
        if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
            i18n.send(player, NEGATIVE, "You are not allowed to edit MarketSigns here");
            manager.exitEditMode(player);
            module.getEditModeCommand().removeUser(player);
            return;
        }
        if (// Its the active MarketSign -> Break or Modify Item
        manager.isActive(loc, player)) {
            if (// Do nothing if sneaking
            sneaking) {
                return;
            }
            if (punch) {
                if (manager.tryBreakActive(player)) {
                    return;
                } else {
                    // TODO resend signtext?
                    event.setCancelled(true);
                }
            }
            if (!punch && player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                manager.modifyItemActive(player, player.getItemInHand(HandTypes.MAIN_HAND).get());
            }
            event.setCancelled(true);
            return;
        }
        if (// Its another MarketSign
        mSignData.isPresent()) {
            // Set Current Sign
            manager.setSign(loc, player);
            event.setCancelled(true);
            return;
        }
        // Its a sign ; but no data yet
        if (// Sneak Interact -> Allow Interaction
        sneaking && !punch) {
            return;
        }
        if (// Sneak AND Punch to convert sign
        sneaking && punch) {
            // sneak + punch -> convert it!
            MarketSignData data = new MarketSignData();
            data.setID(UUID.randomUUID());
            data.setOwner(player.getUniqueId());
            // Sign converted! Now set active
            loc.offer(data);
            manager.setSign(loc, player);
            event.setCancelled(true);
            return;
        }
        i18n.send(player, NEGATIVE, "That is not a market sign!");
        i18n.send(player, NEUTRAL, "Sneak and punch the sign convert it.");
        event.setCancelled(true);
        return;
    }
    if (!mSignData.isPresent()) {
        return;
    }
    MarketSignData data = mSignData.get();
    manager.executeSignAction(data, loc, player, event instanceof InteractBlockEvent.Secondary);
    if (blockType != AIR) {
        // TODO sign somehow is retained /w some invalid data
        loc.offer(data);
        manager.updateSignText(data, loc);
    // event.setCancelled(true);
    }
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) BlockType(org.spongepowered.api.block.BlockType) Primary(org.spongepowered.api.event.block.InteractBlockEvent.Primary) MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 20 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData in project modules-extra by CubeEngine.

the class MarketSignManager method modifyItemActive.

public void modifyItemActive(Player player, ItemStack item) {
    MarketSignData data = getCurrentData(player);
    if (!data.isAdminOwner() && data.getStock() != null && data.getStock() != 0) {
        i18n.send(player, NEGATIVE, "You have to take all items out of the market sign to be able to change the item in it!");
        return;
    }
    Location<World> loc = activeSigns.get(player.getUniqueId());
    data.setItem(item, true);
    loc.offer(data);
    updateSignText(data, loc);
    i18n.send(player, POSITIVE, "Item in sign updated!");
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World)

Aggregations

ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)20 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)20 World (org.spongepowered.api.world.World)19 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)18 Command (org.cubeengine.butler.parametric.Command)14 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)14 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)5 BlockType (org.spongepowered.api.block.BlockType)2 Listener (org.spongepowered.api.event.Listener)2 Restricted (org.cubeengine.butler.filter.Restricted)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 SignData (org.spongepowered.api.data.manipulator.mutable.tileentity.SignData)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 Primary (org.spongepowered.api.event.block.InteractBlockEvent.Primary)1 Text (org.spongepowered.api.text.Text)1 TextColor (org.spongepowered.api.text.format.TextColor)1