Skip to content

Commit 5e4a545

Browse files
authored
Merge pull request #20 from Kawi16/main
Added PlotSquared Hook
2 parents 7bdc9fc + 8464962 commit 5e4a545

8 files changed

Lines changed: 86 additions & 0 deletions

File tree

core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ dependencies {
2424
compileOnly 'pl.minecodes.plots:plugin-api:4.6.2'
2525
compileOnly("io.lumine:Mythic-Dist:5.10.0-SNAPSHOT")
2626
compileOnly("com.iridium:IridiumSkyblock:4.1.0")
27+
implementation(platform("com.intellectualsites.bom:bom-newest:1.55"))
28+
compileOnly("com.intellectualsites.plotsquared:plotsquared-core")
29+
2730
// Lombok
2831
compileOnly("org.projectlombok:lombok:1.18.42")
2932
annotationProcessor("org.projectlombok:lombok:1.18.42")

core/src/main/java/github/nighter/smartspawner/hooks/IntegrationManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package github.nighter.smartspawner.hooks;
22

3+
import com.plotsquared.core.PlotAPI;
34
import github.nighter.smartspawner.SmartSpawner;
45
import github.nighter.smartspawner.hooks.drops.MythicMobsHook;
56
import github.nighter.smartspawner.hooks.protections.api.IridiumSkyblock;
67
import github.nighter.smartspawner.hooks.protections.api.Lands;
8+
import github.nighter.smartspawner.hooks.protections.api.PlotSquared;
79
import github.nighter.smartspawner.hooks.protections.api.SuperiorSkyblock2;
810
import github.nighter.smartspawner.hooks.rpg.AuraSkillsIntegration;
911
import lombok.Getter;
@@ -30,6 +32,7 @@ public class IntegrationManager {
3032
private boolean hasMinePlots = false;
3133
private boolean hasMythicMobs = false;
3234
private boolean hasIridiumSkyblock = false;
35+
private boolean hasPlotSquared = false;
3336

3437
// Integration plugin flags
3538
private boolean hasAuraSkills = false;
@@ -121,6 +124,19 @@ private void checkProtectionPlugins() {
121124
}
122125
return false;
123126
}, true);
127+
128+
hasPlotSquared = checkPlugin("PlotSquared", () -> {
129+
Plugin is = Bukkit.getPluginManager().getPlugin("PlotSquared");
130+
if(is != null && is.isEnabled()) {
131+
PlotAPI api = new PlotAPI();
132+
if(api == null) return false;
133+
PlotSquared ps = new PlotSquared();
134+
api.registerListener(ps);
135+
Bukkit.getPluginManager().registerEvents(ps, SmartSpawner.getInstance());
136+
return true;
137+
}
138+
return false;
139+
}, true);
124140
}
125141

126142
private void checkIntegrationPlugins() {

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckBreakBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static boolean CanPlayerBreakBlock(@NotNull final Player player, @NotNull
1919
if (integrationManager.isHasLands() && !Lands.canPlayerBreakClaimBlock(player, location)) return false;
2020
if (integrationManager.isHasTowny() && !Towny.canPlayerInteractSpawner(player, location)) return false;
2121
if (integrationManager.isHasSimpleClaimSystem() && !SimpleClaimSystem.canPlayerBreakClaimBlock(player, location)) return false;
22+
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2223
return true;
2324
}
2425
}

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckOpenMenu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static boolean CanPlayerOpenMenu(@NotNull final Player player, @NotNull L
2323
return false;
2424
if (integrationManager.isHasMinePlots() && !MinePlots.canPlayerOpenMenu(player, location)) return false;
2525
if (integrationManager.isHasIridiumSkyblock() && !IridiumSkyblock.canPlayerOpenMenu(player, location)) return false;
26+
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2627
return !integrationManager.isHasRedProtect() || RedProtectAPI.canPlayerOpenMenuOnClaim(player, location);
2728
}
2829
}

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckStackBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static boolean CanPlayerPlaceBlock(@NotNull final Player player, @NotNull
2323
return false;
2424
if (integrationManager.isHasMinePlots() && !MinePlots.canPlayerStackBlock(player, location)) return false;
2525
if (integrationManager.isHasIridiumSkyblock() && !IridiumSkyblock.canPlayerStackBlock(player, location)) return false;
26+
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2627
return !integrationManager.isHasRedProtect() || RedProtectAPI.canPlayerStackClaimBlock(player, location);
2728
}
2829
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package github.nighter.smartspawner.hooks.protections.api;
2+
3+
import com.google.common.eventbus.Subscribe;
4+
import com.plotsquared.core.events.PlotDeleteEvent;
5+
import com.plotsquared.core.events.Result;
6+
import com.plotsquared.core.plot.Plot;
7+
import github.nighter.smartspawner.SmartSpawner;
8+
import github.nighter.smartspawner.api.events.SpawnerPlaceEvent;
9+
import github.nighter.smartspawner.spawner.properties.SpawnerData;
10+
import org.bukkit.Location;
11+
import org.bukkit.entity.Player;
12+
import org.bukkit.event.EventHandler;
13+
import org.bukkit.event.EventPriority;
14+
import org.bukkit.event.Listener;
15+
import org.jetbrains.annotations.NotNull;
16+
17+
import java.util.HashMap;
18+
import java.util.HashSet;
19+
20+
public class PlotSquared implements Listener {
21+
private HashMap<Plot, HashSet<Location>> spawnersData = new HashMap<>();
22+
23+
public static boolean canInteract(@NotNull final Player player, @NotNull Location location) {
24+
Plot plot = Plot.getPlot(com.plotsquared.core.location.Location.at(
25+
location.getWorld().getName(),
26+
location.getBlockX(),
27+
location.getBlockY(),
28+
location.getBlockZ()));
29+
if (plot == null) return true;
30+
return plot.isAdded(player.getUniqueId());
31+
}
32+
33+
@Subscribe
34+
public void onPlotDelete(PlotDeleteEvent event) {
35+
if(event.getEventResult() == Result.DENY) return;
36+
Plot plot = event.getPlot();
37+
if(!spawnersData.containsKey(plot)) return;
38+
for(Location loc : spawnersData.get(plot)) {
39+
if(loc == null) return;
40+
SpawnerData spawner = SmartSpawner.getInstance().getSpawnerManager().getSpawnerByLocation(loc);
41+
if (spawner == null) continue;
42+
SmartSpawner.getInstance().getSpawnerManager().removeGhostSpawner(spawner.getSpawnerId());
43+
}
44+
}
45+
46+
@EventHandler (priority = EventPriority.HIGHEST)
47+
private void onSpawnerPlace(SpawnerPlaceEvent e) {
48+
Location location = e.getLocation();
49+
if(location == null) return;
50+
Plot plot = Plot.getPlot(com.plotsquared.core.location.Location.at(
51+
location.getWorld().getName(),
52+
location.getBlockX(),
53+
location.getBlockY(),
54+
location.getBlockZ()));
55+
if(plot == null) return;
56+
if(!spawnersData.containsKey(plot)) spawnersData.put(plot, new HashSet<>());
57+
spawnersData.get(plot).add(location);
58+
}
59+
}

core/src/main/resources/paper-plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ dependencies:
111111
load: BEFORE
112112
required: false
113113
join-classpath: true
114+
PlotSquared:
115+
load: BEFORE
116+
required: false
117+
join-classpath: true
114118

115119
# RPG/Skill Plugins
116120
AuraSkills:

core/src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ softdepend:
2424
- SimpleClaimSystem
2525
- RedProtect
2626
- MinePlots
27+
- PlotSquared
2728

2829
# World Management Plugins
2930
- Multiverse-Core

0 commit comments

Comments
 (0)