From fbb0bfee906d493c5560508cfacde6e5254e3ecf Mon Sep 17 00:00:00 2001
From: Zrips
Date: Sat, 25 Jun 2016 16:27:01 +0300
Subject: [PATCH] Cleanup and some fixes
---
com/gamingmesh/jobs/Jobs.java | 20 +-
com/gamingmesh/jobs/JobsPlugin.java | 5 +-
com/gamingmesh/jobs/PermissionHandler.java | 3 +-
com/gamingmesh/jobs/PlayerManager.java | 3 +-
com/gamingmesh/jobs/Signs/SignUtil.java | 20 +-
.../jobs/commands/JobsCommands.java | 16 +-
.../jobs/commands/list/convert.java | 6 +-
.../jobs/commands/list/expboost.java | 13 +-
.../jobs/commands/list/moneyboost.java | 13 +-
.../jobs/commands/list/pointboost.java | 13 +-
.../jobs/config/BossBarManager.java | 4 +-
.../jobs/config/ExploreManager.java | 37 +-
.../jobs/config/LanguageManager.java | 4 +-
.../jobs/config/NameTranslatorManager.java | 6 +-
com/gamingmesh/jobs/config/TitleManager.java | 2 +-
com/gamingmesh/jobs/config/YmlMaker.java | 23 +-
.../jobs/container/ExploreRegion.java | 5 -
com/gamingmesh/jobs/container/JobsPlayer.java | 7 +-
.../jobs/container/LocaleReader.java | 7 +-
com/gamingmesh/jobs/container/Log.java | 9 +-
com/gamingmesh/jobs/container/TopList.java | 2 -
com/gamingmesh/jobs/dao/JobsDAO.java | 6 +-
com/gamingmesh/jobs/dao/JobsDAOMySQL.java | 3 +-
com/gamingmesh/jobs/dao/JobsDAOSQLite.java | 3 +-
.../jobs/economy/BufferedEconomy.java | 11 +-
com/gamingmesh/jobs/economy/PaymentData.java | 6 +-
com/gamingmesh/jobs/i18n/Language.java | 9 +-
.../jobs/listeners/JobsListener.java | 16 +-
.../jobs/listeners/JobsPaymentListener.java | 39 +-
.../jobs/listeners/McMMOlistener.java | 5 +-
.../jobs/resources/jfep/ConstantNode.java | 62 ++-
.../jobs/resources/jfep/FunctionNode.java | 156 +++---
.../jobs/resources/jfep/Parser.java | 479 +++++++++---------
.../jobs/resources/jfep/VariableNode.java | 45 +-
com/gamingmesh/jobs/stuff/ActionBar.java | 6 +-
35 files changed, 516 insertions(+), 548 deletions(-)
diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java
index 75b665cf..4a3390ea 100644
--- a/com/gamingmesh/jobs/Jobs.java
+++ b/com/gamingmesh/jobs/Jobs.java
@@ -257,7 +257,7 @@ public class Jobs {
return GUIManager;
}
- public static void setGUIManager(JobsPlugin plugin) {
+ public static void setGUIManager() {
GUIManager = new GuiManager();
}
@@ -467,7 +467,7 @@ public class Jobs {
}
Jobs.getGCManager().reload();
- Jobs.getLanguage().reload(Jobs.getGCManager().getLocale());
+ Jobs.getLanguage().reload();
Jobs.getConfigManager().reload();
usedSlots.clear();
for (Job job : jobs) {
@@ -533,8 +533,7 @@ public class Jobs {
public static int getUsedSlots(Job job) {
if (usedSlots.containsKey(job))
return usedSlots.get(job);
- else
- return 0;
+ return 0;
}
/**
@@ -631,8 +630,9 @@ public class Jobs {
if (data.isReseted())
data.setReseted(false);
return false;
- } else
- data.AddAmount(amount);
+ }
+
+ data.AddAmount(amount);
paymentLimit.put(playername, data);
}
return true;
@@ -669,8 +669,8 @@ public class Jobs {
if (data.isReseted())
data.setReseted(false);
return false;
- } else
- data.AddExpAmount(amount);
+ }
+ data.AddExpAmount(amount);
ExpLimit.put(playername, data);
}
return true;
@@ -710,8 +710,8 @@ public class Jobs {
if (data.isReseted())
data.setReseted(false);
return false;
- } else
- data.AddPoints(amount);
+ }
+ data.AddPoints(amount);
PointLimit.put(playername, data);
}
return true;
diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java
index 267fdfb3..f9c65c6f 100644
--- a/com/gamingmesh/jobs/JobsPlugin.java
+++ b/com/gamingmesh/jobs/JobsPlugin.java
@@ -79,7 +79,7 @@ public class JobsPlugin extends JavaPlugin {
Jobs.setScboard(this);
Jobs.setLanguage(this);
- Jobs.setGUIManager(this);
+ Jobs.setGUIManager();
Jobs.setExplore();
Jobs.setBBManager(this);
@@ -103,6 +103,7 @@ public class JobsPlugin extends JavaPlugin {
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
+ Jobs.setMcMMOlistener(this);
if (Jobs.getMcMMOlistener().CheckmcMMO()){
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.");
ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
console.sendMessage(message);
- Jobs.getLanguage().reload(Jobs.getGCManager().getLocale());
+ Jobs.getLanguage().reload();
Jobs.getJobsDAO().loadExplore();
diff --git a/com/gamingmesh/jobs/PermissionHandler.java b/com/gamingmesh/jobs/PermissionHandler.java
index e664e252..39750a3d 100644
--- a/com/gamingmesh/jobs/PermissionHandler.java
+++ b/com/gamingmesh/jobs/PermissionHandler.java
@@ -243,9 +243,8 @@ public class PermissionHandler {
public boolean hasWorldPermission(Player player, String world) {
if (!player.hasPermission("jobs.use")) {
return false;
- } else {
- return player.hasPermission("jobs.world." + world.toLowerCase());
}
+ return player.hasPermission("jobs.world." + world.toLowerCase());
}
}
diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java
index 3bd61e42..25c3da3e 100644
--- a/com/gamingmesh/jobs/PlayerManager.java
+++ b/com/gamingmesh/jobs/PlayerManager.java
@@ -437,8 +437,7 @@ public class PlayerManager {
return;
// LevelUp event
- JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel, job
- .getName()), Jobs.gettitleManager().getTitleForLevel(prog.getLevel(), job.getName()), Jobs.getGCManager().SoundLevelupSound
+ JobsLevelUpEvent levelUpEvent = new JobsLevelUpEvent(jPlayer, job.getName(), prog.getLevel(), Jobs.gettitleManager().getTitleForLevel(oldLevel), Jobs.gettitleManager().getTitleForLevel(prog.getLevel()), Jobs.getGCManager().SoundLevelupSound
.toUpperCase(), Jobs.getGCManager().SoundLevelupVolume, Jobs.getGCManager().SoundLevelupPitch, Jobs.getGCManager().SoundTitleChangeSound.toUpperCase(),
Jobs.getGCManager().SoundTitleChangeVolume, Jobs.getGCManager().SoundTitleChangePitch);
Bukkit.getServer().getPluginManager().callEvent(levelUpEvent);
diff --git a/com/gamingmesh/jobs/Signs/SignUtil.java b/com/gamingmesh/jobs/Signs/SignUtil.java
index 0335f368..3fac2280 100644
--- a/com/gamingmesh/jobs/Signs/SignUtil.java
+++ b/com/gamingmesh/jobs/Signs/SignUtil.java
@@ -88,7 +88,7 @@ public class SignUtil {
try {
writer.save(f);
} catch (IOException e) {
- e.printStackTrace();
+ e.printStackTrace();
}
return;
}
@@ -131,7 +131,7 @@ public class SignUtil {
if (i >= PlayerList.size()) {
break;
}
- String PlayerName = ((TopList) PlayerList.get(i)).getPlayerName();
+ String PlayerName = PlayerList.get(i).getPlayerName();
if (PlayerName != null && PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
@@ -144,14 +144,14 @@ public class SignUtil {
String line = Jobs.getLanguage().getMessage("signs.List");
line = line.replace("[number]", String.valueOf(i + number + 1));
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.update();
- UpdateHead(sign, ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
+ UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
} else {
- String PlayerName = ((TopList) PlayerList.get(0)).getPlayerName();
+ String PlayerName = PlayerList.get(0).getPlayerName();
if (PlayerName.length() > 8) {
String PlayerNameStrip = PlayerName.split("(?<=\\G.{7})")[0];
PlayerName = PlayerNameStrip + "~";
@@ -159,32 +159,32 @@ public class SignUtil {
String line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".1");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
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);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".2");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
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);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".3");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
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);
line1 = Jobs.getLanguage().getMessage("signs.SpecialList." + one.GetNumber() + ".4");
line1 = line1.replace("[number]", String.valueOf(one.GetNumber() + number + 1));
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.update();
- UpdateHead(sign, ((TopList) PlayerList.get(0)).getPlayerName(), timelapse);
+ UpdateHead(sign, PlayerList.get(0).getPlayerName(), timelapse);
}
timelapse++;
diff --git a/com/gamingmesh/jobs/commands/JobsCommands.java b/com/gamingmesh/jobs/commands/JobsCommands.java
index 284991cd..927a0d00 100644
--- a/com/gamingmesh/jobs/commands/JobsCommands.java
+++ b/com/gamingmesh/jobs/commands/JobsCommands.java
@@ -161,7 +161,7 @@ public class JobsCommands implements CommandExecutor {
int amountToShow = 7;
int start = page * amountToShow - 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)
TotalPages++;
if (start >= commands.size()) {
@@ -235,12 +235,11 @@ public class JobsCommands implements CommandExecutor {
}
} catch (Exception e) {
} finally {
- try {
- if (jarFile != null) {
+ if (jarFile != null)
+ try {
jarFile.close();
+ } catch (Exception e) {
}
- } catch (Exception e) {
- }
}
return listOfCommands;
}
@@ -338,9 +337,8 @@ public class JobsCommands implements CommandExecutor {
public boolean hasJobPermission(CommandSender sender, Job job) {
if (!sender.hasPermission("jobs.use")) {
return false;
- } else {
- return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
}
+ return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
}
public void sendValidActions(CommandSender sender) {
@@ -505,7 +503,7 @@ public class JobsCommands implements CommandExecutor {
String message = Jobs.getLanguage().getMessage("command.stats.output",
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
"%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()));
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
}
@@ -545,7 +543,7 @@ public class JobsCommands implements CommandExecutor {
"%joblevel%", Integer.valueOf(splited[1]).toString(),
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
"%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;
}
}
diff --git a/com/gamingmesh/jobs/commands/list/convert.java b/com/gamingmesh/jobs/commands/list/convert.java
index b0687426..04b9360d 100644
--- a/com/gamingmesh/jobs/commands/list/convert.java
+++ b/com/gamingmesh/jobs/commands/list/convert.java
@@ -29,14 +29,12 @@ public class convert implements Cmd {
return true;
}
- Player pSender = (Player) sender;
-
List list = null;
List archivelist = null;
try {
- list = Jobs.getJobsDAO().convertDatabase(pSender, "jobs");
- archivelist = Jobs.getJobsDAO().convertDatabase(pSender, "archive");
+ list = Jobs.getJobsDAO().convertDatabase("jobs");
+ archivelist = Jobs.getJobsDAO().convertDatabase("archive");
} catch (SQLException e) {
e.printStackTrace();
sender.sendMessage(ChatColor.RED + "Can't read data from data base, please send error log to dev's.");
diff --git a/com/gamingmesh/jobs/commands/list/expboost.java b/com/gamingmesh/jobs/commands/list/expboost.java
index ab2d8607..eca74ef4 100644
--- a/com/gamingmesh/jobs/commands/list/expboost.java
+++ b/com/gamingmesh/jobs/commands/list/expboost.java
@@ -66,14 +66,13 @@ public class expboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate));
return true;
- } else {
- if (job == null) {
- 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()));
+ }
+ if (job == null) {
+ 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;
}
}
diff --git a/com/gamingmesh/jobs/commands/list/moneyboost.java b/com/gamingmesh/jobs/commands/list/moneyboost.java
index 4d161d40..2a85a799 100644
--- a/com/gamingmesh/jobs/commands/list/moneyboost.java
+++ b/com/gamingmesh/jobs/commands/list/moneyboost.java
@@ -67,14 +67,13 @@ public class moneyboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate));
return true;
- } else {
- if (job == null) {
- 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()));
+ }
+ if (job == null) {
+ 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;
}
}
diff --git a/com/gamingmesh/jobs/commands/list/pointboost.java b/com/gamingmesh/jobs/commands/list/pointboost.java
index 1da32e56..31f4abff 100644
--- a/com/gamingmesh/jobs/commands/list/pointboost.java
+++ b/com/gamingmesh/jobs/commands/list/pointboost.java
@@ -67,14 +67,13 @@ public class pointboost implements Cmd {
sender.sendMessage(ChatColor.GREEN + Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate));
return true;
- } else {
- if (job == null) {
- 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()));
+ }
+ if (job == null) {
+ 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;
}
}
diff --git a/com/gamingmesh/jobs/config/BossBarManager.java b/com/gamingmesh/jobs/config/BossBarManager.java
index e2855f57..f2370402 100644
--- a/com/gamingmesh/jobs/config/BossBarManager.java
+++ b/com/gamingmesh/jobs/config/BossBarManager.java
@@ -78,8 +78,8 @@ public class BossBarManager {
String message = Jobs.getLanguage().getMessage("command.stats.output",
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
- "%jobxp%", formatter.format(Math.round((Double) jobProg.getExperience() * 100.0) / 100.0),
- "%jobmaxxp%", (int) jobProg.getMaxExperience());
+ "%jobxp%", formatter.format(Math.round(jobProg.getExperience() * 100.0) / 100.0),
+ "%jobmaxxp%", jobProg.getMaxExperience());
if (bar == null) {
BarColor color = BarColor.BLUE;
diff --git a/com/gamingmesh/jobs/config/ExploreManager.java b/com/gamingmesh/jobs/config/ExploreManager.java
index b77890c8..26e0afad 100644
--- a/com/gamingmesh/jobs/config/ExploreManager.java
+++ b/com/gamingmesh/jobs/config/ExploreManager.java
@@ -61,26 +61,23 @@ public class ExploreManager {
eRegion.addChunk(eChunk);
worlds.put(worldName, eRegion);
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);
+ }
}
diff --git a/com/gamingmesh/jobs/config/LanguageManager.java b/com/gamingmesh/jobs/config/LanguageManager.java
index 0513c29b..2db3261e 100644
--- a/com/gamingmesh/jobs/config/LanguageManager.java
+++ b/com/gamingmesh/jobs/config/LanguageManager.java
@@ -7,8 +7,6 @@ import java.util.Arrays;
import java.util.List;
import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.java.JavaPlugin;
-
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.container.LocaleReader;
@@ -39,7 +37,7 @@ public class LanguageManager {
languages.add("tr");
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)
langFile.saveDefaultConfig();
}
diff --git a/com/gamingmesh/jobs/config/NameTranslatorManager.java b/com/gamingmesh/jobs/config/NameTranslatorManager.java
index deeeb0dd..26c44cff 100644
--- a/com/gamingmesh/jobs/config/NameTranslatorManager.java
+++ b/com/gamingmesh/jobs/config/NameTranslatorManager.java
@@ -9,8 +9,6 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.java.JavaPlugin;
-
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.container.JobInfo;
@@ -114,7 +112,7 @@ public class NameTranslatorManager {
}
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();
ConfigurationSection section = ItemFile.getConfig().getConfigurationSection("ItemList");
Set keys = section.getKeys(false);
@@ -178,7 +176,7 @@ public class NameTranslatorManager {
languages.add("fr");
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)
langFile.saveDefaultConfig();
}
diff --git a/com/gamingmesh/jobs/config/TitleManager.java b/com/gamingmesh/jobs/config/TitleManager.java
index 66fafe33..6d3ebb57 100644
--- a/com/gamingmesh/jobs/config/TitleManager.java
+++ b/com/gamingmesh/jobs/config/TitleManager.java
@@ -30,7 +30,7 @@ public class TitleManager {
* @return the correct title
* @return null if no title matches
*/
- public Title getTitleForLevel(int level, String jobName) {
+ public Title getTitleForLevel(int level) {
Title title = null;
for (Title t : titles) {
if (title == null) {
diff --git a/com/gamingmesh/jobs/config/YmlMaker.java b/com/gamingmesh/jobs/config/YmlMaker.java
index 48ec2d0f..058090d8 100644
--- a/com/gamingmesh/jobs/config/YmlMaker.java
+++ b/com/gamingmesh/jobs/config/YmlMaker.java
@@ -47,12 +47,6 @@ public class YmlMaker {
e1.printStackTrace();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
- } finally {
- try {
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
}
this.Configuration = YamlConfiguration.loadConfiguration(f);
@@ -63,11 +57,18 @@ public class YmlMaker {
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
this.Configuration.setDefaults(defConfig);
}
- try {
- defConfigStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (defConfigStream != null)
+ try {
+ defConfigStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (f != null)
+ try {
+ f.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
public FileConfiguration getConfig() {
diff --git a/com/gamingmesh/jobs/container/ExploreRegion.java b/com/gamingmesh/jobs/container/ExploreRegion.java
index 73b3b90a..dee31541 100644
--- a/com/gamingmesh/jobs/container/ExploreRegion.java
+++ b/com/gamingmesh/jobs/container/ExploreRegion.java
@@ -9,11 +9,6 @@ public class ExploreRegion {
int z;
List chunks = new ArrayList();
- public ExploreRegion(int x, int z, List chunks) {
- this.x = x;
- this.z = z;
- }
-
public ExploreRegion(int x, int z) {
this.x = x;
this.z = z;
diff --git a/com/gamingmesh/jobs/container/JobsPlayer.java b/com/gamingmesh/jobs/container/JobsPlayer.java
index 67e8f799..c6116f0e 100644
--- a/com/gamingmesh/jobs/container/JobsPlayer.java
+++ b/com/gamingmesh/jobs/container/JobsPlayer.java
@@ -233,9 +233,8 @@ public class JobsPlayer {
counter.setBoost(Boost);
counter.setTime(time);
return Boost;
- } else {
- return counter.getBoost();
}
+ return counter.getBoost();
}
Boost = getPlayerBoost(JobName, type);
counterList.add(new BoostCounter(type, Boost, time));
@@ -438,7 +437,7 @@ public class JobsPlayer {
// synchronized (saveLock) {
progression.clear();
reloadHonorific();
- Jobs.getPermissionHandler().recalculatePermissions(this);
+ Jobs.getPermissionHandler().recalculatePermissions(this);
return true;
// }
}
@@ -574,7 +573,7 @@ public class JobsPlayer {
builder.append(Jobs.getGCManager().getModifyChatSeparator());
gotTitle = false;
}
- Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel(), prog.getJob().getName());
+ Title title = Jobs.gettitleManager().getTitleForLevel(prog.getLevel());
if (numJobs == 1) {
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
diff --git a/com/gamingmesh/jobs/container/LocaleReader.java b/com/gamingmesh/jobs/container/LocaleReader.java
index 7e51f922..41408af6 100644
--- a/com/gamingmesh/jobs/container/LocaleReader.java
+++ b/com/gamingmesh/jobs/container/LocaleReader.java
@@ -41,13 +41,13 @@ public class LocaleReader {
copySetting(path);
return config.getIntegerList(path);
}
-
+
public List getStringList(String path, List list) {
config.addDefault(path, list);
copySetting(path);
return config.getStringList(path);
}
-
+
public String get(String path, String boo) {
config.addDefault(path, boo);
copySetting(path);
@@ -59,8 +59,7 @@ public class LocaleReader {
copySetting(path);
if (colorize)
return ChatColor.translateAlternateColorCodes('&', config.getString(path));
- else
- return config.getString(path);
+ return config.getString(path);
}
public Double get(String path, Double boo) {
diff --git a/com/gamingmesh/jobs/container/Log.java b/com/gamingmesh/jobs/container/Log.java
index 20851ee5..67f36192 100644
--- a/com/gamingmesh/jobs/container/Log.java
+++ b/com/gamingmesh/jobs/container/Log.java
@@ -67,21 +67,18 @@ public final class Log {
public int getCount(String item) {
if (this.amountMap.containsKey(item))
return this.amountMap.get(item).getCount();
- else
- return 0;
+ return 0;
}
public double getMoney(String item) {
if (this.amountMap.containsKey(item))
return this.amountMap.get(item).getMoney();
- else
- return 0;
+ return 0;
}
public double getExp(String item) {
if (this.amountMap.containsKey(item))
return this.amountMap.get(item).getExp();
- else
- return 0;
+ return 0;
}
}
\ No newline at end of file
diff --git a/com/gamingmesh/jobs/container/TopList.java b/com/gamingmesh/jobs/container/TopList.java
index e6e348d9..679a363c 100644
--- a/com/gamingmesh/jobs/container/TopList.java
+++ b/com/gamingmesh/jobs/container/TopList.java
@@ -19,8 +19,6 @@ public final class TopList {
if (info != null) {
if (info.getValue().getName() != null)
return info.getValue().getName();
- else
- return "Unknown";
}
return "Unknown";
}
diff --git a/com/gamingmesh/jobs/dao/JobsDAO.java b/com/gamingmesh/jobs/dao/JobsDAO.java
index fe0e886d..98641a94 100644
--- a/com/gamingmesh/jobs/dao/JobsDAO.java
+++ b/com/gamingmesh/jobs/dao/JobsDAO.java
@@ -152,8 +152,8 @@ public abstract class JobsDAO {
if (userData == null) {
recordNewPlayer(playerName, uuid);
return jobs;
- } else
- id = userData.getID();
+ }
+ id = userData.getID();
JobsConnection conn = getConnection();
if (conn == null)
@@ -337,7 +337,7 @@ public abstract class JobsDAO {
* @param job - job that the player wishes to join
* @throws SQLException
*/
- public List convertDatabase(Player Player, String table) throws SQLException {
+ public List convertDatabase(String table) throws SQLException {
JobsConnection conn = getConnection();
if (conn == null)
return null;
diff --git a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java
index a6701bb6..65c1cfe2 100644
--- a/com/gamingmesh/jobs/dao/JobsDAOMySQL.java
+++ b/com/gamingmesh/jobs/dao/JobsDAOMySQL.java
@@ -540,7 +540,8 @@ public class JobsDAOMySQL extends JobsDAO {
try {
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
rsLogTemp = prestLogTemp.executeQuery();
- while (next = rsLogTemp.next()) {
+ while (rsLogTemp.next()) {
+ next = true;
rsLogTemp.getInt("userid");
rsLogTemp.getLong("time");
rsLogTemp.getString("action");
diff --git a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java
index 843f9021..6f937590 100644
--- a/com/gamingmesh/jobs/dao/JobsDAOSQLite.java
+++ b/com/gamingmesh/jobs/dao/JobsDAOSQLite.java
@@ -545,7 +545,8 @@ public class JobsDAOSQLite extends JobsDAO {
try {
prestLogTemp = conn.prepareStatement("SELECT * FROM `" + getPrefix() + "log`;");
rsLogTemp = prestLogTemp.executeQuery();
- while (next = rsLogTemp.next()) {
+ while (rsLogTemp.next()) {
+ next = true;
rsLogTemp.getInt("userid");
rsLogTemp.getLong("time");
rsLogTemp.getString("action");
diff --git a/com/gamingmesh/jobs/economy/BufferedEconomy.java b/com/gamingmesh/jobs/economy/BufferedEconomy.java
index 0df4314e..4eee3157 100644
--- a/com/gamingmesh/jobs/economy/BufferedEconomy.java
+++ b/com/gamingmesh/jobs/economy/BufferedEconomy.java
@@ -165,7 +165,7 @@ public class BufferedEconomy {
if (payment.getOfflinePlayer() == null)
continue;
-
+
// JobsPayment event
JobsPaymentEvent JobsPaymentEvent = new JobsPaymentEvent(payment.getOfflinePlayer(), payment.getAmount(), payment.getPoints());
Bukkit.getServer().getPluginManager().callEvent(JobsPaymentEvent);
@@ -180,12 +180,11 @@ public class BufferedEconomy {
if (!hasMoney) {
Jobs.getActionBar().send(payment.getOfflinePlayer().getPlayer(), ChatColor.RED + Jobs.getLanguage().getMessage("economy.error.nomoney"));
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 {
if (Jobs.getGCManager().isEconomyAsync())
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, new BufferedPaymentTask(this, economy, payment), i);
diff --git a/com/gamingmesh/jobs/economy/PaymentData.java b/com/gamingmesh/jobs/economy/PaymentData.java
index b09e59a5..f8bbe72e 100644
--- a/com/gamingmesh/jobs/economy/PaymentData.java
+++ b/com/gamingmesh/jobs/economy/PaymentData.java
@@ -64,8 +64,8 @@ public class PaymentData {
return this.lastAnnouced;
}
- public boolean IsAnnounceTime(int time) {
- if (this.lastAnnouced + (time * 1000) > System.currentTimeMillis())
+ public boolean IsAnnounceTime(int t) {
+ if (this.lastAnnouced + (t * 1000) > System.currentTimeMillis())
return false;
SetAnnouncmentTime();
return true;
@@ -169,6 +169,7 @@ public class PaymentData {
return false;
}
+ @SuppressWarnings("cast")
public int GetLeftsec(int time) {
int lefttime1 = GetLeftTime(time);
int sec = 0;
@@ -185,6 +186,7 @@ public class PaymentData {
return sec;
}
+ @SuppressWarnings("cast")
public int GetLeftMin(int time) {
int lefttime1 = GetLeftTime(time);
int min = 0;
diff --git a/com/gamingmesh/jobs/i18n/Language.java b/com/gamingmesh/jobs/i18n/Language.java
index 98d534f4..3d04f56d 100644
--- a/com/gamingmesh/jobs/i18n/Language.java
+++ b/com/gamingmesh/jobs/i18n/Language.java
@@ -18,11 +18,8 @@
package com.gamingmesh.jobs.i18n;
-import java.util.Locale;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.plugin.java.JavaPlugin;
-
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.config.YmlMaker;
@@ -39,9 +36,9 @@ public class Language {
/**
* Reloads the config
*/
- public void reload(Locale locale) {
- customlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_" + Jobs.getGCManager().localeString + ".yml").getConfig();
- enlocale = new YmlMaker((JavaPlugin) plugin, "locale/messages_en.yml").getConfig();
+ public void reload() {
+ customlocale = new YmlMaker(plugin, "locale/messages_" + Jobs.getGCManager().localeString + ".yml").getConfig();
+ enlocale = new YmlMaker(plugin, "locale/messages_en.yml").getConfig();
if (customlocale == null)
customlocale = enlocale;
}
diff --git a/com/gamingmesh/jobs/listeners/JobsListener.java b/com/gamingmesh/jobs/listeners/JobsListener.java
index 94a66858..db68d988 100644
--- a/com/gamingmesh/jobs/listeners/JobsListener.java
+++ b/com/gamingmesh/jobs/listeners/JobsListener.java
@@ -88,11 +88,11 @@ public class JobsListener implements Listener {
return;
event.setCancelled(true);
-
+
Debug.D(event.getRawSlot());
int tsize = player.getOpenInventory().getTopInventory().getSize();
-
+
if (event.getRawSlot() < 0 || event.getRawSlot() >= tsize)
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)));
}
@@ -259,7 +259,7 @@ public class JobsListener implements Listener {
if (!(block.getState() instanceof Sign))
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
Sign sign = (Sign) block.getState();
String FirstLine = sign.getLine(0);
@@ -316,7 +316,7 @@ public class JobsListener implements Listener {
if (!signtype.equalsIgnoreCase("toplist") && !signtype.equalsIgnoreCase("gtoplist"))
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
if (!event.getPlayer().hasPermission("jobs.command.signs")) {
event.setCancelled(true);
@@ -531,7 +531,7 @@ public class JobsListener implements Listener {
//disabling plugin in world
if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld()))
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
ItemStack iih = player.getItemInHand();
@@ -607,11 +607,7 @@ public class JobsListener implements Listener {
if (oneItem.getenchants().get(oneE.getKey()) <= oneE.getValue()) {
foundEnc = true;
break;
- } else {
- continue;
}
- } else {
- continue;
}
}
diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java
index f79a0a32..f4006473 100644
--- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java
+++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java
@@ -61,7 +61,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.AnvilInventory;
-import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
@@ -112,12 +111,12 @@ public class JobsPaymentListener implements Listener {
if (!(event.getRightClicked() instanceof LivingEntity))
return;
- Entity cow = (LivingEntity) event.getRightClicked();
+ Entity cow = event.getRightClicked();
if (cow.getType() != EntityType.COW && cow.getType() != EntityType.MUSHROOM_COW)
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
if (player == null)
return;
@@ -183,7 +182,7 @@ public class JobsPaymentListener implements Listener {
if (!this.plugin.isEnabled())
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
if (player == null)
return;
@@ -228,7 +227,7 @@ public class JobsPaymentListener implements Listener {
if (jPlayer == null || !jPlayer.getPlayer().isOnline())
return;
- Player player = (Player) jPlayer.getPlayer();
+ Player player = jPlayer.getPlayer();
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return;
@@ -259,7 +258,7 @@ public class JobsPaymentListener implements Listener {
return;
if (Jobs.getGCManager().useBlockTimer)
- if (Jobs.getPistonProtectionListener().checkVegybreak(block, (Player) event.getPlayer()))
+ if (Jobs.getPistonProtectionListener().checkVegybreak(block, event.getPlayer()))
return;
// make sure plugin is enabled
@@ -407,9 +406,8 @@ public class JobsPaymentListener implements Listener {
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
// Entity that died must be living
- if (!(event.getEntity() instanceof LivingEntity))
- return;
- LivingEntity animal = (LivingEntity) event.getEntity();
+
+ LivingEntity animal = event.getEntity();
// mob spawner, no payment or experience
if (animal.hasMetadata(this.mobSpawnerMetadata)) {
@@ -461,7 +459,7 @@ public class JobsPaymentListener implements Listener {
break;
}
- if (!(event.getInventory() instanceof CraftingInventory) || !event.getSlotType().equals(SlotType.RESULT))
+ if (!event.getSlotType().equals(SlotType.RESULT))
return;
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
if (a == null || b == null)
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)
@@ -797,14 +794,11 @@ public class JobsPaymentListener implements Listener {
if (event.getEntity() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld()))
return;
// Entity that died must be living
- if (!(event.getEntity() instanceof LivingEntity))
- return;
- LivingEntity lVictim = (LivingEntity) event.getEntity();
+ LivingEntity lVictim = event.getEntity();
//extra check for Citizens 2 sentry kills
- if (lVictim.getKiller() instanceof Player)
- if (lVictim.getKiller().hasMetadata("NPC"))
- return;
+ if (lVictim.getKiller().hasMetadata("NPC"))
+ return;
if (Jobs.getGCManager().MythicMobsEnabled && Jobs.getMythicManager().MMAPI != null) {
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()))
return;
if (event.getSpawnReason() == SpawnReason.SPAWNER) {
- LivingEntity creature = (LivingEntity) event.getEntity();
+ LivingEntity creature = event.getEntity();
creature.setMetadata(this.mobSpawnerMetadata, new FixedMetadataValue(this.plugin, true));
}
}
@@ -926,11 +920,8 @@ public class JobsPaymentListener implements Listener {
if (!reason.toString().equalsIgnoreCase("BREEDING"))
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
if (!this.plugin.isEnabled())
@@ -1105,7 +1096,7 @@ public class JobsPaymentListener implements Listener {
if (!Jobs.getExplore().isExploreEnabled())
return;
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
if (!Jobs.getGCManager().payExploringWhenFlying())
return;
diff --git a/com/gamingmesh/jobs/listeners/McMMOlistener.java b/com/gamingmesh/jobs/listeners/McMMOlistener.java
index fdecde7c..3521130e 100644
--- a/com/gamingmesh/jobs/listeners/McMMOlistener.java
+++ b/com/gamingmesh/jobs/listeners/McMMOlistener.java
@@ -35,10 +35,7 @@ public class McMMOlistener implements Listener {
if (!plugin.isEnabled())
return;
- if (!(event.getPlayer() instanceof Player))
- return;
-
- Player player = (Player) event.getPlayer();
+ Player player = event.getPlayer();
ItemStack resultStack = event.getRepairedObject();
diff --git a/com/gamingmesh/jobs/resources/jfep/ConstantNode.java b/com/gamingmesh/jobs/resources/jfep/ConstantNode.java
index 6302e6a9..c4ba85d4 100644
--- a/com/gamingmesh/jobs/resources/jfep/ConstantNode.java
+++ b/com/gamingmesh/jobs/resources/jfep/ConstantNode.java
@@ -28,37 +28,37 @@ package com.gamingmesh.jobs.resources.jfep;
*/
public class ConstantNode implements ExpressionNode {
/** 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 */
- 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 */
protected double constant;
/** Name of the constant. Only if it's built-in */
protected String name;
/** An empty array with children */
protected ExpressionNode[] children = new ExpressionNode[0];
-
+
/**
* Builds a constant node
* @param constant constant to be put in node
*/
public ConstantNode(double constant) {
- this.constant = constant;
- name = null;
+ this.constant = constant;
+ name = null;
}
-
+
/**
* Builds a constant node, with an unique constant
* @param name name of the constant in the CONSTANTS array
*/
public ConstantNode(String name) {
- this.name = name;
- for (int i=0; iName: Parser
* Description:
@@ -47,13 +46,13 @@ public class Parser {
private static final char VAR = 'x'; // variable
private static final char OP_BRACKET = '('; // open bracket
private static final char CL_BRACKET = ')'; // closed bracket
-
+
private char[] input;
private boolean error;
private int inp_cur; // Current input position
private Element cc; // Current character
private ExpressionNode root; // Root of expression tree
-
+
private HashSet functions; // Used functions
private HashSet variables; // Used variables
@@ -62,9 +61,9 @@ public class Parser {
* @param str Input string to be analyzed
*/
public Parser(String str) {
- this(str, false);
+ this(str, false);
}
-
+
/**
* Class constructor
* @param str Input string to be analyzed
@@ -73,47 +72,45 @@ public class Parser {
* considered as zero.
*/
public Parser(String str, boolean error) {
- input = convertInput(str);
- root = null;
- inp_cur = 0;
- this.error = error;
- functions = new HashSet();
- variables = new HashSet();
+ input = convertInput(str);
+ root = null;
+ inp_cur = 0;
+ this.error = error;
+ functions = new HashSet();
+ variables = new HashSet();
}
-
+
/**
* Converts input string in a character array and removes unsupported characters
* @param str input string
* @return converted string, terminated by TERM character
*/
protected char[] convertInput(String str) {
- char[] input = str.toCharArray();
- char[] output = new char[input.length+1]; // One more space for terminator
- int pos = 0; // Position on output
- for (int i=0; i= '0' && c <= '9') || c == '.')
- return true;
- return false;
+ if ((c >= '0' && c <= '9') || c == '.')
+ return true;
+ return false;
}
/**
@@ -133,10 +130,10 @@ public class Parser {
* @return truth value
*/
private boolean isOperator(char c) {
- for (int i=0;i= 'A' && c <= 'Z') ||
- (c >= 'a' && c <= 'z') ||
- c == '_');
+ return ((c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z') ||
+ c == '_');
}
-
+
/**
* Returns if input character is a bracket
* @param c character
* @return truth value
*/
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
* @return truth value
*/
- private boolean isEndOfExpression (char c) {
- return c == TERM;
+ private boolean isEndOfExpression(char c) {
+ return c == TERM;
}
/**
@@ -173,84 +170,83 @@ public class Parser {
* @return Element
*/
private Element parse() {
- // Detects implicit multiplication
- if (detectImplicitMult())
- return new Element('*');
- // Matches operators, brackets and termination character
- if (isOperator(input[inp_cur]) || isBracket(input[inp_cur]) || isEndOfExpression(input[inp_cur]))
- return new Element(input[inp_cur++]);
-
- // Matches numbers
- if (isNumber(input[inp_cur])) {
- int tmp = inp_cur++;
- // Finds the end of number
- while (isNumber(input[inp_cur]))
- inp_cur++;
- // Eventual exponential
- if (Character.toLowerCase(input[inp_cur]) == 'e') {
- if (input[inp_cur + 1] == '-' || isNumber(input[inp_cur + 1]))
- inp_cur += 2;
- while (isNumber(input[inp_cur]))
- inp_cur++;
- }
- String s = new String(input, tmp, inp_cur - tmp);
- double d;
- try {
- d = Double.valueOf(s).doubleValue();
- }
- catch (NumberFormatException ex) {
- throw new ParseError("Invalid number: "+s, inp_cur);
- }
- return new Element(NUM, d);
- }
-
- // Matches text (functions or variables or built-in constants)
- if (isText(input[inp_cur])) {
- int tmp = inp_cur++;
- // Finds the end of text
- while (isText(input[inp_cur]) || isNumber(input[inp_cur]))
- inp_cur++;
- String s = new String(input, tmp, inp_cur - tmp);
-
- String lower = s.toLowerCase();
- // Now searches if this string is a function
- for (int i=0; i
* H -> T ('%' T)*
* @return Node
*/
private ExpressionNode H() {
- ExpressionNode current = T();
- while (cc.getToken() == '%') {
- cc = parse();
- current = new OperatorNode(current, T(), '%');
- }
- return current;
+ ExpressionNode current = T();
+ while (cc.getToken() == '%') {
+ cc = parse();
+ current = new OperatorNode(current, T(), '%');
+ }
+ return current;
}
-
+
/**
* Non-terminal T
* T -> F | '-' F
* @return Node
*/
private ExpressionNode T() {
- if (cc.getToken() == '-') {
- cc = parse();
- return new FunctionNode(F(), "-");
- }
- return F();
+ if (cc.getToken() == '-') {
+ cc = parse();
+ return new FunctionNode(F(), "-");
+ }
+ return F();
}
/**
@@ -329,13 +325,13 @@ public class Parser {
* @return Node
*/
private ExpressionNode F() {
- ExpressionNode left;
- left = U();
- if (cc.getToken() == '^') {
- cc = parse();
- return new OperatorNode(left, F(), '^');
- }
- return left;
+ ExpressionNode left;
+ left = U();
+ if (cc.getToken() == '^') {
+ cc = parse();
+ return new OperatorNode(left, F(), '^');
+ }
+ return left;
}
/**
@@ -344,81 +340,80 @@ public class Parser {
* @return Node
*/
private ExpressionNode U() {
- switch(cc.getToken()) {
- case NUM:
- double n = cc.number;
- int constPosition = cc.position; // Position if this is a built-in constant
- cc = parse();
- if (constPosition >= 0)
- return new ConstantNode(constPosition);
- else
- return new ConstantNode(n);
- case VAR :
- String name = cc.name;
- cc = parse();
- return new VariableNode(name, error);
- case OP_BRACKET :
- cc = parse();
- ExpressionNode tmp = S();
- if (cc.getToken() == CL_BRACKET) {
- cc = parse();
- return tmp;
- }
- throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
- case FUNC :
- int function = cc.position;
- cc = parse();
- if (cc.getToken() == OP_BRACKET)
- cc = parse();
- else
- throw new ParseError("Semantic Error, expected '"+OP_BRACKET+"'", inp_cur);
- ExpressionNode tmp2 = S();
- if (cc.getToken() == CL_BRACKET)
- cc = parse();
- else
- throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
- return new FunctionNode(tmp2, function);
- }
- throw new ParseError("Semantic Error, expected function or variable or constant or '('", inp_cur);
+ switch (cc.getToken()) {
+ case NUM:
+ double n = cc.number;
+ int constPosition = cc.position; // Position if this is a built-in constant
+ cc = parse();
+ if (constPosition >= 0)
+ return new ConstantNode(constPosition);
+ return new ConstantNode(n);
+ case VAR:
+ String name = cc.name;
+ cc = parse();
+ return new VariableNode(name, error);
+ case OP_BRACKET:
+ cc = parse();
+ ExpressionNode tmp = S();
+ if (cc.getToken() == CL_BRACKET) {
+ cc = parse();
+ return tmp;
+ }
+ throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
+ case FUNC:
+ int function = cc.position;
+ cc = parse();
+ if (cc.getToken() == OP_BRACKET)
+ cc = parse();
+ else
+ throw new ParseError("Semantic Error, expected '" + OP_BRACKET + "'", inp_cur);
+ ExpressionNode tmp2 = S();
+ if (cc.getToken() == CL_BRACKET)
+ cc = parse();
+ else
+ throw new ParseError("Semantic Error, expected '" + CL_BRACKET + "'", inp_cur);
+ return new FunctionNode(tmp2, function);
+ }
+ throw new ParseError("Semantic Error, expected function or variable or constant or '('", inp_cur);
}
-
+
/**
* Data structure used internally to return parsed elements.
*/
private class Element {
- private char token;
- public double number = Double.NaN;
- public int position = -1;
- public String name = null;
+ private char token;
+ public double number = Double.NaN;
+ public int position = -1;
+ public String name = null;
- public Element (char token) {
- this.token = token;
- }
+ public Element(char token) {
+ this.token = token;
+ }
- public Element (char token, double number) {
- this.token = token;
- this.number = number;
- }
-
- public Element (char token, String name) {
- this.token = token;
- this.name = name;
- }
+ public Element(char token, double number) {
+ this.token = token;
+ this.number = number;
+ }
- public Element (char token, int position) {
- this.token = token;
- this.position = position;
- }
-
- /**
- * Returns the token
- * @return char
- */
- public char getToken() {
- return token;
- }
+ public Element(char token, String name) {
+ this.token = token;
+ this.name = name;
+ }
+
+ public Element(char token, int position) {
+ this.token = token;
+ this.position = position;
+ }
+
+ /**
+ * Returns the token
+ * @return char
+ */
+ public char getToken() {
+ return token;
+ }
}
-
+
/**
* Sets the value for a given variable
* @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
*/
public void setVariable(String name, double value) throws ParseError {
- getTree();
- root.setVariable(name, value);
+ getTree();
+ root.setVariable(name, value);
}
-
+
/**
* Returns the value for evaluated expression
* @return value of expression
@@ -439,48 +434,48 @@ public class Parser {
* @see #Parser(String, boolean)
*/
public double getValue() throws ParseError, EvaluationException {
- getTree();
- return root.getValue();
+ getTree();
+ return root.getValue();
}
-
+
/**
* Returns 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
*/
public String getExpression() throws ParseError {
- getTree();
- return root.toString();
+ getTree();
+ return root.toString();
}
-
+
/**
* Returns a Set of all functions parsed in input string
* @return a set with all parsed functions
* @throws ParseError if parsed input string was malformed
*/
public HashSet getParsedFunctions() throws ParseError {
- getTree();
- return functions;
+ getTree();
+ return functions;
}
-
+
/**
* Returns a Set of all variables parsed in input string
* @return a set with all parsed variables
* @throws ParseError if parsed input string was malformed
*/
public HashSet getParsedVariables() throws ParseError {
- getTree();
- return variables;
+ getTree();
+ return variables;
}
-
+
/**
* Returns input string, without invalid characters
* @return input string without invalid characters
*/
public String getInputString() {
- StringBuffer output = new StringBuffer();
- for (int i=0; i