Skip to content

Commit 4bf6e93

Browse files
Improve the code of recognizing shop sign
1 parent 8d4b0a5 commit 4bf6e93

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

src/main/java/org/maxgamer/quickshop/api/shop/Shop.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.maxgamer.quickshop.shop.ShopSignStorage;
3939

4040
import java.util.List;
41-
import java.util.Objects;
4241
import java.util.UUID;
4342

4443
/**
@@ -561,42 +560,33 @@ default List<ComponentPackage> getSignText(String locale) {
561560
* @return Is shop info sign
562561
*/
563562
default boolean isShopSign(@NotNull Sign sign) {
564-
return isShopSign(sign, null);
565-
}
566-
567-
/**
568-
* Checks if a Sign is a ShopSign and also check if a ShopSign is specific shop's ShopSign.
569-
*
570-
* @param sign Target sign
571-
* @param shop Target shop (null if you don't want check sign owner)
572-
* @return Is specific shop's ShopSign.
573-
*/
574-
default boolean isShopSign(@NotNull Sign sign, @Nullable Shop shop) {
575563
// Check for new shop sign
576564
String[] lines = sign.getLines();
577565
if (lines[0].isEmpty() && lines[1].isEmpty() && lines[2].isEmpty() && lines[3].isEmpty()) {
578566
return true;
579567
}
580568

581569
// Check for exists shop sign (modern)
582-
if (sign.getPersistentDataContainer().has(SHOP_NAMESPACED_KEY, ShopSignPersistentDataType.INSTANCE)) {
583-
if (shop != null) {
584-
ShopSignStorage shopSignStorage = sign.getPersistentDataContainer().get(SHOP_NAMESPACED_KEY, ShopSignPersistentDataType.INSTANCE);
585-
return Objects.equals(shopSignStorage, new ShopSignStorage(getLocation().getWorld().getName(), getLocation().getBlockX(), getLocation().getBlockY(), getLocation().getBlockZ()));
586-
}
587-
return true;
570+
ShopSignStorage shopSignStorage = sign.getPersistentDataContainer().get(SHOP_NAMESPACED_KEY, ShopSignPersistentDataType.INSTANCE);
571+
if (shopSignStorage != null) {
572+
return shopSignStorage.equals(getLocation().getWorld().getName(), getLocation().getBlockX(), getLocation().getBlockY(), getLocation().getBlockZ());
588573
}
589574

590575
// Check for exists shop sign (legacy upgrade)
576+
//Check if attached with the shop block
577+
if (!isAttached(sign.getBlock())) {
578+
return false;
579+
}
580+
//Check sign content
591581
if (lines[1].startsWith(SHOP_SIGN_PATTERN)) {
592582
return true;
593583
} else {
594584
if (!QuickShop.getInstance().getConfiguration().getOrDefault("legacy-updater.shop-sign", false)) {
595585
return false;
596586
}
597587
String header = lines[0];
598-
TextManager textManager=QuickShop.getInstance().text();
599-
String ownerName=this.ownerName(true);
588+
TextManager textManager = QuickShop.getInstance().text();
589+
String ownerName = this.ownerName(true);
600590
//Raw text matching
601591
String adminShopHeader = textManager.of("signs.header", textManager.of("admin-shop").forLocale()).forLocale();
602592
String userShopHeader = textManager.of("signs.header", ownerName).forLocale();

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,15 +1140,11 @@ public void setShopType(@NotNull ShopType newShopType) {
11401140
if (!(state instanceof Sign)) {
11411141
continue;
11421142
}
1143-
if (!isAttached(b)) {
1144-
continue;
1145-
}
11461143
Sign sign = (Sign) state;
1147-
if (!isShopSign(sign)) {
1148-
continue;
1144+
if (isShopSign(sign)) {
1145+
claimShopSign(sign);
1146+
signs.add(sign);
11491147
}
1150-
claimShopSign(sign);
1151-
signs.add(sign);
11521148
}
11531149

11541150
return signs;
@@ -1300,10 +1296,10 @@ public AbstractDisplayItem getDisplayItem() {
13001296
&& plugin.getOpenInvPlugin() != null) { //FIXME: Need better impl
13011297
OpenInv openInv = ((OpenInv) plugin.getOpenInvPlugin());
13021298
return openInv.getSpecialEnderChest(
1303-
Objects.requireNonNull(
1304-
openInv.loadPlayer(
1305-
plugin.getServer().getOfflinePlayer(this.moderator.getOwner()))),
1306-
plugin.getServer().getOfflinePlayer((this.moderator.getOwner())).isOnline())
1299+
Objects.requireNonNull(
1300+
openInv.loadPlayer(
1301+
plugin.getServer().getOfflinePlayer(this.moderator.getOwner()))),
1302+
plugin.getServer().getOfflinePlayer((this.moderator.getOwner())).isOnline())
13071303
.getBukkitInventory();
13081304
}
13091305
} catch (Exception e) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import lombok.Builder;
2424
import lombok.Data;
2525

26+
import java.util.Objects;
27+
2628
/**
2729
* TODO This class used for storage the shop sign
2830
*/
@@ -35,4 +37,7 @@ public class ShopSignStorage {
3537
private int x;
3638
private int y;
3739
private int z;
40+
public boolean equals(String world, int x, int y, int z){
41+
return Objects.equals(this.world,world)&&this.x==x&&this.y==y&&this.z==z;
42+
}
3843
}

0 commit comments

Comments
 (0)