mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-30 21:07:48 +01:00
Fixed array index out of bounds exception
This commit is contained in:
parent
f8d16fdfff
commit
182039647c
@ -115,11 +115,14 @@ public class ItemBoostManager {
|
||||
continue;
|
||||
|
||||
List<Job> jobs = new ArrayList<>();
|
||||
for (String oneJ : cfg.get(one + ".jobs", Arrays.asList(""))) {
|
||||
if (oneJ.equalsIgnoreCase("all")) {
|
||||
jobs.addAll(Jobs.getJobs());
|
||||
} else {
|
||||
List<String> j = cfg.get(one + ".jobs", Arrays.asList(""));
|
||||
|
||||
if (j.contains("all")) {
|
||||
jobs.addAll(Jobs.getJobs());
|
||||
} else {
|
||||
for (String oneJ : j) {
|
||||
Job job = Jobs.getJob(oneJ);
|
||||
|
||||
if (job != null) {
|
||||
jobs.add(job);
|
||||
} else {
|
||||
@ -133,27 +136,29 @@ public class ItemBoostManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
if (cfg.getC().isList(one + ".lore")) {
|
||||
for (String eachLine : cfg.get(one + ".lore", Arrays.asList(""))) {
|
||||
lore.add(CMIChatColor.translate(eachLine));
|
||||
}
|
||||
List<String> lore = cfg.get(one + ".lore", Arrays.asList(""));
|
||||
for (int a = 0; a < lore.size(); a++) {
|
||||
lore.set(a, CMIChatColor.translate(lore.get(a)));
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
if (cfg.getC().isList(one + ".enchants"))
|
||||
for (String eachLine : cfg.get(one + ".enchants", Arrays.asList(""))) {
|
||||
if (!eachLine.contains("="))
|
||||
String[] split = eachLine.split("=", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
String[] split = eachLine.split("=", 2);
|
||||
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
|
||||
Integer level = -1;
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
continue;
|
||||
int level = -1;
|
||||
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ench != null && level != -1)
|
||||
enchants.put(ench, level);
|
||||
}
|
||||
@ -161,7 +166,8 @@ public class ItemBoostManager {
|
||||
BoostMultiplier b = new BoostMultiplier();
|
||||
for (CurrencyType oneC : CurrencyType.values()) {
|
||||
String typeName = oneC.toString().toLowerCase();
|
||||
if (cfg.getC().isDouble(one + "." + typeName + "Boost") || cfg.getC().isInt(one + "." + typeName + "Boost"))
|
||||
|
||||
if (cfg.getC().isDouble(one + "." + typeName + "Boost"))
|
||||
b.add(oneC, cfg.get(one + "." + typeName + "Boost", 1D) - 1);
|
||||
}
|
||||
|
||||
@ -171,8 +177,10 @@ public class ItemBoostManager {
|
||||
String node = one.toLowerCase();
|
||||
|
||||
Color leatherColor = null;
|
||||
if (cfg.getC().isString(one + ".leather-color")) {
|
||||
String[] split = cfg.getC().getString(one + ".leather-color").split(",", 3);
|
||||
String lc = cfg.getC().getString(one + ".leather-color", "");
|
||||
if (!lc.isEmpty()) {
|
||||
String[] split = lc.split(",", 3);
|
||||
|
||||
if (split.length != 0) {
|
||||
int red = Integer.parseInt(split[0]);
|
||||
int green = split.length > 0 ? Integer.parseInt(split[1]) : 0;
|
||||
@ -198,8 +206,9 @@ public class ItemBoostManager {
|
||||
}
|
||||
|
||||
// Lets add into legacy map
|
||||
if (one.contains("_")) {
|
||||
item.setLegacyKey(one.split("_", 2)[1].toLowerCase());
|
||||
String[] split = one.split("_", 2);
|
||||
if (split.length > 1) {
|
||||
item.setLegacyKey(split[1].toLowerCase());
|
||||
LEGACY.put(item.getLegacyKey(), item);
|
||||
}
|
||||
|
||||
|
@ -180,6 +180,12 @@ public class Jobs extends JavaPlugin {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void removeBlockOwnerShip(org.bukkit.block.Block block) {
|
||||
for (BlockOwnerShip ship : blockOwnerShips) {
|
||||
ship.remove(block);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a set of block owner ships.
|
||||
*/
|
||||
|
@ -956,18 +956,16 @@ public class PlayerManager {
|
||||
if (player == null || job == null)
|
||||
return data;
|
||||
|
||||
ItemStack iih;
|
||||
List<JobItems> jitems = new ArrayList<>();
|
||||
|
||||
// Check mainhand slot
|
||||
if (Jobs.getGCManager().boostedItemsInMainHand && (iih = Jobs.getNms().getItemInMainHand(player)) != null) {
|
||||
jitems.add(getJobsItemByNbt(iih));
|
||||
if (Jobs.getGCManager().boostedItemsInMainHand) {
|
||||
jitems.add(getJobsItemByNbt(Jobs.getNms().getItemInMainHand(player)));
|
||||
}
|
||||
|
||||
// Check offhand slot
|
||||
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand
|
||||
&& (iih = CMIReflections.getItemInOffHand(player)) != null) {
|
||||
jitems.add(getJobsItemByNbt(iih));
|
||||
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand) {
|
||||
jitems.add(getJobsItemByNbt(player.getInventory().getItemInOffHand()));
|
||||
}
|
||||
|
||||
// Check armor slots
|
||||
@ -988,7 +986,7 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
private final String jobsItemBoost = "JobsItemBoost";
|
||||
|
||||
|
@ -561,7 +561,7 @@ public class ConfigManager {
|
||||
if (myKey.contains("-")) {
|
||||
String[] split = myKey.split("-", 2);
|
||||
|
||||
if (split.length >= 2) {
|
||||
if (split.length > 1) {
|
||||
subType = ":" + split[1];
|
||||
meta = split[1];
|
||||
}
|
||||
@ -1092,12 +1092,12 @@ public class ConfigManager {
|
||||
String item = guiSection.getString("Item");
|
||||
String subType = "";
|
||||
|
||||
if (item.contains("-")) {
|
||||
String[] split = item.split("-", 2);
|
||||
subType = ":" + split[1];
|
||||
item = split[0];
|
||||
} else if (item.contains(":")) { // when we uses tipped arrow effect types
|
||||
item = item.split(":", 2)[0];
|
||||
String[] itemSplit = item.split("-", 2);
|
||||
if (itemSplit.length > 1) {
|
||||
subType = ":" + itemSplit[1];
|
||||
item = itemSplit[0];
|
||||
} else if ((itemSplit = item.split(":", 2)).length > 0) { // when we uses tipped arrow effect types
|
||||
item = itemSplit[0];
|
||||
}
|
||||
|
||||
CMIMaterial material = CMIMaterial.get(item + (subType));
|
||||
@ -1316,18 +1316,21 @@ public class ConfigManager {
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
for (String eachLine : itemSection.getStringList("enchants")) {
|
||||
if (!eachLine.contains("="))
|
||||
String[] split = eachLine.split("=", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
String[] split = eachLine.split("=", 2);
|
||||
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
|
||||
if (ench == null)
|
||||
continue;
|
||||
|
||||
int level = -1;
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (level != -1)
|
||||
|
@ -481,8 +481,8 @@ public class GeneralConfigManager {
|
||||
String mName = one;
|
||||
String ench = null;
|
||||
|
||||
if (one.contains("=")) {
|
||||
String[] split = one.split("=", 2);
|
||||
String[] split = one.split("=", 2);
|
||||
if (split.length > 1) {
|
||||
mName = split[0];
|
||||
ench = split[1];
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ public class NameTranslatorManager {
|
||||
String mName = materialName;
|
||||
String level = "";
|
||||
|
||||
if (mName.contains(":")) {
|
||||
String[] split = materialName.split(":", 2);
|
||||
String[] split = materialName.split(":", 2);
|
||||
if (split.length > 1) {
|
||||
mName = split[0];
|
||||
level = ":" + split[1];
|
||||
}
|
||||
|
@ -197,6 +197,7 @@ public class RestrictedAreaManager {
|
||||
*/
|
||||
public void load() {
|
||||
restrictedAreas.clear();
|
||||
|
||||
File f = new File(Jobs.getFolder(), "restrictedAreas.yml");
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
||||
|
||||
@ -228,8 +229,9 @@ public class RestrictedAreaManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (restrictedAreas.size() > 0)
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + restrictedAreas.size() + " restricted areas!");
|
||||
int size = restrictedAreas.size();
|
||||
if (size > 0)
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + size + " restricted areas!");
|
||||
|
||||
try {
|
||||
conf.save(f);
|
||||
|
@ -362,10 +362,10 @@ public class ShopManager {
|
||||
Map<String, Integer> requiredJobs = new HashMap<>();
|
||||
|
||||
for (String one : nameSection.getStringList("RequiredJobLevels")) {
|
||||
if (!one.contains("-"))
|
||||
String[] split = one.split("-", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
String[] split = one.split("-", 2);
|
||||
int lvl = 1;
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
@ -413,10 +413,10 @@ public class ShopManager {
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
for (String eachLine : itemSection.getStringList("Enchants")) {
|
||||
if (!eachLine.contains("="))
|
||||
String[] split = eachLine.split("=", 2);
|
||||
if (split.length == 0)
|
||||
continue;
|
||||
|
||||
String[] split = eachLine.split("=", 2);
|
||||
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
|
||||
if (ench == null)
|
||||
continue;
|
||||
|
@ -148,7 +148,8 @@ public class TitleManager {
|
||||
titles.add(new Title(titleName, titleShortName, titleColor, levelReq, titleSection.getString(titleKey + ".JobName")));
|
||||
}
|
||||
|
||||
if (titles.size() > 0)
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + titles.size() + " titles!");
|
||||
int size = titles.size();
|
||||
if (size > 0)
|
||||
Jobs.consoleMsg("&e[Jobs] Loaded " + size + " titles!");
|
||||
}
|
||||
}
|
||||
|
@ -1358,7 +1358,7 @@ public class JobsPlayer {
|
||||
if (perm.isEmpty())
|
||||
return 0;
|
||||
|
||||
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, perm);
|
||||
double maxV = Jobs.getPermissionManager().getMaxPermission(this, perm);
|
||||
|
||||
if (maxV == 0D && type == BlockTypes.FURNACE)
|
||||
maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault();
|
||||
@ -1372,7 +1372,7 @@ public class JobsPlayer {
|
||||
if (maxV == 0D && type == BlockTypes.BREWING_STAND)
|
||||
maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault();
|
||||
|
||||
return maxV.intValue();
|
||||
return (int) maxV;
|
||||
}
|
||||
|
||||
public int getSkippedQuests() {
|
||||
|
@ -90,10 +90,7 @@ public class BlockOwnerShip {
|
||||
boolean owner = false;
|
||||
List<MetadataValue> data = getBlockMetadatas(block);
|
||||
if (!data.isEmpty()) {
|
||||
// only care about first
|
||||
MetadataValue value = data.get(0);
|
||||
|
||||
if (!value.asString().equals(player.getUniqueId().toString())) {
|
||||
if (!data.get(0).asString().equals(jPlayer.getUniqueId().toString())) {
|
||||
return ownershipFeedback.notOwn;
|
||||
}
|
||||
|
||||
@ -110,26 +107,28 @@ public class BlockOwnerShip {
|
||||
if (have >= max && max > 0)
|
||||
return ownershipFeedback.tooMany;
|
||||
|
||||
block.setMetadata(metadataName, new FixedMetadataValue(plugin, player.getUniqueId().toString()));
|
||||
block.setMetadata(metadataName, new FixedMetadataValue(plugin, jPlayer.getUniqueId().toString()));
|
||||
|
||||
if (!Jobs.getGCManager().isBrewingStandsReassign() && !Jobs.getGCManager().isFurnacesReassign()
|
||||
&& !Jobs.getGCManager().BlastFurnacesReassign && !Jobs.getGCManager().SmokerReassign) {
|
||||
return ownershipFeedback.newReg;
|
||||
}
|
||||
|
||||
List<blockLoc> ls = blockOwnerShips.getOrDefault(player.getUniqueId(), new ArrayList<>());
|
||||
List<blockLoc> ls = blockOwnerShips.getOrDefault(jPlayer.getUniqueId(), new ArrayList<>());
|
||||
ls.add(new blockLoc(block.getLocation()));
|
||||
blockOwnerShips.put(player.getUniqueId(), ls);
|
||||
blockOwnerShips.put(jPlayer.getUniqueId(), ls);
|
||||
return ownershipFeedback.newReg;
|
||||
}
|
||||
|
||||
public boolean remove(Block block) {
|
||||
UUID uuid = null;
|
||||
List<MetadataValue> data = getBlockMetadatas(block);
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
// only care about first
|
||||
MetadataValue value = data.get(0);
|
||||
uuid = UUID.fromString(value.asString());
|
||||
try {
|
||||
uuid = UUID.fromString(data.get(0).asString());
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (uuid == null) {
|
||||
@ -137,8 +136,10 @@ public class BlockOwnerShip {
|
||||
}
|
||||
|
||||
List<blockLoc> ls = blockOwnerShips.getOrDefault(uuid, new ArrayList<>());
|
||||
org.bukkit.Location blockLoc = block.getLocation();
|
||||
|
||||
for (blockLoc one : ls) {
|
||||
if (one.getLocation().equals(block.getLocation())) {
|
||||
if (one.getLocation().equals(blockLoc)) {
|
||||
block.removeMetadata(metadataName, plugin);
|
||||
ls.remove(one);
|
||||
return true;
|
||||
|
@ -380,7 +380,7 @@ public class JobsPaymentListener implements Listener {
|
||||
return;
|
||||
|
||||
// Remove block owner ships
|
||||
plugin.getBlockOwnerShips().forEach(os -> os.remove(block));
|
||||
plugin.removeBlockOwnerShip(block);
|
||||
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
return;
|
||||
@ -401,11 +401,14 @@ public class JobsPaymentListener implements Listener {
|
||||
return;
|
||||
|
||||
// Protection for block break with silktouch
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(player);
|
||||
if (Jobs.getGCManager().useSilkTouchProtection && item.getType() != Material.AIR) {
|
||||
for (Enchantment one : item.getEnchantments().keySet()) {
|
||||
if (CMIEnchantment.get(one) == CMIEnchantment.SILK_TOUCH && Jobs.getBpManager().isInBp(block)) {
|
||||
return;
|
||||
if (Jobs.getGCManager().useSilkTouchProtection) {
|
||||
ItemStack item = Jobs.getNms().getItemInMainHand(player);
|
||||
|
||||
if (item.getType() != Material.AIR && Jobs.getBpManager().isInBp(block)) {
|
||||
for (Enchantment one : item.getEnchantments().keySet()) {
|
||||
if (CMIEnchantment.get(one) == CMIEnchantment.SILK_TOUCH) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -834,6 +837,17 @@ public class JobsPaymentListener implements Listener {
|
||||
if (resultStack == null)
|
||||
return;
|
||||
|
||||
// Fix for possible money duplication bugs.
|
||||
switch (event.getClick()) {
|
||||
case UNKNOWN:
|
||||
case WINDOW_BORDER_LEFT:
|
||||
case WINDOW_BORDER_RIGHT:
|
||||
case NUMBER_KEY:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for world permissions
|
||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||
return;
|
||||
@ -846,17 +860,6 @@ public class JobsPaymentListener implements Listener {
|
||||
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
|
||||
return;
|
||||
|
||||
// Fix for possible money duplication bugs.
|
||||
switch (event.getClick()) {
|
||||
case UNKNOWN:
|
||||
case WINDOW_BORDER_LEFT:
|
||||
case WINDOW_BORDER_RIGHT:
|
||||
case NUMBER_KEY:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Checking if this is only item rename
|
||||
ItemStack firstSlot = null;
|
||||
try {
|
||||
@ -1534,7 +1537,7 @@ public class JobsPaymentListener implements Listener {
|
||||
if (block == null)
|
||||
continue;
|
||||
|
||||
plugin.getBlockOwnerShips().forEach(b -> b.remove(block));
|
||||
plugin.removeBlockOwnerShip(block);
|
||||
|
||||
if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(blockMetadata))
|
||||
return;
|
||||
|
@ -50,7 +50,8 @@ public class PageInfo {
|
||||
}
|
||||
|
||||
public boolean isContinueNoAdd() {
|
||||
return currentEntry - 1 >= start && currentEntry - 1 <= end;
|
||||
int entry = currentEntry - 1;
|
||||
return entry >= start && entry <= end;
|
||||
}
|
||||
|
||||
public boolean isBreak() {
|
||||
@ -86,10 +87,12 @@ public class PageInfo {
|
||||
}
|
||||
|
||||
public int getNextPageNumber() {
|
||||
return currentPage + 1 > totalPages ? totalPages : currentPage + 1;
|
||||
int page = currentPage + 1;
|
||||
return page > totalPages ? totalPages : page;
|
||||
}
|
||||
|
||||
public int getPrevPageNumber() {
|
||||
return currentPage - 1 < 1 ? 1 : currentPage - 1;
|
||||
int prev = currentPage - 1;
|
||||
return prev < 1 ? 1 : prev;
|
||||
}
|
||||
}
|
||||
|
@ -5,17 +5,21 @@ import org.bukkit.Bukkit;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
|
||||
public class PerformCommands {
|
||||
public final class PerformCommands {
|
||||
|
||||
public static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) {
|
||||
String pName = jPlayer.getName();
|
||||
|
||||
for (String one : job.getCmdOnLeave()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName()));
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void performCommandsOnJoin(JobsPlayer jPlayer, Job job) {
|
||||
String pName = jPlayer.getName();
|
||||
|
||||
for (String one : job.getCmdOnJoin()) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", jPlayer.getName()).replace("[jobname]", job.getName()));
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one.replace("[name]", pName).replace("[jobname]", job.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,9 +50,6 @@ public class blockLoc {
|
||||
}
|
||||
|
||||
public boolean fromString(String loc) {
|
||||
if (!loc.contains(":"))
|
||||
return false;
|
||||
|
||||
String[] split = loc.split(":", 4);
|
||||
if (split.length == 0) {
|
||||
return false;
|
||||
@ -86,15 +83,11 @@ public class blockLoc {
|
||||
if (worldName == null && w == null)
|
||||
return null;
|
||||
|
||||
World w = this.w == null ? Bukkit.getWorld(worldName) : this.w;
|
||||
// Make sure cached world is loaded
|
||||
World w = this.w == null ? Bukkit.getWorld(worldName) : Bukkit.getWorld(this.w.getName());
|
||||
if (w == null)
|
||||
return null;
|
||||
|
||||
w = Bukkit.getWorld(w.getName());
|
||||
if (w == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.w = w;
|
||||
|
||||
return new Location(w, x, y, z);
|
||||
|
Loading…
Reference in New Issue
Block a user