Skip to content

Commit 0d30727

Browse files
committed
Fix ReloadManager&economy init
1 parent 9c31545 commit 0d30727

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,5 +842,11 @@
842842
<artifactId>simplixstorage</artifactId>
843843
<version>3.2.3</version>
844844
</dependency>
845+
<dependency>
846+
<groupId>de.tr7zw</groupId>
847+
<artifactId>item-nbt-api-plugin</artifactId>
848+
<version>2.8.0</version>
849+
<scope>provided</scope>
850+
</dependency>
845851
</dependencies>
846852
</project>

src/main/java/org/maxgamer/quickshop/QuickShop.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
2525
import de.leonhard.storage.Yaml;
2626
import de.leonhard.storage.sections.FlatFileSection;
27+
import de.tr7zw.nbtapi.plugin.NBTAPI;
2728
import lombok.Getter;
2829
import lombok.Setter;
2930
import me.minebuilders.clearlag.Clearlag;
@@ -52,7 +53,6 @@
5253
import org.maxgamer.quickshop.api.compatibility.CompatibilityManager;
5354
import org.maxgamer.quickshop.api.database.DatabaseHelper;
5455
import org.maxgamer.quickshop.api.economy.AbstractEconomy;
55-
import org.maxgamer.quickshop.api.economy.EconomyCore;
5656
import org.maxgamer.quickshop.api.economy.EconomyType;
5757
import org.maxgamer.quickshop.api.event.QSReloadEvent;
5858
import org.maxgamer.quickshop.api.integration.IntegrateStage;
@@ -256,6 +256,9 @@ public class QuickShop extends JavaPlugin implements QuickShopAPI {
256256
private ShopPurger shopPurger;
257257
@Getter
258258
private final TpsWatcher tpsWatcher = new TpsWatcher();
259+
@Getter
260+
@Nullable
261+
private NBTAPI nbtapi = null;
259262

260263
/**
261264
* Use for mock bukkit
@@ -371,6 +374,17 @@ private void load3rdParty() {
371374
}
372375
}
373376
}
377+
if (getConfiguration().getBoolean("plugin.NBTAPI")) {
378+
this.nbtapi = (NBTAPI) Bukkit.getPluginManager().getPlugin("NBTAPI");
379+
if (this.nbtapi != null) {
380+
if (!this.nbtapi.isCompatible()) {
381+
getLogger().warning("NBTAPI plugin failed to loading, QuickShop NBTAPI support module has been disabled. Try update NBTAPI version to resolve the issue. (" + nbtapi.getDescription().getVersion() + ")");
382+
this.nbtapi = null;
383+
} else {
384+
getLogger().info("Successfully loaded NBTAPI support!");
385+
}
386+
}
387+
}
374388
Bukkit.getPluginManager().registerEvents(this.compatibilityTool, this);
375389
compatibilityTool.searchAndRegisterPlugins();
376390
if (this.display) {
@@ -422,13 +436,12 @@ private void load3rdParty() {
422436
public boolean loadEcon() {
423437
try {
424438
// EconomyCore core = new Economy_Vault();
425-
EconomyCore core = null;
426439
switch (EconomyType.fromID(getConfiguration().getInt("economy-type"))) {
427440
case UNKNOWN:
428441
setupBootError(new BootError(this.getLogger(), "Can't load the Economy provider, invaild value in config.yml."), true);
429442
return false;
430443
case VAULT:
431-
core = new Economy_Vault(this);
444+
economy = new Economy_Vault(this);
432445
Util.debugLog("Now using the Vault economy system.");
433446
if (getConfiguration().getOrDefault("tax", 0.0d) > 0) {
434447
try {
@@ -440,7 +453,7 @@ public boolean loadEcon() {
440453
} else {
441454
tax = Bukkit.getOfflinePlayer(Objects.requireNonNull(taxAccount));
442455
}
443-
Economy_Vault vault = (Economy_Vault) core;
456+
Economy_Vault vault = (Economy_Vault) economy;
444457
if (vault.isValid()) {
445458
if (!Objects.requireNonNull(vault.getVault()).hasAccount(tax)) {
446459
try {
@@ -466,21 +479,21 @@ public boolean loadEcon() {
466479
}
467480
break;
468481
case GEMS_ECONOMY:
469-
core = new Economy_GemsEconomy(this);
482+
economy = new Economy_GemsEconomy(this);
470483
Util.debugLog("Now using the GemsEconomy economy system.");
471484
break;
472485
case TNE:
473-
core = new Economy_TNE(this);
486+
economy = new Economy_TNE(this);
474487
Util.debugLog("Now using the TNE economy system.");
475488
break;
476489
default:
477490
Util.debugLog("No any economy provider selected.");
478491
break;
479492
}
480-
if (core == null) {
493+
if (economy == null) {
481494
return false;
482495
}
483-
if (!core.isValid()) {
496+
if (!economy.isValid()) {
484497
setupBootError(BuiltInSolution.econError(), false);
485498
return false;
486499
}

src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.maxgamer.quickshop.shop;
2121

2222
import com.lishid.openinv.OpenInv;
23+
import de.tr7zw.nbtapi.NBTTileEntity;
2324
import io.papermc.lib.PaperLib;
2425
import lombok.EqualsAndHashCode;
2526
import me.lucko.helper.serialize.BlockPosition;
@@ -734,7 +735,7 @@ public List<ComponentPackage> getSignText(@NotNull String locale) {
734735
lines.add(new ComponentPackage(TextComponent.fromLegacyText(SHOP_SIGN_PREFIX + line2 + " ")));
735736

736737
//line 3
737-
if (this.getItem().hasItemMeta() && this.getItem().getItemMeta().hasDisplayName()) {
738+
if (!this.getItem().hasItemMeta() || !this.getItem().getItemMeta().hasDisplayName()) {
738739
TextComponent left = new TextComponent(plugin.text().of("signs.item-left").forLocale());
739740
TranslatableComponent mediumItem = new TranslatableComponent("item." + getItem().getType().getKey().getNamespace() + "." + getItem().getType().getKey().getKey());
740741
TextComponent right = new TextComponent(plugin.text().of("signs.item-right").forLocale());
@@ -772,8 +773,16 @@ public void setSignText(@NotNull List<ComponentPackage> lines) {
772773
Util.ensureThread(false);
773774
List<Sign> signs = this.getSigns();
774775
for (Sign sign : signs) {
776+
NBTTileEntity tileSign = null;
777+
if (this.plugin.getNbtapi() != null) {
778+
tileSign = new NBTTileEntity(sign);
779+
}
775780
for (int i = 0; i < lines.size(); i++) {
776-
sign.setLine(i, new TextComponent(lines.get(i).getComponents()).toLegacyText());
781+
if (tileSign != null) {
782+
tileSign.setString("Text" + (i + 1), Util.componentsToJson(lines.get(i).getComponents()));
783+
} else {
784+
sign.setLine(i, new TextComponent(lines.get(i).getComponents()).toLegacyText());
785+
}
777786
}
778787
if (plugin.getGameVersion().isSignTextDyeSupport()) {
779788
DyeColor dyeColor = Util.getDyeColor();
@@ -1280,10 +1289,10 @@ public AbstractDisplayItem getDisplayItem() {
12801289
&& plugin.getOpenInvPlugin() != null) { //FIXME: Need better impl
12811290
OpenInv openInv = ((OpenInv) plugin.getOpenInvPlugin());
12821291
return openInv.getSpecialEnderChest(
1283-
Objects.requireNonNull(
1284-
openInv.loadPlayer(
1285-
plugin.getServer().getOfflinePlayer(this.moderator.getOwner()))),
1286-
plugin.getServer().getOfflinePlayer((this.moderator.getOwner())).isOnline())
1292+
Objects.requireNonNull(
1293+
openInv.loadPlayer(
1294+
plugin.getServer().getOfflinePlayer(this.moderator.getOwner()))),
1295+
plugin.getServer().getOfflinePlayer((this.moderator.getOwner())).isOnline())
12871296
.getBukkitInventory();
12881297
}
12891298
} catch (Exception e) {

src/main/java/org/maxgamer/quickshop/util/Util.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import lombok.SneakyThrows;
2929
import net.md_5.bungee.api.ChatColor;
3030
import net.md_5.bungee.api.chat.BaseComponent;
31+
import net.md_5.bungee.chat.ComponentSerializer;
3132
import org.apache.commons.lang.StringUtils;
3233
import org.bukkit.*;
3334
import org.bukkit.block.Block;
@@ -1104,6 +1105,15 @@ public static Material getSignMaterial() {
11041105
return Material.OAK_WALL_SIGN;
11051106
}
11061107

1108+
/**
1109+
* Convert component to json
1110+
*
1111+
* @param components Chat Component
1112+
* @return Json
1113+
*/
1114+
public static String componentsToJson(BaseComponent[] components) {
1115+
return ComponentSerializer.toString(components);
1116+
}
11071117

11081118
@SneakyThrows
11091119
public static void makeExportBackup(@Nullable String backupName) {

src/main/java/org/maxgamer/quickshop/util/reload/ReloadManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public synchronized Map<ReloadableContainer, ReloadResult> reload() {
119119
@NotNull
120120
public synchronized Map<ReloadableContainer, ReloadResult> reload(@Nullable Class<Reloadable> clazz) {
121121
Map<ReloadableContainer, ReloadResult> reloadResultMap = new HashMap<>();
122-
Iterator<ReloadableContainer> iterator = this.registry.iterator();
122+
//noinspection unchecked
123+
Iterator<ReloadableContainer> iterator = ((LinkedList<ReloadableContainer>) ((LinkedList<ReloadableContainer>) this.registry).clone()).iterator();
123124
while (iterator.hasNext()) {
124125
ReloadableContainer reloadable = iterator.next();
125126
if (clazz != null) {

src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ plugin:
466466
only: false
467467
#If you have WorldEdit, QuickShop will try migrating shops in EditSession. [BETA]
468468
WorldEdit: true
469+
#Allow us use NBTAPI to direct modify the blockstate data
470+
NBTAPI: true
469471
effect:
470472
sound:
471473
ontabcomplete: true

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ softdepend:
3333
- ArmShopBridge
3434
- IridiumSkyblock
3535
- FabledSkyblock
36+
- NBTAPI
3637

3738
api-version: 1.15
3839

0 commit comments

Comments
 (0)