Fixed region selector
This commit is contained in:
parent
7710e17d02
commit
bc109013f3
7 changed files with 366 additions and 4 deletions
|
@ -32,7 +32,25 @@
|
|||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/WGEvents.jar!/" />
|
||||
<root url="jar://$USER_HOME$/Downloads/WorldGuardEvents.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/worldedit-bukkit-7.1.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/worldguard-bukkit-7.0.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
|
|
|
@ -134,7 +134,16 @@ public class MCTPAudioCmd implements CommandExecutor {
|
|||
return true;
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("setregion")) {
|
||||
String regionName = args[1];
|
||||
String url = args[1];
|
||||
String url = args[2];
|
||||
|
||||
Main.getPlugin().getConfig().set("Regions." + regionName, url);
|
||||
Main.getPlugin().saveConfig();
|
||||
|
||||
sender.sendMessage(prefix + "De region zal vanaf nu muziek afspelen.");
|
||||
return true;
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("sethueregion")) {
|
||||
String regionName = args[1];
|
||||
String url = args[2];
|
||||
|
||||
Main.getPlugin().getConfig().set("Regions." + regionName, url);
|
||||
Main.getPlugin().saveConfig();
|
||||
|
|
|
@ -2,6 +2,7 @@ package me.mctp;
|
|||
|
||||
import me.mctp.listener.LogoutListener;
|
||||
import me.mctp.listener.WGListener;
|
||||
import me.mctp.managers.WGManager;
|
||||
import me.mctp.socket.Client;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -21,6 +22,12 @@ public class Main extends JavaPlugin implements Listener {
|
|||
|
||||
Bukkit.getLogger().info(prefix + "loading...");
|
||||
|
||||
if (!setupPlugins()) {
|
||||
Bukkit.getLogger().severe(String.format("[%s] Disabled due to no WorldGuard dependency found!", getDescription().getName()));
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
getConfig().addDefault("Regions.demosound", "https://audiopagina.mcthemeparks.eu/gallery/voletarium.mp3");
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
@ -50,6 +57,17 @@ public class Main extends JavaPlugin implements Listener {
|
|||
Bukkit.getLogger().info(prefix + "successfully disabled!");
|
||||
}
|
||||
|
||||
private boolean setupPlugins() {
|
||||
if (hasWorldGuardOnServer()) {
|
||||
WGManager.setWorldGuard(getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static boolean hasWorldGuardOnServer() {
|
||||
return Bukkit.getPluginManager().getPlugin("WorldGuard") != null;
|
||||
}
|
||||
|
||||
public static Plugin getPlugin() {
|
||||
return pl;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public class WGListener implements Listener {
|
|||
@EventHandler
|
||||
public void onRegionEnter(RegionsEnteredEvent e) {
|
||||
Set<String> list = Main.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
Set<String> list2 = Main.getPlugin().getConfig().getConfigurationSection("HueRegions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
@ -34,11 +35,18 @@ public class WGListener implements Listener {
|
|||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
if (!Collections.disjoint(list2, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
||||
//TODO Add hue support
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionExit(RegionsLeftEvent e) {
|
||||
Set<String> list = Main.getPlugin().getConfig().getConfigurationSection("Regions").getKeys(false);
|
||||
Set<String> list2 = Main.getPlugin().getConfig().getConfigurationSection("HueRegions").getKeys(false);
|
||||
|
||||
if (!Collections.disjoint(list, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
@ -51,5 +59,11 @@ public class WGListener implements Listener {
|
|||
data.put("uuid", e.getPlayer().getUniqueId().toString().replace("-", ""));
|
||||
Main.getClient().sendData(data);
|
||||
}
|
||||
|
||||
if (!Collections.disjoint(list2, e.getRegionsNames())) {
|
||||
//One element is the same -> In a region
|
||||
|
||||
//TODO Add hue support
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
295
src/me/mctp/managers/WGManager.java
Normal file
295
src/me/mctp/managers/WGManager.java
Normal file
|
@ -0,0 +1,295 @@
|
|||
package me.mctp.managers;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.regions.Polygonal2DRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.managers.storage.StorageException;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* WorldGuard class to make the usage of WorldGuard easy. This is the 1.14.x version!
|
||||
*
|
||||
* <i>Note that if you do use this in one of your projects, leave this notice.</i>
|
||||
* <i>Please do credit me if you do use this in one of your projects.</i>
|
||||
*
|
||||
* @author SBDeveloper [Fixed 1.13+ support]
|
||||
*/
|
||||
public class WGManager {
|
||||
|
||||
public static WorldGuardPlugin wgp;
|
||||
public static WorldEditPlugin wep;
|
||||
|
||||
public static boolean hasWorldGuard() {
|
||||
return wgp != null;
|
||||
}
|
||||
|
||||
public static boolean hasWorldEdit() {
|
||||
return wep != null;
|
||||
}
|
||||
|
||||
public static boolean setWorldGuard(Plugin plugin) {
|
||||
wgp = (WorldGuardPlugin) plugin;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean setWorldEdit(Plugin plugin) {
|
||||
wep = (WorldEditPlugin) plugin;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ProtectedRegion createRegion(Player p, String id) throws StorageException {
|
||||
LocalSession l = WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(p));
|
||||
Region s;
|
||||
try {
|
||||
s = l.getSelection(l.getSelectionWorld());
|
||||
} catch (IncompleteRegionException e) {
|
||||
return null;
|
||||
}
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(p.getWorld()));
|
||||
rm.removeRegion(id);
|
||||
ProtectedRegion region;
|
||||
// Detect the type of region from WorldEdit
|
||||
if (s instanceof Polygonal2DRegion) {
|
||||
Polygonal2DRegion polySel = (Polygonal2DRegion) s;
|
||||
int minY = polySel.getMinimumY();
|
||||
int maxY = polySel.getMaximumY();
|
||||
region = new ProtectedPolygonalRegion(id, polySel.getPoints(), minY, maxY);
|
||||
} else { /// default everything to cuboid
|
||||
region = new ProtectedCuboidRegion(id,
|
||||
s.getMinimumPoint(),
|
||||
s.getMaximumPoint());
|
||||
}
|
||||
region.setPriority(11); /// some relatively high priority
|
||||
region.setFlag(Flags.INTERACT, State.DENY);
|
||||
region.setFlag(Flags.INTERACT.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
|
||||
rm.addRegion(region);
|
||||
rm.save();
|
||||
return region;
|
||||
}
|
||||
|
||||
public static ArrayList<ProtectedRegion> getRegionsIn(Location loc) {
|
||||
ArrayList<ProtectedRegion> inRegions = new ArrayList<>();
|
||||
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
|
||||
for (ProtectedRegion protectedRegion : rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc))) inRegions.add(protectedRegion);
|
||||
|
||||
return inRegions;
|
||||
}
|
||||
|
||||
public static ProtectedRegion getRegionfromStringList(List<String> str, Location loc) {
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
ApplicableRegionSet mogreg = rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc));
|
||||
for (ProtectedRegion mogregion : mogreg) {
|
||||
for (String strgo : str) {
|
||||
if(strgo.equalsIgnoreCase(mogregion.getId())) {
|
||||
return mogregion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Niks gevonden!
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ProtectedRegion getRegionfromString(String str, Location loc) {
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
ApplicableRegionSet mogreg = rm.getApplicableRegions(BukkitAdapter.asBlockVector(loc));
|
||||
for (ProtectedRegion mogregion : mogreg) {
|
||||
if(str.equalsIgnoreCase(mogregion.getId())) {
|
||||
return mogregion;
|
||||
}
|
||||
}
|
||||
|
||||
//Niks gevonden!
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ProtectedRegion getRegionfromStringListInWorld(List<String> str, Location loc) {
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
Map<String, ProtectedRegion> mp = rm.getRegions();
|
||||
for (Entry<String, ProtectedRegion> pair : mp.entrySet()) {
|
||||
for (String string : str) {
|
||||
if (pair.getValue().getId().equals(string)) {
|
||||
return pair.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Niks gevonden!
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ProtectedRegion getRegionfromStringInWorld(String str, Location loc) {
|
||||
String strgood = str.toLowerCase();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
Map<String, ProtectedRegion> mp = rm.getRegions();
|
||||
return mp.get(strgood);
|
||||
}
|
||||
|
||||
public static boolean isMember(Player p, ProtectedRegion region, OfflinePlayer target) {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentMembers = currentRegion.getMembers();
|
||||
return currentMembers.contains(target.getUniqueId());
|
||||
}
|
||||
|
||||
public static boolean isOwner(Player p, ProtectedRegion region, OfflinePlayer target) {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentOwners = currentRegion.getOwners();
|
||||
return currentOwners.contains(target.getUniqueId());
|
||||
}
|
||||
|
||||
public static boolean addMember(Player p, ProtectedRegion region, OfflinePlayer newmember) {
|
||||
try {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentMembers = currentRegion.getMembers();
|
||||
currentMembers.addPlayer(UUID.fromString(newmember.getUniqueId().toString()));
|
||||
|
||||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addOwner(Player p, ProtectedRegion region, OfflinePlayer newowner) {
|
||||
try {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentOwners = currentRegion.getOwners();
|
||||
currentOwners.addPlayer(UUID.fromString(newowner.getUniqueId().toString()));
|
||||
|
||||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeMember(Player p, ProtectedRegion region, OfflinePlayer newmember) {
|
||||
try {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentMembers = currentRegion.getMembers();
|
||||
currentMembers.removePlayer(UUID.fromString(newmember.getUniqueId().toString()));
|
||||
|
||||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeOwner(Player p, ProtectedRegion region, UUID newowner) {
|
||||
try {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentOwners = currentRegion.getOwners();
|
||||
currentOwners.removePlayer(newowner);
|
||||
|
||||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<String> getMembers(Player p, ProtectedRegion region) {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentMembers = currentRegion.getMembers();
|
||||
|
||||
ArrayList<String> members = new ArrayList<>();
|
||||
for (UUID uuid : currentMembers.getUniqueIds()) {
|
||||
OfflinePlayer member = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
members.add(member.getName());
|
||||
}
|
||||
return members;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getOwners(Player p, ProtectedRegion region) {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(region.getId());
|
||||
DefaultDomain currentOwners = currentRegion.getOwners();
|
||||
|
||||
ArrayList<String> owners = new ArrayList<>();
|
||||
for (UUID uuid : currentOwners.getUniqueIds()) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
owners.add(owner.getName());
|
||||
}
|
||||
return owners;
|
||||
}
|
||||
|
||||
public static boolean removeRegion(Player p, String name) {
|
||||
try {
|
||||
World w = p.getWorld();
|
||||
RegionManager rm = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(w));
|
||||
|
||||
ProtectedRegion currentRegion = rm.getRegion(name);
|
||||
if (currentRegion == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rm.removeRegion(name);
|
||||
rm.save();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (StorageException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package me.mctp.utils;
|
||||
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import me.mctp.managers.WGManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
|
@ -66,8 +68,13 @@ public class SpigotPlayerSelector {
|
|||
Location standPoint = getLocation(commandSender);
|
||||
|
||||
if (getArgument("region").length() != 0) {
|
||||
//TODO FIX REGION SELECTOR
|
||||
throw new UnsupportedOperationException("The region argument is not supported.");
|
||||
String regionID = getArgument("region");
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
ArrayList<ProtectedRegion> regions = WGManager.getRegionsIn(p.getLocation());
|
||||
if (regions.stream().anyMatch(region -> region.getId().equalsIgnoreCase(regionID))) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
} else if (getArgument("r").length() != 0) {
|
||||
int radius = Integer.parseInt(getArgument("r"));
|
||||
players.addAll(Bukkit.getOnlinePlayers().stream()
|
||||
|
|
|
@ -4,6 +4,7 @@ version: 1.0
|
|||
api-version: 1.14
|
||||
author: MaybeFromNL_SBDeveloper
|
||||
description: Copyright MaybeFromNL & SBDeveloper
|
||||
depend: ['WorldGuard']
|
||||
|
||||
commands:
|
||||
mctpaudio:
|
||||
|
|
Loading…
Add table
Reference in a new issue