Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit db2c5d9

Browse files
authored
Update to v1.10.0 (#155)
2 parents 9e9dca4 + 88f9afd commit db2c5d9

47 files changed

Lines changed: 1114 additions & 40 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
name: Gradle Setup
1717
steps:
1818
- uses: actions/checkout@v4
19-
- uses: gradle/wrapper-validation-action@v3
20-
- name: Set up JDK 17
19+
- uses: gradle/actions/wrapper-validation@v3
20+
- name: Set up JDK 21
2121
uses: actions/setup-java@v4
2222
with:
2323
distribution: 'temurin'
24-
java-version: '17'
24+
java-version: '21'
2525
cache: 'gradle'
2626
- name: Change Permissions
2727
run: chmod +x ./gradlew
@@ -36,10 +36,10 @@ jobs:
3636
name: Test Project
3737
steps:
3838
- uses: actions/checkout@v4
39-
- name: Setup JDK 17
39+
- name: Setup JDK 21
4040
uses: actions/setup-java@v4
4141
with:
42-
java-version: '17'
42+
java-version: '21'
4343
distribution: 'temurin'
4444
cache: 'gradle'
4545
- name: Change Permissions
@@ -62,6 +62,8 @@ jobs:
6262
java-version: 17
6363
- version: 1.20.4
6464
java-version: 17
65+
- version: 1.20.6
66+
java-version: 21
6567

6668
name: Test Plugin on MC ${{ matrix.version }}
6769
steps:
@@ -77,7 +79,7 @@ jobs:
7779
- name: Build Plugin
7880
run: ./gradlew clean assemble
7981
- name: Test Plugin - ${{ matrix.version }}
80-
uses: GamerCoder215/TestMC@v1.0.4
82+
uses: gmitch215/TestMC@v1
8183
with:
8284
path: 'plugin/build/libs/novaconomy-*.jar'
8385
runtime: 'paper'
@@ -92,7 +94,7 @@ jobs:
9294
strategy:
9395
fail-fast: false
9496
matrix:
95-
java-version: [8, 11, 16, 17]
97+
java-version: [8, 11, 16, 17, 21]
9698

9799
name: Build Java ${{ matrix.java-version }}
98100
steps:
@@ -116,11 +118,11 @@ jobs:
116118
name: Create Artifacts
117119
steps:
118120
- uses: actions/checkout@v4
119-
- name: Set up JDK 17
121+
- name: Set up JDK 21
120122
uses: actions/setup-java@v4
121123
with:
122124
distribution: 'temurin'
123-
java-version: '17'
125+
java-version: '21'
124126
cache: 'gradle'
125127
- name: Change Permissions
126128
run: chmod +x ./gradlew
@@ -145,11 +147,11 @@ jobs:
145147
- uses: actions/checkout@v4
146148
with:
147149
fetch-depth: 0
148-
- name: Set up JDK 17
150+
- name: Set up JDK 21
149151
uses: actions/setup-java@v4
150152
with:
151153
distribution: 'temurin'
152-
java-version: '17'
154+
java-version: '21'
153155
cache: 'gradle'
154156
- name: Cache SonarCloud packages
155157
uses: actions/cache@v4
@@ -174,11 +176,11 @@ jobs:
174176

175177
steps:
176178
- uses: actions/checkout@v4
177-
- name: Set up JDK 17
179+
- name: Set up JDK 21
178180
uses: actions/setup-java@v4
179181
with:
180182
distribution: 'temurin'
181-
java-version: '17'
183+
java-version: '21'
182184
cache: 'gradle'
183185
- name: Change Permissions
184186
run: chmod +x ./gradlew

abstraction/src/main/java/us/teaminceptus/novaconomy/abstraction/CommandWrapper.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import us.teaminceptus.novaconomy.api.SortingType;
3232
import us.teaminceptus.novaconomy.api.bank.Bank;
3333
import us.teaminceptus.novaconomy.api.business.Business;
34+
import us.teaminceptus.novaconomy.api.business.BusinessCopyright;
3435
import us.teaminceptus.novaconomy.api.business.BusinessStatistics;
3536
import us.teaminceptus.novaconomy.api.business.Rating;
3637
import us.teaminceptus.novaconomy.api.corporation.Corporation;
@@ -772,6 +773,12 @@ default void addProduct(Player p, double price) {
772773
return;
773774
}
774775

776+
Corporation c = b.getParentCorporation();
777+
if (BusinessCopyright.isRegistered(pr) && (c == null || !c.equals(BusinessCopyright.getOwner(pr).getParentCorporation()))) {
778+
messages.sendMessage(p, "error.business.product_copyright");
779+
return;
780+
}
781+
775782
Economy econ = Economy.first();
776783

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

4472+
default void businessCopyright(Player p) {
4473+
if (!p.hasPermission("novaconomy.user.business")) {
4474+
messages.sendMessage(p, ERROR_PERMISSION_ARGUMENT);
4475+
return;
4476+
}
4477+
4478+
if (!Business.exists(p)) {
4479+
messages.sendError(p, "error.business.none");
4480+
return;
4481+
}
4482+
4483+
Business b = Business.byOwner(p);
4484+
4485+
NovaInventory inv = Generator.generateBusinessCopyright(b, SortingType.MATERIAL_TYPE_ASCENDING, p).get(0);
4486+
p.openInventory(inv);
4487+
NovaSound.BLOCK_ENDER_CHEST_OPEN.play(p);
4488+
}
4489+
4490+
default void registerBusinessCopyright(Player p) {
4491+
if (!p.hasPermission("novaconomy.user.business")) {
4492+
messages.sendMessage(p, ERROR_PERMISSION_ARGUMENT);
4493+
return;
4494+
}
4495+
4496+
if (!Business.exists(p)) {
4497+
messages.sendError(p, "error.business.none");
4498+
return;
4499+
}
4500+
4501+
Business b = Business.byOwner(p);
4502+
4503+
if (p.getItemInHand() == null || p.getItemInHand().getType() == Material.AIR) {
4504+
messages.sendError(p, "error.argument.item.hold");
4505+
return;
4506+
}
4507+
4508+
ItemStack item = p.getItemInHand().clone();
4509+
item.setAmount(1);
4510+
4511+
if (BusinessCopyright.isDisallowed(item)) {
4512+
messages.sendError(p, "error.business.cant_copyright");
4513+
return;
4514+
}
4515+
4516+
if (BusinessCopyright.isRegistered(item)) {
4517+
messages.sendError(p, "error.business.already_copyright", ChatColor.GOLD + BusinessCopyright.getOwner(item).getName());
4518+
return;
4519+
}
4520+
4521+
if (!b.isProduct(item)) {
4522+
messages.sendError(p, "error.argument.item");
4523+
return;
4524+
}
4525+
4526+
NovaPlayer np = new NovaPlayer(p);
4527+
if (!np.canAfford(NovaConfig.getConfiguration().getBusinessCopyrightCost(), NovaConfig.getConfiguration().getWhenNegativeAllowPurchaseProducts())) {
4528+
messages.sendError(p, "error.market.not_enough_money");
4529+
return;
4530+
}
4531+
4532+
NovaInventory inv = InventorySelector.confirm(p, cInv -> {
4533+
BusinessCopyright.setOwner(item, b);
4534+
messages.sendSuccess(p, "success.business.add_copyright");
4535+
p.closeInventory();
4536+
});
4537+
4538+
inv.setItem(11, economyWheel(p));
4539+
inv.setItem(13, item);
4540+
4541+
double cost = NovaConfig.getConfiguration().getBusinessCopyrightCost();
4542+
inv.setItem(15, Items.builder(Material.GOLD_BLOCK,
4543+
meta -> meta.setDisplayName(format(get(p, "constants.price"), cost, ""))
4544+
));
4545+
4546+
4547+
p.openInventory(inv);
4548+
NovaSound.ENTITY_ARROW_HIT_PLAYER.playSuccess(p);
4549+
}
4550+
44654551
}

abstraction/src/main/java/us/teaminceptus/novaconomy/util/inventory/Generator.java

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import java.util.*;
4343
import java.util.concurrent.atomic.AtomicBoolean;
4444
import java.util.concurrent.atomic.AtomicInteger;
45-
import java.util.function.BiConsumer;
46-
import java.util.function.Consumer;
4745
import java.util.function.Function;
4846
import java.util.function.Predicate;
4947
import java.util.stream.Collectors;
@@ -192,11 +190,21 @@ public static List<NovaInventory> generateBusinessData(Business b, Player viewer
192190
}
193191
);
194192

193+
ItemStack copyright = builder(
194+
Material.PAPER,
195+
meta -> meta.setDisplayName(ChatColor.AQUA + get(viewer, "constants.business.copyright")),
196+
nbt -> {
197+
nbt.setID("business:copyright");
198+
nbt.set(BUSINESS_TAG, b.getUniqueId());
199+
}
200+
);
201+
195202
if (b.isOwner(viewer)) {
196203
inv.setItem(16, mailbox);
197204
inv.setItem(17, invites);
198205
inv.setItem(26, advInfo);
199206
inv.setItem(27, supplyChests);
207+
inv.setItem(36, copyright);
200208
inv.setItem(53, settings);
201209
}
202210

@@ -1732,6 +1740,64 @@ public static NovaInventory confirmMail(@NotNull Mail mail, @NotNull Player view
17321740
return inv;
17331741
}
17341742

1743+
public static List<NovaInventory> generateBusinessCopyright(@NotNull Business b, SortingType<Material> sorter, Player viewer) {
1744+
List<NovaInventory> invs = new ArrayList<>();
1745+
Set<ItemStack> copyrighted = b.getCopyrightedItems();
1746+
1747+
int limit = Math.max(((copyrighted.size() - 1) / 26) + 1, 1);
1748+
for (int i = 0; i < limit; i++) {
1749+
final int fI = i;
1750+
1751+
NovaInventory inv = genGUI(54, b.getName() + " | " + get(viewer, "constants.business.copyright"));
1752+
inv.setCancelled();
1753+
1754+
inv.setAttribute("sorting_type", Material.class);
1755+
inv.setAttribute("sorting_function", (Function<SortingType<? super Material>, NovaInventory>)
1756+
s -> generateBusinessCopyright(b, sorter, viewer).get(fI));
1757+
1758+
inv.setItem(4, b.getPublicIcon());
1759+
inv.setItem(18, sorter(sorter));
1760+
1761+
List<ItemStack> items = copyrighted.stream()
1762+
.sorted(Comparator.comparing(ItemStack::getType, sorter))
1763+
.collect(Collectors.toList())
1764+
.subList(i * 26, Math.min((i + 1) * 26, copyrighted.size()));
1765+
1766+
for (ItemStack item : items)
1767+
inv.addItem(builder(item,
1768+
meta -> {
1769+
List<String> lore = meta.hasLore() ? new ArrayList<>(meta.getLore()) : new ArrayList<>();
1770+
lore.add(" ");
1771+
lore.add(ChatColor.YELLOW + get(viewer, "constants.click_remove"));
1772+
1773+
meta.setLore(lore);
1774+
},
1775+
nbt -> {
1776+
nbt.setID("business:remove_copyright");
1777+
nbt.set(BUSINESS_TAG, b.getUniqueId());
1778+
nbt.set(PRODUCT_TAG, b.getProduct(item));
1779+
})
1780+
);
1781+
1782+
inv.setItem(46, builder(BACK, nbt -> {
1783+
nbt.setID("business:click");
1784+
nbt.set(BUSINESS_TAG, b.getUniqueId());
1785+
}));
1786+
1787+
if (limit > 1) {
1788+
if (i > 0)
1789+
inv.setItem(47, Items.prev(STORED));
1790+
1791+
if (i < (limit - 1))
1792+
inv.setItem(53, Items.next(STORED));
1793+
}
1794+
1795+
invs.add(inv);
1796+
}
1797+
1798+
return invs;
1799+
}
1800+
17351801
// Utilities
17361802

17371803
public static void modelData(@NotNull ItemStack item, int data) {

api/src/main/java/us/teaminceptus/novaconomy/api/NovaConfig.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ static FileConfiguration loadConfig() {
392392
if (!config.isBoolean("Business.Advertising.Enabled")) config.set("Business.Advertising.Enabled", true);
393393
if (!config.isDouble("Business.Advertising.ClickReward") && !config.isInt("Business.Advertising.ClickReward")) config.set("Business.Advertising.ClickReward", 5D);
394394

395+
if (!config.isConfigurationSection("Business.Copyright")) config.createSection("Business.Copyright");
396+
if (!config.isBoolean("Business.Copyright.Enabled")) config.set("Business.Copyright.Enabled", true);
397+
if (!config.isDouble("Business.Copyright.Cost") && !config.isInt("Business.Copyright.Cost"))
398+
config.set("Business.Copyright.Cost", 1000);
399+
395400
// Database
396401

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

1314+
/**
1315+
* Whether Business Copyright is enabled.
1316+
* @return true if enabled, else false
1317+
*/
1318+
boolean isBusinessCopyrightEnabled();
1319+
1320+
/**
1321+
* Sets whether Business Copyright is enabled.
1322+
* @param enabled true if enabled, else false
1323+
*/
1324+
void setBusinessCopyrightEnabled(boolean enabled);
1325+
1326+
/**
1327+
* Fetches the cost of a Business Copyright.
1328+
* @return Cost of Business Copyright
1329+
*/
1330+
double getBusinessCopyrightCost();
1331+
1332+
/**
1333+
* Sets the cost of a Business Copyright.
1334+
* @param cost Cost of Business Copyright
1335+
*/
1336+
void setBusinessCopyrightCost(double cost);
13091337

13101338
}

api/src/main/java/us/teaminceptus/novaconomy/api/business/Business.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,39 @@ public boolean canSendMail(@NotNull OfflinePlayer p) {
17171717
return getSetting(Settings.Business.OPEN_MAILBOX);
17181718
}
17191719

1720+
/**
1721+
* Gets all the items copyrighted by this Business.
1722+
* @return All Copyrighted Items
1723+
*/
1724+
@NotNull
1725+
public Set<ItemStack> getCopyrightedItems() {
1726+
return ImmutableSet.copyOf(BusinessCopyright.getAllItems().entrySet()
1727+
.stream()
1728+
.filter(e -> e.getValue().equals(this))
1729+
.map(Map.Entry::getKey)
1730+
.collect(Collectors.toSet()));
1731+
}
1732+
1733+
/**
1734+
* Registers an item as being copyrighted under this business.
1735+
* @param item Item to register
1736+
* @throws IllegalStateException if the item is already copyrighted
1737+
*/
1738+
public void registerCopyright(@NotNull ItemStack item) throws IllegalStateException {
1739+
if (item == null) return;
1740+
BusinessCopyright.setOwner(item, this);
1741+
}
1742+
1743+
/**
1744+
* Gets whether this Business is the owner of an item.
1745+
* @param item Item to check
1746+
* @return true if owner, else false
1747+
*/
1748+
public boolean isOwner(@Nullable ItemStack item) {
1749+
if (item == null) return false;
1750+
return BusinessCopyright.getOwner(item) == this;
1751+
}
1752+
17201753
@Override
17211754
public boolean equals(Object o) {
17221755
if (this == o) return true;

0 commit comments

Comments
 (0)