Skip to content

Commit 7409981

Browse files
authored
Merge pull request Ghost-chu#1608 from Ghost-chu/master
5.0.0.16
2 parents 5c91bb3 + 7bdbf45 commit 7409981

File tree

8 files changed

+88
-53
lines changed

8 files changed

+88
-53
lines changed

pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<artifactId>QuickShop</artifactId>
2626

2727
<properties>
28-
<pluginver>5.0.0.15</pluginver>
28+
<pluginver>5.0.0.16</pluginver>
2929
<package>org.maxgamer.quickshop</package>
3030
<developer>Ghost-chu</developer>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -344,10 +344,6 @@
344344
<id>sonatype-oss</id>
345345
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
346346
</repository>
347-
<repository>
348-
<id>minebench-repo</id>
349-
<url>https://repo.minebench.de/</url>
350-
</repository>
351347
<repository>
352348
<id>papermc</id>
353349
<url>https://papermc.io/repo/repository/maven-public/</url>
@@ -489,7 +485,7 @@
489485
<dependency>
490486
<groupId>fr.neatmonster</groupId>
491487
<artifactId>nocheatplus</artifactId>
492-
<version>3.17-SNAPSHOT</version>
488+
<version>3.16.1-SNAPSHOT</version>
493489
<scope>provided</scope>
494490
</dependency>
495491
<dependency>
@@ -698,6 +694,10 @@
698694
<artifactId>paperlib</artifactId>
699695
<groupId>io.papermc</groupId>
700696
</exclusion>
697+
<exclusion>
698+
<artifactId>particleeffect</artifactId>
699+
<groupId>com.darkblade12</groupId>
700+
</exclusion>
701701
</exclusions>
702702
</dependency>
703703
<dependency>
@@ -713,9 +713,9 @@
713713
<artifactId>rollbar-java</artifactId>
714714
</dependency>
715715
<dependency>
716-
<groupId>de.themoep</groupId>
717-
<artifactId>minedown</artifactId>
718-
<version>1.7.1-SNAPSHOT</version>
716+
<groupId>com.github.Ghost-chu</groupId>
717+
<artifactId>MineDown</artifactId>
718+
<version>master-SNAPSHOT</version>
719719
<scope>compile</scope>
720720
</dependency>
721721
<dependency>
@@ -735,7 +735,7 @@
735735
<dependency>
736736
<groupId>com.songoda</groupId>
737737
<artifactId>skyblock</artifactId>
738-
<version>2.2.13</version>
738+
<version>2.3.30</version>
739739
<scope>provided</scope>
740740
<exclusions>
741741
<exclusion>

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121

2222
import com.google.common.cache.CacheBuilder;
2323
import com.google.common.cache.CacheStats;
24+
import lombok.AllArgsConstructor;
25+
import lombok.Data;
2426
import org.bukkit.Location;
2527
import org.checkerframework.checker.nullness.qual.NonNull;
2628
import org.jetbrains.annotations.NotNull;
2729
import org.jetbrains.annotations.Nullable;
2830
import org.maxgamer.quickshop.api.shop.Shop;
31+
import org.maxgamer.quickshop.shop.SimpleShopManager;
2932

3033
import java.util.concurrent.TimeUnit;
3134

@@ -36,11 +39,10 @@
3639
*/
3740
public class Cache {
3841
private final QuickShop plugin;
39-
private final com.google.common.cache.Cache<Location, Shop> accessCaching = CacheBuilder
42+
private final com.google.common.cache.Cache<Location, BoxedShop> accessCaching = CacheBuilder
4043
.newBuilder()
41-
.initialCapacity(1000)
44+
.initialCapacity(5000)
4245
.expireAfterAccess(120, TimeUnit.MINUTES)
43-
.weakValues()
4446
.recordStats()
4547
.build();
4648

@@ -56,24 +58,22 @@ public Cache(QuickShop plugin) {
5658
/**
5759
* Gets shop from plugin caching
5860
*
59-
* @param location The shop location that you want to get
60-
* @param includeAttached Include attached shops
61+
* @param location The shop location that you want to get
62+
* @param attached Does search for attached
6163
* @return The shop, null for no shops found in caching and memory
6264
*/
6365
@Nullable
64-
public Shop getCaching(@NotNull Location location, boolean includeAttached) {
65-
Shop shop = accessCaching.getIfPresent(location);
66-
if (shop == null) {
67-
if (includeAttached) {
68-
shop = plugin.getShopManager().getShopIncludeAttached(location, false);
66+
public Shop find(@NotNull Location location, boolean attached) {
67+
BoxedShop boxedShop = accessCaching.getIfPresent(location);
68+
if (boxedShop == null) {
69+
if (attached) {
70+
boxedShop = new BoxedShop(((SimpleShopManager) plugin.getShopManager()).findShopIncludeAttached(location, false));
6971
} else {
70-
shop = plugin.getShopManager().getShop(location);
72+
boxedShop = new BoxedShop(plugin.getShopManager().getShop(location));
7173
}
7274
}
73-
if (shop != null) {
74-
setCache(location, shop);
75-
}
76-
return shop;
75+
setCache(location, boxedShop.getShop());
76+
return boxedShop.getShop();
7777
}
7878

7979
/**
@@ -83,10 +83,20 @@ public Shop getCaching(@NotNull Location location, boolean includeAttached) {
8383
* @param shop null for invalidate and Shop object for update
8484
*/
8585
public void setCache(@NotNull Location location, @Nullable Shop shop) {
86-
if (shop == null) {
87-
accessCaching.invalidate(location);
88-
return;
86+
accessCaching.put(location, new BoxedShop(shop));
87+
}
88+
89+
public void invalidate(@NotNull Location location) {
90+
accessCaching.invalidate(location);
91+
}
92+
93+
@AllArgsConstructor
94+
@Data
95+
static class BoxedShop {
96+
private Shop shop;
97+
98+
public boolean isPresent() {
99+
return shop != null;
89100
}
90-
accessCaching.put(location, shop);
91101
}
92102
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,10 @@ public final void onEnable() {
902902
new ShopProtectionListener(this, this.shopCache).register();
903903
new PluginListener(this).register();
904904
new EconomySetupListener(this).register();
905-
// shopVaildWatcher = new ShopVaildWatcher(this);
906-
ongoingFeeWatcher = new OngoingFeeWatcher(this);
907905
InternalListener internalListener = new InternalListener(this);
908-
Bukkit.getPluginManager().registerEvents(internalListener, this);
906+
internalListener.register();
907+
ongoingFeeWatcher = new OngoingFeeWatcher(this);
908+
909909
if (this.display && AbstractDisplayItem.getNowUsing() != DisplayType.VIRTUALITEM) {
910910
displayWatcher = new DisplayWatcher(this);
911911
new DisplayProtectionListener(this, this.shopCache).register();

src/main/java/org/maxgamer/quickshop/listener/AbstractProtectionListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* This file is a part of project QuickShop, the name is ProtectionListenerBase.java
2+
* This file is a part of project QuickShop, the name is AbstractProtectionListener.java
33
* Copyright (C) PotatoCraft Studio and contributors
44
*
55
* This program is free software: you can redistribute it and/or modify it
@@ -52,7 +52,7 @@ public QuickShop getPlugin() {
5252
@Nullable
5353
public Shop getShopRedstone(@NotNull Location location, boolean includeAttached) {
5454
if (cache != null) {
55-
return cache.getCaching(location, includeAttached);
55+
return cache.find(location, includeAttached);
5656
} else {
5757
if (includeAttached) {
5858
return plugin.getShopManager().getShopIncludeAttached(location);

src/main/java/org/maxgamer/quickshop/listener/BlockListener.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.bukkit.event.block.BlockPlaceEvent;
3737
import org.bukkit.event.block.SignChangeEvent;
3838
import org.bukkit.event.inventory.InventoryMoveItemEvent;
39-
import org.bukkit.inventory.Inventory;
4039
import org.jetbrains.annotations.NotNull;
4140
import org.jetbrains.annotations.Nullable;
4241
import org.maxgamer.quickshop.Cache;
@@ -60,6 +59,7 @@ public class BlockListener extends AbstractProtectionListener {
6059

6160
public BlockListener(@NotNull final QuickShop plugin, @Nullable final Cache cache) {
6261
super(plugin, cache);
62+
init();
6363
}
6464

6565
private void init() {
@@ -171,18 +171,23 @@ public void onInventoryMove(InventoryMoveItemEvent event) {
171171
if (!this.update_sign_when_inventory_moving) {
172172
return;
173173
}
174-
175-
final Inventory inventory = event.getDestination();
176-
final Location location = inventory.getLocation();
177-
178-
if (location == null) {
179-
return;
174+
Location destination = event.getDestination().getLocation();
175+
Location source = event.getSource().getLocation();
176+
Shop destShop = null;
177+
Shop sourceShop = null;
178+
if (destination != null) {
179+
destination = Util.getBlockLocation(destination);
180+
destShop = getShopRedstone(destination, true);
180181
}
181-
182-
// Delayed task. Event triggers when item is moved, not when it is received.
183-
final Shop shop = getShopRedstone(location, true);
184-
if (shop != null) {
185-
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(shop);
182+
if (source != null) {
183+
source = Util.getBlockLocation(source);
184+
sourceShop = getShopRedstone(source, true);
185+
}
186+
if (destShop != null) {
187+
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(destShop);
188+
}
189+
if (sourceShop != null) {
190+
super.getPlugin().getSignUpdateWatcher().scheduleSignUpdate(sourceShop);
186191
}
187192
}
188193

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ public List<ComponentPackage> getSignText(@NotNull String locale) {
748748
lines.add(new ComponentPackage(new ComponentBuilder()
749749
.color(ChatColor.RESET)
750750
.append(left)
751-
.appendLegacy(Util.getItemStackName(getItem()))
751+
.append(TextComponent.fromLegacyText(Util.getItemStackName(getItem())))
752752
.append(right)
753753
.create()));
754754
} else {
@@ -762,7 +762,7 @@ public List<ComponentPackage> getSignText(@NotNull String locale) {
762762
}
763763
} else {
764764
lines.add(new ComponentPackage(new ComponentBuilder().color(ChatColor.RESET).appendLegacy(plugin.text().of("signs.item-left").forLocale())
765-
.append(Util.getItemStackName(getItem()))
765+
.append(TextComponent.fromLegacyText(Util.getItemStackName(getItem())))
766766
.appendLegacy(plugin.text().of("signs.item-right").forLocale()).create()));
767767
}
768768

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ public void createShop(@NotNull Shop shop, @NotNull Info info) {
417417
Util.debugLog("Location is null.");
418418
return null;
419419
}
420-
return getShopIncludeAttached_Fast(loc, false, useCache);
420+
if (useCache) {
421+
if (plugin.getShopCache() != null) {
422+
return plugin.getShopCache().find(loc, true);
423+
}
424+
}
425+
return findShopIncludeAttached(loc, false);
421426
}
422427

423428
@Override
@@ -1439,8 +1444,8 @@ private void actionTrade(@NotNull Player p, Info info, @NotNull String message)
14391444
}
14401445
}
14411446

1442-
private @Nullable Shop getShopIncludeAttached_Fast(
1443-
@NotNull Location loc, boolean fromAttach, boolean writeCache) {
1447+
@Nullable
1448+
public Shop findShopIncludeAttached(@NotNull Location loc, boolean fromAttach) {
14441449
Shop shop = getShop(loc);
14451450

14461451
// failed, get attached shop
@@ -1455,7 +1460,7 @@ private void actionTrade(@NotNull Player p, Info info, @NotNull String message)
14551460
if (Util.isWallSign(currentBlock.getType())) {
14561461
final Block attached = Util.getAttached(currentBlock);
14571462
if (attached != null) {
1458-
shop = this.getShopIncludeAttached_Fast(attached.getLocation(), true, writeCache);
1463+
shop = this.findShopIncludeAttached(attached.getLocation(), true);
14591464
}
14601465
} else {
14611466
// optimize for performance
@@ -1471,7 +1476,7 @@ private void actionTrade(@NotNull Player p, Info info, @NotNull String message)
14711476
}
14721477
}
14731478
// add cache if using
1474-
if (plugin.getShopCache() != null && writeCache) {
1479+
if (plugin.getShopCache() != null) {
14751480
plugin.getShopCache().setCache(loc, shop);
14761481
}
14771482
return shop;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,4 +1330,19 @@ public static String createRegexFromGlob(@NotNull String glob) {
13301330
return out.toString();
13311331
}
13321332

1333+
/**
1334+
* Get location that converted to block position (.0)
1335+
*
1336+
* @param loc location
1337+
* @return blocked location
1338+
*/
1339+
@NotNull
1340+
public static Location getBlockLocation(@NotNull Location loc) {
1341+
loc = loc.clone();
1342+
loc.setX(loc.getBlockX());
1343+
loc.setY(loc.getBlockY());
1344+
loc.setZ(loc.getBlockZ());
1345+
return loc;
1346+
}
1347+
13331348
}

0 commit comments

Comments
 (0)