Search in sources :

Example 1 with ImmutableMarketSignData

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

the class MarketSignManager method setSign.

public void setSign(Location<World> loc, Player player) {
    if (activeSigns.values().contains(loc)) {
        i18n.send(ACTION_BAR, player, NEGATIVE, "Someone else is editing this sign!");
        return;
    }
    MarketSignData data = loc.get(MarketSignData.class).get();
    if (data.isAdminOwner()) {
        if (!player.hasPermission(module.perms().EDIT_ADMIN.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
        }
    } else {
        if (data.isOwner(player.getUniqueId())) {
            if (!player.hasPermission(module.perms().EDIT_PLAYER_SELF.getId())) {
                throw new PermissionDeniedException(module.perms().EDIT_PLAYER_SELF);
            }
        } else {
            if (!player.hasPermission(module.perms().EDIT_PLAYER_OTHER.getId())) {
                throw new PermissionDeniedException(module.perms().EDIT_PLAYER_OTHER);
            }
        }
    }
    Location<World> last = activeSigns.put(player.getUniqueId(), loc);
    if (last != null) {
        ImmutableMarketSignData prevData = last.get(MarketSignData.class).map(MarketSignData::asImmutable).orElse(previousSign.get(player.getUniqueId()));
        previousSign.put(player.getUniqueId(), prevData);
        updateSignText(prevData.asMutable(), last);
    }
    updateSignText(loc.get(MarketSignData.class).get(), loc);
    i18n.send(ACTION_BAR, player, POSITIVE, "Changed active sign!");
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) 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)

Example 2 with ImmutableMarketSignData

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

the class MarketSignListener method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot orig = transaction.getOriginal();
        BlockType type = orig.getState().getType();
        if (type == STANDING_SIGN || type == WALL_SIGN) {
            Optional<ImmutableMarketSignData> signData = orig.get(ImmutableMarketSignData.class);
            if (signData.isPresent()) {
                if (signData.get().getSignType() != null) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
        Location<World> origLoc = orig.getLocation().get();
        for (Direction blockFace : BlockUtil.BLOCK_FACES) {
            if (blockFace == DOWN) {
                continue;
            }
            Location<World> relative = origLoc.getRelative(blockFace);
            if (!relative.get(MarketSignData.class).isPresent()) {
                continue;
            }
            if (blockFace == UP) {
                if (relative.getBlockType() == STANDING_SIGN) {
                    event.setCancelled(true);
                    return;
                }
            } else {
                if (relative.getBlockType() == WALL_SIGN && relative.get(Keys.DIRECTION).get() == blockFace) {
                    event.setCancelled(true);
                    return;
                }
            }
        }
    }
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 3 with ImmutableMarketSignData

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

the class EditModeCommand method copy.

@Restricted(Player.class)
@Command(desc = "Copies the settings from the previous sign")
public void copy(Player context) {
    ImmutableMarketSignData data = manager.getPreviousData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No previous market sign");
        return;
    }
    if (data.getOwner().equals(IMarketSignData.ADMIN_SIGN)) {
        if (!context.hasPermission(module.perms().EDIT_ADMIN.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_ADMIN);
        }
    } else {
        if (!context.hasPermission(module.perms().EDIT_USE.getId())) {
            throw new PermissionDeniedException(module.perms().EDIT_USE);
        }
    }
    MarketSignData copy = data.asMutable();
    if (!copy.isAdminOwner()) {
        copy.setStock(0);
    }
    Location<World> loc = manager.updateData(copy, context);
    manager.executeShowInfo(copy, context, loc);
}
Also used : ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) 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) Restricted(org.cubeengine.butler.filter.Restricted) Command(org.cubeengine.butler.parametric.Command) ConversationCommand(org.cubeengine.libcube.service.command.conversation.ConversationCommand)

Example 4 with ImmutableMarketSignData

use of org.cubeengine.module.signmarket.data.ImmutableMarketSignData 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)

Aggregations

ImmutableMarketSignData (org.cubeengine.module.signmarket.data.ImmutableMarketSignData)4 World (org.spongepowered.api.world.World)4 MarketSignData (org.cubeengine.module.signmarket.data.MarketSignData)3 PermissionDeniedException (org.cubeengine.libcube.service.command.exception.PermissionDeniedException)2 IMarketSignData (org.cubeengine.module.signmarket.data.IMarketSignData)2 BlockType (org.spongepowered.api.block.BlockType)2 Listener (org.spongepowered.api.event.Listener)2 Restricted (org.cubeengine.butler.filter.Restricted)1 Command (org.cubeengine.butler.parametric.Command)1 ConversationCommand (org.cubeengine.libcube.service.command.conversation.ConversationCommand)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 InteractBlockEvent (org.spongepowered.api.event.block.InteractBlockEvent)1 Primary (org.spongepowered.api.event.block.InteractBlockEvent.Primary)1 Direction (org.spongepowered.api.util.Direction)1