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);
}
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);
}
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!");
}
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);
}
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);
}
Aggregations