1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Fixed array index out of bounds exception

This commit is contained in:
montlikadani 2021-05-28 20:41:08 +02:00
parent f8d16fdfff
commit 182039647c
15 changed files with 121 additions and 98 deletions

View File

@ -115,11 +115,14 @@ public class ItemBoostManager {
continue; continue;
List<Job> jobs = new ArrayList<>(); List<Job> jobs = new ArrayList<>();
for (String oneJ : cfg.get(one + ".jobs", Arrays.asList(""))) { List<String> j = cfg.get(one + ".jobs", Arrays.asList(""));
if (oneJ.equalsIgnoreCase("all")) {
jobs.addAll(Jobs.getJobs()); if (j.contains("all")) {
} else { jobs.addAll(Jobs.getJobs());
} else {
for (String oneJ : j) {
Job job = Jobs.getJob(oneJ); Job job = Jobs.getJob(oneJ);
if (job != null) { if (job != null) {
jobs.add(job); jobs.add(job);
} else { } else {
@ -133,27 +136,29 @@ public class ItemBoostManager {
continue; continue;
} }
List<String> lore = new ArrayList<>(); List<String> lore = cfg.get(one + ".lore", Arrays.asList(""));
if (cfg.getC().isList(one + ".lore")) { for (int a = 0; a < lore.size(); a++) {
for (String eachLine : cfg.get(one + ".lore", Arrays.asList(""))) { lore.set(a, CMIChatColor.translate(lore.get(a)));
lore.add(CMIChatColor.translate(eachLine));
}
} }
Map<Enchantment, Integer> enchants = new HashMap<>(); Map<Enchantment, Integer> enchants = new HashMap<>();
if (cfg.getC().isList(one + ".enchants")) if (cfg.getC().isList(one + ".enchants"))
for (String eachLine : cfg.get(one + ".enchants", Arrays.asList(""))) { for (String eachLine : cfg.get(one + ".enchants", Arrays.asList(""))) {
if (!eachLine.contains("=")) String[] split = eachLine.split("=", 2);
if (split.length == 0)
continue; continue;
String[] split = eachLine.split("=", 2);
Enchantment ench = CMIEnchantment.getEnchantment(split[0]); Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Integer level = -1; int level = -1;
try {
level = Integer.parseInt(split[1]); if (split.length > 1) {
} catch (NumberFormatException e) { try {
continue; level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
} }
if (ench != null && level != -1) if (ench != null && level != -1)
enchants.put(ench, level); enchants.put(ench, level);
} }
@ -161,7 +166,8 @@ public class ItemBoostManager {
BoostMultiplier b = new BoostMultiplier(); BoostMultiplier b = new BoostMultiplier();
for (CurrencyType oneC : CurrencyType.values()) { for (CurrencyType oneC : CurrencyType.values()) {
String typeName = oneC.toString().toLowerCase(); 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); b.add(oneC, cfg.get(one + "." + typeName + "Boost", 1D) - 1);
} }
@ -171,8 +177,10 @@ public class ItemBoostManager {
String node = one.toLowerCase(); String node = one.toLowerCase();
Color leatherColor = null; Color leatherColor = null;
if (cfg.getC().isString(one + ".leather-color")) { String lc = cfg.getC().getString(one + ".leather-color", "");
String[] split = cfg.getC().getString(one + ".leather-color").split(",", 3); if (!lc.isEmpty()) {
String[] split = lc.split(",", 3);
if (split.length != 0) { if (split.length != 0) {
int red = Integer.parseInt(split[0]); int red = Integer.parseInt(split[0]);
int green = split.length > 0 ? Integer.parseInt(split[1]) : 0; int green = split.length > 0 ? Integer.parseInt(split[1]) : 0;
@ -198,8 +206,9 @@ public class ItemBoostManager {
} }
// Lets add into legacy map // Lets add into legacy map
if (one.contains("_")) { String[] split = one.split("_", 2);
item.setLegacyKey(one.split("_", 2)[1].toLowerCase()); if (split.length > 1) {
item.setLegacyKey(split[1].toLowerCase());
LEGACY.put(item.getLegacyKey(), item); LEGACY.put(item.getLegacyKey(), item);
} }

View File

@ -180,6 +180,12 @@ public class Jobs extends JavaPlugin {
return Optional.empty(); 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. * @return a set of block owner ships.
*/ */

View File

@ -956,18 +956,16 @@ public class PlayerManager {
if (player == null || job == null) if (player == null || job == null)
return data; return data;
ItemStack iih;
List<JobItems> jitems = new ArrayList<>(); List<JobItems> jitems = new ArrayList<>();
// Check mainhand slot // Check mainhand slot
if (Jobs.getGCManager().boostedItemsInMainHand && (iih = Jobs.getNms().getItemInMainHand(player)) != null) { if (Jobs.getGCManager().boostedItemsInMainHand) {
jitems.add(getJobsItemByNbt(iih)); jitems.add(getJobsItemByNbt(Jobs.getNms().getItemInMainHand(player)));
} }
// Check offhand slot // Check offhand slot
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand if (Version.isCurrentEqualOrHigher(Version.v1_9_R1) && Jobs.getGCManager().boostedItemsInOffHand) {
&& (iih = CMIReflections.getItemInOffHand(player)) != null) { jitems.add(getJobsItemByNbt(player.getInventory().getItemInOffHand()));
jitems.add(getJobsItemByNbt(iih));
} }
// Check armor slots // Check armor slots
@ -988,7 +986,7 @@ public class PlayerManager {
} }
return data; return data;
} }
private final String jobsItemBoost = "JobsItemBoost"; private final String jobsItemBoost = "JobsItemBoost";

View File

@ -561,7 +561,7 @@ public class ConfigManager {
if (myKey.contains("-")) { if (myKey.contains("-")) {
String[] split = myKey.split("-", 2); String[] split = myKey.split("-", 2);
if (split.length >= 2) { if (split.length > 1) {
subType = ":" + split[1]; subType = ":" + split[1];
meta = split[1]; meta = split[1];
} }
@ -1092,12 +1092,12 @@ public class ConfigManager {
String item = guiSection.getString("Item"); String item = guiSection.getString("Item");
String subType = ""; String subType = "";
if (item.contains("-")) { String[] itemSplit = item.split("-", 2);
String[] split = item.split("-", 2); if (itemSplit.length > 1) {
subType = ":" + split[1]; subType = ":" + itemSplit[1];
item = split[0]; item = itemSplit[0];
} else if (item.contains(":")) { // when we uses tipped arrow effect types } else if ((itemSplit = item.split(":", 2)).length > 0) { // when we uses tipped arrow effect types
item = item.split(":", 2)[0]; item = itemSplit[0];
} }
CMIMaterial material = CMIMaterial.get(item + (subType)); CMIMaterial material = CMIMaterial.get(item + (subType));
@ -1316,18 +1316,21 @@ public class ConfigManager {
Map<Enchantment, Integer> enchants = new HashMap<>(); Map<Enchantment, Integer> enchants = new HashMap<>();
for (String eachLine : itemSection.getStringList("enchants")) { for (String eachLine : itemSection.getStringList("enchants")) {
if (!eachLine.contains("=")) String[] split = eachLine.split("=", 2);
if (split.length == 0)
continue; continue;
String[] split = eachLine.split("=", 2);
Enchantment ench = CMIEnchantment.getEnchantment(split[0]); Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
if (ench == null) if (ench == null)
continue; continue;
int level = -1; int level = -1;
try {
level = Integer.parseInt(split[1]); if (split.length > 1) {
} catch (NumberFormatException e) { try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
}
} }
if (level != -1) if (level != -1)

View File

@ -481,8 +481,8 @@ public class GeneralConfigManager {
String mName = one; String mName = one;
String ench = null; String ench = null;
if (one.contains("=")) { String[] split = one.split("=", 2);
String[] split = one.split("=", 2); if (split.length > 1) {
mName = split[0]; mName = split[0];
ench = split[1]; ench = split[1];
} }

View File

@ -131,8 +131,8 @@ public class NameTranslatorManager {
String mName = materialName; String mName = materialName;
String level = ""; String level = "";
if (mName.contains(":")) { String[] split = materialName.split(":", 2);
String[] split = materialName.split(":", 2); if (split.length > 1) {
mName = split[0]; mName = split[0];
level = ":" + split[1]; level = ":" + split[1];
} }

View File

@ -197,6 +197,7 @@ public class RestrictedAreaManager {
*/ */
public void load() { public void load() {
restrictedAreas.clear(); restrictedAreas.clear();
File f = new File(Jobs.getFolder(), "restrictedAreas.yml"); File f = new File(Jobs.getFolder(), "restrictedAreas.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f); YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
@ -228,8 +229,9 @@ public class RestrictedAreaManager {
} }
} }
if (restrictedAreas.size() > 0) int size = restrictedAreas.size();
Jobs.consoleMsg("&e[Jobs] Loaded " + restrictedAreas.size() + " restricted areas!"); if (size > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + size + " restricted areas!");
try { try {
conf.save(f); conf.save(f);

View File

@ -362,10 +362,10 @@ public class ShopManager {
Map<String, Integer> requiredJobs = new HashMap<>(); Map<String, Integer> requiredJobs = new HashMap<>();
for (String one : nameSection.getStringList("RequiredJobLevels")) { for (String one : nameSection.getStringList("RequiredJobLevels")) {
if (!one.contains("-")) String[] split = one.split("-", 2);
if (split.length == 0)
continue; continue;
String[] split = one.split("-", 2);
int lvl = 1; int lvl = 1;
if (split.length > 1) { if (split.length > 1) {
try { try {
@ -413,10 +413,10 @@ public class ShopManager {
Map<Enchantment, Integer> enchants = new HashMap<>(); Map<Enchantment, Integer> enchants = new HashMap<>();
for (String eachLine : itemSection.getStringList("Enchants")) { for (String eachLine : itemSection.getStringList("Enchants")) {
if (!eachLine.contains("=")) String[] split = eachLine.split("=", 2);
if (split.length == 0)
continue; continue;
String[] split = eachLine.split("=", 2);
Enchantment ench = CMIEnchantment.getEnchantment(split[0]); Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
if (ench == null) if (ench == null)
continue; continue;

View File

@ -148,7 +148,8 @@ public class TitleManager {
titles.add(new Title(titleName, titleShortName, titleColor, levelReq, titleSection.getString(titleKey + ".JobName"))); titles.add(new Title(titleName, titleShortName, titleColor, levelReq, titleSection.getString(titleKey + ".JobName")));
} }
if (titles.size() > 0) int size = titles.size();
Jobs.consoleMsg("&e[Jobs] Loaded " + titles.size() + " titles!"); if (size > 0)
Jobs.consoleMsg("&e[Jobs] Loaded " + size + " titles!");
} }
} }

View File

@ -1358,7 +1358,7 @@ public class JobsPlayer {
if (perm.isEmpty()) if (perm.isEmpty())
return 0; return 0;
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, perm); double maxV = Jobs.getPermissionManager().getMaxPermission(this, perm);
if (maxV == 0D && type == BlockTypes.FURNACE) if (maxV == 0D && type == BlockTypes.FURNACE)
maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault(); maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault();
@ -1372,7 +1372,7 @@ public class JobsPlayer {
if (maxV == 0D && type == BlockTypes.BREWING_STAND) if (maxV == 0D && type == BlockTypes.BREWING_STAND)
maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault(); maxV = (double) Jobs.getGCManager().getBrewingStandsMaxDefault();
return maxV.intValue(); return (int) maxV;
} }
public int getSkippedQuests() { public int getSkippedQuests() {

View File

@ -90,10 +90,7 @@ public class BlockOwnerShip {
boolean owner = false; boolean owner = false;
List<MetadataValue> data = getBlockMetadatas(block); List<MetadataValue> data = getBlockMetadatas(block);
if (!data.isEmpty()) { if (!data.isEmpty()) {
// only care about first if (!data.get(0).asString().equals(jPlayer.getUniqueId().toString())) {
MetadataValue value = data.get(0);
if (!value.asString().equals(player.getUniqueId().toString())) {
return ownershipFeedback.notOwn; return ownershipFeedback.notOwn;
} }
@ -110,26 +107,28 @@ public class BlockOwnerShip {
if (have >= max && max > 0) if (have >= max && max > 0)
return ownershipFeedback.tooMany; 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() if (!Jobs.getGCManager().isBrewingStandsReassign() && !Jobs.getGCManager().isFurnacesReassign()
&& !Jobs.getGCManager().BlastFurnacesReassign && !Jobs.getGCManager().SmokerReassign) { && !Jobs.getGCManager().BlastFurnacesReassign && !Jobs.getGCManager().SmokerReassign) {
return ownershipFeedback.newReg; 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())); ls.add(new blockLoc(block.getLocation()));
blockOwnerShips.put(player.getUniqueId(), ls); blockOwnerShips.put(jPlayer.getUniqueId(), ls);
return ownershipFeedback.newReg; return ownershipFeedback.newReg;
} }
public boolean remove(Block block) { public boolean remove(Block block) {
UUID uuid = null; UUID uuid = null;
List<MetadataValue> data = getBlockMetadatas(block); List<MetadataValue> data = getBlockMetadatas(block);
if (!data.isEmpty()) { if (!data.isEmpty()) {
// only care about first try {
MetadataValue value = data.get(0); uuid = UUID.fromString(data.get(0).asString());
uuid = UUID.fromString(value.asString()); } catch (IllegalArgumentException e) {
}
} }
if (uuid == null) { if (uuid == null) {
@ -137,8 +136,10 @@ public class BlockOwnerShip {
} }
List<blockLoc> ls = blockOwnerShips.getOrDefault(uuid, new ArrayList<>()); List<blockLoc> ls = blockOwnerShips.getOrDefault(uuid, new ArrayList<>());
org.bukkit.Location blockLoc = block.getLocation();
for (blockLoc one : ls) { for (blockLoc one : ls) {
if (one.getLocation().equals(block.getLocation())) { if (one.getLocation().equals(blockLoc)) {
block.removeMetadata(metadataName, plugin); block.removeMetadata(metadataName, plugin);
ls.remove(one); ls.remove(one);
return true; return true;

View File

@ -380,7 +380,7 @@ public class JobsPaymentListener implements Listener {
return; return;
// Remove block owner ships // Remove block owner ships
plugin.getBlockOwnerShips().forEach(os -> os.remove(block)); plugin.removeBlockOwnerShip(block);
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return; return;
@ -401,11 +401,14 @@ public class JobsPaymentListener implements Listener {
return; return;
// Protection for block break with silktouch // Protection for block break with silktouch
ItemStack item = Jobs.getNms().getItemInMainHand(player); if (Jobs.getGCManager().useSilkTouchProtection) {
if (Jobs.getGCManager().useSilkTouchProtection && item.getType() != Material.AIR) { ItemStack item = Jobs.getNms().getItemInMainHand(player);
for (Enchantment one : item.getEnchantments().keySet()) {
if (CMIEnchantment.get(one) == CMIEnchantment.SILK_TOUCH && Jobs.getBpManager().isInBp(block)) { if (item.getType() != Material.AIR && Jobs.getBpManager().isInBp(block)) {
return; 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) if (resultStack == null)
return; 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 // Check for world permissions
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return; return;
@ -846,17 +860,6 @@ public class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
return; 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 // Checking if this is only item rename
ItemStack firstSlot = null; ItemStack firstSlot = null;
try { try {
@ -1534,7 +1537,7 @@ public class JobsPaymentListener implements Listener {
if (block == null) if (block == null)
continue; continue;
plugin.getBlockOwnerShips().forEach(b -> b.remove(block)); plugin.removeBlockOwnerShip(block);
if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(blockMetadata)) if (Jobs.getGCManager().useBlockProtection && block.getState().hasMetadata(blockMetadata))
return; return;

View File

@ -50,7 +50,8 @@ public class PageInfo {
} }
public boolean isContinueNoAdd() { public boolean isContinueNoAdd() {
return currentEntry - 1 >= start && currentEntry - 1 <= end; int entry = currentEntry - 1;
return entry >= start && entry <= end;
} }
public boolean isBreak() { public boolean isBreak() {
@ -86,10 +87,12 @@ public class PageInfo {
} }
public int getNextPageNumber() { public int getNextPageNumber() {
return currentPage + 1 > totalPages ? totalPages : currentPage + 1; int page = currentPage + 1;
return page > totalPages ? totalPages : page;
} }
public int getPrevPageNumber() { public int getPrevPageNumber() {
return currentPage - 1 < 1 ? 1 : currentPage - 1; int prev = currentPage - 1;
return prev < 1 ? 1 : prev;
} }
} }

View File

@ -5,17 +5,21 @@ import org.bukkit.Bukkit;
import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.JobsPlayer;
public class PerformCommands { public final class PerformCommands {
public static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) { public static void performCommandsOnLeave(JobsPlayer jPlayer, Job job) {
String pName = jPlayer.getName();
for (String one : job.getCmdOnLeave()) { 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) { public static void performCommandsOnJoin(JobsPlayer jPlayer, Job job) {
String pName = jPlayer.getName();
for (String one : job.getCmdOnJoin()) { 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()));
} }
} }
} }

View File

@ -50,9 +50,6 @@ public class blockLoc {
} }
public boolean fromString(String loc) { public boolean fromString(String loc) {
if (!loc.contains(":"))
return false;
String[] split = loc.split(":", 4); String[] split = loc.split(":", 4);
if (split.length == 0) { if (split.length == 0) {
return false; return false;
@ -86,15 +83,11 @@ public class blockLoc {
if (worldName == null && w == null) if (worldName == null && w == null)
return 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) if (w == null)
return null; return null;
w = Bukkit.getWorld(w.getName());
if (w == null) {
return null;
}
this.w = w; this.w = w;
return new Location(w, x, y, z); return new Location(w, x, y, z);