mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
feat: disable playing emotes in WG region
This commit is contained in:
@@ -17,21 +17,26 @@ public class WGHook {
|
||||
/**
|
||||
* @implNote Please use {@link #getCosmeticEnableFlag()} instead
|
||||
*/
|
||||
public static StateFlag COSMETIC_ENABLE_FLAG;
|
||||
private static StateFlag COSMETIC_ENABLE_FLAG;
|
||||
|
||||
private static StateFlag EMOTES_ENABLE_FLAG;
|
||||
|
||||
/**
|
||||
* @implNote Please use {@link #getCosmeticWardrobeFlag()} instead
|
||||
*/
|
||||
public static StringFlag COSMETIC_WARDROBE_FLAG;
|
||||
private static StringFlag COSMETIC_WARDROBE_FLAG;
|
||||
|
||||
public WGHook() {
|
||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||
try {
|
||||
StateFlag cosmeticFlag = new StateFlag("cosmetic-enable", false);
|
||||
StateFlag emoteFlag = new StateFlag("emotes-enable", false);
|
||||
StringFlag wardrobeFlag = new StringFlag("cosmetic-wardrobe");
|
||||
registry.register(cosmeticFlag);
|
||||
registry.register(emoteFlag);
|
||||
registry.register(wardrobeFlag);
|
||||
COSMETIC_ENABLE_FLAG = cosmeticFlag;
|
||||
EMOTES_ENABLE_FLAG = emoteFlag;
|
||||
COSMETIC_WARDROBE_FLAG = wardrobeFlag;
|
||||
} catch (FlagConflictException e) {
|
||||
Flag<?> existing = registry.get("cosmetic-enable");
|
||||
@@ -53,6 +58,14 @@ public class WGHook {
|
||||
return COSMETIC_ENABLE_FLAG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the emotes enable {@link StateFlag}
|
||||
* @return The emotes enable {@link StateFlag}
|
||||
*/
|
||||
public static StateFlag getEmotesEnableFlag() {
|
||||
return EMOTES_ENABLE_FLAG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cosmetic wardrobe {@link StateFlag}
|
||||
* @return The cosmetic wardrobe {@link StateFlag}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -11,6 +12,7 @@ import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@@ -26,10 +28,7 @@ public class WGListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
Location location = event.getPlayer().getLocation();
|
||||
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
|
||||
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = region.createQuery();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(loc);
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
if (user.getHidden()) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
|
||||
user.showCosmetics();
|
||||
@@ -57,10 +56,7 @@ public class WGListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
Location location = event.getTo();
|
||||
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
|
||||
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = region.createQuery();
|
||||
ApplicableRegionSet set = query.getApplicableRegions(loc);
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
if (user.getHidden()) {
|
||||
if (user.getHiddenReason() == CosmeticUser.HiddenReason.WORLDGUARD && set.getRegions().size() == 0) {
|
||||
user.showCosmetics();
|
||||
@@ -82,4 +78,28 @@ public class WGListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerEmote(PlayerEmoteStartEvent event) {
|
||||
Player player = event.getUser().getPlayer();
|
||||
if (player == null) return;
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicableRegionSet getRegions(Location location) {
|
||||
com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location);
|
||||
RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = region.createQuery();
|
||||
return query.getApplicableRegions(loc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user