mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Add WorldGuard hook/context
This commit is contained in:
1 parent
d5d066fcb6
commit
126df2c3e2
8 files changed
+97
-4
No files matched your search
@@ -5,7 +5,6 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.130'
|
||||
|
||||
api project(':SimpleChat')
|
||||
|
||||
@@ -18,7 +18,11 @@ public final class SimpleChatMCMMO extends JavaPlugin {
|
||||
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||
|
||||
simpleChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||
return isInSameParty(context.getSender(), context.getTarget());
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameParty(context.getSender(), context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,15 @@ default:
|
||||
default: '<gray>[%vault_prefix%<gray>] %player_displayname%<gray>: <color><pre><message>'
|
||||
contexts:
|
||||
distance: -1 # -1 to disable, 0 to set to world, 1+ to fully enable
|
||||
# mcmmo-party only works when the SiumpleChatMCMMO addon is installed.
|
||||
# mcmmo-party only works when the SimpleChatMCMMO addon is installed.
|
||||
# Requires both players to be in the same party to see the message.
|
||||
mcmmo-party: false
|
||||
# worldguard-region only works when the SimpleChatWorldGuard addon is installed.
|
||||
# Requires both players to be in the same region to see the message.
|
||||
worldguard-region: false
|
||||
# towny-town only works when the SimpleChatTowny addon is installed.
|
||||
# Requires both players to be in the same town to see the message.
|
||||
towny-town: false
|
||||
color: '#FFFFFF'
|
||||
# Can players /toggle this channel and hide its messages?
|
||||
ignorable: true
|
||||
|
||||
@@ -20,7 +20,11 @@ public final class SimpleChatTowny extends JavaPlugin {
|
||||
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||
|
||||
simpleChat.getContextManager().register("towny-town", (context) -> {
|
||||
return isInSameTown(context.getSender(), context.getTarget());
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameTown(context.getSender(), context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
|
||||
maven { url = "https://maven.enginehub.org/repo/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
|
||||
api project(':SimpleChat')
|
||||
}
|
||||
|
||||
description = 'SimpleChatWorldGuard'
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package net.draycia.simplechatworldguard;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import net.draycia.simplechat.SimpleChat;
|
||||
import net.draycia.simplechat.storage.ChatUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class SimpleChatWorldGuard extends JavaPlugin {
|
||||
|
||||
private SimpleChat simpleChat;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
simpleChat = (SimpleChat) Bukkit.getPluginManager().getPlugin("SimpleChat");
|
||||
|
||||
simpleChat.getContextManager().register("worldguard-region", (context) -> {
|
||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||
return isInSameRegion(context.getSender(), context.getTarget());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
||||
if (!user1.isOnline() || !user2.isOnline()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Location user1Location = BukkitAdapter.adapt(user1.asPlayer().getLocation());
|
||||
Location user2Location = BukkitAdapter.adapt(user2.asPlayer().getLocation());
|
||||
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery regionQuery = container.createQuery();
|
||||
|
||||
ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||
ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||
|
||||
for (ProtectedRegion region : user1Regions) {
|
||||
if (user2Regions.getRegions().contains(region)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
name: SimpleChatWorldGuard
|
||||
version: ${project.version}
|
||||
main: net.draycia.simplechatmcmmo.SimpleChatWorldGuard
|
||||
api-version: 1.16
|
||||
depend: [WorldGuard]
|
||||
@@ -9,5 +9,6 @@ include(':SimpleChat')
|
||||
include(':SimpleChatModeration')
|
||||
include(':SimpleChatMCMMO')
|
||||
include(':SimpleChatTowny')
|
||||
include(':SimpleChatWorldGuard')
|
||||
|
||||
project(':SimpleChat').projectDir = file('SimpleChatPlugin')
|
||||
Reference in new issue
Block a user