Search in sources :

Example 1 with MarketSignData

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

the class MarketSignManager method tryBreakActive.

public boolean tryBreakActive(Player player) {
    MarketSignData data = getCurrentData(player);
    Location<World> at = activeSigns.get(player.getUniqueId());
    return executeTryBreak(data, player, at);
}
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)

Example 2 with MarketSignData

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

the class MarketSignManager method updateSignText.

public void updateSignText(MarketSignData data, Location<World> loc) {
    SignData sign = loc.get(SignData.class).orElse(null);
    if (sign == null) {
        return;
    }
    boolean isValid = isValidSign(data, null);
    boolean inEditMode = isInEditMode(loc);
    boolean isAdmin = data.isAdminOwner();
    // First Line: SignType
    TextColor color = inEditMode ? DARK_PURPLE : !isValid ? TextColors.DARK_RED : isAdmin ? TextColors.BLUE : TextColors.DARK_BLUE;
    if (this.signInventories.containsKey(data.getID())) {
        color = LIGHT_PURPLE;
    }
    String raw;
    if (data.getSignType() != null) {
        // Buy or Sell
        raw = data.getSignType().getName();
    } else if (// Edit
    inEditMode) {
        raw = "Edit";
    } else {
        // Invalid
        raw = "Invalid";
    }
    if (// Append Admin?
    isAdmin) {
        raw = "Admin-" + raw;
    } else if (// !isAdmin
    !inEditMode && isValid) {
        if (data.getSignType() == SignType.BUY && data.getStock() == 0) {
            color = TextColors.RED;
            // Replace with Sold out
            raw = "Sold out";
        } else if (data.getSignType() == SignType.SELL && data.isSatisfied()) {
            color = TextColors.RED;
            // Replace with Satisfied
            raw = "Satisfied";
        }
    }
    Text line1 = Text.of(color, TextStyles.BOLD, raw);
    // Second Line: Item
    Text line2 = getItemText(data, inEditMode);
    // Third Line: Amount
    color = inEditMode ? DARK_PURPLE : TextColors.DARK_RED;
    raw = "No amount";
    if (data.getAmount() != null) {
        raw = data.getAmount().toString();
        color = TextColors.BLACK;
    }
    String raw2 = "";
    TextColor color2 = TextColors.RED;
    if (data.getStock() != null && data.getAmount() != null) {
        if (data.getSignType() == SignType.BUY) {
            raw2 = " x" + data.getStock();
            if (data.getStock() >= data.getAmount()) {
                color2 = TextColors.DARK_BLUE;
            }
        } else // Sell
        {
            raw2 = " x?";
            color2 = TextColors.AQUA;
            if (data.getDemand() != null) {
                raw2 = " x" + (data.getDemand() - data.getStock());
                if (data.getStock() >= data.getDemand()) {
                    color2 = TextColors.DARK_RED;
                }
            }
        }
    }
    Text line3 = Text.of(color, raw, color2, raw2);
    // Fourth Line: Price
    color = inEditMode ? DARK_PURPLE : TextColors.DARK_RED;
    Text line4 = Text.of(color, "No Price");
    if (data.getPrice() != null && data.getPrice() != 0) {
        line4 = formatPrice(data).toBuilder().color(TextColors.BLACK).build();
    }
    sign.setElements(Arrays.asList(line1, line2, line3, line4));
    loc.offer(sign);
}
Also used : MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) IMarketSignData(org.cubeengine.module.signmarket.data.IMarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor)

Example 3 with MarketSignData

use of org.cubeengine.module.signmarket.data.MarketSignData 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 4 with MarketSignData

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

the class EditModeCommand method stock.

@Command(desc = "Changes whether the sign has stock")
public void stock(Player context) {
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    if (!data.isAdminOwner()) {
        i18n.send(context, NEGATIVE, "Player signs cannot have no stock!");
        return;
    }
    if (data.getStock() == null) {
        data.setStock(0);
    } else {
        data.setStock(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 5 with MarketSignData

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

the class EditModeCommand method price.

@Command(desc = "Sets the price")
public void price(Player context, Double price) {
    if (price < 0) {
        i18n.send(context, NEGATIVE, "A negative price!? Are you serious?");
        return;
    }
    MarketSignData data = manager.getCurrentData(context);
    if (data == null) {
        i18n.send(context, NEGATIVE, "No active sign!");
        return;
    }
    data.setPrice(price);
    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)

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