mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-03 23:08:07 +01:00
Cleanup and some fixes
This commit is contained in:
parent
324b4dc0b4
commit
fbb0bfee90
@ -257,7 +257,7 @@ public class Jobs {
|
|||||||
return GUIManager;
|
return GUIManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setGUIManager(JobsPlugin plugin) {
|
public static void setGUIManager() {
|
||||||
GUIManager = new GuiManager();
|
GUIManager = new GuiManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -467,7 +467,7 @@ public class Jobs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Jobs.getGCManager().reload();
|
Jobs.getGCManager().reload();
|
||||||
Jobs.getLanguage().reload(Jobs.getGCManager().getLocale());
|
Jobs.getLanguage().reload();
|
||||||
Jobs.getConfigManager().reload();
|
Jobs.getConfigManager().reload();
|
||||||
usedSlots.clear();
|
usedSlots.clear();
|
||||||
for (Job job : jobs) {
|
for (Job job : jobs) {
|
||||||
@ -533,8 +533,7 @@ public class Jobs {
|
|||||||
public static int getUsedSlots(Job job) {
|
public static int getUsedSlots(Job job) {
|
||||||
if (usedSlots.containsKey(job))
|
if (usedSlots.containsKey(job))
|
||||||
return usedSlots.get(job);
|
return usedSlots.get(job);
|
||||||
else
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -631,8 +630,9 @@ public class Jobs {
|
|||||||
if (data.isReseted())
|
if (data.isReseted())
|
||||||
data.setReseted(false);
|
data.setReseted(false);
|
||||||
return false;
|
return false;
|
||||||
} else
|
}
|
||||||
data.AddAmount(amount);
|
|
||||||
|
data.AddAmount(amount);
|
||||||
paymentLimit.put(playername, data);
|
paymentLimit.put(playername, data);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -669,8 +669,8 @@ public class Jobs {
|
|||||||
if (data.isReseted())
|
if (data.isReseted())
|
||||||
data.setReseted(false);
|
data.setReseted(false);
|
||||||
return false;
|
return false;
|
||||||
} else
|
}
|
||||||
data.AddExpAmount(amount);
|
data.AddExpAmount(amount);
|
||||||
ExpLimit.put(playername, data);
|
ExpLimit.put(playername, data);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -710,8 +710,8 @@ public class Jobs {
|
|||||||
if (data.isReseted())
|
if (data.isReseted())
|
||||||
data.setReseted(false);
|
data.setReseted(false);
|
||||||
return false;
|
return false;
|
||||||
} else
|
}
|
||||||
data.AddPoints(amount);
|
data.AddPoints(amount);
|
||||||
PointLimit.put(playername, data);
|
PointLimit.put(playername, data);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -79,7 +79,7 @@ public class JobsPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
Jobs.setScboard(this);
|
Jobs.setScboard(this);
|
||||||
Jobs.setLanguage(this);
|
Jobs.setLanguage(this);
|
||||||
Jobs.setGUIManager(this);
|
Jobs.setGUIManager();
|
||||||
Jobs.setExplore();
|
Jobs.setExplore();
|
||||||
|
|
||||||
Jobs.setBBManager(this);
|
Jobs.setBBManager(this);
|
||||||
@ -103,6 +103,7 @@ public class JobsPlugin extends JavaPlugin {
|
|||||||
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
|
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
|
||||||
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
|
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
|
||||||
|
|
||||||
|
Jobs.setMcMMOlistener(this);
|
||||||
if (Jobs.getMcMMOlistener().CheckmcMMO()){
|
if (Jobs.getMcMMOlistener().CheckmcMMO()){
|
||||||
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
|
getServer().getPluginManager().registerEvents(new McMMOlistener(this), this);
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ public class JobsPlugin extends JavaPlugin {
|
|||||||
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully.");
|
String message = ChatColor.translateAlternateColorCodes('&', "&e[Jobs] Plugin has been enabled succesfully.");
|
||||||
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
|
||||||
console.sendMessage(message);
|
console.sendMessage(message);
|
||||||
Jobs.getLanguage().reload(Jobs.getGCManager().getLocale());
|
Jobs.getLanguage().reload();
|
||||||
|
|
||||||
Jobs.getJobsDAO().loadExplore();
|
Jobs.getJobsDAO().loadExplore();
|
||||||
|
|
||||||
|
@ -243,9 +243,8 @@ public class PermissionHandler {
|
|||||||
public boolean hasWorldPermission(Player player, String world) {
|
public boolean hasWorldPermission(Player player, String world) {
|
||||||
if (!player.hasPermission("jobs.use")) {
|
if (!player.hasPermission("jobs.use")) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return player.hasPermission("jobs.world." + world.toLowerCase());
|
|
||||||
}
|
}
|
||||||
|
return player.hasPermission("jobs.world." + world.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -437,8 +437,7 @@ public class PlayerManager {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// LevelUp event
|
// LevelUp event
|
||||||
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel, job
|
JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel), Jobs.gettitleManager().getTitleForLevel(prog.getLevel()), Jobs.getGCManager().SoundLevelupSound
|
||||||
.getName()), Jobs.gettitleManager().getTitleForLevel(prog.getLevel(), job.getName()), Jobs.getGCManager().SoundLevelupSound
|
|
||||||
.toUpperCase(), Jobs.getGCManager().SoundLevelupVolume, Jobs.getGCManager().SoundLevelupPitch, Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
|
.toUpperCase(), Jobs.getGCManager().SoundLevelupVolume, Jobs.getGCManager().SoundLevelupPitch, Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
|
||||||
Jobs.getGCManager().SoundTitleChangeVolume, Jobs.getGCManager().SoundTitleChangePitch);
|
Jobs.getGCManager().SoundTitleChangeVolume, Jobs.getGCManager().SoundTitleChangePitch);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
|
||||||
|
@ -88,7 +88,7 @@ public class SignUtil {
|
|||||||
try {
|
try {
|
||||||
writer.save(f);
|
writer.save(f);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ public class SignUtil {
|
|||||||
if (i >= PlayerList.size()) {
|
if (i >= PlayerList.size()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName();
|
String PlayerName = PlayerList.get(i).getPlayerName();
|
||||||
|
|
||||||
if (PlayerName != null && PlayerName.length() > 8) {
|
if (PlayerName != null && PlayerName.length() > 8) {
|
||||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
||||||
@ -144,14 +144,14 @@ public class SignUtil {
|
|||||||
String line = Jobs.getLanguage().getMessage("signs.List");
|
String line = Jobs.getLanguage().getMessage("signs.List");
|
||||||
line = line.replace("[number]", String.valueOf(i + number + 1));
|
line = line.replace("[number]", String.valueOf(i + number + 1));
|
||||||
line = line.replace("[player]", PlayerName);
|
line = line.replace("[player]", PlayerName);
|
||||||
line = line.replace("[level]", String.valueOf(((TopList) PlayerList.get(i)).getLevel()));
|
line = line.replace("[level]", String.valueOf(PlayerList.get(i).getLevel()));
|
||||||
|
|
||||||
sign.setLine(i, line);
|
sign.setLine(i, line);
|
||||||
}
|
}
|
||||||
sign.update();
|
sign.update();
|
||||||
UpdateHead(sign, ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
|
||||||
} else {
|
} else {
|
||||||
String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName();
|
String PlayerName = PlayerList.get(0).getPlayerName();
|
||||||
if (PlayerName.length() > 8) {
|
if (PlayerName.length() > 8) {
|
||||||
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
|
||||||
PlayerName = PlayerNameStrip + "~";
|
PlayerName = PlayerNameStrip + "~";
|
||||||
@ -159,32 +159,32 @@ public class SignUtil {
|
|||||||
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".1");
|
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".1");
|
||||||
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
||||||
line1 = line1.replace("[player]", PlayerName);
|
line1 = line1.replace("[player]", PlayerName);
|
||||||
line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel()));
|
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
|
||||||
|
|
||||||
sign.setLine(0, line1);
|
sign.setLine(0, line1);
|
||||||
|
|
||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".2");
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".2");
|
||||||
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
||||||
line1 = line1.replace("[player]", PlayerName);
|
line1 = line1.replace("[player]", PlayerName);
|
||||||
line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel()));
|
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
|
||||||
|
|
||||||
sign.setLine(1, line1);
|
sign.setLine(1, line1);
|
||||||
|
|
||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".3");
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".3");
|
||||||
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
||||||
line1 = line1.replace("[player]", PlayerName);
|
line1 = line1.replace("[player]", PlayerName);
|
||||||
line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel()));
|
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
|
||||||
|
|
||||||
sign.setLine(2, line1);
|
sign.setLine(2, line1);
|
||||||
|
|
||||||
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".4");
|
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".4");
|
||||||
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
|
||||||
line1 = line1.replace("[player]", PlayerName);
|
line1 = line1.replace("[player]", PlayerName);
|
||||||
line1 = line1.replace("[level]", String.valueOf(((TopList) PlayerList.get(0)).getLevel()));
|
line1 = line1.replace("[level]", String.valueOf(PlayerList.get(0).getLevel()));
|
||||||
|
|
||||||
sign.setLine(3, line1);
|
sign.setLine(3, line1);
|
||||||
sign.update();
|
sign.update();
|
||||||
UpdateHead(sign, ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
|
UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
|
||||||
}
|
}
|
||||||
|
|
||||||
timelapse++;
|
timelapse++;
|
||||||
|
@ -161,7 +161,7 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
int amountToShow = 7;
|
int amountToShow = 7;
|
||||||
int start = page * amountToShow - amountToShow;
|
int start = page * amountToShow - amountToShow;
|
||||||
int end = page * amountToShow;
|
int end = page * amountToShow;
|
||||||
int TotalPages = (int) commands.size() / amountToShow;
|
int TotalPages = commands.size() / amountToShow;
|
||||||
if (((commands.size() * 1.0) / (amountToShow * 1.0)) - TotalPages > 0)
|
if (((commands.size() * 1.0) / (amountToShow * 1.0)) - TotalPages > 0)
|
||||||
TotalPages++;
|
TotalPages++;
|
||||||
if (start >= commands.size()) {
|
if (start >= commands.size()) {
|
||||||
@ -235,12 +235,11 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
if (jarFile != null)
|
||||||
if (jarFile != null) {
|
try {
|
||||||
jarFile.close();
|
jarFile.close();
|
||||||
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return listOfCommands;
|
return listOfCommands;
|
||||||
}
|
}
|
||||||
@ -338,9 +337,8 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
public boolean hasJobPermission(CommandSender sender, Job job) {
|
public boolean hasJobPermission(CommandSender sender, Job job) {
|
||||||
if (!sender.hasPermission("jobs.use")) {
|
if (!sender.hasPermission("jobs.use")) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
|
|
||||||
}
|
}
|
||||||
|
return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendValidActions(CommandSender sender) {
|
public void sendValidActions(CommandSender sender) {
|
||||||
@ -505,7 +503,7 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
String message = Jobs.getLanguage().getMessage("command.stats.output",
|
String message = Jobs.getLanguage().getMessage("command.stats.output",
|
||||||
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
|
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
|
||||||
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
||||||
"%jobxp%", Double.toString(Math.round((Double) jobProg.getExperience() * 100.0) / 100.0),
|
"%jobxp%", Double.toString(Math.round(jobProg.getExperience() * 100.0) / 100.0),
|
||||||
"%jobmaxxp%", Integer.toString(jobProg.getMaxExperience()));
|
"%jobmaxxp%", Integer.toString(jobProg.getMaxExperience()));
|
||||||
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
|
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
|
||||||
}
|
}
|
||||||
@ -545,7 +543,7 @@ public class JobsCommands implements CommandExecutor {
|
|||||||
"%joblevel%", Integer.valueOf(splited[1]).toString(),
|
"%joblevel%", Integer.valueOf(splited[1]).toString(),
|
||||||
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
|
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
|
||||||
"%jobname%", Jobs.getJob(splited[0]).getChatColor() + splited[0] + ChatColor.WHITE,
|
"%jobname%", Jobs.getJob(splited[0]).getChatColor() + splited[0] + ChatColor.WHITE,
|
||||||
"%jobxp%", Double.toString(Math.round((Double) Double.valueOf(splited[3]) * 100.0) / 100.0));
|
"%jobxp%", Double.toString(Math.round(Double.valueOf(splited[3]) * 100.0) / 100.0));
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,12 @@ public class convert implements Cmd {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player pSender = (Player) sender;
|
|
||||||
|
|
||||||
List<Convert> list = null;
|
List<Convert> list = null;
|
||||||
List<Convert> archivelist = null;
|
List<Convert> archivelist = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
list = Jobs.getJobsDAO().convertDatabase(pSender, "jobs");
|
list = Jobs.getJobsDAO().convertDatabase("jobs");
|
||||||
archivelist = Jobs.getJobsDAO().convertDatabase(pSender, "archive");
|
archivelist = Jobs.getJobsDAO().convertDatabase("archive");
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
sender.sendMessage(ChatColor.RED + "Can't read data from data base, please send error log to dev's.");
|
sender.sendMessage(ChatColor.RED + "Can't read data from data base, please send error log to dev's.");
|
||||||
|
@ -66,14 +66,13 @@ public class expboost implements Cmd {
|
|||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
job.setExpBoost(rate);
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
job.setExpBoost(rate);
|
||||||
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,14 +67,13 @@ public class moneyboost implements Cmd {
|
|||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
job.setMoneyBoost(rate);
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
job.setMoneyBoost(rate);
|
||||||
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,14 +67,13 @@ public class pointboost implements Cmd {
|
|||||||
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("general.error.job"));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
job.setPointBoost(rate);
|
|
||||||
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
job.setPointBoost(rate);
|
||||||
|
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ public class BossBarManager {
|
|||||||
String message = Jobs.getLanguage().getMessage("command.stats.output",
|
String message = Jobs.getLanguage().getMessage("command.stats.output",
|
||||||
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
|
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
|
||||||
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
|
||||||
"%jobxp%", formatter.format(Math.round((Double) jobProg.getExperience() * 100.0) / 100.0),
|
"%jobxp%", formatter.format(Math.round(jobProg.getExperience() * 100.0) / 100.0),
|
||||||
"%jobmaxxp%", (int) jobProg.getMaxExperience());
|
"%jobmaxxp%", jobProg.getMaxExperience());
|
||||||
|
|
||||||
if (bar == null) {
|
if (bar == null) {
|
||||||
BarColor color = BarColor.BLUE;
|
BarColor color = BarColor.BLUE;
|
||||||
|
@ -61,26 +61,23 @@ public class ExploreManager {
|
|||||||
eRegion.addChunk(eChunk);
|
eRegion.addChunk(eChunk);
|
||||||
worlds.put(worldName, eRegion);
|
worlds.put(worldName, eRegion);
|
||||||
return new ExploreRespond(eChunk.getCount(), true);
|
return new ExploreRespond(eChunk.getCount(), true);
|
||||||
} else {
|
|
||||||
ExploreRegion eRegion = worlds.get(worldName);
|
|
||||||
ExploreChunk eChunk = null;
|
|
||||||
for (ExploreChunk one : eRegion.getChunks()) {
|
|
||||||
if (one.getX() != ChunkX)
|
|
||||||
continue;
|
|
||||||
if (one.getZ() != ChunkZ)
|
|
||||||
continue;
|
|
||||||
eChunk = one;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eChunk == null) {
|
|
||||||
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
|
||||||
eRegion.addChunk(eChunk);
|
|
||||||
return new ExploreRespond(eChunk.getCount(), true);
|
|
||||||
} else {
|
|
||||||
return eChunk.addPlayer(player);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
ExploreRegion eRegion = worlds.get(worldName);
|
||||||
|
ExploreChunk eChunk = null;
|
||||||
|
for (ExploreChunk one : eRegion.getChunks()) {
|
||||||
|
if (one.getX() != ChunkX)
|
||||||
|
continue;
|
||||||
|
if (one.getZ() != ChunkZ)
|
||||||
|
continue;
|
||||||
|
eChunk = one;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eChunk == null) {
|
||||||
|
eChunk = new ExploreChunk(player, ChunkX, ChunkZ);
|
||||||
|
eRegion.addChunk(eChunk);
|
||||||
|
return new ExploreRespond(eChunk.getCount(), true);
|
||||||
|
}
|
||||||
|
return eChunk.addPlayer(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.JobsPlugin;
|
import com.gamingmesh.jobs.JobsPlugin;
|
||||||
import com.gamingmesh.jobs.container.LocaleReader;
|
import com.gamingmesh.jobs.container.LocaleReader;
|
||||||
@ -39,7 +37,7 @@ public class LanguageManager {
|
|||||||
languages.add("tr");
|
languages.add("tr");
|
||||||
|
|
||||||
for (String lang : languages) {
|
for (String lang : languages) {
|
||||||
YmlMaker langFile = new YmlMaker((JavaPlugin) plugin, "locale" + File.separator + "messages_" + lang + ".yml");
|
YmlMaker langFile = new YmlMaker(plugin, "locale" + File.separator + "messages_" + lang + ".yml");
|
||||||
if (langFile != null)
|
if (langFile != null)
|
||||||
langFile.saveDefaultConfig();
|
langFile.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import java.util.Set;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.JobsPlugin;
|
import com.gamingmesh.jobs.JobsPlugin;
|
||||||
import com.gamingmesh.jobs.container.JobInfo;
|
import com.gamingmesh.jobs.container.JobInfo;
|
||||||
@ -114,7 +112,7 @@ public class NameTranslatorManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readFile() {
|
public void readFile() {
|
||||||
YmlMaker ItemFile = new YmlMaker((JavaPlugin) plugin, "TranslatableWords" + File.separator + "Words_" + Jobs.getGCManager().localeString + ".yml");
|
YmlMaker ItemFile = new YmlMaker(plugin, "TranslatableWords" + File.separator + "Words_" + Jobs.getGCManager().localeString + ".yml");
|
||||||
ItemFile.saveDefaultConfig();
|
ItemFile.saveDefaultConfig();
|
||||||
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ItemList");
|
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ItemList");
|
||||||
Set<String> keys = section.getKeys(false);
|
Set<String> keys = section.getKeys(false);
|
||||||
@ -178,7 +176,7 @@ public class NameTranslatorManager {
|
|||||||
languages.add("fr");
|
languages.add("fr");
|
||||||
|
|
||||||
for (String lang : languages) {
|
for (String lang : languages) {
|
||||||
YmlMaker langFile = new YmlMaker((JavaPlugin) plugin, "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
YmlMaker langFile = new YmlMaker(plugin, "TranslatableWords" + File.separator + "Words_" + lang + ".yml");
|
||||||
if (langFile != null)
|
if (langFile != null)
|
||||||
langFile.saveDefaultConfig();
|
langFile.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class TitleManager {
|
|||||||
* @return the correct title
|
* @return the correct title
|
||||||
* @return null if no title matches
|
* @return null if no title matches
|
||||||
*/
|
*/
|
||||||
public Title getTitleForLevel(int level, String jobName) {
|
public Title getTitleForLevel(int level) {
|
||||||
Title title = null;
|
Title title = null;
|
||||||
for (Title t : titles) {
|
for (Title t : titles) {
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
|
@ -47,12 +47,6 @@ public class YmlMaker {
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
f.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.Configuration = YamlConfiguration.loadConfiguration(f);
|
this.Configuration = YamlConfiguration.loadConfiguration(f);
|
||||||
@ -63,11 +57,18 @@ public class YmlMaker {
|
|||||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||||
this.Configuration.setDefaults(defConfig);
|
this.Configuration.setDefaults(defConfig);
|
||||||
}
|
}
|
||||||
try {
|
if (defConfigStream != null)
|
||||||
defConfigStream.close();
|
try {
|
||||||
} catch (IOException e) {
|
defConfigStream.close();
|
||||||
e.printStackTrace();
|
} catch (IOException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (f != null)
|
||||||
|
try {
|
||||||
|
f.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
|
@ -9,11 +9,6 @@ public class ExploreRegion {
|
|||||||
int z;
|
int z;
|
||||||
List<ExploreChunk> chunks = new ArrayList<ExploreChunk>();
|
List<ExploreChunk> chunks = new ArrayList<ExploreChunk>();
|
||||||
|
|
||||||
public ExploreRegion(int x, int z, List<ExploreChunk> chunks) {
|
|
||||||
this.x = x;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExploreRegion(int x, int z) {
|
public ExploreRegion(int x, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
@ -233,9 +233,8 @@ public class JobsPlayer {
|
|||||||
counter.setBoost(Boost);
|
counter.setBoost(Boost);
|
||||||
counter.setTime(time);
|
counter.setTime(time);
|
||||||
return Boost;
|
return Boost;
|
||||||
} else {
|
|
||||||
return counter.getBoost();
|
|
||||||
}
|
}
|
||||||
|
return counter.getBoost();
|
||||||
}
|
}
|
||||||
Boost = getPlayerBoost(JobName, type);
|
Boost = getPlayerBoost(JobName, type);
|
||||||
counterList.add(new BoostCounter(type, Boost, time));
|
counterList.add(new BoostCounter(type, Boost, time));
|
||||||
@ -438,7 +437,7 @@ public class JobsPlayer {
|
|||||||
// synchronized (saveLock) {
|
// synchronized (saveLock) {
|
||||||
progression.clear();
|
progression.clear();
|
||||||
reloadHonorific();
|
reloadHonorific();
|
||||||
Jobs.getPermissionHandler().recalculatePermissions(this);
|
Jobs.getPermissionHandler().recalculatePermissions(this);
|
||||||
return true;
|
return true;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@ -574,7 +573,7 @@ public class JobsPlayer {
|
|||||||
builder.append(Jobs.getGCManager().getModifyChatSeparator());
|
builder.append(Jobs.getGCManager().getModifyChatSeparator());
|
||||||
gotTitle = false;
|
gotTitle = false;
|
||||||
}
|
}
|
||||||
Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel(), prog.getJob().getName());
|
Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel());
|
||||||
|
|
||||||
if (numJobs == 1) {
|
if (numJobs == 1) {
|
||||||
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
|
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
|
||||||
|
@ -41,13 +41,13 @@ public class LocaleReader {
|
|||||||
copySetting(path);
|
copySetting(path);
|
||||||
return config.getIntegerList(path);
|
return config.getIntegerList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getStringList(String path, List<String> list) {
|
public List<String> getStringList(String path, List<String> list) {
|
||||||
config.addDefault(path, list);
|
config.addDefault(path, list);
|
||||||
copySetting(path);
|
copySetting(path);
|
||||||
return config.getStringList(path);
|
return config.getStringList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get(String path, String boo) {
|
public String get(String path, String boo) {
|
||||||
config.addDefault(path, boo);
|
config.addDefault(path, boo);
|
||||||
copySetting(path);
|
copySetting(path);
|
||||||
@ -59,8 +59,7 @@ public class LocaleReader {
|
|||||||
copySetting(path);
|
copySetting(path);
|
||||||
if (colorize)
|
if (colorize)
|
||||||
return ChatColor.translateAlternateColorCodes('&', config.getString(path));
|
return ChatColor.translateAlternateColorCodes('&', config.getString(path));
|
||||||
else
|
return config.getString(path);
|
||||||
return config.getString(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double get(String path, Double boo) {
|
public Double get(String path, Double boo) {
|
||||||
|
@ -67,21 +67,18 @@ public final class Log {
|
|||||||
public int getCount(String item) {
|
public int getCount(String item) {
|
||||||
if (this.amountMap.containsKey(item))
|
if (this.amountMap.containsKey(item))
|
||||||
return this.amountMap.get(item).getCount();
|
return this.amountMap.get(item).getCount();
|
||||||
else
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMoney(String item) {
|
public double getMoney(String item) {
|
||||||
if (this.amountMap.containsKey(item))
|
if (this.amountMap.containsKey(item))
|
||||||
return this.amountMap.get(item).getMoney();
|
return this.amountMap.get(item).getMoney();
|
||||||
else
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getExp(String item) {
|
public double getExp(String item) {
|
||||||
if (this.amountMap.containsKey(item))
|
if (this.amountMap.containsKey(item))
|
||||||
return this.amountMap.get(item).getExp();
|
return this.amountMap.get(item).getExp();
|
||||||
else
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,8 +19,6 @@ public final class TopList {
|
|||||||
if (info != null) {
|
if (info != null) {
|
||||||
if (info.getValue().getName() != null)
|
if (info.getValue().getName() != null)
|
||||||
return info.getValue().getName();
|
return info.getValue().getName();
|
||||||
else
|
|
||||||
return "Unknown";
|
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
@ -152,8 +152,8 @@ public abstract class JobsDAO {
|
|||||||
if (userData == null) {
|
if (userData == null) {
|
||||||
recordNewPlayer(playerName, uuid);
|
recordNewPlayer(playerName, uuid);
|
||||||
return jobs;
|
return jobs;
|
||||||
} else
|
}
|
||||||
id = userData.getID();
|
id = userData.getID();
|
||||||
|
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
@ -337,7 +337,7 @@ public abstract class JobsDAO {
|
|||||||
* @param job - job that the player wishes to join
|
* @param job - job that the player wishes to join
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public List<Convert> convertDatabase(Player Player, String table) throws SQLException {
|
public List<Convert> convertDatabase(String table) throws SQLException {
|
||||||
JobsConnection conn = getConnection();
|
JobsConnection conn = getConnection();
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -540,7 +540,8 @@ public class JobsDAOMySQL extends JobsDAO {
|
|||||||
try {
|
try {
|
||||||
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
||||||
rsLogTemp = prestLogTemp.executeQuery();
|
rsLogTemp = prestLogTemp.executeQuery();
|
||||||
while (next = rsLogTemp.next()) {
|
while (rsLogTemp.next()) {
|
||||||
|
next = true;
|
||||||
rsLogTemp.getInt("userid");
|
rsLogTemp.getInt("userid");
|
||||||
rsLogTemp.getLong("time");
|
rsLogTemp.getLong("time");
|
||||||
rsLogTemp.getString("action");
|
rsLogTemp.getString("action");
|
||||||
|
@ -545,7 +545,8 @@ public class JobsDAOSQLite extends JobsDAO {
|
|||||||
try {
|
try {
|
||||||
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
|
||||||
rsLogTemp = prestLogTemp.executeQuery();
|
rsLogTemp = prestLogTemp.executeQuery();
|
||||||
while (next = rsLogTemp.next()) {
|
while (rsLogTemp.next()) {
|
||||||
|
next = true;
|
||||||
rsLogTemp.getInt("userid");
|
rsLogTemp.getInt("userid");
|
||||||
rsLogTemp.getLong("time");
|
rsLogTemp.getLong("time");
|
||||||
rsLogTemp.getString("action");
|
rsLogTemp.getString("action");
|
||||||
|
@ -165,7 +165,7 @@ public class BufferedEconomy {
|
|||||||
|
|
||||||
if (payment.getOfflinePlayer() == null)
|
if (payment.getOfflinePlayer() == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// JobsPayment event
|
// JobsPayment event
|
||||||
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getAmount(), payment.getPoints());
|
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getAmount(), payment.getPoints());
|
||||||
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
|
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
|
||||||
@ -180,12 +180,11 @@ public class BufferedEconomy {
|
|||||||
if (!hasMoney) {
|
if (!hasMoney) {
|
||||||
Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Jobs.getLanguage().getMessage("economy.error.nomoney"));
|
Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Jobs.getLanguage().getMessage("economy.error.nomoney"));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
|
||||||
if (Jobs.getGCManager().isEconomyAsync())
|
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
|
||||||
else
|
|
||||||
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
|
||||||
}
|
}
|
||||||
|
if (Jobs.getGCManager().isEconomyAsync())
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
||||||
|
else
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
||||||
} else {
|
} else {
|
||||||
if (Jobs.getGCManager().isEconomyAsync())
|
if (Jobs.getGCManager().isEconomyAsync())
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
|
||||||
|
@ -64,8 +64,8 @@ public class PaymentData {
|
|||||||
return this.lastAnnouced;
|
return this.lastAnnouced;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean IsAnnounceTime(int time) {
|
public boolean IsAnnounceTime(int t) {
|
||||||
if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis())
|
if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis())
|
||||||
return false;
|
return false;
|
||||||
SetAnnouncmentTime();
|
SetAnnouncmentTime();
|
||||||
return true;
|
return true;
|
||||||
@ -169,6 +169,7 @@ public class PaymentData {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("cast")
|
||||||
public int GetLeftsec(int time) {
|
public int GetLeftsec(int time) {
|
||||||
int lefttime1 = GetLeftTime(time);
|
int lefttime1 = GetLeftTime(time);
|
||||||
int sec = 0;
|
int sec = 0;
|
||||||
@ -185,6 +186,7 @@ public class PaymentData {
|
|||||||
return sec;
|
return sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("cast")
|
||||||
public int GetLeftMin(int time) {
|
public int GetLeftMin(int time) {
|
||||||
int lefttime1 = GetLeftTime(time);
|
int lefttime1 = GetLeftTime(time);
|
||||||
int min = 0;
|
int min = 0;
|
||||||
|
@ -18,11 +18,8 @@
|
|||||||
|
|
||||||
package com.gamingmesh.jobs.i18n;
|
package com.gamingmesh.jobs.i18n;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import com.gamingmesh.jobs.Jobs;
|
import com.gamingmesh.jobs.Jobs;
|
||||||
import com.gamingmesh.jobs.JobsPlugin;
|
import com.gamingmesh.jobs.JobsPlugin;
|
||||||
import com.gamingmesh.jobs.config.YmlMaker;
|
import com.gamingmesh.jobs.config.YmlMaker;
|
||||||
@ -39,9 +36,9 @@ public class Language {
|
|||||||
/**
|
/**
|
||||||
* Reloads the config
|
* Reloads the config
|
||||||
*/
|
*/
|
||||||
public void reload(Locale locale) {
|
public void reload() {
|
||||||
customlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_" + Jobs.getGCManager().localeString + ".yml").getConfig();
|
customlocale = new YmlMaker(plugin, "locale/messages_" + Jobs.getGCManager().localeString + ".yml").getConfig();
|
||||||
enlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_en.yml").getConfig();
|
enlocale = new YmlMaker(plugin, "locale/messages_en.yml").getConfig();
|
||||||
if (customlocale == null)
|
if (customlocale == null)
|
||||||
customlocale = enlocale;
|
customlocale = enlocale;
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,11 @@ public class JobsListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
Debug.D(event.getRawSlot());
|
Debug.D(event.getRawSlot());
|
||||||
|
|
||||||
int tsize = player.getOpenInventory().getTopInventory().getSize();
|
int tsize = player.getOpenInventory().getTopInventory().getSize();
|
||||||
|
|
||||||
if (event.getRawSlot() < 0 || event.getRawSlot() >= tsize)
|
if (event.getRawSlot() < 0 || event.getRawSlot() >= tsize)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ public class JobsListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3)));
|
Bukkit.dispatchCommand(player, "jobs " + command + " " + ChatColor.stripColor(sign.getLine(2)) + " " + ChatColor.stripColor(sign.getLine(3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +259,7 @@ public class JobsListener implements Listener {
|
|||||||
if (!(block.getState() instanceof Sign))
|
if (!(block.getState() instanceof Sign))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
Sign sign = (Sign) block.getState();
|
Sign sign = (Sign) block.getState();
|
||||||
String FirstLine = sign.getLine(0);
|
String FirstLine = sign.getLine(0);
|
||||||
@ -316,7 +316,7 @@ public class JobsListener implements Listener {
|
|||||||
if (!signtype.equalsIgnoreCase("toplist") && !signtype.equalsIgnoreCase("gtoplist"))
|
if (!signtype.equalsIgnoreCase("toplist") && !signtype.equalsIgnoreCase("gtoplist"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!event.getPlayer().hasPermission("jobs.command.signs")) {
|
if (!event.getPlayer().hasPermission("jobs.command.signs")) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -531,7 +531,7 @@ public class JobsListener implements Listener {
|
|||||||
//disabling plugin in world
|
//disabling plugin in world
|
||||||
if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld()))
|
if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld()))
|
||||||
return;
|
return;
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
ItemStack iih = player.getItemInHand();
|
ItemStack iih = player.getItemInHand();
|
||||||
|
|
||||||
@ -607,11 +607,7 @@ public class JobsListener implements Listener {
|
|||||||
if (oneItem.getenchants().get(oneE.getKey()) <= oneE.getValue()) {
|
if (oneItem.getenchants().get(oneE.getKey()) <= oneE.getValue()) {
|
||||||
foundEnc = true;
|
foundEnc = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerShearEntityEvent;
|
import org.bukkit.event.player.PlayerShearEntityEvent;
|
||||||
import org.bukkit.inventory.AnvilInventory;
|
import org.bukkit.inventory.AnvilInventory;
|
||||||
import org.bukkit.inventory.CraftingInventory;
|
|
||||||
import org.bukkit.inventory.EnchantingInventory;
|
import org.bukkit.inventory.EnchantingInventory;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -112,12 +111,12 @@ public class JobsPaymentListener implements Listener {
|
|||||||
|
|
||||||
if (!(event.getRightClicked() instanceof LivingEntity))
|
if (!(event.getRightClicked() instanceof LivingEntity))
|
||||||
return;
|
return;
|
||||||
Entity cow = (LivingEntity) event.getRightClicked();
|
Entity cow = event.getRightClicked();
|
||||||
|
|
||||||
if (cow.getType() != EntityType.COW && cow.getType() != EntityType.MUSHROOM_COW)
|
if (cow.getType() != EntityType.COW && cow.getType() != EntityType.MUSHROOM_COW)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
@ -183,7 +182,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (!this.plugin.isEnabled())
|
if (!this.plugin.isEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
return;
|
return;
|
||||||
@ -228,7 +227,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (jPlayer == null || !jPlayer.getPlayer().isOnline())
|
if (jPlayer == null || !jPlayer.getPlayer().isOnline())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) jPlayer.getPlayer();
|
Player player = jPlayer.getPlayer();
|
||||||
|
|
||||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||||
return;
|
return;
|
||||||
@ -259,7 +258,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (Jobs.getGCManager().useBlockTimer)
|
if (Jobs.getGCManager().useBlockTimer)
|
||||||
if (Jobs.getPistonProtectionListener().checkVegybreak(block, (Player) event.getPlayer()))
|
if (Jobs.getPistonProtectionListener().checkVegybreak(block, event.getPlayer()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// make sure plugin is enabled
|
// make sure plugin is enabled
|
||||||
@ -407,9 +406,8 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
// Entity that died must be living
|
// Entity that died must be living
|
||||||
if (!(event.getEntity() instanceof LivingEntity))
|
|
||||||
return;
|
LivingEntity animal = event.getEntity();
|
||||||
LivingEntity animal = (LivingEntity) event.getEntity();
|
|
||||||
|
|
||||||
// mob spawner, no payment or experience
|
// mob spawner, no payment or experience
|
||||||
if (animal.hasMetadata(this.mobSpawnerMetadata)) {
|
if (animal.hasMetadata(this.mobSpawnerMetadata)) {
|
||||||
@ -461,7 +459,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(event.getInventory() instanceof CraftingInventory) || !event.getSlotType().equals(SlotType.RESULT))
|
if (!event.getSlotType().equals(SlotType.RESULT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ItemStack resultStack = event.getRecipe().getResult();
|
ItemStack resultStack = event.getRecipe().getResult();
|
||||||
@ -622,8 +620,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
// See if we can create a new item stack with the combined elements of a and b
|
// See if we can create a new item stack with the combined elements of a and b
|
||||||
if (a == null || b == null)
|
if (a == null || b == null)
|
||||||
return true;// Treat null as an empty stack
|
return true;// Treat null as an empty stack
|
||||||
else
|
return a.getAmount() + b.getAmount() <= a.getType().getMaxStackSize();
|
||||||
return a.getAmount() + b.getAmount() <= a.getType().getMaxStackSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
@ -797,14 +794,11 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
// Entity that died must be living
|
// Entity that died must be living
|
||||||
if (!(event.getEntity() instanceof LivingEntity))
|
LivingEntity lVictim = event.getEntity();
|
||||||
return;
|
|
||||||
LivingEntity lVictim = (LivingEntity) event.getEntity();
|
|
||||||
|
|
||||||
//extra check for Citizens 2 sentry kills
|
//extra check for Citizens 2 sentry kills
|
||||||
if (lVictim.getKiller() instanceof Player)
|
if (lVictim.getKiller().hasMetadata("NPC"))
|
||||||
if (lVictim.getKiller().hasMetadata("NPC"))
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (Jobs.getGCManager().MythicMobsEnabled && Jobs.getMythicManager().MMAPI != null) {
|
if (Jobs.getGCManager().MythicMobsEnabled && Jobs.getMythicManager().MMAPI != null) {
|
||||||
if (Jobs.getMythicManager().MMAPI.getMobAPI().isMythicMob(lVictim))
|
if (Jobs.getMythicManager().MMAPI.getMobAPI().isMythicMob(lVictim))
|
||||||
@ -888,7 +882,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
|
||||||
return;
|
return;
|
||||||
if (event.getSpawnReason() == SpawnReason.SPAWNER) {
|
if (event.getSpawnReason() == SpawnReason.SPAWNER) {
|
||||||
LivingEntity creature = (LivingEntity) event.getEntity();
|
LivingEntity creature = event.getEntity();
|
||||||
creature.setMetadata(this.mobSpawnerMetadata, new FixedMetadataValue(this.plugin, true));
|
creature.setMetadata(this.mobSpawnerMetadata, new FixedMetadataValue(this.plugin, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -926,11 +920,8 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (!reason.toString().equalsIgnoreCase("BREEDING"))
|
if (!reason.toString().equalsIgnoreCase("BREEDING"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Entity that spawn must be living
|
|
||||||
if (!(event.getEntity() instanceof LivingEntity))
|
|
||||||
return;
|
|
||||||
|
|
||||||
LivingEntity animal = (LivingEntity) event.getEntity();
|
LivingEntity animal = event.getEntity();
|
||||||
|
|
||||||
// make sure plugin is enabled
|
// make sure plugin is enabled
|
||||||
if (!this.plugin.isEnabled())
|
if (!this.plugin.isEnabled())
|
||||||
@ -1105,7 +1096,7 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (!Jobs.getExplore().isExploreEnabled())
|
if (!Jobs.getExplore().isExploreEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
if (!Jobs.getGCManager().payExploringWhenFlying())
|
if (!Jobs.getGCManager().payExploringWhenFlying())
|
||||||
return;
|
return;
|
||||||
|
@ -35,10 +35,7 @@ public class McMMOlistener implements Listener {
|
|||||||
if (!plugin.isEnabled())
|
if (!plugin.isEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!(event.getPlayer() instanceof Player))
|
Player player = event.getPlayer();
|
||||||
return;
|
|
||||||
|
|
||||||
Player player = (Player) event.getPlayer();
|
|
||||||
|
|
||||||
ItemStack resultStack = event.getRepairedObject();
|
ItemStack resultStack = event.getRepairedObject();
|
||||||
|
|
||||||
|
@ -28,37 +28,37 @@ package com.gamingmesh.jobs.resources.jfep;
|
|||||||
*/
|
*/
|
||||||
public class ConstantNode implements ExpressionNode {
|
public class ConstantNode implements ExpressionNode {
|
||||||
/** List of built-in constant names */
|
/** List of built-in constant names */
|
||||||
public static final String[] CONSTANTS = new String[] {"pi", "e"};
|
public static final String[] CONSTANTS = new String[] { "pi", "e" };
|
||||||
/** List of built-in constant values */
|
/** List of built-in constant values */
|
||||||
public static final double[] VALUES = new double[] {Math.PI, Math.E};
|
public static final double[] VALUES = new double[] { Math.PI, Math.E };
|
||||||
/** Value of the constant */
|
/** Value of the constant */
|
||||||
protected double constant;
|
protected double constant;
|
||||||
/** Name of the constant. Only if it's built-in */
|
/** Name of the constant. Only if it's built-in */
|
||||||
protected String name;
|
protected String name;
|
||||||
/** An empty array with children */
|
/** An empty array with children */
|
||||||
protected ExpressionNode[] children = new ExpressionNode[0];
|
protected ExpressionNode[] children = new ExpressionNode[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a constant node
|
* Builds a constant node
|
||||||
* @param constant constant to be put in node
|
* @param constant constant to be put in node
|
||||||
*/
|
*/
|
||||||
public ConstantNode(double constant) {
|
public ConstantNode(double constant) {
|
||||||
this.constant = constant;
|
this.constant = constant;
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a constant node, with an unique constant
|
* Builds a constant node, with an unique constant
|
||||||
* @param name name of the constant in the CONSTANTS array
|
* @param name name of the constant in the CONSTANTS array
|
||||||
*/
|
*/
|
||||||
public ConstantNode(String name) {
|
public ConstantNode(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
for (int i=0; i<CONSTANTS.length;i++)
|
for (int i = 0; i < CONSTANTS.length; i++)
|
||||||
if (CONSTANTS[i].equals(name)) {
|
if (CONSTANTS[i].equals(name)) {
|
||||||
constant = VALUES[i];
|
constant = VALUES[i];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unrecognized constant");
|
throw new IllegalArgumentException("Unrecognized constant");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,77 +67,75 @@ public class ConstantNode implements ExpressionNode {
|
|||||||
* @see ConstantNode#CONSTANTS
|
* @see ConstantNode#CONSTANTS
|
||||||
*/
|
*/
|
||||||
public ConstantNode(int pos) {
|
public ConstantNode(int pos) {
|
||||||
this.name = CONSTANTS[pos];
|
this.name = CONSTANTS[pos];
|
||||||
this.constant = VALUES[pos];
|
this.constant = VALUES[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||||
*/
|
*/
|
||||||
public int count() {
|
public int count() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||||
*/
|
*/
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return 1; // This is a leaf node
|
return 1; // This is a leaf node
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||||
*/
|
*/
|
||||||
public String getSubtype() {
|
public String getSubtype() {
|
||||||
// Checks if this is integer or double
|
// Checks if this is integer or double
|
||||||
if (Math.floor(constant) == constant)
|
if (Math.floor(constant) == constant)
|
||||||
return Long.toString(Math.round(constant));
|
return Long.toString(Math.round(constant));
|
||||||
else
|
return Double.toString(constant);
|
||||||
return Double.toString(constant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return ExpressionNode.CONSTANT_NODE;
|
return ExpressionNode.CONSTANT_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||||
*/
|
*/
|
||||||
public double getValue() {
|
public double getValue() {
|
||||||
return constant;
|
return constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||||
*/
|
*/
|
||||||
public void setVariable(String name, double value) {
|
public void setVariable(String name, double value) {
|
||||||
// Nothing to be done here...
|
// Nothing to be done here...
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||||
*/
|
*/
|
||||||
public ExpressionNode[] getChildrenNodes() {
|
public ExpressionNode[] getChildrenNodes() {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
return new ConstantNode(constant);
|
return new ConstantNode(constant);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return getSubtype();
|
return getSubtype();
|
||||||
else
|
return name;
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,16 @@ package com.gamingmesh.jobs.resources.jfep;
|
|||||||
*/
|
*/
|
||||||
public class FunctionNode implements ExpressionNode {
|
public class FunctionNode implements ExpressionNode {
|
||||||
/** List of supported functions */
|
/** List of supported functions */
|
||||||
public static final String[] FUNCTIONS = new String[] {"-", "sin", "cos", "tan",
|
public static final String[] FUNCTIONS = new String[] { "-", "sin", "cos", "tan",
|
||||||
"asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh",
|
"asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh",
|
||||||
"ln", "log", "abs", "rand", "sqrt", "erf", "erfc", "gamma", "exp", "cot", "log2"};
|
"ln", "log", "abs", "rand", "sqrt", "erf", "erfc", "gamma", "exp", "cot", "log2" };
|
||||||
/** Child node */
|
/** Child node */
|
||||||
protected ExpressionNode child;
|
protected ExpressionNode child;
|
||||||
/** Function of this node */
|
/** Function of this node */
|
||||||
protected int function;
|
protected int function;
|
||||||
/** An array with children */
|
/** An array with children */
|
||||||
protected ExpressionNode[] children;
|
protected ExpressionNode[] children;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function node.
|
* Creates a function node.
|
||||||
* @param child child node of this node
|
* @param child child node of this node
|
||||||
@ -45,11 +45,11 @@ public class FunctionNode implements ExpressionNode {
|
|||||||
* @see FunctionNode#FUNCTIONS
|
* @see FunctionNode#FUNCTIONS
|
||||||
*/
|
*/
|
||||||
public FunctionNode(ExpressionNode child, int function) {
|
public FunctionNode(ExpressionNode child, int function) {
|
||||||
this.child = child;
|
this.child = child;
|
||||||
this.function = function;
|
this.function = function;
|
||||||
children = new ExpressionNode[] {child};
|
children = new ExpressionNode[] { child };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function node.
|
* Creates a function node.
|
||||||
* @param child child node of this node
|
* @param child child node of this node
|
||||||
@ -57,118 +57,138 @@ public class FunctionNode implements ExpressionNode {
|
|||||||
* @throws IllegalArgumentException if function is unsupported
|
* @throws IllegalArgumentException if function is unsupported
|
||||||
*/
|
*/
|
||||||
public FunctionNode(ExpressionNode child, String function) throws IllegalArgumentException {
|
public FunctionNode(ExpressionNode child, String function) throws IllegalArgumentException {
|
||||||
this.child = child;
|
this.child = child;
|
||||||
this.function = -1;
|
this.function = -1;
|
||||||
children = new ExpressionNode[] {child};
|
children = new ExpressionNode[] { child };
|
||||||
for (int i=0; i<FUNCTIONS.length;i++) {
|
for (int i = 0; i < FUNCTIONS.length; i++) {
|
||||||
if (FUNCTIONS[i].equals(function)) {
|
if (FUNCTIONS[i].equals(function)) {
|
||||||
this.function = i;
|
this.function = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.function < 0)
|
if (this.function < 0)
|
||||||
throw new IllegalArgumentException("Unrecognized function");
|
throw new IllegalArgumentException("Unrecognized function");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||||
*/
|
*/
|
||||||
public int count() {
|
public int count() {
|
||||||
return 1 + child.count();
|
return 1 + child.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||||
*/
|
*/
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return 1 + child.getDepth();
|
return 1 + child.getDepth();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||||
*/
|
*/
|
||||||
public String getSubtype() {
|
public String getSubtype() {
|
||||||
return FUNCTIONS[function];
|
return FUNCTIONS[function];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return ExpressionNode.FUNCTION_NODE;
|
return ExpressionNode.FUNCTION_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||||
*/
|
*/
|
||||||
public double getValue() {
|
public double getValue() {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case 0: return - child.getValue();
|
case 0:
|
||||||
case 1: return Math.sin(child.getValue());
|
return -child.getValue();
|
||||||
case 2: return Math.cos(child.getValue());
|
case 1:
|
||||||
case 3: return Math.tan(child.getValue());
|
return Math.sin(child.getValue());
|
||||||
case 4: return Math.asin(child.getValue());
|
case 2:
|
||||||
case 5: return Math.acos(child.getValue());
|
return Math.cos(child.getValue());
|
||||||
case 6: return Math.atan(child.getValue());
|
case 3:
|
||||||
case 7: return Sfun.sinh(child.getValue());
|
return Math.tan(child.getValue());
|
||||||
case 8: return Sfun.cosh(child.getValue());
|
case 4:
|
||||||
case 9: return Sfun.tanh(child.getValue());
|
return Math.asin(child.getValue());
|
||||||
case 10: return Sfun.asinh(child.getValue());
|
case 5:
|
||||||
case 11: return Sfun.acosh(child.getValue());
|
return Math.acos(child.getValue());
|
||||||
case 12: return Sfun.atanh(child.getValue());
|
case 6:
|
||||||
case 13: return Math.log(child.getValue());
|
return Math.atan(child.getValue());
|
||||||
case 14: return Math.log(child.getValue()) * 0.43429448190325182765;
|
case 7:
|
||||||
case 15: return Math.abs(child.getValue());
|
return Sfun.sinh(child.getValue());
|
||||||
case 16: return Math.random() * child.getValue();
|
case 8:
|
||||||
case 17: return Math.sqrt(child.getValue());
|
return Sfun.cosh(child.getValue());
|
||||||
case 18: return Sfun.erf(child.getValue());
|
case 9:
|
||||||
case 19: return Sfun.erfc(child.getValue());
|
return Sfun.tanh(child.getValue());
|
||||||
case 20: return Sfun.gamma(child.getValue());
|
case 10:
|
||||||
case 21: return Math.exp(child.getValue());
|
return Sfun.asinh(child.getValue());
|
||||||
case 22: return Sfun.cot(child.getValue());
|
case 11:
|
||||||
case 23: return Math.log(child.getValue()) * 1.442695040888963407360;
|
return Sfun.acosh(child.getValue());
|
||||||
}
|
case 12:
|
||||||
// This is never reached
|
return Sfun.atanh(child.getValue());
|
||||||
return 0;
|
case 13:
|
||||||
|
return Math.log(child.getValue());
|
||||||
|
case 14:
|
||||||
|
return Math.log(child.getValue()) * 0.43429448190325182765;
|
||||||
|
case 15:
|
||||||
|
return Math.abs(child.getValue());
|
||||||
|
case 16:
|
||||||
|
return Math.random() * child.getValue();
|
||||||
|
case 17:
|
||||||
|
return Math.sqrt(child.getValue());
|
||||||
|
case 18:
|
||||||
|
return Sfun.erf(child.getValue());
|
||||||
|
case 19:
|
||||||
|
return Sfun.erfc(child.getValue());
|
||||||
|
case 20:
|
||||||
|
return Sfun.gamma(child.getValue());
|
||||||
|
case 21:
|
||||||
|
return Math.exp(child.getValue());
|
||||||
|
case 22:
|
||||||
|
return Sfun.cot(child.getValue());
|
||||||
|
case 23:
|
||||||
|
return Math.log(child.getValue()) * 1.442695040888963407360;
|
||||||
|
}
|
||||||
|
// This is never reached
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||||
*/
|
*/
|
||||||
public void setVariable(String name, double value) {
|
public void setVariable(String name, double value) {
|
||||||
child.setVariable(name, value);
|
child.setVariable(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||||
*/
|
*/
|
||||||
public ExpressionNode[] getChildrenNodes() {
|
public ExpressionNode[] getChildrenNodes() {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
ExpressionNode n_child = (ExpressionNode)child.clone();
|
ExpressionNode n_child = (ExpressionNode) child.clone();
|
||||||
return new FunctionNode(n_child, function);
|
return new FunctionNode(n_child, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
// Special case for negation function
|
// Special case for negation function
|
||||||
if (function != 0)
|
if (function != 0)
|
||||||
return this.getSubtype() + "(" + child.toString() + ")";
|
return this.getSubtype() + "(" + child.toString() + ")";
|
||||||
else {
|
if (child.getType() == CONSTANT_NODE || child.getType() == VARIABLE_NODE ||
|
||||||
if (child.getType() == CONSTANT_NODE || child.getType() == VARIABLE_NODE ||
|
(child.getType() == FUNCTION_NODE && !child.getSubtype().equals(FUNCTIONS[0])))
|
||||||
(child.getType() == FUNCTION_NODE && !child.getSubtype().equals(FUNCTIONS[0])))
|
return FUNCTIONS[0] + child.toString();
|
||||||
return FUNCTIONS[0] + child.toString();
|
return FUNCTIONS[0] + "(" + child.toString() + ")";
|
||||||
else
|
|
||||||
return FUNCTIONS[0] + "(" + child.toString() + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package com.gamingmesh.jobs.resources.jfep;
|
|||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p><b>Name:</b> Parser</p>
|
* <p><b>Name:</b> Parser</p>
|
||||||
* <p><b>Description:</b>
|
* <p><b>Description:</b>
|
||||||
@ -47,13 +46,13 @@ public class Parser {
|
|||||||
private static final char VAR = 'x'; // variable
|
private static final char VAR = 'x'; // variable
|
||||||
private static final char OP_BRACKET = '('; // open bracket
|
private static final char OP_BRACKET = '('; // open bracket
|
||||||
private static final char CL_BRACKET = ')'; // closed bracket
|
private static final char CL_BRACKET = ')'; // closed bracket
|
||||||
|
|
||||||
private char[] input;
|
private char[] input;
|
||||||
private boolean error;
|
private boolean error;
|
||||||
private int inp_cur; // Current input position
|
private int inp_cur; // Current input position
|
||||||
private Element cc; // Current character
|
private Element cc; // Current character
|
||||||
private ExpressionNode root; // Root of expression tree
|
private ExpressionNode root; // Root of expression tree
|
||||||
|
|
||||||
private HashSet<String> functions; // Used functions
|
private HashSet<String> functions; // Used functions
|
||||||
private HashSet<String> variables; // Used variables
|
private HashSet<String> variables; // Used variables
|
||||||
|
|
||||||
@ -62,9 +61,9 @@ public class Parser {
|
|||||||
* @param str Input string to be analyzed
|
* @param str Input string to be analyzed
|
||||||
*/
|
*/
|
||||||
public Parser(String str) {
|
public Parser(String str) {
|
||||||
this(str, false);
|
this(str, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
* @param str Input string to be analyzed
|
* @param str Input string to be analyzed
|
||||||
@ -73,47 +72,45 @@ public class Parser {
|
|||||||
* considered as zero.
|
* considered as zero.
|
||||||
*/
|
*/
|
||||||
public Parser(String str, boolean error) {
|
public Parser(String str, boolean error) {
|
||||||
input = convertInput(str);
|
input = convertInput(str);
|
||||||
root = null;
|
root = null;
|
||||||
inp_cur = 0;
|
inp_cur = 0;
|
||||||
this.error = error;
|
this.error = error;
|
||||||
functions = new HashSet<String>();
|
functions = new HashSet<String>();
|
||||||
variables = new HashSet<String>();
|
variables = new HashSet<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts input string in a character array and removes unsupported characters
|
* Converts input string in a character array and removes unsupported characters
|
||||||
* @param str input string
|
* @param str input string
|
||||||
* @return converted string, terminated by TERM character
|
* @return converted string, terminated by TERM character
|
||||||
*/
|
*/
|
||||||
protected char[] convertInput(String str) {
|
protected char[] convertInput(String str) {
|
||||||
char[] input = str.toCharArray();
|
char[] input = str.toCharArray();
|
||||||
char[] output = new char[input.length+1]; // One more space for terminator
|
char[] output = new char[input.length + 1]; // One more space for terminator
|
||||||
int pos = 0; // Position on output
|
int pos = 0; // Position on output
|
||||||
for (int i=0; i<input.length; i++) {
|
for (int i = 0; i < input.length; i++) {
|
||||||
char c = input[i];
|
char c = input[i];
|
||||||
if (isNumber(c) || isOperator(c) || isText(c) || isBracket(c))
|
if (isNumber(c) || isOperator(c) || isText(c) || isBracket(c))
|
||||||
output[pos++] = c;
|
output[pos++] = c;
|
||||||
}
|
}
|
||||||
output[pos++] = TERM;
|
output[pos++] = TERM;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the tree of the function generated by the parser
|
* Returns the tree of the function generated by the parser
|
||||||
* @return Node root node of parsed tree
|
* @return Node root node of parsed tree
|
||||||
* @throws ParseError if parsed input string was malformed
|
* @throws ParseError if parsed input string was malformed
|
||||||
*/
|
*/
|
||||||
public ExpressionNode getTree() throws ParseError {
|
public ExpressionNode getTree() throws ParseError {
|
||||||
if (root == null) { // Function need parsing
|
if (root == null) { // Function need parsing
|
||||||
cc = parse();
|
cc = parse();
|
||||||
root = S();
|
root = S();
|
||||||
if (!isEndOfExpression(cc.getToken()))
|
if (!isEndOfExpression(cc.getToken()))
|
||||||
throw new ParseError("Expecting operator or end of input", inp_cur);
|
throw new ParseError("Expecting operator or end of input", inp_cur);
|
||||||
return root;
|
}
|
||||||
}
|
return root; // Parsing was already performed before
|
||||||
else
|
|
||||||
return root; // Parsing was already performed before
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,9 +119,9 @@ public class Parser {
|
|||||||
* @return truth value
|
* @return truth value
|
||||||
*/
|
*/
|
||||||
private boolean isNumber(char c) {
|
private boolean isNumber(char c) {
|
||||||
if ((c >= '0' && c <= '9') || c == '.')
|
if ((c >= '0' && c <= '9') || c == '.')
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,10 +130,10 @@ public class Parser {
|
|||||||
* @return truth value
|
* @return truth value
|
||||||
*/
|
*/
|
||||||
private boolean isOperator(char c) {
|
private boolean isOperator(char c) {
|
||||||
for (int i=0;i<OperatorNode.OPERATIONS.length;i++)
|
for (int i = 0; i < OperatorNode.OPERATIONS.length; i++)
|
||||||
if (c == OperatorNode.OPERATIONS[i])
|
if (c == OperatorNode.OPERATIONS[i])
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,18 +142,18 @@ public class Parser {
|
|||||||
* @return truth value
|
* @return truth value
|
||||||
*/
|
*/
|
||||||
private boolean isText(char c) {
|
private boolean isText(char c) {
|
||||||
return ((c >= 'A' && c <= 'Z') ||
|
return ((c >= 'A' && c <= 'Z') ||
|
||||||
(c >= 'a' && c <= 'z') ||
|
(c >= 'a' && c <= 'z') ||
|
||||||
c == '_');
|
c == '_');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if input character is a bracket
|
* Returns if input character is a bracket
|
||||||
* @param c character
|
* @param c character
|
||||||
* @return truth value
|
* @return truth value
|
||||||
*/
|
*/
|
||||||
private boolean isBracket(char c) {
|
private boolean isBracket(char c) {
|
||||||
return (c == OP_BRACKET) || (c == CL_BRACKET);
|
return (c == OP_BRACKET) || (c == CL_BRACKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,8 +161,8 @@ public class Parser {
|
|||||||
* @param c input character
|
* @param c input character
|
||||||
* @return truth value
|
* @return truth value
|
||||||
*/
|
*/
|
||||||
private boolean isEndOfExpression (char c) {
|
private boolean isEndOfExpression(char c) {
|
||||||
return c == TERM;
|
return c == TERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,84 +170,83 @@ public class Parser {
|
|||||||
* @return Element
|
* @return Element
|
||||||
*/
|
*/
|
||||||
private Element parse() {
|
private Element parse() {
|
||||||
// Detects implicit multiplication
|
// Detects implicit multiplication
|
||||||
if (detectImplicitMult())
|
if (detectImplicitMult())
|
||||||
return new Element('*');
|
return new Element('*');
|
||||||
// Matches operators, brackets and termination character
|
// Matches operators, brackets and termination character
|
||||||
if (isOperator(input[inp_cur]) || isBracket(input[inp_cur]) || isEndOfExpression(input[inp_cur]))
|
if (isOperator(input[inp_cur]) || isBracket(input[inp_cur]) || isEndOfExpression(input[inp_cur]))
|
||||||
return new Element(input[inp_cur++]);
|
return new Element(input[inp_cur++]);
|
||||||
|
|
||||||
// Matches numbers
|
// Matches numbers
|
||||||
if (isNumber(input[inp_cur])) {
|
if (isNumber(input[inp_cur])) {
|
||||||
int tmp = inp_cur++;
|
int tmp = inp_cur++;
|
||||||
// Finds the end of number
|
// Finds the end of number
|
||||||
while (isNumber(input[inp_cur]))
|
while (isNumber(input[inp_cur]))
|
||||||
inp_cur++;
|
inp_cur++;
|
||||||
// Eventual exponential
|
// Eventual exponential
|
||||||
if (Character.toLowerCase(input[inp_cur]) == 'e') {
|
if (Character.toLowerCase(input[inp_cur]) == 'e') {
|
||||||
if (input[inp_cur + 1] == '-' || isNumber(input[inp_cur + 1]))
|
if (input[inp_cur + 1] == '-' || isNumber(input[inp_cur + 1]))
|
||||||
inp_cur += 2;
|
inp_cur += 2;
|
||||||
while (isNumber(input[inp_cur]))
|
while (isNumber(input[inp_cur]))
|
||||||
inp_cur++;
|
inp_cur++;
|
||||||
}
|
}
|
||||||
String s = new String(input, tmp, inp_cur - tmp);
|
String s = new String(input, tmp, inp_cur - tmp);
|
||||||
double d;
|
double d;
|
||||||
try {
|
try {
|
||||||
d = Double.valueOf(s).doubleValue();
|
d = Double.valueOf(s).doubleValue();
|
||||||
}
|
} catch (NumberFormatException ex) {
|
||||||
catch (NumberFormatException ex) {
|
throw new ParseError("Invalid number: " + s, inp_cur);
|
||||||
throw new ParseError("Invalid number: "+s, inp_cur);
|
}
|
||||||
}
|
return new Element(NUM, d);
|
||||||
return new Element(NUM, d);
|
}
|
||||||
}
|
|
||||||
|
// Matches text (functions or variables or built-in constants)
|
||||||
// Matches text (functions or variables or built-in constants)
|
if (isText(input[inp_cur])) {
|
||||||
if (isText(input[inp_cur])) {
|
int tmp = inp_cur++;
|
||||||
int tmp = inp_cur++;
|
// Finds the end of text
|
||||||
// Finds the end of text
|
while (isText(input[inp_cur]) || isNumber(input[inp_cur]))
|
||||||
while (isText(input[inp_cur]) || isNumber(input[inp_cur]))
|
inp_cur++;
|
||||||
inp_cur++;
|
String s = new String(input, tmp, inp_cur - tmp);
|
||||||
String s = new String(input, tmp, inp_cur - tmp);
|
|
||||||
|
String lower = s.toLowerCase();
|
||||||
String lower = s.toLowerCase();
|
// Now searches if this string is a function
|
||||||
// Now searches if this string is a function
|
for (int i = 0; i < FunctionNode.FUNCTIONS.length; i++) {
|
||||||
for (int i=0; i<FunctionNode.FUNCTIONS.length;i++) {
|
if (lower.equals(FunctionNode.FUNCTIONS[i])) {
|
||||||
if (lower.equals(FunctionNode.FUNCTIONS[i])) {
|
functions.add(FunctionNode.FUNCTIONS[i]);
|
||||||
functions.add(FunctionNode.FUNCTIONS[i]);
|
return new Element(FUNC, i);
|
||||||
return new Element(FUNC, i);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Now searches if this string is a built-in constant
|
||||||
// Now searches if this string is a built-in constant
|
for (int i = 0; i < ConstantNode.CONSTANTS.length; i++) {
|
||||||
for (int i=0; i<ConstantNode.CONSTANTS.length;i++) {
|
if (lower.equals(ConstantNode.CONSTANTS[i]))
|
||||||
if (lower.equals(ConstantNode.CONSTANTS[i]))
|
return new Element(NUM, i);
|
||||||
return new Element(NUM, i);
|
}
|
||||||
}
|
|
||||||
|
// String was not a function, so treat it as a variable
|
||||||
// String was not a function, so treat it as a variable
|
variables.add(s);
|
||||||
variables.add(s);
|
return new Element(VAR, s);
|
||||||
return new Element(VAR, s);
|
}
|
||||||
}
|
//At this point everything not recognized is an error
|
||||||
//At this point everything not recognized is an error
|
throw new ParseError("Unrecognized identifier", inp_cur);
|
||||||
throw new ParseError("Unrecognized identifier", inp_cur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to detect implicit multiplication
|
* Helper method to detect implicit multiplication
|
||||||
* @return true only if inplicit multiplication is detected
|
* @return true only if inplicit multiplication is detected
|
||||||
*/
|
*/
|
||||||
private boolean detectImplicitMult() {
|
private boolean detectImplicitMult() {
|
||||||
if (cc != null && cc.getToken() == NUM) {
|
if (cc != null && cc.getToken() == NUM) {
|
||||||
cc = null; // Otherwise we will loop forever
|
cc = null; // Otherwise we will loop forever
|
||||||
// Stores old pointer to restore it back
|
// Stores old pointer to restore it back
|
||||||
int old_input = inp_cur;
|
int old_input = inp_cur;
|
||||||
Element next = parse();
|
Element next = parse();
|
||||||
// Restores old pointer back
|
// Restores old pointer back
|
||||||
inp_cur = old_input;
|
inp_cur = old_input;
|
||||||
if (next.getToken() == VAR || next.getToken() == FUNC)
|
if (next.getToken() == VAR || next.getToken() == FUNC)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,13 +255,13 @@ public class Parser {
|
|||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode S() {
|
private ExpressionNode S() {
|
||||||
ExpressionNode current = E();
|
ExpressionNode current = E();
|
||||||
while (cc.getToken() == '+' || cc.getToken() == '-') {
|
while (cc.getToken() == '+' || cc.getToken() == '-') {
|
||||||
char operator = cc.getToken();
|
char operator = cc.getToken();
|
||||||
cc = parse();
|
cc = parse();
|
||||||
current = new OperatorNode(current, E(), operator);
|
current = new OperatorNode(current, E(), operator);
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,12 +270,12 @@ public class Parser {
|
|||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode E() {
|
private ExpressionNode E() {
|
||||||
ExpressionNode current = G();
|
ExpressionNode current = G();
|
||||||
while (cc.getToken() == '*') {
|
while (cc.getToken() == '*') {
|
||||||
cc = parse();
|
cc = parse();
|
||||||
current = new OperatorNode(current, G(), '*');
|
current = new OperatorNode(current, G(), '*');
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,39 +284,39 @@ public class Parser {
|
|||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode G() {
|
private ExpressionNode G() {
|
||||||
ExpressionNode current = H();
|
ExpressionNode current = H();
|
||||||
while (cc.getToken() == '/') {
|
while (cc.getToken() == '/') {
|
||||||
cc = parse();
|
cc = parse();
|
||||||
current = new OperatorNode(current, H(), '/');
|
current = new OperatorNode(current, H(), '/');
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-terminal H<br>
|
* Non-terminal H<br>
|
||||||
* H -> T ('%' T)*<br>
|
* H -> T ('%' T)*<br>
|
||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode H() {
|
private ExpressionNode H() {
|
||||||
ExpressionNode current = T();
|
ExpressionNode current = T();
|
||||||
while (cc.getToken() == '%') {
|
while (cc.getToken() == '%') {
|
||||||
cc = parse();
|
cc = parse();
|
||||||
current = new OperatorNode(current, T(), '%');
|
current = new OperatorNode(current, T(), '%');
|
||||||
}
|
}
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-terminal T<br>
|
* Non-terminal T<br>
|
||||||
* T -> F | '-' F<br>
|
* T -> F | '-' F<br>
|
||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode T() {
|
private ExpressionNode T() {
|
||||||
if (cc.getToken() == '-') {
|
if (cc.getToken() == '-') {
|
||||||
cc = parse();
|
cc = parse();
|
||||||
return new FunctionNode(F(), "-");
|
return new FunctionNode(F(), "-");
|
||||||
}
|
}
|
||||||
return F();
|
return F();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -329,13 +325,13 @@ public class Parser {
|
|||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode F() {
|
private ExpressionNode F() {
|
||||||
ExpressionNode left;
|
ExpressionNode left;
|
||||||
left = U();
|
left = U();
|
||||||
if (cc.getToken() == '^') {
|
if (cc.getToken() == '^') {
|
||||||
cc = parse();
|
cc = parse();
|
||||||
return new OperatorNode(left, F(), '^');
|
return new OperatorNode(left, F(), '^');
|
||||||
}
|
}
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -344,81 +340,80 @@ public class Parser {
|
|||||||
* @return Node
|
* @return Node
|
||||||
*/
|
*/
|
||||||
private ExpressionNode U() {
|
private ExpressionNode U() {
|
||||||
switch(cc.getToken()) {
|
switch (cc.getToken()) {
|
||||||
case NUM:
|
case NUM:
|
||||||
double n = cc.number;
|
double n = cc.number;
|
||||||
int constPosition = cc.position; // Position if this is a built-in constant
|
int constPosition = cc.position; // Position if this is a built-in constant
|
||||||
cc = parse();
|
cc = parse();
|
||||||
if (constPosition >= 0)
|
if (constPosition >= 0)
|
||||||
return new ConstantNode(constPosition);
|
return new ConstantNode(constPosition);
|
||||||
else
|
return new ConstantNode(n);
|
||||||
return new ConstantNode(n);
|
case VAR:
|
||||||
case VAR :
|
String name = cc.name;
|
||||||
String name = cc.name;
|
cc = parse();
|
||||||
cc = parse();
|
return new VariableNode(name, error);
|
||||||
return new VariableNode(name, error);
|
case OP_BRACKET:
|
||||||
case OP_BRACKET :
|
cc = parse();
|
||||||
cc = parse();
|
ExpressionNode tmp = S();
|
||||||
ExpressionNode tmp = S();
|
if (cc.getToken() == CL_BRACKET) {
|
||||||
if (cc.getToken() == CL_BRACKET) {
|
cc = parse();
|
||||||
cc = parse();
|
return tmp;
|
||||||
return tmp;
|
}
|
||||||
}
|
throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
|
||||||
throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
|
case FUNC:
|
||||||
case FUNC :
|
int function = cc.position;
|
||||||
int function = cc.position;
|
cc = parse();
|
||||||
cc = parse();
|
if (cc.getToken() == OP_BRACKET)
|
||||||
if (cc.getToken() == OP_BRACKET)
|
cc = parse();
|
||||||
cc = parse();
|
else
|
||||||
else
|
throw new ParseError("Semantic Error, expected '" + OP_BRACKET + "'", inp_cur);
|
||||||
throw new ParseError("Semantic Error, expected '"+OP_BRACKET+"'", inp_cur);
|
ExpressionNode tmp2 = S();
|
||||||
ExpressionNode tmp2 = S();
|
if (cc.getToken() == CL_BRACKET)
|
||||||
if (cc.getToken() == CL_BRACKET)
|
cc = parse();
|
||||||
cc = parse();
|
else
|
||||||
else
|
throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
|
||||||
throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
|
return new FunctionNode(tmp2, function);
|
||||||
return new FunctionNode(tmp2, function);
|
}
|
||||||
}
|
throw new ParseError("Semantic Error, expected function or variable or constant or '('", inp_cur);
|
||||||
throw new ParseError("Semantic Error, expected function or variable or constant or '('", inp_cur);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data structure used internally to return parsed elements.
|
* Data structure used internally to return parsed elements.
|
||||||
*/
|
*/
|
||||||
private class Element {
|
private class Element {
|
||||||
private char token;
|
private char token;
|
||||||
public double number = Double.NaN;
|
public double number = Double.NaN;
|
||||||
public int position = -1;
|
public int position = -1;
|
||||||
public String name = null;
|
public String name = null;
|
||||||
|
|
||||||
public Element (char token) {
|
public Element(char token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element (char token, double number) {
|
public Element(char token, double number) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.number = number;
|
this.number = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Element (char token, String name) {
|
|
||||||
this.token = token;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element (char token, int position) {
|
public Element(char token, String name) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.position = position;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Element(char token, int position) {
|
||||||
* Returns the token
|
this.token = token;
|
||||||
* @return char
|
this.position = position;
|
||||||
*/
|
}
|
||||||
public char getToken() {
|
|
||||||
return token;
|
/**
|
||||||
}
|
* Returns the token
|
||||||
|
* @return char
|
||||||
|
*/
|
||||||
|
public char getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value for a given variable
|
* Sets the value for a given variable
|
||||||
* @param name name of the variable to be set (case sensitive)
|
* @param name name of the variable to be set (case sensitive)
|
||||||
@ -426,10 +421,10 @@ public class Parser {
|
|||||||
* @throws ParseError if parsed input string was malformed
|
* @throws ParseError if parsed input string was malformed
|
||||||
*/
|
*/
|
||||||
public void setVariable(String name, double value) throws ParseError {
|
public void setVariable(String name, double value) throws ParseError {
|
||||||
getTree();
|
getTree();
|
||||||
root.setVariable(name, value);
|
root.setVariable(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for evaluated expression
|
* Returns the value for evaluated expression
|
||||||
* @return value of expression
|
* @return value of expression
|
||||||
@ -439,48 +434,48 @@ public class Parser {
|
|||||||
* @see #Parser(String, boolean)
|
* @see #Parser(String, boolean)
|
||||||
*/
|
*/
|
||||||
public double getValue() throws ParseError, EvaluationException {
|
public double getValue() throws ParseError, EvaluationException {
|
||||||
getTree();
|
getTree();
|
||||||
return root.getValue();
|
return root.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string rappresentation of parsed expression with the right parentesis
|
* Returns a string rappresentation of parsed expression with the right parentesis
|
||||||
* @return a string rappresentation of parsed expression with the right parentesis
|
* @return a string rappresentation of parsed expression with the right parentesis
|
||||||
* @throws ParseError if parsed input string was malformed
|
* @throws ParseError if parsed input string was malformed
|
||||||
*/
|
*/
|
||||||
public String getExpression() throws ParseError {
|
public String getExpression() throws ParseError {
|
||||||
getTree();
|
getTree();
|
||||||
return root.toString();
|
return root.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Set of all functions parsed in input string
|
* Returns a Set of all functions parsed in input string
|
||||||
* @return a set with all parsed functions
|
* @return a set with all parsed functions
|
||||||
* @throws ParseError if parsed input string was malformed
|
* @throws ParseError if parsed input string was malformed
|
||||||
*/
|
*/
|
||||||
public HashSet<String> getParsedFunctions() throws ParseError {
|
public HashSet<String> getParsedFunctions() throws ParseError {
|
||||||
getTree();
|
getTree();
|
||||||
return functions;
|
return functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Set of all variables parsed in input string
|
* Returns a Set of all variables parsed in input string
|
||||||
* @return a set with all parsed variables
|
* @return a set with all parsed variables
|
||||||
* @throws ParseError if parsed input string was malformed
|
* @throws ParseError if parsed input string was malformed
|
||||||
*/
|
*/
|
||||||
public HashSet<String> getParsedVariables() throws ParseError {
|
public HashSet<String> getParsedVariables() throws ParseError {
|
||||||
getTree();
|
getTree();
|
||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns input string, without invalid characters
|
* Returns input string, without invalid characters
|
||||||
* @return input string without invalid characters
|
* @return input string without invalid characters
|
||||||
*/
|
*/
|
||||||
public String getInputString() {
|
public String getInputString() {
|
||||||
StringBuffer output = new StringBuffer();
|
StringBuffer output = new StringBuffer();
|
||||||
for (int i=0; i<input.length && input[i] != TERM;i++)
|
for (int i = 0; i < input.length && input[i] != TERM; i++)
|
||||||
output.append(input[i]);
|
output.append(input[i]);
|
||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class VariableNode implements ExpressionNode {
|
|||||||
protected String name;
|
protected String name;
|
||||||
/** An empty array with children */
|
/** An empty array with children */
|
||||||
protected ExpressionNode[] children = new ExpressionNode[0];
|
protected ExpressionNode[] children = new ExpressionNode[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new variable node with given name.
|
* Creates a new variable node with given name.
|
||||||
* @param name name of the variable
|
* @param name name of the variable
|
||||||
@ -43,79 +43,78 @@ public class VariableNode implements ExpressionNode {
|
|||||||
* is not initialized. Otherwise 0.0 is returned.
|
* is not initialized. Otherwise 0.0 is returned.
|
||||||
*/
|
*/
|
||||||
public VariableNode(String name, boolean error) {
|
public VariableNode(String name, boolean error) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
value = 0.0;
|
value = 0.0;
|
||||||
this.error = error;
|
this.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||||
*/
|
*/
|
||||||
public int count() {
|
public int count() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||||
*/
|
*/
|
||||||
public int getDepth() {
|
public int getDepth() {
|
||||||
return 1; // This is a leaf node
|
return 1; // This is a leaf node
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||||
*/
|
*/
|
||||||
public String getSubtype() {
|
public String getSubtype() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return ExpressionNode.VARIABLE_NODE;
|
return ExpressionNode.VARIABLE_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||||
*/
|
*/
|
||||||
public double getValue() {
|
public double getValue() {
|
||||||
if (!error)
|
if (!error)
|
||||||
return value;
|
return value;
|
||||||
else
|
throw new EvaluationException("Variable '" + name + "' was not initialized.");
|
||||||
throw new EvaluationException("Variable '" + name + "' was not initialized.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||||
*/
|
*/
|
||||||
public void setVariable(String name, double value) {
|
public void setVariable(String name, double value) {
|
||||||
if (this.name.equals(name)) {
|
if (this.name.equals(name)) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
error = false;
|
error = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||||
*/
|
*/
|
||||||
public ExpressionNode[] getChildrenNodes() {
|
public ExpressionNode[] getChildrenNodes() {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
VariableNode node = new VariableNode(name, error);
|
VariableNode node = new VariableNode(name, error);
|
||||||
node.value = value;
|
node.value = value;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getSubtype();
|
return getSubtype();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,11 +162,9 @@ public class ActionBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getChatSerializerClasspath() {
|
private String getChatSerializerClasspath() {
|
||||||
if (cleanVersion < 1820) {
|
if (cleanVersion < 1820)
|
||||||
return "net.minecraft.server." + version + ".ChatSerializer";
|
return "net.minecraft.server." + version + ".ChatSerializer";
|
||||||
} else {
|
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
|
||||||
return "net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer";// 1_8_R2 moved to IChatBaseComponent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPacketPlayOutChat() {
|
private String getPacketPlayOutChat() {
|
||||||
|
Loading…
Reference in New Issue
Block a user