mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-08 08:21:41 +01:00
Now supports WorldGuard 7.0.0
- Added a placeholder %jobs_user_archived_jobs% to show the archived jobs for the user. - Fix file saving problem when removed the restricted area - /jobs area command now works
This commit is contained in:
parent
753ecefb10
commit
06538ed4e6
18
pom.xml
18
pom.xml
@ -68,12 +68,28 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/libs/MythicMobs-4.5.5.jar</systemPath>
|
||||
</dependency>
|
||||
<!-- WorldGuard -->
|
||||
<!-- WorldGuard old version -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>worldguard</artifactId>
|
||||
<version>6.1</version>
|
||||
</dependency>
|
||||
<!-- WorldGuard new version -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-legacy</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<groupId>org.bukkit</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>bukkit-classloader-check</artifactId>
|
||||
<groupId>org.sk89q.bukkit</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- WorldEdit -->
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
|
@ -42,6 +42,7 @@ public class Placeholder {
|
||||
user_joinedjobcount,
|
||||
user_points,
|
||||
user_total_points,
|
||||
user_archived_jobs,
|
||||
user_boost_$1_$2("jname/number", "money/exp/points"),
|
||||
user_isin_$1("jname/number"),
|
||||
user_canjoin_$1("jname/number"),
|
||||
@ -74,9 +75,6 @@ public class Placeholder {
|
||||
private ChatFilterRule rule = null;
|
||||
private boolean hidden = false;
|
||||
|
||||
JobsPlaceHolders() {
|
||||
}
|
||||
|
||||
JobsPlaceHolders(String... vars) {
|
||||
Matcher matcher = numericalRule.getMatcher(this.toString());
|
||||
if (matcher != null) {
|
||||
@ -383,33 +381,35 @@ public class Placeholder {
|
||||
if (user != null) {
|
||||
switch (placeHolder) {
|
||||
case user_id:
|
||||
return String.valueOf(user.getUserId());
|
||||
return Integer.toString(user.getUserId());
|
||||
case user_bstandcount:
|
||||
return String.valueOf(user.getBrewingStandCount());
|
||||
return Integer.toString(user.getBrewingStandCount());
|
||||
case user_maxbstandcount:
|
||||
return String.valueOf(user.getMaxBrewingStandsAllowed());
|
||||
return Integer.toString(user.getMaxBrewingStandsAllowed());
|
||||
case user_furncount:
|
||||
return String.valueOf(user.getFurnaceCount());
|
||||
return Integer.toString(user.getFurnaceCount());
|
||||
case user_maxfurncount:
|
||||
return String.valueOf(user.getMaxFurnacesAllowed());
|
||||
return Integer.toString(user.getMaxFurnacesAllowed());
|
||||
case user_doneq:
|
||||
return String.valueOf(user.getDoneQuests());
|
||||
return Integer.toString(user.getDoneQuests());
|
||||
case user_seen:
|
||||
return TimeManage.to24hourShort(System.currentTimeMillis() - user.getSeen());
|
||||
case user_totallevels:
|
||||
return String.valueOf(user.getTotalLevels());
|
||||
return Integer.toString(user.getTotalLevels());
|
||||
case user_points:
|
||||
PlayerPoints pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
return String.valueOf(pointInfo.getCurrentPoints());
|
||||
return Double.toString(pointInfo.getCurrentPoints());
|
||||
case user_total_points:
|
||||
pointInfo = Jobs.getPlayerManager().getPointsData().getPlayerPointsInfo(user.getPlayerUUID());
|
||||
return String.valueOf(pointInfo.getTotalPoints());
|
||||
return Double.toString(pointInfo.getTotalPoints());
|
||||
case user_issaved:
|
||||
return convert(user.isSaved());
|
||||
case user_displayhonorific:
|
||||
return String.valueOf(user.getDisplayHonorific());
|
||||
return user.getDisplayHonorific();
|
||||
case user_joinedjobcount:
|
||||
return String.valueOf(user.getJobProgression().size());
|
||||
return Integer.toString(user.getJobProgression().size());
|
||||
case user_archived_jobs:
|
||||
return Integer.toString(user.getArchivedJobs().getArchivedJobs().size());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -422,21 +422,21 @@ public class Placeholder {
|
||||
switch (placeHolder) {
|
||||
case limit_$1:
|
||||
CurrencyType t = CurrencyType.getByName(vals.get(0));
|
||||
return String.valueOf(user.getLimit(t));
|
||||
return Integer.toString(user.getLimit(t));
|
||||
case plimit_$1:
|
||||
t = CurrencyType.getByName(vals.get(0));
|
||||
return String.valueOf(user.getPaymentLimit().GetAmount(t));
|
||||
return Double.toString(user.getPaymentLimit().GetAmount(t));
|
||||
case plimit_tleft_$1:
|
||||
t = CurrencyType.getByName(vals.get(0));
|
||||
return TimeManage.to24hourShort(user.getPaymentLimit().GetLeftTime(t));
|
||||
case user_jlevel_$1:
|
||||
return j == null ? "" : String.valueOf(j.getLevel());
|
||||
return j == null ? "" : Integer.toString(j.getLevel());
|
||||
case user_jexp_$1:
|
||||
return j == null ? "" : String.valueOf(j.getExperience());
|
||||
return j == null ? "" : Double.toString(j.getExperience());
|
||||
case user_jmaxexp_$1:
|
||||
return j == null ? "" : String.valueOf(j.getMaxExperience());
|
||||
return j == null ? "" : Integer.toString(j.getMaxExperience());
|
||||
case user_jmaxlvl_$1:
|
||||
return j == null ? "" : String.valueOf(j.getJob().getMaxLevel(user));
|
||||
return j == null ? "" : Integer.toString(j.getJob().getMaxLevel(user));
|
||||
case user_boost_$1_$2:
|
||||
if (vals.size() < 2)
|
||||
return "";
|
||||
@ -451,7 +451,7 @@ public class Placeholder {
|
||||
case maxjobs:
|
||||
Double max = Jobs.getPermissionManager().getMaxPermission(user, "jobs.max");
|
||||
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
|
||||
return String.valueOf(max);
|
||||
return Double.toString(max);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -517,17 +517,17 @@ public class Placeholder {
|
||||
case description_$1:
|
||||
return jo.getDescription();
|
||||
case maxdailyq_$1:
|
||||
return String.valueOf(jo.getMaxDailyQuests());
|
||||
return Integer.toString(jo.getMaxDailyQuests());
|
||||
case maxlvl_$1:
|
||||
return String.valueOf(jo.getMaxLevel());
|
||||
return Integer.toString(jo.getMaxLevel());
|
||||
case maxviplvl_$1:
|
||||
return String.valueOf(jo.getVipMaxLevel());
|
||||
return Integer.toString(jo.getVipMaxLevel());
|
||||
case bonus_$1:
|
||||
return String.valueOf(jo.getBonus());
|
||||
return Double.toString(jo.getBonus());
|
||||
case totalplayers_$1:
|
||||
return String.valueOf(jo.getTotalPlayers());
|
||||
return Integer.toString(jo.getTotalPlayers());
|
||||
case maxslots_$1:
|
||||
return String.valueOf(jo.getMaxSlots());
|
||||
return Integer.toString(jo.getMaxSlots());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -536,13 +536,13 @@ public class Placeholder {
|
||||
// Global placeholders
|
||||
switch (placeHolder) {
|
||||
case maxjobs:
|
||||
return String.valueOf(Jobs.getGCManager().getMaxJobs());
|
||||
return Integer.toString(Jobs.getGCManager().getMaxJobs());
|
||||
case total_workers:
|
||||
int count = 0;
|
||||
for (Job one : Jobs.getJobs()) {
|
||||
count += one.getTotalPlayers();
|
||||
}
|
||||
return String.valueOf(count);
|
||||
return Integer.toString(count);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -12,28 +12,46 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.RestrictedArea;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
|
||||
public class WorldGuardManager {
|
||||
|
||||
private WorldGuardPlugin wg;
|
||||
private boolean useOld = false;
|
||||
|
||||
public WorldGuardManager() {
|
||||
Plugin pl = Bukkit.getPluginManager().getPlugin("WorldGuard");
|
||||
if (pl != null && (pl instanceof WorldGuardPlugin)) {
|
||||
wg = (WorldGuardPlugin) pl;
|
||||
if (wg != null && wg.getDescription().getVersion().equals("6.1")) {
|
||||
wg = (WorldGuardPlugin) pl;
|
||||
useOld = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<RestrictedArea> getArea(Location loc) {
|
||||
try {
|
||||
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());
|
||||
if (useOld) {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
for (ProtectedRegion one : regions.getRegions().values()) {
|
||||
if (!Jobs.getRestrictedAreaManager().isExist(one.getId()))
|
||||
continue;
|
||||
return Jobs.getRestrictedAreaManager().getRestrictedAreasByName(one.getId());
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
@ -41,20 +59,38 @@ public class WorldGuardManager {
|
||||
}
|
||||
|
||||
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;
|
||||
if (useOld) {
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionManager regions = container.get(BukkitAdapter.adapt(loc.getWorld()));
|
||||
for (ProtectedRegion one : regions.getRegions().values()) {
|
||||
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();
|
||||
Map<String, ProtectedRegion> regions = null;
|
||||
if (useOld) {
|
||||
regions = wg.getRegionContainer().get(one).getRegions();
|
||||
} else {
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
regions = container.get(BukkitAdapter.adapt(one)).getRegions();
|
||||
}
|
||||
for (Entry<String, ProtectedRegion> oneR : regions.entrySet()) {
|
||||
if (!oneR.getKey().equalsIgnoreCase(name))
|
||||
continue;
|
||||
|
@ -26,63 +26,70 @@ public class area implements Cmd {
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (args.length == 0)
|
||||
return false;
|
||||
|
||||
RestrictedAreaManager ra = Jobs.getRestrictedAreaManager();
|
||||
|
||||
if (args.length == 3 && args[0].equalsIgnoreCase("add") && player.hasPermission("jobs.area.add")) {
|
||||
String name = args[1];
|
||||
double bonus = 0D;
|
||||
try {
|
||||
bonus = Double.parseDouble(args[2]);
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
Boolean wg = false;
|
||||
if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
if (!Jobs.hasPermission(player, "jobs.area.add", true))
|
||||
return true;
|
||||
|
||||
if (name.startsWith("wg:")) {
|
||||
wg = true;
|
||||
name = name.substring("wg:".length(), name.length());
|
||||
}
|
||||
String name = args[1];
|
||||
double bonus = 0D;
|
||||
try {
|
||||
bonus = Double.parseDouble(args[2]);
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
boolean wg = false;
|
||||
|
||||
if (ra.isExist(name)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.exist"));
|
||||
return true;
|
||||
}
|
||||
if (name.startsWith("wg:")) {
|
||||
wg = true;
|
||||
name = name.substring("wg:".length(), name.length());
|
||||
}
|
||||
|
||||
if (!wg && !Jobs.getSelectionManager().hasPlacedBoth(player)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.select", "%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (wg && Jobs.getWorldGuardManager() != null) {
|
||||
name = Jobs.getWorldGuardManager().getNameByName(name);
|
||||
if (name == null) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.wgDontExist"));
|
||||
if (ra.isExist(name)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.exist"));
|
||||
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;
|
||||
}
|
||||
if (!wg && !Jobs.getSelectionManager().hasPlacedBoth(player)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.select", "%tool%", CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getName()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && player.hasPermission("jobs.area.remove")) {
|
||||
String name = args[1];
|
||||
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 (!ra.isExist(name)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.dontExist"));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ra.remove(name, true);
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.removed", "%name%", name));
|
||||
return true;
|
||||
if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (!Jobs.hasPermission(player, "jobs.area.remove", true))
|
||||
return true;
|
||||
|
||||
String name = args[1];
|
||||
|
||||
if (!ra.isExist(name)) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.dontExist"));
|
||||
return true;
|
||||
}
|
||||
|
||||
ra.remove(name);
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.output.removed", "%name%", name));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("info")) {
|
||||
@ -139,11 +146,12 @@ public class area implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length > 1) {
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.help.addUsage"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.area.help.removeUsage"));
|
||||
return true;
|
||||
|
@ -40,15 +40,27 @@ public class RestrictedAreaManager {
|
||||
save();
|
||||
}
|
||||
|
||||
public void remove(String name, boolean save) {
|
||||
public void remove(String name) {
|
||||
for (Entry<String, RestrictedArea> area : restrictedAreas.entrySet()) {
|
||||
if (area.getKey().equalsIgnoreCase(name)) {
|
||||
restrictedAreas.remove(area.getKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (save)
|
||||
save();
|
||||
File f = new File(Jobs.getFolder(), "restrictedAreas.yml");
|
||||
if (f.exists()) {
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
||||
conf.options().indent(2);
|
||||
conf.options().copyDefaults(true);
|
||||
StringBuilder header = new StringBuilder();
|
||||
header = addHeader(header);
|
||||
conf.set("restrictedareas." + name, null);
|
||||
try {
|
||||
conf.save(f);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashMap<String, RestrictedArea> getRestrictedAres() {
|
||||
@ -98,9 +110,8 @@ public class RestrictedAreaManager {
|
||||
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())) {
|
||||
if (area.getWgName() != null && Jobs.getWorldGuardManager() != null && Jobs.getWorldGuardManager().inArea(player.getLocation(), area.getWgName()))
|
||||
return area.getMultiplier();
|
||||
}
|
||||
|
||||
}
|
||||
return 0D;
|
||||
@ -113,9 +124,8 @@ public class RestrictedAreaManager {
|
||||
areas.add(area.getValue());
|
||||
}
|
||||
|
||||
if (Jobs.getWorldGuardManager() != null) {
|
||||
if (Jobs.getWorldGuardManager() != null)
|
||||
areas.addAll(Jobs.getWorldGuardManager().getArea(loc));
|
||||
}
|
||||
|
||||
return areas;
|
||||
}
|
||||
@ -171,7 +181,7 @@ public class RestrictedAreaManager {
|
||||
* loads from Jobs/restrictedAreas.yml
|
||||
*/
|
||||
public synchronized void load() {
|
||||
this.restrictedAreas.clear();
|
||||
restrictedAreas.clear();
|
||||
File f = new File(Jobs.getFolder(), "restrictedAreas.yml");
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
||||
conf.options().indent(2);
|
||||
@ -186,10 +196,9 @@ public class RestrictedAreaManager {
|
||||
for (String areaKey : areaSection.getKeys(false)) {
|
||||
double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0.0);
|
||||
|
||||
if (conf.isBoolean("restrictedareas." + areaKey + ".WG")) {
|
||||
RestrictedArea ar = new RestrictedArea(areaKey, areaKey, multiplier);
|
||||
addNew(ar);
|
||||
} else {
|
||||
if (conf.isBoolean("restrictedareas." + areaKey + ".WG"))
|
||||
addNew(new RestrictedArea(areaKey, areaKey, multiplier));
|
||||
else {
|
||||
|
||||
String worldName = conf.getString("restrictedareas." + areaKey + ".world");
|
||||
World world = Bukkit.getServer().getWorld(worldName);
|
||||
@ -205,7 +214,7 @@ public class RestrictedAreaManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (restrictedAreas.size() != 0)
|
||||
if (restrictedAreas.size() > 0)
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + restrictedAreas.size() + " restricted areas!");
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user