2222import net .alex9849 .arm .events .RemoveRegionEvent ;
2323import net .alex9849 .arm .events .RestoreRegionEvent ;
2424import net .alex9849 .arm .regions .Region ;
25- import net .alex9849 .armshopbridge .ArmShopBridge ;
26- import net .alex9849 .armshopbridge .adapters .QuickShop4Adapter ;
27- import net .alex9849 .armshopbridge .adapters .QuickShopAdapter ;
28- import net .alex9849 .armshopbridge .interfaces .IShopPluginAdapter ;
29- import org .bukkit .Bukkit ;
3025import org .bukkit .Chunk ;
3126import org .bukkit .Location ;
3227import org .bukkit .World ;
3328import org .bukkit .entity .Player ;
3429import org .bukkit .event .EventHandler ;
3530import org .bukkit .event .EventPriority ;
36- import org .bukkit .event .server .PluginEnableEvent ;
3731import org .bukkit .util .Vector ;
3832import org .jetbrains .annotations .NotNull ;
3933import org .maxgamer .quickshop .QuickShop ;
4438import org .maxgamer .quickshop .util .reload .ReloadResult ;
4539import org .maxgamer .quickshop .util .reload .ReloadStatus ;
4640
47- import java .util .*;
48- import java .util .logging .Level ;
41+ import java .util .HashMap ;
42+ import java .util .HashSet ;
43+ import java .util .Map ;
44+ import java .util .Set ;
4945
5046@ IntegrationStage (loadStage = IntegrateStage .onEnableAfter )
5147public class AdvancedShopRegionMarketIntegration extends AbstractQSIntegratedPlugin {
@@ -94,36 +90,35 @@ public boolean canTradeShopHere(@NotNull Player player, @NotNull Location locati
9490 */
9591 @ Override
9692 public void load () {
97- scanAndUnregister ();
9893 registerListener ();
9994 }
10095
101- @ EventHandler (priority = EventPriority .MONITOR , ignoreCancelled = true )
102- public void onPluginLoad (PluginEnableEvent event ) {
103- if ("ArmShopBridge" .equals (event .getPlugin ().getName ())) {
104- scanAndUnregister ();
105- }
106- }
107-
108- private void scanAndUnregister () {
109- try {
110- if (Bukkit .getPluginManager ().getPlugin ("ArmShopBridge" ) == null || ArmShopBridge .getInstance () == null ) {
111- return ;
112- }
113- Iterator <IShopPluginAdapter > adapterListIterator = ArmShopBridge .getInstance ().getShopPluginAdapters ().iterator ();
114- //noinspection
115- //Use legacy way to prevent lambda internal method causing listener load failed
116- while (adapterListIterator .hasNext ()) {
117- IShopPluginAdapter adapter = adapterListIterator .next ();
118- if (adapter instanceof QuickShopAdapter || adapter instanceof QuickShop4Adapter ) {
119- adapterListIterator .remove ();
120- plugin .getLogger ().log (Level .INFO , "Successfully remove redundant ARM-ShopBridge handlers!" );
121- }
122- }
123- } catch (Throwable exception ) {
124- plugin .getLogger ().log (Level .WARNING , "Cannot to handle ARM-ShopBridge handlers, ignoring..." , exception );
125- }
126- }
96+ // @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
97+ // public void onPluginLoad(PluginEnableEvent event) {
98+ // if ("ArmShopBridge".equals(event.getPlugin().getName())) {
99+ // scanAndUnregister();
100+ // }
101+ // }
102+ //
103+ // private void scanAndUnregister() {
104+ // try {
105+ // if (Bukkit.getPluginManager().getPlugin("ArmShopBridge") == null || ArmShopBridge.getInstance() == null) {
106+ // return;
107+ // }
108+ // Iterator<IShopPluginAdapter> adapterListIterator = ArmShopBridge.getInstance().getShopPluginAdapters().iterator();
109+ // //noinspection
110+ // //Use legacy way to prevent lambda internal method causing listener load failed
111+ // while (adapterListIterator.hasNext()) {
112+ // IShopPluginAdapter adapter = adapterListIterator.next();
113+ // if (adapter instanceof QuickShopAdapter || adapter instanceof QuickShop4Adapter) {
114+ // adapterListIterator.remove();
115+ // plugin.getLogger().log(Level.INFO, "Successfully remove redundant ARM-ShopBridge handlers!");
116+ // }
117+ // }
118+ // } catch (Throwable exception) {
119+ // plugin.getLogger().log(Level.WARNING, "Cannot to handle ARM-ShopBridge handlers, ignoring...", exception);
120+ // }
121+ // }
127122
128123 /**
129124 * Unloding logic
@@ -136,9 +131,9 @@ public void unload() {
136131
137132 private void handleDeletion (Region region ) {
138133 Vector minPoint = region .getRegion ().getMinPoint ();
139- Vector maxPoint = region .getRegion ().getMaxPoint ();
134+ Vector maxPoint = region .getRegion ().getMinPoint ();
140135 World world = region .getRegionworld ();
141- Set <Chunk > chuckLocations = new HashSet <>();
136+ Set <Chunk > chuckLocations = new HashSet <Chunk >();
142137
143138 for (int x = minPoint .getBlockX (); x <= maxPoint .getBlockX () + 16 ; x += 16 ) {
144139 for (int z = minPoint .getBlockZ (); z <= maxPoint .getBlockZ () + 16 ; z += 16 ) {
@@ -155,12 +150,10 @@ private void handleDeletion(Region region) {
155150 shopMap .putAll (shopsInChunk );
156151 }
157152 }
158- for (Map .Entry <Location , Shop > shopEntry : shopMap .entrySet ()) {
159- Location shopLocation = shopEntry .getKey ();
153+ for (Location shopLocation : shopMap .keySet ()) {
160154 if (region .getRegion ().contains (shopLocation .getBlockX (), shopLocation .getBlockY (), shopLocation .getBlockZ ())) {
161- Shop shop = shopEntry . getValue ( );
155+ Shop shop = shopMap . get ( shopLocation );
162156 if (shop != null ) {
163- shop .onUnload ();
164157 shop .delete (false );
165158 }
166159 }
0 commit comments