1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 05:55:27 +01:00

Support for worldguard and restricted areas

This commit is contained in:
Zrips 2017-06-22 16:40:13 +03:00
parent c591f35671
commit 9940e9f3c6
11 changed files with 219 additions and 75 deletions

11
pom.xml
View File

@ -76,8 +76,19 @@
<scope>system</scope>
<systemPath>${basedir}/libs/MythicMobs-4.1.0.jar</systemPath>
</dependency>
<!-- WorldGuard -->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>worldguard</artifactId>
<version>6.1</version>
</dependency>
</dependencies>
<repositories>
<!-- WorldGuard -->
<repository>
<id>sk89q-repo</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<!-- Spigot -->
<repository>
<id>spigot-repo</id>

View File

@ -37,6 +37,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import com.gamingmesh.jobs.CmiItems.ItemManager;
@ -46,6 +47,7 @@ import com.gamingmesh.jobs.MythicMobs.MythicMobInterface;
import com.gamingmesh.jobs.MythicMobs.MythicMobs2;
import com.gamingmesh.jobs.MythicMobs.MythicMobs4;
import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.WorldGuard.WorldGuardManager;
import com.gamingmesh.jobs.api.JobsExpGainEvent;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.config.BlockProtectionManager;
@ -119,6 +121,7 @@ public class Jobs extends JavaPlugin {
private static MythicMobInterface MythicManager;
private static MyPetManager myPetManager;
private static WorldGuardManager worldGuardManager;
private static ConfigManager configManager;
private static GeneralConfigManager GconfigManager;
@ -177,6 +180,10 @@ public class Jobs extends JavaPlugin {
return myPetManager;
}
public static WorldGuardManager getWorldGuardManager() {
return worldGuardManager;
}
public void setMythicManager() {
try {
Class.forName("net.elseland.xikage.MythicMobs.API.MythicMobsAPI");
@ -186,9 +193,20 @@ public class Jobs extends JavaPlugin {
Class.forName("io.lumine.xikage.mythicmobs.api.bukkit.BukkitAPIHelper");
MythicManager = new MythicMobs4(this);
} catch (ClassNotFoundException ex) {
}
}
if (MythicManager != null)
consoleMsg("&e[Jobs] MythicMobs detected.");
}
private boolean setWorldGuard() {
Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
if (plugin != null) {
worldGuardManager = new WorldGuardManager(this);
consoleMsg("&e[Jobs] WorldGuard detected.");
return true;
}
return false;
}
public static MythicMobInterface getMythicManager() {
@ -776,6 +794,7 @@ public class Jobs extends JavaPlugin {
}
setMyPetManager();
setWorldGuard();
setMythicManager();
if (MythicManager != null && MythicManager.Check() && GconfigManager.MythicMobsEnabled) {

View File

@ -53,7 +53,7 @@ public class MyPetManager {
mp = MyPetApi.getPlayerManager();
mppm = MyPetApi.getMyPetManager();
enabled = true;
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[Jobs] &6MyPet was found - Enabling capabilities."));
Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e[Jobs] &6MyPet detected"));
}
}

View File

@ -0,0 +1,6 @@
/MythicMobs2Listener.class
/MythicMobsManager.class
/MythicMobInterface.class
/MythicMobs2.class
/MythicMobs4.class
/MythicMobs4Listener.class

View File

@ -0,0 +1,66 @@
package com.gamingmesh.jobs.WorldGuard;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.RestrictedArea;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
public class WorldGuardManager {
private Jobs plugin;
WorldGuardPlugin wg;
public WorldGuardManager(Jobs plugin) {
this.plugin = plugin;
Plugin pl = Bukkit.getPluginManager().getPlugin("WorldGuard");
if (pl != null && (pl instanceof WorldGuardPlugin)) {
wg = (WorldGuardPlugin) pl;
}
}
public List<RestrictedArea> getArea(Location loc) {
ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc);
for (ProtectedRegion one : regions.getRegions()) {
if (!Jobs.getRestrictedAreaManager().isExist(one.getId()))
continue;
return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId());
}
return new ArrayList<RestrictedArea>();
}
public boolean inArea(Location loc, String name) {
ApplicableRegionSet regions = wg.getRegionContainer().get(loc.getWorld()).getApplicableRegions(loc);
for (ProtectedRegion one : regions.getRegions()) {
if (!one.getId().equalsIgnoreCase(name))
continue;
if (!one.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
continue;
return true;
}
return false;
}
public String getNameByName(String name) {
for (World one : Bukkit.getWorlds()) {
Map<String, ProtectedRegion> regions = wg.getRegionContainer().get(one).getRegions();
for (Entry<String, ProtectedRegion> oneR : regions.entrySet()) {
if (!oneR.getKey().equalsIgnoreCase(name))
continue;
return oneR.getKey();
}
}
return null;
}
}

View File

@ -13,6 +13,7 @@ import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.config.RestrictedAreaManager;
import com.gamingmesh.jobs.container.CuboidArea;
import com.gamingmesh.jobs.container.RestrictedArea;
import com.gamingmesh.jobs.stuff.Debug;
public class area implements Cmd {
@ -40,16 +41,35 @@ public class area implements Cmd {
} catch (Exception e) {
return false;
}
Boolean wg = false;
if (name.startsWith("wg:")) {
wg = true;
name = name.substring("wg:".length(), name.length());
}
if (ra.isExist(name)) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.exist"));
return true;
}
if (!Jobs.getSelectionManager().hasPlacedBoth(player)) {
if (!wg && !Jobs.getSelectionManager().hasPlacedBoth(player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.select", "%tool%", Material.getMaterial(Jobs.getGCManager().getSelectionTooldID).name().toLowerCase()));
return true;
}
ra.addNew(new RestrictedArea(name, Jobs.getSelectionManager().getSelectionCuboid(player), bonus), true);
if (wg && Jobs.getWorldGuardManager() != null) {
name = Jobs.getWorldGuardManager().getNameByName(name);
if (name == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist"));
return true;
}
}
if (!wg)
ra.addNew(new RestrictedArea(name, Jobs.getSelectionManager().getSelectionCuboid(player), bonus), true);
else
ra.addNew(new RestrictedArea(name, name, bonus), true);
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.addedNew", "%bonus%", bonus));
return true;
}
@ -100,16 +120,22 @@ public class area implements Cmd {
for (Entry<String, RestrictedArea> area : areas.entrySet()) {
i++;
CuboidArea cuboid = area.getValue().getCuboidArea();
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.list", "%number%", i,
"%areaname%", area.getKey(),
"%worldname%", cuboid.getWorld().getName(),
"%x1%", cuboid.getLowLoc().getBlockX(),
"%y1%", cuboid.getLowLoc().getBlockY(),
"%z1%", cuboid.getLowLoc().getBlockZ(),
"%x2%", cuboid.getHighLoc().getBlockX(),
"%y2%", cuboid.getHighLoc().getBlockY(),
"%z2%", cuboid.getHighLoc().getBlockZ(),
"%bonus%", area.getValue().getMultiplier()));
if (area.getValue().getWgName() == null) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.list", "%number%", i,
"%areaname%", area.getKey(),
"%worldname%", cuboid.getWorld().getName(),
"%x1%", cuboid.getLowLoc().getBlockX(),
"%y1%", cuboid.getLowLoc().getBlockY(),
"%z1%", cuboid.getLowLoc().getBlockZ(),
"%x2%", cuboid.getHighLoc().getBlockX(),
"%y2%", cuboid.getHighLoc().getBlockY(),
"%z2%", cuboid.getHighLoc().getBlockZ(),
"%bonus%", area.getValue().getMultiplier()));
} else {
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgList", "%number%", i,
"%areaname%", area.getKey(),
"%bonus%", area.getValue().getMultiplier()));
}
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
return true;
@ -126,7 +152,7 @@ public class area implements Cmd {
}
}
return true;
return false;
}
}

View File

@ -369,11 +369,12 @@ public class LanguageManager {
c.get("command.area.help.info", "Modify restricted areas.");
c.get("command.area.help.args", "add/remove/info/list");
c.get("command.area.help.addUsage", "&eUsage: &6/Jobs area add [areaName] [bonus]");
c.get("command.area.help.addUsage", "&eUsage: &6/Jobs area add [areaName/wg:worldGuardAreaName] [bonus]");
c.get("command.area.help.removeUsage", "&eUsage: &6/Jobs area remove [areaName]");
c.get("command.area.output.addedNew", "&eAdded new restricted area with &6%bonus% &ebonus");
c.get("command.area.output.removed", "&eRemoved restricted area &6%name%");
c.get("command.area.output.list", "&e%number%&a. &e%areaname% &e%worldname% (&a%x1%:%y1%:%z1%/&e%x2%:%y2%:%z2%) &6%bonus%");
c.get("command.area.output.wgList", "&e%number%&a. WorldGuard: &e%areaname% &6%bonus%");
c.get("command.area.output.noAreas", "&eThere is no saved restricted areas");
c.get("command.area.output.noAreasByLoc", "&eThere is no restricted areas in this location");
c.get("command.area.output.areaList", "&eRestricted areas by your location: &6%list%");
@ -382,6 +383,7 @@ public class LanguageManager {
c.get("command.area.output.select", "&eSelect 2 points with selection tool (%tool%)");
c.get("command.area.output.exist", "&eRestriction area by this name already exist");
c.get("command.area.output.dontExist", "&eRestriction area by this name don't exist");
c.get("command.area.output.wgDontExist", "&eWorldGuard area by this name don't exist");
c.get("command.log.help.info", "Shows statistics.");
c.get("command.log.help.args", "[playername]");

View File

@ -49,7 +49,7 @@ public class RestrictedAreaManager {
public void remove(String name, boolean save) {
for (Entry<String, RestrictedArea> area : restrictedAreas.entrySet()) {
if (area.getKey().equalsIgnoreCase(name)){
if (area.getKey().equalsIgnoreCase(name)) {
restrictedAreas.remove(area.getKey());
break;
}
@ -58,7 +58,7 @@ public class RestrictedAreaManager {
save();
}
public HashMap<String, RestrictedArea> getRestrictedAres(){
public HashMap<String, RestrictedArea> getRestrictedAres() {
return restrictedAreas;
}
@ -72,15 +72,21 @@ public class RestrictedAreaManager {
for (Entry<String, RestrictedArea> area : restrictedAreas.entrySet()) {
String areaKey = area.getKey();
CuboidArea cuboid = area.getValue().getCuboidArea();
conf.set("restrictedareas." + areaKey + ".world", cuboid.getWorld().getName());
conf.set("restrictedareas." + areaKey + ".multiplier", area.getValue().getMultiplier());
conf.set("restrictedareas." + areaKey + ".point1.x", cuboid.getLowLoc().getBlockX());
conf.set("restrictedareas." + areaKey + ".point1.y", cuboid.getLowLoc().getBlockY());
conf.set("restrictedareas." + areaKey + ".point1.z", cuboid.getLowLoc().getBlockZ());
conf.set("restrictedareas." + areaKey + ".point2.x", cuboid.getHighLoc().getBlockX());
conf.set("restrictedareas." + areaKey + ".point2.y", cuboid.getHighLoc().getBlockY());
conf.set("restrictedareas." + areaKey + ".point2.z", cuboid.getHighLoc().getBlockZ());
if (area.getValue().getWgName() == null) {
conf.set("restrictedareas." + areaKey + ".world", cuboid.getWorld().getName());
conf.set("restrictedareas." + areaKey + ".point1.x", cuboid.getLowLoc().getBlockX());
conf.set("restrictedareas." + areaKey + ".point1.y", cuboid.getLowLoc().getBlockY());
conf.set("restrictedareas." + areaKey + ".point1.z", cuboid.getLowLoc().getBlockZ());
conf.set("restrictedareas." + areaKey + ".point2.x", cuboid.getHighLoc().getBlockX());
conf.set("restrictedareas." + areaKey + ".point2.y", cuboid.getHighLoc().getBlockY());
conf.set("restrictedareas." + areaKey + ".point2.z", cuboid.getHighLoc().getBlockZ());
} else
conf.set("restrictedareas." + areaKey + ".WG", true);
}
try {
conf.save(f);
} catch (IOException e) {
@ -96,9 +102,13 @@ public class RestrictedAreaManager {
public synchronized double getRestrictedMultiplier(Player player) {
if (player == null)
return 0D;
for (Entry<String, RestrictedArea> area : restrictedAreas.entrySet()) {
if (area.getValue().inRestrictedArea(player.getLocation()))
return area.getValue().getMultiplier();
for (RestrictedArea area : getRestrictedAreasByLoc(player.getLocation())) {
if (area.inRestrictedArea(player.getLocation()))
return area.getMultiplier();
if (area.getWgName() != null && Jobs.getWorldGuardManager() != null && Jobs.getWorldGuardManager().inArea(player.getLocation(), area.getWgName())) {
return area.getMultiplier();
}
}
return 0D;
}
@ -109,6 +119,20 @@ public class RestrictedAreaManager {
if (area.getValue().inRestrictedArea(loc))
areas.add(area.getValue());
}
if (Jobs.getWorldGuardManager() != null) {
areas.addAll(Jobs.getWorldGuardManager().getArea(loc));
}
return areas;
}
public synchronized List<RestrictedArea> getRestrictedAreasByName(String name) {
List<RestrictedArea> areas = new ArrayList<RestrictedArea>();
for (Entry<String, RestrictedArea> area : restrictedAreas.entrySet()) {
if (area.getKey().equalsIgnoreCase(name))
areas.add(area.getValue());
}
return areas;
}
@ -167,17 +191,24 @@ public class RestrictedAreaManager {
ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
if (areaSection != null) {
for (String areaKey : areaSection.getKeys(false)) {
String worldName = conf.getString("restrictedareas." + areaKey + ".world");
double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0.0);
World world = Bukkit.getServer().getWorld(worldName);
if (world == null)
continue;
Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0.0), conf.getDouble("restrictedareas." + areaKey
+ ".point1.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0.0));
Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey
+ ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0));
addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier));
if (conf.isBoolean("restrictedareas." + areaKey + ".WG")) {
RestrictedArea ar = new RestrictedArea(areaKey, areaKey, multiplier);
addNew(ar);
} else {
String worldName = conf.getString("restrictedareas." + areaKey + ".world");
World world = Bukkit.getServer().getWorld(worldName);
if (world == null)
continue;
Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0.0), conf.getDouble("restrictedareas." + areaKey
+ ".point1.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0.0));
Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey
+ ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0));
addNew(new RestrictedArea(areaKey, new CuboidArea(point1, point2), multiplier));
}
}
}

View File

@ -25,6 +25,7 @@ public class RestrictedArea {
private CuboidArea area;
private double multiplier;
private String name;
private String wgName;
public RestrictedArea(String name, CuboidArea area, double multiplier) {
this.name = name;
@ -32,6 +33,12 @@ public class RestrictedArea {
this.multiplier = multiplier;
}
public RestrictedArea(String name, String wgName, double multiplier) {
this.name = name;
this.wgName = wgName;
this.multiplier = multiplier;
}
public CuboidArea getCuboidArea() {
return this.area;
}
@ -52,8 +59,9 @@ public class RestrictedArea {
* @return false - the location is outside the restricted area
*/
public boolean inRestrictedArea(Location loc) {
if (loc == null)
if (loc == null || area == null)
return false;
if (!loc.getWorld().getName().equals(area.getWorld().getName()))
return false;
if (area.getLowLoc().getBlockX() > loc.getBlockX())
@ -74,4 +82,12 @@ public class RestrictedArea {
public String getName() {
return name;
}
public String getWgName() {
return wgName;
}
public void setWgName(String wgName) {
this.wgName = wgName;
}
}

View File

@ -3,7 +3,6 @@ package com.gamingmesh.jobs.selection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.container.CuboidArea;
@ -74,36 +73,4 @@ public class SelectionManager {
playerLoc1.remove(player.getName());
playerLoc2.remove(player.getName());
}
public void selectChunk(Player player) {
Chunk chunk = player.getWorld().getChunkAt(player.getLocation());
int xcoord = chunk.getX() * 16;
int zcoord = chunk.getZ() * 16;
int ycoord = MIN_HEIGHT;
int xmax = xcoord + 15;
int zmax = zcoord + 15;
int ymax = player.getLocation().getWorld().getMaxHeight() - 1;
playerLoc1.put(player.getName(), new Location(player.getWorld(), xcoord, ycoord, zcoord));
playerLoc2.put(player.getName(), new Location(player.getWorld(), xmax, ymax, zmax));
player.sendMessage("msg");
}
public boolean worldEdit(Player player) {
player.sendMessage("msg");
return false;
}
public boolean worldEditUpdate(Player player) {
player.sendMessage("msg");
return false;
}
public void selectBySize(Player player, int xsize, int ysize, int zsize) {
Location myloc = player.getLocation();
Location loc1 = new Location(myloc.getWorld(), myloc.getBlockX() + xsize, myloc.getBlockY() + ysize, myloc.getBlockZ() + zsize);
Location loc2 = new Location(myloc.getWorld(), myloc.getBlockX() - xsize, myloc.getBlockY() - ysize, myloc.getBlockZ() - zsize);
placeLoc1(player, loc1);
placeLoc2(player, loc2);
player.sendMessage("msg");
}
}

View File

@ -4,7 +4,7 @@ main: com.gamingmesh.jobs.Jobs
version: 3.9.3
website: https://www.spigotmc.org/resources/jobs-reborn.4216/
author: phrstbrn
softdepend: [Vault, iConomy, MythicMobs, McMMO]
softdepend: [Vault, iConomy, MythicMobs, McMMO, WorldGuard]
commands:
jobs:
description: Jobs