Skip to content

Commit 65aa023

Browse files
committed
From [GitHub PR 6: [#5] Implement WorldGuard Wrapper](#6)
GitOrigin-RevId: addbb35fd35d36972506c5651df5698d179b529f
1 parent 0310305 commit 65aa023

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ plugins {
1515
shadowJar {
1616
relocate 'cloud.commandframework', 'us.mcparks.showscript.cloud.commandframework'
1717
relocate 'co.aikar.timings.lib', 'us.mcparks.showscript.aikar.timings.lib'
18+
relocate 'org.codemc.worldguardwrapper', 'us.mcparks.showscript.codemc.worldguardwrapper'
1819
}
1920

2021
sourceSets {
@@ -63,6 +64,11 @@ repositories {
6364
url = uri('https://repo.aikar.co/nexus/content/groups/aikar/')
6465
}
6566

67+
// codemc - worldguardwrapper
68+
maven {
69+
url = uri('https://repo.codemc.org/repository/maven-public/')
70+
}
71+
6672
}
6773

6874
dependencies {
@@ -78,6 +84,7 @@ dependencies {
7884
implementation "net.kyori:adventure-platform-bukkit:4.3.0"
7985
implementation "commons-io:commons-io:2.16.1"
8086
implementation "co.aikar:minecraft-timings:1.0.4"
87+
implementation "org.codemc.worldguardwrapper:worldguardwrapper:1.2.1-SNAPSHOT"
8188

8289
}
8390

src/us/mcparks/showscript/Main.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import co.aikar.timings.lib.MCTiming;
1919
import co.aikar.timings.lib.TimingManager;
20-
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
20+
import org.codemc.worldguardwrapper.WorldGuardWrapper;
2121
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
2222
import us.mcparks.showscript.event.region.RegionListener;
2323
import us.mcparks.showscript.event.show.ShowStartEvent;
@@ -49,8 +49,8 @@ public class Main extends JavaPlugin implements Listener {
4949

5050
private RegionListener regionListener;
5151

52-
public static Supplier<List<String>> showFileNames = new AsynchronouslyRefreshingSupplier<>(() -> {
53-
File fs = new File(Main.getPlugin(Main.class).getRealDataFolder(), "Shows");
52+
public Supplier<List<String>> showFileNames = new AsynchronouslyRefreshingSupplier<>(() -> {
53+
File fs = new File(getRealDataFolder(), "Shows");
5454
if (!fs.exists()) {
5555
fs.mkdir();
5656
}
@@ -94,7 +94,8 @@ public void onEnable() {
9494
// start RegionListener if WorldGuard is present
9595
Plugin worldGuard = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
9696
if (worldGuard != null) {
97-
regionListener = new RegionListener((WorldGuardPlugin) worldGuard);
97+
getLogger().info("Using WorldGuardWrapper");
98+
regionListener = new RegionListener(WorldGuardWrapper.getInstance());
9899
} else {
99100
getLogger().warning("WorldGuard not found. Region Shows will not function.");
100101
}

src/us/mcparks/showscript/Shows.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public List<String> showNames(CommandContext<CommandSender> sender, String input
131131
return new ArrayList<>();
132132
}
133133

134-
return Main.showFileNames.get().stream().filter(s -> s.startsWith(input)).collect(Collectors.toList());
134+
return main.showFileNames.get().stream().filter(s -> s.startsWith(input)).collect(Collectors.toList());
135135
}
136136

137137
@Suggestions("showDirectoryNames")
@@ -140,7 +140,7 @@ public List<String> showDirectories(CommandContext<CommandSender> sender, String
140140
return new ArrayList<>();
141141
}
142142

143-
return Main.showFileNames.get().stream().map(path -> path.lastIndexOf("/") == -1 ? path : path.substring(0, path.lastIndexOf("/"))).distinct().filter(s -> s.startsWith(input)).collect(Collectors.toList());
143+
return main.showFileNames.get().stream().map(path -> path.lastIndexOf("/") == -1 ? path : path.substring(0, path.lastIndexOf("/"))).distinct().filter(s -> s.startsWith(input)).collect(Collectors.toList());
144144
}
145145

146146
public static String getShowNameFromAbsolutePath(String absolutePath) {

src/us/mcparks/showscript/event/region/RegionListener.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package us.mcparks.showscript.event.region;
22

33
import com.google.common.collect.Sets;
4-
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
5-
import com.sk89q.worldguard.protection.managers.RegionManager;
6-
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
4+
import org.codemc.worldguardwrapper.WorldGuardWrapper;
5+
import org.codemc.worldguardwrapper.region.IWrappedRegion;
76
import us.mcparks.showscript.Main;
87
import org.bukkit.Bukkit;
98
import org.bukkit.Location;
@@ -18,16 +17,16 @@
1817
import java.util.stream.Collectors;
1918

2019
public class RegionListener implements Listener {
21-
public static Map<Player, Set<ProtectedRegion>> regionMap;
22-
private WorldGuardPlugin worldGuard;
20+
public static Map<Player, Set<IWrappedRegion>> regionMap;
21+
private final WorldGuardWrapper worldGuardWrapper;
2322

2423
// Players in this set won't have their regions updated as long as they're passengers in a vehicle
2524
private Set<Player> disabledPassengers;
2625

27-
public RegionListener(WorldGuardPlugin wgp) {
26+
public RegionListener(WorldGuardWrapper wgpw) {
2827
regionMap = new HashMap<>();
2928
disabledPassengers = new HashSet<>();
30-
worldGuard = wgp;
29+
worldGuardWrapper = wgpw;
3130
Bukkit.getPluginManager().registerEvents(this, Main.getPlugin(Main.class));
3231
}
3332

@@ -39,7 +38,7 @@ public Collection<Player> getPlayersInRegion(String regionId) {
3938
}
4039

4140
public Collection<String> getRegionsForPlayer(Player player) {
42-
return regionMap.get(player).stream().map(ProtectedRegion::getId).collect(Collectors.toList());
41+
return regionMap.get(player).stream().map(IWrappedRegion::getId).collect(Collectors.toList());
4342
}
4443

4544
@EventHandler
@@ -88,31 +87,30 @@ public void onVehicleExit(VehicleExitEvent e) {
8887

8988
private synchronized void updateRegions(final Player player, final MovementType movementType,
9089
Location to) {
91-
Set<ProtectedRegion> oldRegions;
90+
Set<IWrappedRegion> oldRegions;
9291

9392
if (regionMap.get(player) == null) {
9493
oldRegions = new HashSet<>();
9594
} else {
9695
oldRegions = new HashSet<>(regionMap.get(player));
9796
}
9897

99-
RegionManager rm = worldGuard.getRegionManager(to.getWorld());
98+
Set<IWrappedRegion> applicableRegions = worldGuardWrapper.getRegions(to);
10099

101-
if (rm != null) {
102-
Set<ProtectedRegion> applicableRegions = rm.getApplicableRegions(to).getRegions();
100+
if (applicableRegions != null) {
103101
// System.out.println("------------");
104102
// for (ProtectedRegion region : oldRegions) {
105103
// System.out.println("old: " + region.getId());
106104
// }
107105
// for (ProtectedRegion region : applicableRegions) {
108106
// System.out.println("new: " + region.getId());
109107
// }
110-
for (ProtectedRegion region : Sets.difference(applicableRegions, oldRegions)) {
108+
for (IWrappedRegion region : Sets.difference(applicableRegions, oldRegions)) {
111109
Bukkit.getServer().getPluginManager()
112110
.callEvent(new PlayerEnterRegionEvent(player, region.getId()));
113111
}
114112

115-
for (ProtectedRegion region : Sets.difference(oldRegions, applicableRegions)) {
113+
for (IWrappedRegion region : Sets.difference(oldRegions, applicableRegions)) {
116114
Bukkit.getServer().getPluginManager()
117115
.callEvent(new PlayerLeaveRegionEvent(player, region.getId()));
118116
}

0 commit comments

Comments
 (0)