mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-31 21:37:57 +01:00
Cleanup and some fixes
This commit is contained in:
parent
324b4dc0b4
commit
fbb0bfee90
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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++;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -29,14 +29,12 @@ public class convert implements Cmd {
|
||||
return true;
|
||||
}
|
||||
|
||||
Player pSender = (Player) sender;
|
||||
|
||||
List<Convert> list = null;
|
||||
List<Convert> 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.");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<String> 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();
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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() {
|
||||
|
@ -9,11 +9,6 @@ public class ExploreRegion {
|
||||
int z;
|
||||
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) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
|
@ -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)) {
|
||||
|
@ -41,13 +41,13 @@ public class LocaleReader {
|
||||
copySetting(path);
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getStringList(String path, List<String> 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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
|
@ -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<Convert> convertDatabase(Player Player, String table) throws SQLException {
|
||||
public List<Convert> convertDatabase(String table) throws SQLException {
|
||||
JobsConnection conn = getConnection();
|
||||
if (conn == null)
|
||||
return null;
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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; i<CONSTANTS.length;i++)
|
||||
if (CONSTANTS[i].equals(name)) {
|
||||
constant = VALUES[i];
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("Unrecognized constant");
|
||||
this.name = name;
|
||||
for (int i = 0; i < CONSTANTS.length; i++)
|
||||
if (CONSTANTS[i].equals(name)) {
|
||||
constant = VALUES[i];
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("Unrecognized constant");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,77 +67,75 @@ public class ConstantNode implements ExpressionNode {
|
||||
* @see ConstantNode#CONSTANTS
|
||||
*/
|
||||
public ConstantNode(int pos) {
|
||||
this.name = CONSTANTS[pos];
|
||||
this.constant = VALUES[pos];
|
||||
this.name = CONSTANTS[pos];
|
||||
this.constant = VALUES[pos];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||
*/
|
||||
public int count() {
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||
*/
|
||||
public int getDepth() {
|
||||
return 1; // This is a leaf node
|
||||
return 1; // This is a leaf node
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||
*/
|
||||
public String getSubtype() {
|
||||
// Checks if this is integer or double
|
||||
if (Math.floor(constant) == constant)
|
||||
return Long.toString(Math.round(constant));
|
||||
else
|
||||
return Double.toString(constant);
|
||||
// Checks if this is integer or double
|
||||
if (Math.floor(constant) == constant)
|
||||
return Long.toString(Math.round(constant));
|
||||
return Double.toString(constant);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return ExpressionNode.CONSTANT_NODE;
|
||||
return ExpressionNode.CONSTANT_NODE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||
*/
|
||||
public double getValue() {
|
||||
return constant;
|
||||
return constant;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||
*/
|
||||
public void setVariable(String name, double value) {
|
||||
// Nothing to be done here...
|
||||
// Nothing to be done here...
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||
*/
|
||||
public ExpressionNode[] getChildrenNodes() {
|
||||
return children;
|
||||
return children;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
public Object clone() {
|
||||
return new ConstantNode(constant);
|
||||
return new ConstantNode(constant);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
if (name == null)
|
||||
return getSubtype();
|
||||
else
|
||||
return name;
|
||||
if (name == null)
|
||||
return getSubtype();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -28,16 +28,16 @@ package com.gamingmesh.jobs.resources.jfep;
|
||||
*/
|
||||
public class FunctionNode implements ExpressionNode {
|
||||
/** List of supported functions */
|
||||
public static final String[] FUNCTIONS = new String[] {"-", "sin", "cos", "tan",
|
||||
"asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh",
|
||||
"ln", "log", "abs", "rand", "sqrt", "erf", "erfc", "gamma", "exp", "cot", "log2"};
|
||||
public static final String[] FUNCTIONS = new String[] { "-", "sin", "cos", "tan",
|
||||
"asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh",
|
||||
"ln", "log", "abs", "rand", "sqrt", "erf", "erfc", "gamma", "exp", "cot", "log2" };
|
||||
/** Child node */
|
||||
protected ExpressionNode child;
|
||||
/** Function of this node */
|
||||
protected int function;
|
||||
/** An array with children */
|
||||
protected ExpressionNode[] children;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a function node.
|
||||
* @param child child node of this node
|
||||
@ -45,11 +45,11 @@ public class FunctionNode implements ExpressionNode {
|
||||
* @see FunctionNode#FUNCTIONS
|
||||
*/
|
||||
public FunctionNode(ExpressionNode child, int function) {
|
||||
this.child = child;
|
||||
this.function = function;
|
||||
children = new ExpressionNode[] {child};
|
||||
this.child = child;
|
||||
this.function = function;
|
||||
children = new ExpressionNode[] { child };
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a function node.
|
||||
* @param child child node of this node
|
||||
@ -57,118 +57,138 @@ public class FunctionNode implements ExpressionNode {
|
||||
* @throws IllegalArgumentException if function is unsupported
|
||||
*/
|
||||
public FunctionNode(ExpressionNode child, String function) throws IllegalArgumentException {
|
||||
this.child = child;
|
||||
this.function = -1;
|
||||
children = new ExpressionNode[] {child};
|
||||
for (int i=0; i<FUNCTIONS.length;i++) {
|
||||
if (FUNCTIONS[i].equals(function)) {
|
||||
this.function = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.function < 0)
|
||||
throw new IllegalArgumentException("Unrecognized function");
|
||||
this.child = child;
|
||||
this.function = -1;
|
||||
children = new ExpressionNode[] { child };
|
||||
for (int i = 0; i < FUNCTIONS.length; i++) {
|
||||
if (FUNCTIONS[i].equals(function)) {
|
||||
this.function = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.function < 0)
|
||||
throw new IllegalArgumentException("Unrecognized function");
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||
*/
|
||||
public int count() {
|
||||
return 1 + child.count();
|
||||
return 1 + child.count();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||
*/
|
||||
public int getDepth() {
|
||||
return 1 + child.getDepth();
|
||||
return 1 + child.getDepth();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||
*/
|
||||
public String getSubtype() {
|
||||
return FUNCTIONS[function];
|
||||
return FUNCTIONS[function];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return ExpressionNode.FUNCTION_NODE;
|
||||
return ExpressionNode.FUNCTION_NODE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||
*/
|
||||
public double getValue() {
|
||||
switch (function) {
|
||||
case 0: return - child.getValue();
|
||||
case 1: return Math.sin(child.getValue());
|
||||
case 2: return Math.cos(child.getValue());
|
||||
case 3: return Math.tan(child.getValue());
|
||||
case 4: return Math.asin(child.getValue());
|
||||
case 5: return Math.acos(child.getValue());
|
||||
case 6: return Math.atan(child.getValue());
|
||||
case 7: return Sfun.sinh(child.getValue());
|
||||
case 8: return Sfun.cosh(child.getValue());
|
||||
case 9: return Sfun.tanh(child.getValue());
|
||||
case 10: return Sfun.asinh(child.getValue());
|
||||
case 11: return Sfun.acosh(child.getValue());
|
||||
case 12: return Sfun.atanh(child.getValue());
|
||||
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;
|
||||
switch (function) {
|
||||
case 0:
|
||||
return -child.getValue();
|
||||
case 1:
|
||||
return Math.sin(child.getValue());
|
||||
case 2:
|
||||
return Math.cos(child.getValue());
|
||||
case 3:
|
||||
return Math.tan(child.getValue());
|
||||
case 4:
|
||||
return Math.asin(child.getValue());
|
||||
case 5:
|
||||
return Math.acos(child.getValue());
|
||||
case 6:
|
||||
return Math.atan(child.getValue());
|
||||
case 7:
|
||||
return Sfun.sinh(child.getValue());
|
||||
case 8:
|
||||
return Sfun.cosh(child.getValue());
|
||||
case 9:
|
||||
return Sfun.tanh(child.getValue());
|
||||
case 10:
|
||||
return Sfun.asinh(child.getValue());
|
||||
case 11:
|
||||
return Sfun.acosh(child.getValue());
|
||||
case 12:
|
||||
return Sfun.atanh(child.getValue());
|
||||
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)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||
*/
|
||||
public void setVariable(String name, double value) {
|
||||
child.setVariable(name, value);
|
||||
child.setVariable(name, value);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||
*/
|
||||
public ExpressionNode[] getChildrenNodes() {
|
||||
return children;
|
||||
return children;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
public Object clone() {
|
||||
ExpressionNode n_child = (ExpressionNode)child.clone();
|
||||
return new FunctionNode(n_child, function);
|
||||
ExpressionNode n_child = (ExpressionNode) child.clone();
|
||||
return new FunctionNode(n_child, function);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
// Special case for negation function
|
||||
if (function != 0)
|
||||
return this.getSubtype() + "(" + child.toString() + ")";
|
||||
else {
|
||||
if (child.getType() == CONSTANT_NODE || child.getType() == VARIABLE_NODE ||
|
||||
(child.getType() == FUNCTION_NODE && !child.getSubtype().equals(FUNCTIONS[0])))
|
||||
return FUNCTIONS[0] + child.toString();
|
||||
else
|
||||
return FUNCTIONS[0] + "(" + child.toString() + ")";
|
||||
}
|
||||
// Special case for negation function
|
||||
if (function != 0)
|
||||
return this.getSubtype() + "(" + child.toString() + ")";
|
||||
if (child.getType() == CONSTANT_NODE || child.getType() == VARIABLE_NODE ||
|
||||
(child.getType() == FUNCTION_NODE && !child.getSubtype().equals(FUNCTIONS[0])))
|
||||
return FUNCTIONS[0] + child.toString();
|
||||
return FUNCTIONS[0] + "(" + child.toString() + ")";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ package com.gamingmesh.jobs.resources.jfep;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
/**
|
||||
* <p><b>Name:</b> Parser</p>
|
||||
* <p><b>Description:</b>
|
||||
@ -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<String> functions; // Used functions
|
||||
private HashSet<String> 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<String>();
|
||||
variables = new HashSet<String>();
|
||||
input = convertInput(str);
|
||||
root = null;
|
||||
inp_cur = 0;
|
||||
this.error = error;
|
||||
functions = new HashSet<String>();
|
||||
variables = new HashSet<String>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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<input.length; i++) {
|
||||
char c = input[i];
|
||||
if (isNumber(c) || isOperator(c) || isText(c) || isBracket(c))
|
||||
output[pos++] = c;
|
||||
}
|
||||
output[pos++] = TERM;
|
||||
return output;
|
||||
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 < input.length; i++) {
|
||||
char c = input[i];
|
||||
if (isNumber(c) || isOperator(c) || isText(c) || isBracket(c))
|
||||
output[pos++] = c;
|
||||
}
|
||||
output[pos++] = TERM;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the tree of the function generated by the parser
|
||||
* @return Node root node of parsed tree
|
||||
* @throws ParseError if parsed input string was malformed
|
||||
*/
|
||||
public ExpressionNode getTree() throws ParseError {
|
||||
if (root == null) { // Function need parsing
|
||||
cc = parse();
|
||||
root = S();
|
||||
if (!isEndOfExpression(cc.getToken()))
|
||||
throw new ParseError("Expecting operator or end of input", inp_cur);
|
||||
return root;
|
||||
}
|
||||
else
|
||||
return root; // Parsing was already performed before
|
||||
if (root == null) { // Function need parsing
|
||||
cc = parse();
|
||||
root = S();
|
||||
if (!isEndOfExpression(cc.getToken()))
|
||||
throw new ParseError("Expecting operator or end of input", inp_cur);
|
||||
}
|
||||
return root; // Parsing was already performed before
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,9 +119,9 @@ public class Parser {
|
||||
* @return truth value
|
||||
*/
|
||||
private boolean isNumber(char c) {
|
||||
if ((c >= '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<OperatorNode.OPERATIONS.length;i++)
|
||||
if (c == OperatorNode.OPERATIONS[i])
|
||||
return true;
|
||||
return false;
|
||||
for (int i = 0; i < OperatorNode.OPERATIONS.length; i++)
|
||||
if (c == OperatorNode.OPERATIONS[i])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,18 +142,18 @@ public class Parser {
|
||||
* @return truth value
|
||||
*/
|
||||
private boolean isText(char c) {
|
||||
return ((c >= '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<FunctionNode.FUNCTIONS.length;i++) {
|
||||
if (lower.equals(FunctionNode.FUNCTIONS[i])) {
|
||||
functions.add(FunctionNode.FUNCTIONS[i]);
|
||||
return new Element(FUNC, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Now searches if this string is a built-in constant
|
||||
for (int i=0; i<ConstantNode.CONSTANTS.length;i++) {
|
||||
if (lower.equals(ConstantNode.CONSTANTS[i]))
|
||||
return new Element(NUM, i);
|
||||
}
|
||||
|
||||
// String was not a function, so treat it as a variable
|
||||
variables.add(s);
|
||||
return new Element(VAR, s);
|
||||
}
|
||||
//At this point everything not recognized is an error
|
||||
throw new ParseError("Unrecognized identifier", inp_cur);
|
||||
// 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 < FunctionNode.FUNCTIONS.length; i++) {
|
||||
if (lower.equals(FunctionNode.FUNCTIONS[i])) {
|
||||
functions.add(FunctionNode.FUNCTIONS[i]);
|
||||
return new Element(FUNC, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Now searches if this string is a built-in constant
|
||||
for (int i = 0; i < ConstantNode.CONSTANTS.length; i++) {
|
||||
if (lower.equals(ConstantNode.CONSTANTS[i]))
|
||||
return new Element(NUM, i);
|
||||
}
|
||||
|
||||
// String was not a function, so treat it as a variable
|
||||
variables.add(s);
|
||||
return new Element(VAR, s);
|
||||
}
|
||||
//At this point everything not recognized is an error
|
||||
throw new ParseError("Unrecognized identifier", inp_cur);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method to detect implicit multiplication
|
||||
* @return true only if inplicit multiplication is detected
|
||||
*/
|
||||
private boolean detectImplicitMult() {
|
||||
if (cc != null && cc.getToken() == NUM) {
|
||||
cc = null; // Otherwise we will loop forever
|
||||
// Stores old pointer to restore it back
|
||||
int old_input = inp_cur;
|
||||
Element next = parse();
|
||||
// Restores old pointer back
|
||||
inp_cur = old_input;
|
||||
if (next.getToken() == VAR || next.getToken() == FUNC)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (cc != null && cc.getToken() == NUM) {
|
||||
cc = null; // Otherwise we will loop forever
|
||||
// Stores old pointer to restore it back
|
||||
int old_input = inp_cur;
|
||||
Element next = parse();
|
||||
// Restores old pointer back
|
||||
inp_cur = old_input;
|
||||
if (next.getToken() == VAR || next.getToken() == FUNC)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,13 +255,13 @@ public class Parser {
|
||||
* @return Node
|
||||
*/
|
||||
private ExpressionNode S() {
|
||||
ExpressionNode current = E();
|
||||
while (cc.getToken() == '+' || cc.getToken() == '-') {
|
||||
char operator = cc.getToken();
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, E(), operator);
|
||||
}
|
||||
return current;
|
||||
ExpressionNode current = E();
|
||||
while (cc.getToken() == '+' || cc.getToken() == '-') {
|
||||
char operator = cc.getToken();
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, E(), operator);
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -274,12 +270,12 @@ public class Parser {
|
||||
* @return Node
|
||||
*/
|
||||
private ExpressionNode E() {
|
||||
ExpressionNode current = G();
|
||||
while (cc.getToken() == '*') {
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, G(), '*');
|
||||
}
|
||||
return current;
|
||||
ExpressionNode current = G();
|
||||
while (cc.getToken() == '*') {
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, G(), '*');
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -288,39 +284,39 @@ public class Parser {
|
||||
* @return Node
|
||||
*/
|
||||
private ExpressionNode G() {
|
||||
ExpressionNode current = H();
|
||||
while (cc.getToken() == '/') {
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, H(), '/');
|
||||
}
|
||||
return current;
|
||||
ExpressionNode current = H();
|
||||
while (cc.getToken() == '/') {
|
||||
cc = parse();
|
||||
current = new OperatorNode(current, H(), '/');
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Non-terminal H<br>
|
||||
* H -> T ('%' T)*<br>
|
||||
* @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<br>
|
||||
* T -> F | '-' F<br>
|
||||
* @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<String> 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<String> 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<input.length && input[i] != TERM;i++)
|
||||
output.append(input[i]);
|
||||
return output.toString();
|
||||
StringBuffer output = new StringBuffer();
|
||||
for (int i = 0; i < input.length && input[i] != TERM; i++)
|
||||
output.append(input[i]);
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class VariableNode implements ExpressionNode {
|
||||
protected String name;
|
||||
/** An empty array with children */
|
||||
protected ExpressionNode[] children = new ExpressionNode[0];
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new variable node with given name.
|
||||
* @param name name of the variable
|
||||
@ -43,79 +43,78 @@ public class VariableNode implements ExpressionNode {
|
||||
* is not initialized. Otherwise 0.0 is returned.
|
||||
*/
|
||||
public VariableNode(String name, boolean error) {
|
||||
this.name = name;
|
||||
value = 0.0;
|
||||
this.error = error;
|
||||
this.name = name;
|
||||
value = 0.0;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#count()
|
||||
*/
|
||||
public int count() {
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getDepth()
|
||||
*/
|
||||
public int getDepth() {
|
||||
return 1; // This is a leaf node
|
||||
return 1; // This is a leaf node
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getSubtype()
|
||||
*/
|
||||
public String getSubtype() {
|
||||
return name;
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getType()
|
||||
*/
|
||||
public int getType() {
|
||||
return ExpressionNode.VARIABLE_NODE;
|
||||
return ExpressionNode.VARIABLE_NODE;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#getValue()
|
||||
*/
|
||||
public double getValue() {
|
||||
if (!error)
|
||||
return value;
|
||||
else
|
||||
throw new EvaluationException("Variable '" + name + "' was not initialized.");
|
||||
if (!error)
|
||||
return value;
|
||||
throw new EvaluationException("Variable '" + name + "' was not initialized.");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see jmt.engine.math.parser.ExpressionNode#setVariable(java.lang.String, double)
|
||||
*/
|
||||
public void setVariable(String name, double value) {
|
||||
if (this.name.equals(name)) {
|
||||
this.value = value;
|
||||
error = false;
|
||||
}
|
||||
if (this.name.equals(name)) {
|
||||
this.value = value;
|
||||
error = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mbertoli.jfep.ExpressionNode#getChildrenNodes()
|
||||
*/
|
||||
public ExpressionNode[] getChildrenNodes() {
|
||||
return children;
|
||||
return children;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
public Object clone() {
|
||||
VariableNode node = new VariableNode(name, error);
|
||||
node.value = value;
|
||||
return node;
|
||||
VariableNode node = new VariableNode(name, error);
|
||||
node.value = value;
|
||||
return node;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return getSubtype();
|
||||
return getSubtype();
|
||||
}
|
||||
}
|
||||
|
@ -162,11 +162,9 @@ public class ActionBar {
|
||||
}
|
||||
|
||||
private String getChatSerializerClasspath() {
|
||||
if (cleanVersion < 1820) {
|
||||
if (cleanVersion < 1820)
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user