Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
name: Gradle Setup
steps:
- uses: actions/checkout@v4
- uses: gradle/wrapper-validation-action@v3
- name: Set up JDK 17
- uses: gradle/actions/wrapper-validation@v3
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Change Permissions
run: chmod +x ./gradlew
Expand All @@ -36,10 +36,10 @@ jobs:
name: Test Project
steps:
- uses: actions/checkout@v4
- name: Setup JDK 17
- name: Setup JDK 21
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: 'gradle'
- name: Change Permissions
Expand All @@ -62,6 +62,8 @@ jobs:
java-version: 17
- version: 1.20.4
java-version: 17
- version: 1.20.6
java-version: 21

name: Test Plugin on MC ${{ matrix.version }}
steps:
Expand All @@ -77,7 +79,7 @@ jobs:
- name: Build Plugin
run: ./gradlew clean assemble
- name: Test Plugin - ${{ matrix.version }}
uses: GamerCoder215/TestMC@v1.0.4
uses: gmitch215/TestMC@v1
with:
path: 'plugin/build/libs/novaconomy-*.jar'
runtime: 'paper'
Expand All @@ -92,7 +94,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: [8, 11, 16, 17]
java-version: [8, 11, 16, 17, 21]

name: Build Java ${{ matrix.java-version }}
steps:
Expand All @@ -116,11 +118,11 @@ jobs:
name: Create Artifacts
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Change Permissions
run: chmod +x ./gradlew
Expand All @@ -145,11 +147,11 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Cache SonarCloud packages
uses: actions/cache@v4
Expand All @@ -174,11 +176,11 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Change Permissions
run: chmod +x ./gradlew
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import us.teaminceptus.novaconomy.api.SortingType;
import us.teaminceptus.novaconomy.api.bank.Bank;
import us.teaminceptus.novaconomy.api.business.Business;
import us.teaminceptus.novaconomy.api.business.BusinessCopyright;
import us.teaminceptus.novaconomy.api.business.BusinessStatistics;
import us.teaminceptus.novaconomy.api.business.Rating;
import us.teaminceptus.novaconomy.api.corporation.Corporation;
Expand Down Expand Up @@ -772,6 +773,12 @@ default void addProduct(Player p, double price) {
return;
}

Corporation c = b.getParentCorporation();
if (BusinessCopyright.isRegistered(pr) && (c == null || !c.equals(BusinessCopyright.getOwner(pr).getParentCorporation()))) {
messages.sendMessage(p, "error.business.product_copyright");
return;
}

Economy econ = Economy.first();

NovaInventory inv = genGUI(36, pr.hasItemMeta() && pr.getItemMeta().hasDisplayName() ? pr.getItemMeta().getDisplayName() : capitalize(pr.getType().name().replace('_', ' ')));
Expand Down Expand Up @@ -4462,4 +4469,83 @@ default void mailbox(Player p, Corporation c) {
NovaSound.ITEM_BOOK_PAGE_TURN.play(p);
}

default void businessCopyright(Player p) {
if (!p.hasPermission("novaconomy.user.business")) {
messages.sendMessage(p, ERROR_PERMISSION_ARGUMENT);
return;
}

if (!Business.exists(p)) {
messages.sendError(p, "error.business.none");
return;
}

Business b = Business.byOwner(p);

NovaInventory inv = Generator.generateBusinessCopyright(b, SortingType.MATERIAL_TYPE_ASCENDING, p).get(0);
p.openInventory(inv);
NovaSound.BLOCK_ENDER_CHEST_OPEN.play(p);
}

default void registerBusinessCopyright(Player p) {
if (!p.hasPermission("novaconomy.user.business")) {
messages.sendMessage(p, ERROR_PERMISSION_ARGUMENT);
return;
}

if (!Business.exists(p)) {
messages.sendError(p, "error.business.none");
return;
}

Business b = Business.byOwner(p);

if (p.getItemInHand() == null || p.getItemInHand().getType() == Material.AIR) {
messages.sendError(p, "error.argument.item.hold");
return;
}

ItemStack item = p.getItemInHand().clone();
item.setAmount(1);

if (BusinessCopyright.isDisallowed(item)) {
messages.sendError(p, "error.business.cant_copyright");
return;
}

if (BusinessCopyright.isRegistered(item)) {
messages.sendError(p, "error.business.already_copyright", ChatColor.GOLD + BusinessCopyright.getOwner(item).getName());
return;
}

if (!b.isProduct(item)) {
messages.sendError(p, "error.argument.item");
return;
}

NovaPlayer np = new NovaPlayer(p);
if (!np.canAfford(NovaConfig.getConfiguration().getBusinessCopyrightCost(), NovaConfig.getConfiguration().getWhenNegativeAllowPurchaseProducts())) {
messages.sendError(p, "error.market.not_enough_money");
return;
}

NovaInventory inv = InventorySelector.confirm(p, cInv -> {
BusinessCopyright.setOwner(item, b);
messages.sendSuccess(p, "success.business.add_copyright");
p.closeInventory();
});

inv.setItem(11, economyWheel(p));
inv.setItem(13, item);

double cost = NovaConfig.getConfiguration().getBusinessCopyrightCost();
inv.setItem(15, Items.builder(Material.GOLD_BLOCK,
meta -> meta.setDisplayName(format(get(p, "constants.price"), cost, ""))
));


p.openInventory(inv);
NovaSound.ENTITY_ARROW_HIT_PLAYER.playSuccess(p);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -192,11 +190,21 @@ public static List<NovaInventory> generateBusinessData(Business b, Player viewer
}
);

ItemStack copyright = builder(
Material.PAPER,
meta -> meta.setDisplayName(ChatColor.AQUA + get(viewer, "constants.business.copyright")),
nbt -> {
nbt.setID("business:copyright");
nbt.set(BUSINESS_TAG, b.getUniqueId());
}
);

if (b.isOwner(viewer)) {
inv.setItem(16, mailbox);
inv.setItem(17, invites);
inv.setItem(26, advInfo);
inv.setItem(27, supplyChests);
inv.setItem(36, copyright);
inv.setItem(53, settings);
}

Expand Down Expand Up @@ -1732,6 +1740,64 @@ public static NovaInventory confirmMail(@NotNull Mail mail, @NotNull Player view
return inv;
}

public static List<NovaInventory> generateBusinessCopyright(@NotNull Business b, SortingType<Material> sorter, Player viewer) {
List<NovaInventory> invs = new ArrayList<>();
Set<ItemStack> copyrighted = b.getCopyrightedItems();

int limit = Math.max(((copyrighted.size() - 1) / 26) + 1, 1);
for (int i = 0; i < limit; i++) {
final int fI = i;

NovaInventory inv = genGUI(54, b.getName() + " | " + get(viewer, "constants.business.copyright"));
inv.setCancelled();

inv.setAttribute("sorting_type", Material.class);
inv.setAttribute("sorting_function", (Function<SortingType<? super Material>, NovaInventory>)
s -> generateBusinessCopyright(b, sorter, viewer).get(fI));

inv.setItem(4, b.getPublicIcon());
inv.setItem(18, sorter(sorter));

List<ItemStack> items = copyrighted.stream()
.sorted(Comparator.comparing(ItemStack::getType, sorter))
.collect(Collectors.toList())
.subList(i * 26, Math.min((i + 1) * 26, copyrighted.size()));

for (ItemStack item : items)
inv.addItem(builder(item,
meta -> {
List<String> lore = meta.hasLore() ? new ArrayList<>(meta.getLore()) : new ArrayList<>();
lore.add(" ");
lore.add(ChatColor.YELLOW + get(viewer, "constants.click_remove"));

meta.setLore(lore);
},
nbt -> {
nbt.setID("business:remove_copyright");
nbt.set(BUSINESS_TAG, b.getUniqueId());
nbt.set(PRODUCT_TAG, b.getProduct(item));
})
);

inv.setItem(46, builder(BACK, nbt -> {
nbt.setID("business:click");
nbt.set(BUSINESS_TAG, b.getUniqueId());
}));

if (limit > 1) {
if (i > 0)
inv.setItem(47, Items.prev(STORED));

if (i < (limit - 1))
inv.setItem(53, Items.next(STORED));
}

invs.add(inv);
}

return invs;
}

// Utilities

public static void modelData(@NotNull ItemStack item, int data) {
Expand Down
28 changes: 28 additions & 0 deletions api/src/main/java/us/teaminceptus/novaconomy/api/NovaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ static FileConfiguration loadConfig() {
if (!config.isBoolean("Business.Advertising.Enabled")) config.set("Business.Advertising.Enabled", true);
if (!config.isDouble("Business.Advertising.ClickReward") && !config.isInt("Business.Advertising.ClickReward")) config.set("Business.Advertising.ClickReward", 5D);

if (!config.isConfigurationSection("Business.Copyright")) config.createSection("Business.Copyright");
if (!config.isBoolean("Business.Copyright.Enabled")) config.set("Business.Copyright.Enabled", true);
if (!config.isDouble("Business.Copyright.Cost") && !config.isInt("Business.Copyright.Cost"))
config.set("Business.Copyright.Cost", 1000);

// Database

if (!config.isConfigurationSection("Database")) config.createSection("Database");
Expand Down Expand Up @@ -1306,5 +1311,28 @@ default boolean isIgnoredTax(OfflinePlayer p) {
*/
boolean canBypassMaxNegativeAmount(@NotNull OfflinePlayer p);

/**
* Whether Business Copyright is enabled.
* @return true if enabled, else false
*/
boolean isBusinessCopyrightEnabled();

/**
* Sets whether Business Copyright is enabled.
* @param enabled true if enabled, else false
*/
void setBusinessCopyrightEnabled(boolean enabled);

/**
* Fetches the cost of a Business Copyright.
* @return Cost of Business Copyright
*/
double getBusinessCopyrightCost();

/**
* Sets the cost of a Business Copyright.
* @param cost Cost of Business Copyright
*/
void setBusinessCopyrightCost(double cost);

}
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,39 @@ public boolean canSendMail(@NotNull OfflinePlayer p) {
return getSetting(Settings.Business.OPEN_MAILBOX);
}

/**
* Gets all the items copyrighted by this Business.
* @return All Copyrighted Items
*/
@NotNull
public Set<ItemStack> getCopyrightedItems() {
return ImmutableSet.copyOf(BusinessCopyright.getAllItems().entrySet()
.stream()
.filter(e -> e.getValue().equals(this))
.map(Map.Entry::getKey)
.collect(Collectors.toSet()));
}

/**
* Registers an item as being copyrighted under this business.
* @param item Item to register
* @throws IllegalStateException if the item is already copyrighted
*/
public void registerCopyright(@NotNull ItemStack item) throws IllegalStateException {
if (item == null) return;
BusinessCopyright.setOwner(item, this);
}

/**
* Gets whether this Business is the owner of an item.
* @param item Item to check
* @return true if owner, else false
*/
public boolean isOwner(@Nullable ItemStack item) {
if (item == null) return false;
return BusinessCopyright.getOwner(item) == this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Loading