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