-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix bug with NPE in EntityPickupItemEvent
- Add custom WG flags to fix a bug where users couldn't open shops in their own claims
- Loading branch information
Showing
23 changed files
with
125 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 78 additions & 9 deletions
87
modules/Plugin/src/main/java/xyz/mackan/Slabbo/pluginsupport/WorldguardSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,115 @@ | ||
package xyz.mackan.Slabbo.pluginsupport; | ||
|
||
import com.sk89q.worldedit.bukkit.BukkitAdapter; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
import com.sk89q.worldguard.LocalPlayer; | ||
import com.sk89q.worldguard.WorldGuard; | ||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; | ||
import com.sk89q.worldguard.protection.ApplicableRegionSet; | ||
import com.sk89q.worldguard.protection.flags.Flags; | ||
import com.sk89q.worldguard.protection.flags.StateFlag; | ||
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; | ||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; | ||
import com.sk89q.worldguard.protection.managers.RegionManager; | ||
import com.sk89q.worldguard.protection.regions.ProtectedRegion; | ||
import com.sk89q.worldguard.protection.regions.RegionContainer; | ||
import com.sk89q.worldguard.protection.regions.RegionQuery; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Player; | ||
import xyz.mackan.Slabbo.Slabbo; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Set; | ||
|
||
public class WorldguardSupport { | ||
public static StateFlag CREATE_SHOPS; | ||
public static StateFlag USE_SHOPS; | ||
|
||
public static void registerFlags () { | ||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); | ||
|
||
try { | ||
StateFlag createShopsFlag = new StateFlag("slabbo-others-create-shops", true); | ||
StateFlag useShopsFlag = new StateFlag("slabbo-others-use-shops", true); | ||
|
||
registry.register(createShopsFlag); | ||
registry.register(useShopsFlag); | ||
|
||
CREATE_SHOPS = createShopsFlag; | ||
USE_SHOPS = useShopsFlag; | ||
} catch (FlagConflictException e) { | ||
Bukkit.getLogger().severe("One or more flags conflict!"); | ||
} | ||
} | ||
|
||
public static boolean canBypass (Player player) { | ||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); | ||
|
||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld()); | ||
} | ||
|
||
public static Set<ProtectedRegion> getRegions(final Location location) { | ||
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
|
||
final RegionManager manager = container.get(BukkitAdapter.adapt(location.getWorld())); | ||
|
||
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ())); | ||
|
||
return regions.getRegions(); | ||
} | ||
|
||
public static boolean canCreateShop (Location location, Player player) { | ||
if (canBypass(player)) return true; | ||
|
||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); | ||
|
||
com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location); | ||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
Set<ProtectedRegion> regions = getRegions(location); | ||
|
||
boolean isOwner = true; | ||
boolean canOthersCreate = true; | ||
|
||
for (ProtectedRegion region : regions) { | ||
if (!region.isOwner(localPlayer)) { | ||
isOwner = false; | ||
} | ||
|
||
Object createShopsValue = region.getFlag(CREATE_SHOPS); | ||
|
||
if (createShopsValue == null) continue; | ||
|
||
RegionQuery query = container.createQuery(); | ||
if (createShopsValue.equals("DENY")) { | ||
canOthersCreate = false; | ||
} | ||
} | ||
|
||
return query.testState(weLocation, localPlayer, Flags.BUILD); | ||
return isOwner || canOthersCreate; | ||
} | ||
|
||
public static boolean canUseShop (Location location, Player player) { | ||
if (canBypass(player)) return true; | ||
|
||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player); | ||
|
||
com.sk89q.worldedit.util.Location weLocation = BukkitAdapter.adapt(location); | ||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); | ||
Set<ProtectedRegion> regions = getRegions(location); | ||
|
||
boolean isOwner = true; | ||
boolean canOthersUse = true; | ||
|
||
for (ProtectedRegion region : regions) { | ||
if (!region.isOwner(localPlayer)) { | ||
isOwner = false; | ||
} | ||
|
||
Object useShopsValue = region.getFlag(USE_SHOPS); | ||
|
||
if (useShopsValue == null) continue; | ||
|
||
RegionQuery query = container.createQuery(); | ||
if (useShopsValue.equals("DENY")) { | ||
canOthersUse = false; | ||
} | ||
} | ||
|
||
return query.testState(weLocation, localPlayer, Flags.INTERACT); | ||
return isOwner || canOthersUse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.