From b7cfc104bbad99c5ee2410ba260de9631ebc74b0 Mon Sep 17 00:00:00 2001 From: Zrips Date: Mon, 15 Apr 2024 13:17:32 +0300 Subject: [PATCH] Fixing stats command when reaching max level limits --- src/main/java/com/gamingmesh/jobs/Jobs.java | 2 +- .../com/gamingmesh/jobs/Signs/SignUtil.java | 2 + .../com/gamingmesh/jobs/Signs/jobsSign.java | 132 ++-- .../gamingmesh/jobs/api/JobsExpGainEvent.java | 36 +- .../jobs/commands/JobsCommands.java | 32 +- .../gamingmesh/jobs/commands/list/gtop.java | 2 +- .../gamingmesh/jobs/commands/list/stats.java | 2 +- .../blockOwnerShip/BlockOwnerShip.java | 575 +++++++++--------- 8 files changed, 397 insertions(+), 386 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 4908d5ec..38302e12 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -1454,7 +1454,7 @@ public final class Jobs extends JavaPlugin { payment.set(CurrencyType.POINTS, jobsPrePaymentEvent.getPoints()); JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, expPayment, - block, ent, victim, info); + block, ent, victim, info); Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent); // If event is canceled, don't do anything if (jobsExpGainEvent.isCancelled()) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index 949be3d8..8f2965d1 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -17,6 +18,7 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.commands.list.gtop; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; diff --git a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java index 70b072ac..9443ae82 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java @@ -12,144 +12,146 @@ public class jobsSign { private String worldName; - private Integer x, y, z; + private int x; + private int y; + private int z; private World world; private Location loc; - private Integer number; + private int number = 0; private String jobName; private boolean special = false; private SignTopType type; public void setSpecial(boolean special) { - this.special = special; + this.special = special; } public boolean isSpecial() { - return special; + return special; } public void setJobName(String jobName) { - this.jobName = jobName; + this.jobName = jobName; } public String getJobName() { - return jobName; + return jobName; } public void setX(int x) { - this.x = x; + this.x = x; } public void setY(int y) { - this.y = y; + this.y = y; } public void setZ(int z) { - this.z = z; + this.z = z; } public void setWorldName(String worldName) { - this.worldName = worldName; + this.worldName = worldName; } public String getWorldName() { - return worldName; + return worldName; } public Location getLocation() { - if (loc != null) - return loc; - if (worldName == null) - return null; - if ((world = Bukkit.getWorld(worldName)) == null) - return null; - return loc = new Location(world, x, y, z); + if (loc != null) + return loc; + if (worldName == null) + return null; + if ((world = Bukkit.getWorld(worldName)) == null) + return null; + return loc = new Location(world, x, y, z); } public void setNumber(int number) { - this.number = number; + this.number = number; } public int getNumber() { - return number; + return number; } public String locToBlockString() { - return worldName + ";" + x + ";" + y + ";" + z; + return worldName + ";" + x + ";" + y + ";" + z; } public static String locToBlockString(Location loc) { - return loc == null ? "" : loc.getWorld().getName() + ";" + loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); + return loc == null ? "" : loc.getWorld().getName() + ";" + loc.getBlockX() + ";" + loc.getBlockY() + ";" + loc.getBlockZ(); } public void setLoc(Location loc) { - if (loc == null) - return; - this.worldName = loc.getWorld().getName(); - this.x = loc.getBlockX(); - this.y = loc.getBlockY(); - this.z = loc.getBlockZ(); - this.world = loc.getWorld(); - this.loc = loc; + if (loc == null) + return; + this.worldName = loc.getWorld().getName(); + this.x = loc.getBlockX(); + this.y = loc.getBlockY(); + this.z = loc.getBlockZ(); + this.world = loc.getWorld(); + this.loc = loc; } public void setLoc(String string) { - if (!string.contains(";")) - return; + if (!string.contains(";")) + return; - String[] split = string.replace(',', '.').split(";", 4); + String[] split = string.replace(',', '.').split(";", 4); - int x = 0, y = 0, z = 0; + int x = 0, y = 0, z = 0; - if (split.length > 0) - try { - x = Integer.parseInt(split[1]); - } catch (NumberFormatException e) { - return; - } + if (split.length > 0) + try { + x = Integer.parseInt(split[1]); + } catch (NumberFormatException e) { + return; + } - if (split.length > 1) - try { - y = Integer.parseInt(split[2]); - } catch (NumberFormatException e) { - return; - } + if (split.length > 1) + try { + y = Integer.parseInt(split[2]); + } catch (NumberFormatException e) { + return; + } - if (split.length > 2) - try { - z = Integer.parseInt(split[3]); - } catch (NumberFormatException e) { - return; - } + if (split.length > 2) + try { + z = Integer.parseInt(split[3]); + } catch (NumberFormatException e) { + return; + } - World world = CMIWorld.getWorld(split[0]); - if (world == null) - return; + World world = CMIWorld.getWorld(split[0]); + if (world == null) + return; - setLoc(new Location(world, x, y, z)); + setLoc(new Location(world, x, y, z)); } public SignTopType getType() { - return type == null ? SignTopType.toplist : type; + return type == null ? SignTopType.toplist : type; } public void setType(SignTopType type) { - this.type = type; + this.type = type; } public String getIdentifier() { - SignTopType type = getType(); + SignTopType type = getType(); - if (type != SignTopType.toplist) - return type.toString(); + if (type != SignTopType.toplist) + return type.toString(); - return jobName != null ? jobName + ":" + type.toString() : type.toString(); + return jobName != null ? jobName + ":" + type.toString() : type.toString(); } public static String getIdentifier(Job job, SignTopType type) { - if (type != SignTopType.toplist) - return type.toString(); - return job != null ? job.getName() + ":" + type.toString() : type.toString(); + if (type != SignTopType.toplist) + return type.toString(); + return job != null ? job.getName() + ":" + type.toString() : type.toString(); } } diff --git a/src/main/java/com/gamingmesh/jobs/api/JobsExpGainEvent.java b/src/main/java/com/gamingmesh/jobs/api/JobsExpGainEvent.java index 31d686b9..4040e73d 100644 --- a/src/main/java/com/gamingmesh/jobs/api/JobsExpGainEvent.java +++ b/src/main/java/com/gamingmesh/jobs/api/JobsExpGainEvent.java @@ -25,14 +25,14 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { private boolean cancelled = false; public JobsExpGainEvent(OfflinePlayer offlinePlayer, Job job, double exp, Block block, - Entity entity, LivingEntity living, ActionInfo info) { - this.offlinePlayer = offlinePlayer; - this.job = job; - this.exp = exp; - this.block = block; - this.entity = entity; - this.living = living; - this.info = info; + Entity entity, LivingEntity living, ActionInfo info) { + this.offlinePlayer = offlinePlayer; + this.job = job; + this.exp = exp; + this.block = block; + this.entity = entity; + this.living = living; + this.info = info; } /** @@ -41,7 +41,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link OfflinePlayer} */ public OfflinePlayer getPlayer() { - return offlinePlayer; + return offlinePlayer; } /** @@ -50,7 +50,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link Job} */ public Job getJob() { - return job; + return job; } /** @@ -59,7 +59,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return the amount of experience the player got */ public double getExp() { - return exp; + return exp; } /** @@ -68,7 +68,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @param exp the new value */ public void setExp(double exp) { - this.exp = exp; + this.exp = exp; } /** @@ -77,7 +77,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link Block} */ public Block getBlock() { - return block; + return block; } /** @@ -88,7 +88,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link Entity} */ public Entity getEntity() { - return entity; + return entity; } /** @@ -97,7 +97,7 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link LivingEntity} */ public LivingEntity getLivingEntity() { - return living; + return living; } /** @@ -106,16 +106,16 @@ public final class JobsExpGainEvent extends BaseEvent implements Cancellable { * @return {@link ActionInfo} */ public ActionInfo getActionInfo() { - return info; + return info; } @Override public boolean isCancelled() { - return cancelled; + return cancelled; } @Override public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; + this.cancelled = cancelled; } } \ No newline at end of file diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index 4fe0baf9..fc0dce8b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -7,7 +7,6 @@ import java.util.Set; import java.util.TreeSet; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -28,6 +27,7 @@ import com.gamingmesh.jobs.i18n.Language; import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; +import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Container.CMIArray; import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Locale.LC; @@ -373,15 +373,15 @@ public class JobsCommands implements CommandExecutor { double income = info.getIncome(level, numjobs, player.maxJobsEquation); income = boost.getFinalAmount(CurrencyType.MONEY, income); - String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); + String incomeColor = income >= 0 ? "" : CMIChatColor.DARK_RED.toString(); double xp = info.getExperience(level, numjobs, player.maxJobsEquation); xp = boost.getFinalAmount(CurrencyType.EXP, xp); - String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); + String xpColor = xp >= 0 ? "" : CMIChatColor.GRAY.toString(); double points = info.getPoints(level, numjobs, player.maxJobsEquation); points = boost.getFinalAmount(CurrencyType.POINTS, points); - String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); + String pointsColor = xp >= 0 ? "" : CMIChatColor.RED.toString(); if (income == 0D && points == 0D && xp == 0D) continue; @@ -390,7 +390,7 @@ public class JobsCommands implements CommandExecutor { message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName)); if (prog != null && !info.isInLevelRange(prog.getLevel())) - message.append(ChatColor.RED + " -> "); + message.append(CMIChatColor.RED + " -> "); else message.append(" -> "); @@ -417,19 +417,27 @@ public class JobsCommands implements CommandExecutor { return message.toString(); } + @Deprecated + public String jobStatsMessage(JobProgression jobProg) { + return jobStatsMessage(jobProg, null, true); + } + + @Deprecated + public String jobStatsMessage(JobProgression jobProg, boolean progressBar) { + return jobStatsMessage(jobProg, null, progressBar); + } + /** * Displays job stats about a particular player's job * @param jobProg - the job progress of the players job + * @param jPlayer - the player of the job + * @param progressBar - if the progress bar should be displayed * @return the message */ - public String jobStatsMessage(JobProgression jobProg) { - return jobStatsMessage(jobProg, true); - } + public String jobStatsMessage(JobProgression jobProg, JobsPlayer jPlayer, boolean progressBar) { - public String jobStatsMessage(JobProgression jobProg, boolean progressBar) { - boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); - String path = "command.stats.output." + (isMaxLevelReached ? "max-level" - : "message"); + boolean isMaxLevelReached = jobProg.getLevel() >= (jPlayer == null ? jobProg.getJob().getMaxLevel() : jPlayer.getMaxJobLevelAllowed(jobProg.getJob())); + String path = "command.stats.output." + (isMaxLevelReached ? "max-level" : "message"); Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()); String message = Jobs.getLanguage().getMessage(path, diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java index dd43bba1..4e2b8dec 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -103,7 +103,7 @@ public class gtop implements Cmd { pi.autoPagination(sender, "jobs gtop"); } - private static boolean hasToBeSeenInGlobalTop(TopList topList) { + public static boolean hasToBeSeenInGlobalTop(TopList topList) { Player player = topList.getPlayerInfo().getJobsPlayer().getPlayer(); if (player != null) return !player.hasPermission("jobs.hidegtop"); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java index a0da689d..4714741f 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/stats.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/stats.java @@ -47,7 +47,7 @@ public class stats implements Cmd { String pref = JobsCommands.LABEL + " " + info.class.getSimpleName() + " "; for (JobProgression jobProg : jPlayer.getJobProgression()) { - for (String msg : Jobs.getCommandManager().jobStatsMessage(jobProg, sender instanceof Player).split("\n")) { + for (String msg : Jobs.getCommandManager().jobStatsMessage(jobProg, jPlayer, sender instanceof Player).split("\n")) { new RawMessage().addText(msg).addHover(leftClick).addCommand(pref + jobProg.getJob().getName()).show(sender); } } diff --git a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java index 507c5613..00fa2222 100644 --- a/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java +++ b/src/main/java/com/gamingmesh/jobs/container/blockOwnerShip/BlockOwnerShip.java @@ -40,411 +40,410 @@ public class BlockOwnerShip { private final Jobs plugin = org.bukkit.plugin.java.JavaPlugin.getPlugin(Jobs.class); public BlockOwnerShip(CMIMaterial type) { - // Type should be any type of furnace, smoker or brewing stand - if (type != CMIMaterial.FURNACE && type != CMIMaterial.LEGACY_BURNING_FURNACE - && type != CMIMaterial.BLAST_FURNACE && type != CMIMaterial.SMOKER && type != CMIMaterial.BREWING_STAND - && type != CMIMaterial.LEGACY_BREWING_STAND) { - throw new IllegalArgumentException("Material types should be any type of furnace, smoker or brewing stand"); - } + // Type should be any type of furnace, smoker or brewing stand + if (type != CMIMaterial.FURNACE && type != CMIMaterial.LEGACY_BURNING_FURNACE + && type != CMIMaterial.BLAST_FURNACE && type != CMIMaterial.SMOKER && type != CMIMaterial.BREWING_STAND + && type != CMIMaterial.LEGACY_BREWING_STAND) { + throw new IllegalArgumentException("Material types should be any type of furnace, smoker or brewing stand"); + } - material = type; + material = type; - switch (this.type = BlockTypes.getFromCMIMaterial(type)) { - case BLAST_FURNACE: - metadataName = "jobsBlastFurnaceOwner"; - break; - case BREWING_STAND: - metadataName = "jobsBrewingOwner"; - break; - case FURNACE: - metadataName = "jobsFurnaceOwner"; - break; - case SMOKER: - metadataName = "jobsSmokerOwner"; - break; - default: - break; - } + switch (this.type = BlockTypes.getFromCMIMaterial(type)) { + case BLAST_FURNACE: + metadataName = "jobsBlastFurnaceOwner"; + break; + case BREWING_STAND: + metadataName = "jobsBrewingOwner"; + break; + case FURNACE: + metadataName = "jobsFurnaceOwner"; + break; + case SMOKER: + metadataName = "jobsSmokerOwner"; + break; + default: + break; + } } public BlockTypes getType() { - return type; + return type; } public CMIMaterial getMaterial() { - return material; + return material; } public String getMetadataName() { - return metadataName; + return metadataName; } public Map> getBlockOwnerShips() { - return blockOwnerShips; + return blockOwnerShips; } public boolean isDisabled(UUID uuid, Location loc) { - HashMap records = getBlockOwnerShips().get(uuid); - if (records == null) - return false; + HashMap records = getBlockOwnerShips().get(uuid); + if (records == null) + return false; - blockLoc old = records.get(CMILocation.toString(loc, ":", true, true)); - if (old == null) - return false; + blockLoc old = records.get(CMILocation.toString(loc, ":", true, true)); + if (old == null) + return false; - return old.isDisabled(); + return old.isDisabled(); } public ownershipFeedback register(Player player, Block block) { - if (type != BlockTypes.getFromCMIMaterial(CMIMaterial.get(block))) { - return ownershipFeedback.invalid; - } + if (type != BlockTypes.getFromCMIMaterial(CMIMaterial.get(block))) { + return ownershipFeedback.invalid; + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); - if (jPlayer == null) { - return ownershipFeedback.invalid; - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jPlayer == null) { + return ownershipFeedback.invalid; + } - JobsBlockOwnershipRegisterEvent jobsBlockOwnershipRegisterEvent = new JobsBlockOwnershipRegisterEvent(player, block); - Bukkit.getServer().getPluginManager().callEvent(jobsBlockOwnershipRegisterEvent); - if(jobsBlockOwnershipRegisterEvent.isCancelled()) { - return ownershipFeedback.invalid; - } + JobsBlockOwnershipRegisterEvent jobsBlockOwnershipRegisterEvent = new JobsBlockOwnershipRegisterEvent(player, block); + Bukkit.getServer().getPluginManager().callEvent(jobsBlockOwnershipRegisterEvent); + if (jobsBlockOwnershipRegisterEvent.isCancelled()) { + return ownershipFeedback.invalid; + } - UUID ownerUUID = this.getOwnerByLocation(block.getLocation()); + UUID ownerUUID = this.getOwnerByLocation(block.getLocation()); - if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) { - HashMap records = getBlockOwnerShips().get(ownerUUID); - if (records != null) { - blockLoc old = records.get(CMILocation.toString(block.getLocation(), ":", true, true)); - if (old != null && old.isDisabled()) { - old.setDisabled(false); - return ownershipFeedback.reenabled; - } - } - return ownershipFeedback.old; - } + if (ownerUUID != null && ownerUUID.equals(player.getUniqueId())) { + HashMap records = getBlockOwnerShips().get(ownerUUID); + if (records != null) { + blockLoc old = records.get(CMILocation.toString(block.getLocation(), ":", true, true)); + if (old != null && old.isDisabled()) { + old.setDisabled(false); + return ownershipFeedback.reenabled; + } + } + return ownershipFeedback.old; + } - if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId())) { - if (Jobs.getGCManager().blockOwnershipTakeOver) { - // Removing ownership to record new player - this.remove(ownerUUID, CMILocation.toString(block.getLocation(), ":", true, true)); - block.removeMetadata(metadataName, plugin); + if (ownerUUID != null && !ownerUUID.equals(player.getUniqueId())) { + if (Jobs.getGCManager().blockOwnershipTakeOver) { + // Removing ownership to record new player + this.remove(ownerUUID, CMILocation.toString(block.getLocation(), ":", true, true)); + block.removeMetadata(metadataName, plugin); - Player owningPlayer = Bukkit.getPlayer(ownerUUID); + Player owningPlayer = Bukkit.getPlayer(ownerUUID); - if (owningPlayer != null && owningPlayer.isOnline()) { - owningPlayer.sendMessage(Jobs.getLanguage().getMessage("command.clearownership.output.lost", "[type]", CMIMaterial.get(type.toString()).getName(), "[location]", CMILocation.toString( - block.getLocation(), ":", - true, true))); - } + if (owningPlayer != null && owningPlayer.isOnline()) { + owningPlayer.sendMessage(Jobs.getLanguage().getMessage("command.clearownership.output.lost", "[type]", CMIMaterial.get(type.toString()).getName(), "[location]", CMILocation.toString( + block.getLocation(), ":", + true, true))); + } - } else - return ownershipFeedback.notOwn; - } + } else + return ownershipFeedback.notOwn; + } - int max = jPlayer.getMaxOwnerShipAllowed(type); - int have = getTotal(jPlayer.getUniqueId()); + int max = jPlayer.getMaxOwnerShipAllowed(type); + int have = getTotal(jPlayer.getUniqueId()); - boolean owner = false; - List data = getBlockMetadatas(block); - if (!data.isEmpty()) { - if (have > max && max > 0) { - remove(block); - } - owner = true; - } + boolean owner = false; + List data = getBlockMetadatas(block); + if (!data.isEmpty()) { + if (have > max && max > 0) { + remove(block); + } + owner = true; + } - if (owner) - return ownershipFeedback.old; + if (owner) + return ownershipFeedback.old; - if (have >= max && max > 0) - return ownershipFeedback.tooMany; + if (have >= max && max > 0) + return ownershipFeedback.tooMany; - block.setMetadata(metadataName, new FixedMetadataValue(plugin, jPlayer.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; - } + if (!Jobs.getGCManager().isBrewingStandsReassign() && !Jobs.getGCManager().isFurnacesReassign() + && !Jobs.getGCManager().BlastFurnacesReassign && !Jobs.getGCManager().SmokerReassign) { + return ownershipFeedback.newReg; + } - HashMap ls = blockOwnerShips.getOrDefault(jPlayer.getUniqueId(), new HashMap()); + HashMap ls = blockOwnerShips.getOrDefault(jPlayer.getUniqueId(), new HashMap()); - String locString = CMILocation.toString(block.getLocation(), ":", true, true); + String locString = CMILocation.toString(block.getLocation(), ":", true, true); - if (ls.containsKey(locString)) - return ownershipFeedback.old; + if (ls.containsKey(locString)) + return ownershipFeedback.old; - blockLoc bloc = new blockLoc(block.getLocation()); + blockLoc bloc = new blockLoc(block.getLocation()); - ls.put(locString, bloc); - blockOwnerShips.put(jPlayer.getUniqueId(), ls); + ls.put(locString, bloc); + blockOwnerShips.put(jPlayer.getUniqueId(), ls); - Map oldRecord = ownerMapByLocation.getOrDefault(block.getLocation().getWorld().getName(), new HashMap()); - oldRecord.put(bloc.toVectorString(), jPlayer.getUniqueId()); - ownerMapByLocation.put(block.getLocation().getWorld().getName(), oldRecord); + Map oldRecord = ownerMapByLocation.getOrDefault(block.getLocation().getWorld().getName(), new HashMap()); + oldRecord.put(bloc.toVectorString(), jPlayer.getUniqueId()); + ownerMapByLocation.put(block.getLocation().getWorld().getName(), oldRecord); - return ownershipFeedback.newReg; + return ownershipFeedback.newReg; } public boolean disable(Block block) { - UUID uuid = getOwnerByLocation(block.getLocation()); - if (uuid == null) { - List data = getBlockMetadatas(block); - if (!data.isEmpty()) { - try { - uuid = UUID.fromString(data.get(0).asString()); - } catch (IllegalArgumentException e) { - } - } - } - if (uuid == null) { - return false; - } - return disable(uuid, block); + UUID uuid = getOwnerByLocation(block.getLocation()); + if (uuid == null) { + List data = getBlockMetadatas(block); + if (!data.isEmpty()) { + try { + uuid = UUID.fromString(data.get(0).asString()); + } catch (IllegalArgumentException e) { + } + } + } + if (uuid == null) { + return false; + } + return disable(uuid, block); } public boolean disable(UUID uuid, Block block) { - if (uuid == null) { - return false; - } - HashMap ls = blockOwnerShips.getOrDefault(uuid, new HashMap()); - String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true); - blockLoc rec = ls.get(blockLoc); - if (rec != null) { + if (uuid == null) { + return false; + } + HashMap ls = blockOwnerShips.getOrDefault(uuid, new HashMap()); + String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true); + blockLoc rec = ls.get(blockLoc); + if (rec != null) { - if (rec.isDisabled()) - return false; + if (rec.isDisabled()) + return false; - rec.setDisabled(true); - return true; - } - return false; + rec.setDisabled(true); + return true; + } + return false; } public boolean remove(Block block) { - UUID uuid = getOwnerByLocation(block.getLocation()); + UUID uuid = getOwnerByLocation(block.getLocation()); - if (uuid == null) { - List data = getBlockMetadatas(block); - if (!data.isEmpty()) { - try { - uuid = UUID.fromString(data.get(0).asString()); - } catch (IllegalArgumentException e) { - } - } - } - if (uuid == null) { - return false; - } - return remove(uuid, block); + if (uuid == null) { + List data = getBlockMetadatas(block); + if (!data.isEmpty()) { + try { + uuid = UUID.fromString(data.get(0).asString()); + } catch (IllegalArgumentException e) { + } + } + } + if (uuid == null) { + return false; + } + return remove(uuid, block); } public boolean remove(UUID uuid, Block block) { - if (uuid == null) { - return false; - } - HashMap ls = blockOwnerShips.getOrDefault(uuid, new HashMap()); - String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true); - com.gamingmesh.jobs.stuff.blockLoc removed = ls.remove(blockLoc); - if (removed != null) { - block.removeMetadata(metadataName, plugin); - Map oldRecord = ownerMapByLocation.get(block.getLocation().getWorld().getName()); - if (oldRecord != null) - oldRecord.remove(block.getLocation().getBlockX() + ":" + block.getLocation().getBlockY() + ":" + block.getLocation().getBlockZ()); - } - return removed != null; + if (uuid == null) { + return false; + } + HashMap ls = blockOwnerShips.getOrDefault(uuid, new HashMap()); + String blockLoc = CMILocation.toString(block.getLocation(), ":", true, true); + com.gamingmesh.jobs.stuff.blockLoc removed = ls.remove(blockLoc); + if (removed != null) { + block.removeMetadata(metadataName, plugin); + Map oldRecord = ownerMapByLocation.get(block.getLocation().getWorld().getName()); + if (oldRecord != null) + oldRecord.remove(block.getLocation().getBlockX() + ":" + block.getLocation().getBlockY() + ":" + block.getLocation().getBlockZ()); + } + return removed != null; } public UUID getOwnerByLocation(Location loc) { - Map record = ownerMapByLocation.get(loc.getWorld().getName()); - if (record == null) { - return null; - } - blockLoc bl = new blockLoc(loc); - return record.get(bl.toVectorString()); + Map record = ownerMapByLocation.get(loc.getWorld().getName()); + if (record == null) + return null; + + blockLoc bl = new blockLoc(loc); + return record.get(bl.toVectorString()); } public int clear(UUID uuid) { - HashMap ls = blockOwnerShips.remove(uuid); - if (ls == null) { - return 0; - } + HashMap ls = blockOwnerShips.remove(uuid); + if (ls == null) + return 0; - for (blockLoc one : ls.values()) { - if (one.getBlock() != null) { - one.getBlock().removeMetadata(metadataName, plugin); + for (blockLoc one : ls.values()) { + if (one.getBlock() == null) + continue; - Map oldRecord = ownerMapByLocation.get(one.getWorldName()); - if (oldRecord != null) - oldRecord.remove(one.toVectorString()); - } + one.getBlock().removeMetadata(metadataName, plugin); - } + Map oldRecord = ownerMapByLocation.get(one.getWorldName()); + if (oldRecord != null) + oldRecord.remove(one.toVectorString()); + } - return ls.size(); - } + return ls.size(); + } public int remove(UUID uuid, String location) { - HashMap ls = blockOwnerShips.get(uuid); - if (ls == null) - return 0; + HashMap ls = blockOwnerShips.get(uuid); + if (ls == null) + return 0; - for (Entry one : new HashMap(ls).entrySet()) { + for (Entry one : new HashMap(ls).entrySet()) { - if (!one.getKey().equalsIgnoreCase(location)) - continue; + if (!one.getKey().equalsIgnoreCase(location)) + continue; - one.getValue().getBlock().removeMetadata(metadataName, plugin); + one.getValue().getBlock().removeMetadata(metadataName, plugin); - ls.remove(one.getKey()); + ls.remove(one.getKey()); - Map oldRecord = ownerMapByLocation.get(one.getValue().getWorldName()); - if (oldRecord != null) - oldRecord.remove(one.getValue().toVectorString()); - } + Map oldRecord = ownerMapByLocation.get(one.getValue().getWorldName()); + if (oldRecord != null) + oldRecord.remove(one.getValue().toVectorString()); + } - return 1; + return 1; } public List getBlockMetadatas(Block block) { - return block.getMetadata(metadataName); + return block.getMetadata(metadataName); } public int getTotal(UUID uuid) { - HashMap list = blockOwnerShips.get(uuid); - return list == null ? 0 : list.size(); + HashMap list = blockOwnerShips.get(uuid); + return list == null ? 0 : list.size(); } public void load() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); - YmlMaker f2 = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml"); - if (!f.exists() && !f2.exists()) - return; + YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); + YmlMaker f2 = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml"); + if (!f.exists() && !f2.exists()) + return; - if (f.exists()) { - f.getConfigFile().renameTo(f2.getConfigFile()); - } + if (f.exists()) { + f.getConfigFile().renameTo(f2.getConfigFile()); + } - f = f2; + f = f2; - String path = ""; - switch (type) { - case BLAST_FURNACE: - path = "BlastFurnace"; - break; - case BREWING_STAND: - path = "Brewing"; - break; - case FURNACE: - path = "Furnace"; - break; - case SMOKER: - path = "Smoker"; - break; - default: - break; - } + String path = ""; + switch (type) { + case BLAST_FURNACE: + path = "BlastFurnace"; + break; + case BREWING_STAND: + path = "Brewing"; + break; + case FURNACE: + path = "Furnace"; + break; + case SMOKER: + path = "Smoker"; + break; + default: + break; + } - if (isReassignDisabled()) - return; + if (isReassignDisabled()) + return; - ConfigurationSection section = f.getConfig().getConfigurationSection(path); - if (section == null) { - return; - } + ConfigurationSection section = f.getConfig().getConfigurationSection(path); + if (section == null) { + return; + } - int total = 0; - for (String one : section.getKeys(false)) { - String value = section.getString(one); - List ls = new ArrayList<>(); + int total = 0; + for (String one : section.getKeys(false)) { + String value = section.getString(one); + List ls = new ArrayList<>(); - if (value.contains(";")) - ls.addAll(Arrays.asList(value.split(";"))); - else - ls.add(value); + if (value.contains(";")) + ls.addAll(Arrays.asList(value.split(";"))); + else + ls.add(value); - UUID uuid; - try { - uuid = UUID.fromString(one); - } catch (IllegalArgumentException e) { - continue; - } + UUID uuid; + try { + uuid = UUID.fromString(one); + } catch (IllegalArgumentException e) { + continue; + } - HashMap blist = new HashMap(); - for (String oneL : ls) { - blockLoc bl = new blockLoc(oneL); - CMILocation cmil = CMILocation.fromString(oneL, ":"); + HashMap blist = new HashMap(); + for (String oneL : ls) { + blockLoc bl = new blockLoc(oneL); + CMILocation cmil = CMILocation.fromString(oneL, ":"); - blist.put(CMILocation.toString(cmil, ":", true, true), bl); + blist.put(CMILocation.toString(cmil, ":", true, true), bl); - Map oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap()); - oldRecord.put(bl.toVectorString(), uuid); - ownerMapByLocation.put(bl.getWorldName(), oldRecord); + Map oldRecord = ownerMapByLocation.getOrDefault(bl.getWorldName(), new HashMap()); + oldRecord.put(bl.toVectorString(), uuid); + ownerMapByLocation.put(bl.getWorldName(), oldRecord); - total++; - } + total++; + } - if (!blist.isEmpty()) { - blockOwnerShips.put(uuid, blist); - } - } + if (!blist.isEmpty()) { + blockOwnerShips.put(uuid, blist); + } + } - if (total > 0) { - CMIMessages.consoleMessage("&eLoaded &6" + total + " " + path.toLowerCase() + " &efor reassigning."); - } + if (total > 0) { + CMIMessages.consoleMessage("&eLoaded &6" + total + " " + path.toLowerCase() + " &efor reassigning."); + } } public void save() { - YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); - if (f.exists()) { - f.getConfigFile().renameTo(new File(Jobs.getFolder(), "blockOwnerShips.yml")); - } + YmlMaker f = new YmlMaker(Jobs.getFolder(), "furnaceBrewingStands.yml"); + if (f.exists()) { + f.getConfigFile().renameTo(new File(Jobs.getFolder(), "blockOwnerShips.yml")); + } - f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml"); + f = new YmlMaker(Jobs.getFolder(), "blockOwnerShips.yml"); - if (blockOwnerShips.isEmpty() && f.getConfigFile().length() == 0L) { - f.getConfigFile().delete(); - return; - } + if (blockOwnerShips.isEmpty() && f.getConfigFile().length() == 0L) { + f.getConfigFile().delete(); + return; + } - f.createNewFile(); - f.saveDefaultConfig(); + f.createNewFile(); + f.saveDefaultConfig(); - if (isReassignDisabled()) { - return; - } + if (isReassignDisabled()) { + return; + } - String path = (type == BlockTypes.FURNACE ? "Furnace" - : type == BlockTypes.BLAST_FURNACE ? "BlastFurnace" - : type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : ""); - f.getConfig().set(path, null); + String path = (type == BlockTypes.FURNACE ? "Furnace" + : type == BlockTypes.BLAST_FURNACE ? "BlastFurnace" + : type == BlockTypes.BREWING_STAND ? "Brewing" : type == BlockTypes.SMOKER ? "Smoker" : ""); + f.getConfig().set(path, null); - for (Entry> one : blockOwnerShips.entrySet()) { - StringBuilder full = new StringBuilder(); + for (Entry> one : blockOwnerShips.entrySet()) { + StringBuilder full = new StringBuilder(); - for (String oneL : one.getValue().keySet()) { - if (!full.toString().isEmpty()) - full.append(";"); + for (String oneL : one.getValue().keySet()) { + if (!full.toString().isEmpty()) + full.append(";"); - full.append(oneL); - } + full.append(oneL); + } - if (!full.toString().isEmpty()) - f.getConfig().set(path + "." + one.getKey().toString(), full.toString()); - } + if (!full.toString().isEmpty()) + f.getConfig().set(path + "." + one.getKey().toString(), full.toString()); + } - f.saveConfig(); + f.saveConfig(); } public boolean isReassignDisabled() { - return (type == BlockTypes.FURNACE && !Jobs.getGCManager().isFurnacesReassign()) - || (type == BlockTypes.BLAST_FURNACE && !Jobs.getGCManager().BlastFurnacesReassign) - || (type == BlockTypes.BREWING_STAND && !Jobs.getGCManager().isBrewingStandsReassign()) - || (type == BlockTypes.SMOKER && !Jobs.getGCManager().SmokerReassign); + return (type == BlockTypes.FURNACE && !Jobs.getGCManager().isFurnacesReassign()) + || (type == BlockTypes.BLAST_FURNACE && !Jobs.getGCManager().BlastFurnacesReassign) + || (type == BlockTypes.BREWING_STAND && !Jobs.getGCManager().isBrewingStandsReassign()) + || (type == BlockTypes.SMOKER && !Jobs.getGCManager().SmokerReassign); } public enum ownershipFeedback { - invalid, tooMany, newReg, old, notOwn, reenabled + invalid, tooMany, newReg, old, notOwn, reenabled } }